usiing the new notificationcontroller and mailproperties for mail
Change-Id: I22b79ea63b449c3179c94dff754043cc15e4ab1e
This commit is contained in:
parent
8a74bac9a6
commit
c236d6addf
@ -5,6 +5,7 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
@ -17,7 +18,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import se.su.dsv.scipro.conference.pages.SupervisorConferencePage;
|
||||
import se.su.dsv.scipro.data.controllers.NotificationController;
|
||||
import se.su.dsv.scipro.data.controllers.NotificationMessage;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.FileDescriptionDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.FileDescription;
|
||||
@ -27,6 +30,7 @@ import se.su.dsv.scipro.data.dataobjects.ProjectClassSettings;
|
||||
import se.su.dsv.scipro.data.dataobjects.Student;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.enums.NotificationEventType;
|
||||
import se.su.dsv.scipro.data.enums.NotificationPriority;
|
||||
import se.su.dsv.scipro.exceptions.UpdatedSincePageLoadException;
|
||||
import se.su.dsv.scipro.peer.data.dao.interfaces.PeerRequestDao;
|
||||
import se.su.dsv.scipro.peer.data.dao.interfaces.PeerReviewDao;
|
||||
@ -34,309 +38,381 @@ import se.su.dsv.scipro.peer.data.dataobjects.PeerRequest;
|
||||
import se.su.dsv.scipro.peer.data.dataobjects.PeerReview;
|
||||
import se.su.dsv.scipro.peer.enums.RequestStatus;
|
||||
import se.su.dsv.scipro.peer.pages.ProjectPeerReviewPage;
|
||||
import se.su.dsv.scipro.peer.pages.ProjectPeerStatsPage;
|
||||
import se.su.dsv.scipro.peer.pages.SupervisorPeerReviewPage;
|
||||
import se.su.dsv.scipro.repository.FileRepository;
|
||||
import se.su.dsv.scipro.repository.util.FileStorageException;
|
||||
import se.su.dsv.scipro.security.auth.roles.Roles;
|
||||
import se.su.dsv.scipro.util.PropsUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Martin Peters - mpeters@dsv.su.se
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Controller("peerPortalController")
|
||||
public class PeerPortalControllerImpl implements PeerPortalController {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
public static final String PEER_FILE_PATH = "peer/";
|
||||
public static final String PEER_REQUEST_PATH = PEER_FILE_PATH + "request/";
|
||||
public static final String PEER_REVIEW_PATH = PEER_FILE_PATH + "review/";
|
||||
|
||||
|
||||
@Autowired
|
||||
private PeerRequestDao peerRequestDao;
|
||||
|
||||
|
||||
@Autowired
|
||||
private PeerReviewDao peerReviewDao;
|
||||
|
||||
|
||||
@Autowired
|
||||
private FileRepository fileRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
private FileDescriptionDao fileDescriptionDao;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ProjectDao projectDao;
|
||||
|
||||
|
||||
@Autowired
|
||||
private NotificationController notificationController;
|
||||
|
||||
|
||||
/**
|
||||
* Gets a list of PeerRequests and if it is reviewable by the combination of Student + Project. All input parameters are optional
|
||||
* @param projectClass may be null.
|
||||
* @param project may be null.
|
||||
* @param student may be null.
|
||||
* Gets a list of PeerRequests and if it is reviewable by the combination of
|
||||
* Student + Project. All input parameters are optional
|
||||
*
|
||||
* @param projectClass
|
||||
* may be null.
|
||||
* @param project
|
||||
* may be null.
|
||||
* @param student
|
||||
* may be null.
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public List<Tuple> getPeerRequests(final ProjectClass projectClass, final Project project, final Student student){
|
||||
//TODO how to handle project with ProjectClass = UNKNOWN?
|
||||
|
||||
List<PeerRequest> temp = peerRequestDao.getPeerRequests(RequestStatus.WAITING, projectClass );
|
||||
public List<Tuple> getPeerRequests(final ProjectClass projectClass, final Project project,
|
||||
final Student student) {
|
||||
// TODO how to handle project with ProjectClass = UNKNOWN?
|
||||
|
||||
List<PeerRequest> temp = peerRequestDao
|
||||
.getPeerRequests(RequestStatus.WAITING, projectClass);
|
||||
List<Tuple> result = new ArrayList<Tuple>(temp.size());
|
||||
|
||||
|
||||
ProjectClassSettings settings = projectClass.getProjectClassSettings();
|
||||
Date priorityDate = new DateTime().minusDays( settings.getNumDaysBeforePeerRequestPriority() ).toDate();
|
||||
Date priorityDate = new DateTime()
|
||||
.minusDays(settings.getNumDaysBeforePeerRequestPriority()).toDate();
|
||||
boolean foundExpiredPriorityDate = false;
|
||||
|
||||
for(PeerRequest peerRequest : temp){
|
||||
|
||||
for (PeerRequest peerRequest : temp) {
|
||||
Student requestingStudent = peerRequest.getRequester();
|
||||
Project requestingProject = peerRequest.getProject();
|
||||
int given = peerReviewDao.countReviewsGiven(requestingStudent, requestingProject);
|
||||
int received = peerReviewDao.countReviewsReceived(requestingStudent, requestingProject);
|
||||
|
||||
Pair<Boolean,NotReviewableReason> pair = this.isReviewableTo(peerRequest, student, project); //Checks basics reviewable rules
|
||||
Pair<Boolean, NotReviewableReason> pair = this.isReviewableTo(peerRequest, student,
|
||||
project); // Checks basics reviewable rules
|
||||
NotReviewableReason notReviewableReason = pair.tail;
|
||||
boolean isReviewable = pair.head;
|
||||
if( isReviewable ){ //If it's reviewable at all do following:
|
||||
if (isReviewable) { // If it's reviewable at all do following:
|
||||
/*
|
||||
* Reviews come sorted, oldest first. If it's older than priorityDate, flag that we've found
|
||||
* one that's "expired".
|
||||
* Reviews come sorted, oldest first. If it's older than
|
||||
* priorityDate, flag that we've found one that's "expired".
|
||||
*/
|
||||
boolean reviewOlderThanPriorityDate = priorityDate.compareTo( peerRequest.getDateCreated() ) > 0;
|
||||
if( reviewOlderThanPriorityDate ) {
|
||||
boolean reviewOlderThanPriorityDate = priorityDate.compareTo(peerRequest
|
||||
.getDateCreated()) > 0;
|
||||
if (reviewOlderThanPriorityDate) {
|
||||
foundExpiredPriorityDate = true;
|
||||
}
|
||||
if( foundExpiredPriorityDate ){
|
||||
if (foundExpiredPriorityDate) {
|
||||
/*
|
||||
* If we've found something expired, make only those also older than expiration-date
|
||||
* reviewable.
|
||||
* If we've found something expired, make only those also
|
||||
* older than expiration-date reviewable.
|
||||
*/
|
||||
isReviewable = reviewOlderThanPriorityDate;
|
||||
notReviewableReason = NotReviewableReason.OTHERS_PAST_PRIORITY_AGE;
|
||||
}
|
||||
if( (given - received > 0) ) {
|
||||
if ((given - received > 0)) {
|
||||
/*
|
||||
* ..except those with good ratio, they are reviewable any time
|
||||
* ..except those with good ratio, they are reviewable any
|
||||
* time
|
||||
*/
|
||||
isReviewable = true;
|
||||
notReviewableReason = null;
|
||||
}
|
||||
}
|
||||
result.add(new Tuple(peerRequest, isReviewable , given, received, notReviewableReason));
|
||||
result.add(new Tuple(peerRequest, isReviewable, given, received, notReviewableReason));
|
||||
}
|
||||
|
||||
|
||||
Collections.sort(result, new Comparator<Tuple>() {
|
||||
@Override
|
||||
public int compare(Tuple t1, Tuple t2) {
|
||||
if( t1.isReviewable == t2.isReviewable ) //If equal, present oldest first
|
||||
return t1.peerRequest.getDateCreated().compareTo( t2.peerRequest.getDateCreated() );
|
||||
if( t1.isReviewable ) //If unequal, present those that are reviewable first
|
||||
if (t1.isReviewable == t2.isReviewable) // If equal, present
|
||||
// oldest first
|
||||
return t1.peerRequest.getDateCreated().compareTo(
|
||||
t2.peerRequest.getDateCreated());
|
||||
if (t1.isReviewable) // If unequal, present those that are
|
||||
// reviewable first
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for "basic reviewability". Does not take into account the more complex rule that looks at all other available requests
|
||||
* Checks for "basic reviewability". Does not take into account the more
|
||||
* complex rule that looks at all other available requests
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public Pair<Boolean,NotReviewableReason> isReviewableTo(final PeerRequest peerRequest, final Student student, final Project activeProject){
|
||||
if( student == null || activeProject == null || peerRequest == null )
|
||||
return new Pair<Boolean,NotReviewableReason>(false,NotReviewableReason.YOU_ARE_SUPERVISOR);
|
||||
public Pair<Boolean, NotReviewableReason> isReviewableTo(final PeerRequest peerRequest,
|
||||
final Student student, final Project activeProject) {
|
||||
if (student == null || activeProject == null || peerRequest == null)
|
||||
return new Pair<Boolean, NotReviewableReason>(false,
|
||||
NotReviewableReason.YOU_ARE_SUPERVISOR);
|
||||
|
||||
final Project requestingProject = peerRequest.getProject();
|
||||
final ProjectClass requestingProjectClass = requestingProject.getProjectClass();
|
||||
final ProjectClass reviewingProjectClass = activeProject.getProjectClass();
|
||||
/*
|
||||
* You may not review something in a different ProjectClass, current page design prevents this from
|
||||
* happening but it's a cheap safeguard.
|
||||
* You may not review something in a different ProjectClass, current
|
||||
* page design prevents this from happening but it's a cheap safeguard.
|
||||
*/
|
||||
if( !requestingProjectClass.equals(reviewingProjectClass) )
|
||||
return new Pair<Boolean,NotReviewableReason>(false,NotReviewableReason.DIFFERENT_PROJECTCLASS);
|
||||
//You may not review something you're part of!
|
||||
if( projectDao.isPartOf(student.getUser(), requestingProject ) )
|
||||
return new Pair<Boolean,NotReviewableReason>(false,NotReviewableReason.PART_OF_PROJECT);
|
||||
|
||||
if (!requestingProjectClass.equals(reviewingProjectClass))
|
||||
return new Pair<Boolean, NotReviewableReason>(false,
|
||||
NotReviewableReason.DIFFERENT_PROJECTCLASS);
|
||||
// You may not review something you're part of!
|
||||
if (projectDao.isPartOf(student.getUser(), requestingProject))
|
||||
return new Pair<Boolean, NotReviewableReason>(false,
|
||||
NotReviewableReason.PART_OF_PROJECT);
|
||||
|
||||
/*
|
||||
* This last section handles reviews performed previously by the student on the same
|
||||
* requesting project and makes sure you cannot accept reviews within a certain time frame
|
||||
* after having done one.
|
||||
* This last section handles reviews performed previously by the student
|
||||
* on the same requesting project and makes sure you cannot accept
|
||||
* reviews within a certain time frame after having done one.
|
||||
*
|
||||
* Using getLastModified is potentially "risky" since this might get updated for reasons other
|
||||
* than one's that should prohibit re-reviewing, thus preventing reviews that should be allowed.
|
||||
* Using getLastModified is potentially "risky" since this might get
|
||||
* updated for reasons other than one's that should prohibit
|
||||
* re-reviewing, thus preventing reviews that should be allowed.
|
||||
*/
|
||||
ProjectClassSettings settings = requestingProjectClass.getProjectClassSettings();
|
||||
int daysBetweenReviewsOnSameProject = settings.getNumDaysBetweenPeerReviewsOnSameProject();
|
||||
|
||||
DateTime earliestPermissibleDateSinceReview = new DateTime();
|
||||
earliestPermissibleDateSinceReview = earliestPermissibleDateSinceReview.minusDays(daysBetweenReviewsOnSameProject);
|
||||
|
||||
List<PeerReview> performedReviews = peerReviewDao.findPeerReviewsByStudentAndProject(student, activeProject);
|
||||
for(PeerReview pr : performedReviews){
|
||||
earliestPermissibleDateSinceReview = earliestPermissibleDateSinceReview
|
||||
.minusDays(daysBetweenReviewsOnSameProject);
|
||||
|
||||
List<PeerReview> performedReviews = peerReviewDao.findPeerReviewsByStudentAndProject(
|
||||
student, activeProject);
|
||||
for (PeerReview pr : performedReviews) {
|
||||
boolean sameProject = pr.getPeerRequest().getProject().equals(requestingProject);
|
||||
if( sameProject ){
|
||||
boolean reviewPerformedBeforeLimit = pr.getLastModified().compareTo( earliestPermissibleDateSinceReview.toDate() ) > 0;
|
||||
if( reviewPerformedBeforeLimit ){
|
||||
return new Pair<Boolean,NotReviewableReason>(false,NotReviewableReason.RECENTLY_REVIEWED);
|
||||
if (sameProject) {
|
||||
boolean reviewPerformedBeforeLimit = pr.getLastModified().compareTo(
|
||||
earliestPermissibleDateSinceReview.toDate()) > 0;
|
||||
if (reviewPerformedBeforeLimit) {
|
||||
return new Pair<Boolean, NotReviewableReason>(false,
|
||||
NotReviewableReason.RECENTLY_REVIEWED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Pair<Boolean,NotReviewableReason>(true,null);
|
||||
}
|
||||
|
||||
return new Pair<Boolean, NotReviewableReason>(true, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PeerReview acceptReview(PeerRequest request, Student student, Project project) throws Exception, UpdatedSincePageLoadException {
|
||||
|
||||
public PeerReview acceptReview(PeerRequest request, Student student, Project project)
|
||||
throws Exception, UpdatedSincePageLoadException {
|
||||
|
||||
request = peerRequestDao.reLoad(request);
|
||||
|
||||
if(request.getStatus() != RequestStatus.WAITING){
|
||||
|
||||
if (request.getStatus() != RequestStatus.WAITING) {
|
||||
throw new UpdatedSincePageLoadException("Peer request taken since page loaded");
|
||||
}
|
||||
|
||||
|
||||
PeerReview review = new PeerReview();
|
||||
|
||||
|
||||
try {
|
||||
//Save the review
|
||||
// Save the review
|
||||
review.setPeerRequest(request);
|
||||
review.setProject(project);
|
||||
review.setReviewer(student);
|
||||
review = peerReviewDao.save(review);
|
||||
|
||||
//Update request status
|
||||
|
||||
// Update request status
|
||||
request.setStatus(RequestStatus.TAKEN);
|
||||
request = peerRequestDao.save(request);
|
||||
|
||||
//Notify the requester
|
||||
|
||||
// Notify the requester
|
||||
notifyAcceptOfReview(request, student, project);
|
||||
|
||||
|
||||
return review;
|
||||
} catch (Exception e){
|
||||
Logger.getRootLogger().log(Level.ERROR, "Error while accepting peer request: " + e.getMessage());
|
||||
if(review.getId() != null){
|
||||
//Something must have gone wrong while updating request status
|
||||
} catch (Exception e) {
|
||||
Logger.getRootLogger().log(Level.ERROR,
|
||||
"Error while accepting peer request: " + e.getMessage());
|
||||
if (review.getId() != null) {
|
||||
// Something must have gone wrong while updating request status
|
||||
review = peerReviewDao.reLoad(review);
|
||||
peerReviewDao.delete(review);
|
||||
}
|
||||
if(request.getStatus() != RequestStatus.WAITING){
|
||||
//reset status
|
||||
if (request.getStatus() != RequestStatus.WAITING) {
|
||||
// reset status
|
||||
request.setStatus(RequestStatus.WAITING);
|
||||
peerRequestDao.save(request);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO Rewrite using template engine of some sort
|
||||
*
|
||||
* @param request
|
||||
* @param student
|
||||
* @param project
|
||||
*/
|
||||
protected void notifyAcceptOfReview(PeerRequest request, Student student, Project project){
|
||||
try{
|
||||
protected void notifyAcceptOfReview(PeerRequest request, Student student, Project project) {
|
||||
try {
|
||||
Properties props = null;
|
||||
|
||||
props = PropsUtils.load("notification.properties");
|
||||
|
||||
String mailSubject = props.getProperty("acceptPeerReviewSubject");
|
||||
String requestAccepted = props.getProperty("requestAccepted");
|
||||
String heShe = props.getProperty("heShe");
|
||||
String complete = props.getProperty("complete");
|
||||
|
||||
User requestingUser = request.getRequester().getUser();
|
||||
|
||||
String messageBody = requestAccepted
|
||||
+ student.getUser().toString()
|
||||
+ heShe
|
||||
+ project.getProjectClass().getProjectClassSettings()
|
||||
.getNumDaysToSubmitPeerReview() + complete;
|
||||
|
||||
String subject = "Your request for peer-review has been accepted";
|
||||
|
||||
String messageBody = "Hello "+requestingUser.getFirstName()+",\n\n"+
|
||||
"Your request was accepted by "+student.getUser().toString()+", he/she now has "+
|
||||
project.getProjectClass().getProjectClassSettings().getNumDaysToSubmitPeerReview()+" days to complete a review."+
|
||||
"\n\nThis is an auto-generated message from SciPro";
|
||||
|
||||
notificationController.processSystemNotification(requestingUser, Roles.STUDENT, subject, messageBody, NotificationEventType.PEER_REVIEW_ACCEPTED);
|
||||
}
|
||||
catch( Exception e ){
|
||||
String webNotificationMessage = requestAccepted + student.getUser().toString();
|
||||
|
||||
NotificationMessage notificationMessage = new NotificationMessage(webNotificationMessage,
|
||||
mailSubject, messageBody);
|
||||
|
||||
PageParameters pp = new PageParameters();
|
||||
|
||||
String peerStatsUrl = RequestUtils.toAbsolutePath(RequestCycle.get()
|
||||
.urlFor(ProjectPeerStatsPage.class, pp).toString());
|
||||
|
||||
notificationController.processNotification(requestingUser, notificationMessage,
|
||||
peerStatsUrl, NotificationPriority.MEDIUM);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Rewrite
|
||||
*
|
||||
* @param review
|
||||
*/
|
||||
public void notifyCompletionOfReview(PeerReview review) {
|
||||
try{
|
||||
try {
|
||||
|
||||
Properties props = null;
|
||||
props = PropsUtils.load("notification.properties");
|
||||
String mailSubject = props.getProperty("completedReviewSubject");
|
||||
String requestReviewed = props.getProperty("requestReviewed");
|
||||
String supervisorMessageBody = props.getProperty("supervisorMessageBody");
|
||||
String supervisorMessageBody2 = props.getProperty("supervisorMessageBody2");
|
||||
String supervisorMessageBody3 = props.getProperty("supervisorMessageBody3");
|
||||
String commaWithLinebreak = props.getProperty("commaWithLinebreak");
|
||||
String inProject = props.getProperty("inProject");
|
||||
String hasPerformed = props.getProperty("hasPerformed");
|
||||
PeerRequest peerRequest = review.getPeerRequest();
|
||||
User requestingUser = peerRequest.getRequester().getUser();
|
||||
|
||||
String messageFooter = "\n\nThis is an auto-generated message from SciPro";
|
||||
|
||||
|
||||
PageParameters pp = new PageParameters();
|
||||
pp.add(PeerReview.PP_PEER_REVIEW_ID, review.getId().toString());
|
||||
String projectReviewUrl = RequestUtils.toAbsolutePath(
|
||||
RequestCycle.get().urlFor(ProjectPeerReviewPage.class, pp).toString());
|
||||
String supervisorReviewUrl = RequestUtils.toAbsolutePath(
|
||||
RequestCycle.get().urlFor(SupervisorPeerReviewPage.class, pp).toString());
|
||||
|
||||
String reviewUrl = RequestUtils.toAbsolutePath(RequestCycle.get()
|
||||
.urlFor(ProjectPeerReviewPage.class, pp).toString());
|
||||
String supervisorReviewUrl = RequestUtils.toAbsolutePath(RequestCycle.get()
|
||||
.urlFor(SupervisorPeerReviewPage.class, pp).toString());
|
||||
|
||||
//Message for student when his/her review request is completed.
|
||||
String messageBody = requestReviewed;
|
||||
|
||||
NotificationMessage notificationMessage = new NotificationMessage(messageBody,
|
||||
mailSubject, messageBody);
|
||||
|
||||
notificationController.processNotification(requestingUser, notificationMessage,
|
||||
reviewUrl, NotificationPriority.MEDIUM);
|
||||
|
||||
|
||||
String subject = "A peer review has been completed!";
|
||||
|
||||
String messageBody = "Hello "+requestingUser.getFirstName()+",\n\n"+
|
||||
"Your request has now been reviewed and is available here:\n"+
|
||||
projectReviewUrl+
|
||||
messageFooter;
|
||||
|
||||
notificationController.processSystemNotification(requestingUser, Roles.STUDENT, subject, messageBody, NotificationEventType.PEER_REVIEW_RATED);
|
||||
|
||||
messageBody = "Hello "+peerRequest.getProject().getHeadSupervisor().getUser().getFirstName()+",\n\n"+
|
||||
"You're getting this message because you are supervisor of \""+peerRequest.getProject().getTitle()+"\"."+
|
||||
"\nA peer review on this project has been completed and is available for you to read here:\n"+
|
||||
supervisorReviewUrl+
|
||||
messageFooter;
|
||||
//Message for supervisor of the project with a completed review.
|
||||
messageBody =
|
||||
supervisorMessageBody
|
||||
+ peerRequest.getProject().getTitle()
|
||||
+ supervisorMessageBody2;
|
||||
User requestSupervisor = peerRequest.getProject().getHeadSupervisor().getUser();
|
||||
notificationController.processSystemNotification(requestSupervisor, Roles.EMPLOYEE, subject, messageBody, NotificationEventType.PEER_REVIEW_RATED);
|
||||
|
||||
NotificationMessage notificationMessageSupervisorOfProject = new NotificationMessage(messageBody,
|
||||
mailSubject, messageBody);
|
||||
|
||||
messageBody = "Hello "+review.getProject().getHeadSupervisor().getUser().getFirstName()+",\n\n"+
|
||||
"You receive this message because you are supervisor of \""+review.getProject().getTitle()+"\".\n"+
|
||||
review.getReviewer().getUser().toString()+" has performed a peer review on someone elses work which is available for you to read here:\n"+
|
||||
supervisorReviewUrl+
|
||||
messageFooter;
|
||||
notificationController.processNotification(requestSupervisor,
|
||||
notificationMessageSupervisorOfProject, supervisorReviewUrl, NotificationPriority.MEDIUM);
|
||||
|
||||
//Message for supervisor of the reviewer that have made a review for another project.
|
||||
|
||||
String webNotificationMessage = review.getReviewer().getUser().toString() + inProject + review.getProject().getTitle() + hasPerformed;
|
||||
|
||||
messageBody = supervisorMessageBody
|
||||
+ review.getProject().getTitle()
|
||||
+ commaWithLinebreak + review.getReviewer().getUser().toString()
|
||||
+ supervisorMessageBody3;
|
||||
|
||||
User reviewSupervisor = review.getProject().getHeadSupervisor().getUser();
|
||||
notificationController.processSystemNotification(reviewSupervisor, Roles.EMPLOYEE, subject, messageBody, NotificationEventType.PEER_REVIEW_RATED);
|
||||
NotificationMessage notificationMessageSupervisorOfReviewer = new NotificationMessage(webNotificationMessage,
|
||||
mailSubject, messageBody);
|
||||
|
||||
}
|
||||
catch( Exception e ){
|
||||
notificationController.processNotification(reviewSupervisor, notificationMessageSupervisorOfReviewer, supervisorReviewUrl, NotificationPriority.MEDIUM);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Rewrite
|
||||
*
|
||||
* @param review
|
||||
*/
|
||||
public void notifyOfReviewRating(PeerReview review) {
|
||||
try{
|
||||
try {
|
||||
Properties props = null;
|
||||
props = PropsUtils.load("notification.properties");
|
||||
String mailSubject = props.getProperty("reviewRatedSubject");
|
||||
String reviewRatedBody = props.getProperty("reviewRatedBody");
|
||||
User reviewingUser = review.getReviewer().getUser();
|
||||
|
||||
String messageFooter = "\n\nThis is an auto-generated message from SciPro";
|
||||
|
||||
|
||||
PageParameters pp = new PageParameters();
|
||||
pp.add(PeerReview.PP_PEER_REVIEW_ID, review.getId().toString());
|
||||
String projectReviewUrl = RequestUtils.toAbsolutePath(
|
||||
RequestCycle.get().urlFor(ProjectPeerReviewPage.class, pp).toString());
|
||||
String projectReviewUrl = RequestUtils.toAbsolutePath(RequestCycle.get()
|
||||
.urlFor(ProjectPeerReviewPage.class, pp).toString());
|
||||
|
||||
|
||||
String messageBody = reviewRatedBody;
|
||||
|
||||
String subject = "You've received a rating for a review you've done!";
|
||||
|
||||
String messageBody = "Hello "+reviewingUser.getFirstName()+",\n\n"+
|
||||
"Your review has been rated." +
|
||||
" If you want to see the rating or add a comment to the review, the review is available here:\n"+
|
||||
projectReviewUrl+
|
||||
messageFooter;
|
||||
|
||||
notificationController.processSystemNotification(reviewingUser, Roles.STUDENT, subject, messageBody, NotificationEventType.PEER_REVIEW_GRADED);
|
||||
|
||||
}
|
||||
catch( Exception e ){
|
||||
NotificationMessage notificationMessage = new NotificationMessage(messageBody,
|
||||
mailSubject, messageBody);
|
||||
|
||||
notificationController.processNotification(reviewingUser, notificationMessage,
|
||||
projectReviewUrl, NotificationPriority.MEDIUM);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store file to a pre-populated PeerRequest
|
||||
*
|
||||
@ -346,92 +422,100 @@ public class PeerPortalControllerImpl implements PeerPortalController {
|
||||
* @throws Exception
|
||||
*/
|
||||
@Transactional
|
||||
public PeerRequest storePeerRequest(final FileUpload upload, PeerRequest request)
|
||||
throws Exception {
|
||||
public PeerRequest storePeerRequest(final FileUpload upload, PeerRequest request)
|
||||
throws Exception {
|
||||
String path = null;
|
||||
try {
|
||||
request = peerRequestDao.save(request);
|
||||
|
||||
if(request.getId() == null){
|
||||
|
||||
if (request.getId() == null) {
|
||||
throw new NullPointerException("Peer request id is null after save");
|
||||
}
|
||||
|
||||
|
||||
path = getAbsolutePeerRequestPath(request);
|
||||
|
||||
|
||||
fileRepository.storeFile(upload, path);
|
||||
List<FileDescription> fdesc = fileRepository.searchFiles(path);
|
||||
if(fdesc.size() == 0){
|
||||
if (fdesc.size() == 0) {
|
||||
throw new FileStorageException(path, null);
|
||||
} else {
|
||||
FileDescription fd = fileDescriptionDao.save(fdesc.get(0));
|
||||
request.setFile(fd);
|
||||
return peerRequestDao.save(request);
|
||||
}
|
||||
} catch (Exception e){
|
||||
Logger.getRootLogger().log(Level.ERROR, "Error while storing Peer Request: " + e.getMessage());
|
||||
if(request.getId() != null){
|
||||
} catch (Exception e) {
|
||||
Logger.getRootLogger().log(Level.ERROR,
|
||||
"Error while storing Peer Request: " + e.getMessage());
|
||||
if (request.getId() != null) {
|
||||
peerRequestDao.delete(request);
|
||||
}
|
||||
if(path != null){
|
||||
if (path != null) {
|
||||
fileRepository.delete(path);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stores a file to the repository and populates the file-attribute on the PeerReview object.
|
||||
* Note: the file description is not persisted, saving the peer review object will cascade
|
||||
* to the file description.
|
||||
* Stores a file to the repository and populates the file-attribute on the
|
||||
* PeerReview object. Note: the file description is not persisted, saving
|
||||
* the peer review object will cascade to the file description.
|
||||
*
|
||||
* @param upload the fileupload to store
|
||||
* @param review the review to store the fileupload to
|
||||
* @param upload
|
||||
* the fileupload to store
|
||||
* @param review
|
||||
* the review to store the fileupload to
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
@Transactional
|
||||
public boolean storePeerReviewFileUpload(final FileUpload upload, PeerReview review) {
|
||||
|
||||
//Return true there is no file upload
|
||||
if ( upload == null ){
|
||||
|
||||
// Return true there is no file upload
|
||||
if (upload == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
String path = null;
|
||||
try {
|
||||
path = getAbsolutePeerReviewPath(review);
|
||||
fileRepository.storeFile(upload, path);
|
||||
List<FileDescription> fdesc = fileRepository.searchFiles(path);
|
||||
if(fdesc.size() == 0){
|
||||
if (fdesc.size() == 0) {
|
||||
throw new FileStorageException(path, null);
|
||||
}
|
||||
review.setFile(fdesc.get(0));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Logger.getRootLogger().log(Level.ERROR, "Error while storing file for peer review: " + e.getMessage());
|
||||
if(review.getFile() != null){
|
||||
//Clean up the repository
|
||||
Logger.getRootLogger().log(Level.ERROR,
|
||||
"Error while storing file for peer review: " + e.getMessage());
|
||||
if (review.getFile() != null) {
|
||||
// Clean up the repository
|
||||
fileRepository.delete(path);
|
||||
//reset the file attribute
|
||||
// reset the file attribute
|
||||
review.setFile(null);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
private String getAbsolutePeerRequestPath(final PeerRequest request){
|
||||
if(request.getId() == null){
|
||||
throw new NullPointerException("Trying to get file repository path for PeerRequest with id null");
|
||||
private String getAbsolutePeerRequestPath(final PeerRequest request) {
|
||||
if (request.getId() == null) {
|
||||
throw new NullPointerException(
|
||||
"Trying to get file repository path for PeerRequest with id null");
|
||||
}
|
||||
return fileRepository.getProjectRootPath(request.getProject().getId()) + PEER_REQUEST_PATH + request.getId();
|
||||
return fileRepository.getProjectRootPath(request.getProject().getId()) + PEER_REQUEST_PATH
|
||||
+ request.getId();
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
private String getAbsolutePeerReviewPath(final PeerReview review){
|
||||
if(review.getId() == null){
|
||||
throw new NullPointerException("Trying to get file repository path for PeerReview with id null");
|
||||
private String getAbsolutePeerReviewPath(final PeerReview review) {
|
||||
if (review.getId() == null) {
|
||||
throw new NullPointerException(
|
||||
"Trying to get file repository path for PeerReview with id null");
|
||||
}
|
||||
return fileRepository.getProjectRootPath(review.getProject().getId()) + PEER_REVIEW_PATH + review.getId();
|
||||
return fileRepository.getProjectRootPath(review.getProject().getId()) + PEER_REVIEW_PATH
|
||||
+ review.getId();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user