hooked up comment reminder worker to workdays

This commit is contained in:
fred-fri 2013-05-02 11:10:22 +09:00
parent 35d774b409
commit 3d1f05d0ac

@ -2,6 +2,8 @@ package se.su.dsv.scipro.workerthreads;
import org.apache.log4j.Logger;
import org.apache.wicket.PageParameters;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.joda.time.DateMidnight;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
@ -11,6 +13,7 @@ import se.su.dsv.scipro.data.dataobjects.FinalSeminar;
import se.su.dsv.scipro.data.dataobjects.GeneralSystemSettings;
import se.su.dsv.scipro.data.dataobjects.Project;
import se.su.dsv.scipro.data.dataobjects.ProjectClassSettings;
import se.su.dsv.scipro.data.enums.DateStyle;
import se.su.dsv.scipro.notifications.dataobject.NotificationSource;
import se.su.dsv.scipro.notifications.dataobject.PeerEvent;
import se.su.dsv.scipro.notifications.dataobject.SeminarEvent;
@ -20,9 +23,12 @@ import se.su.dsv.scipro.peer.enums.RequestStatus;
import se.su.dsv.scipro.project.pages.ProjectDetailsPage;
import se.su.dsv.scipro.project.pages.ProjectOppositionPage;
import se.su.dsv.scipro.reusable.SciProUtilities;
import se.su.dsv.scipro.reusable.WorkDaysModel;
import se.su.dsv.scipro.springdata.services.DaysService;
import se.su.dsv.scipro.springdata.services.FinalSeminarService;
import se.su.dsv.scipro.springdata.services.GeneralSystemSettingsService;
import se.su.dsv.scipro.supervisor.pages.SupervisorProjectDetailsPage;
import se.su.dsv.scipro.util.DateFormatter;
import se.su.dsv.scipro.util.NotificationUtils;
import javax.annotation.Resource;
@ -40,58 +46,58 @@ public class ThesisCommentReminderWorker extends AbstractWorker {
FinalSeminarService finalSeminarService;
@Autowired
NotificationController notificationController;
@Autowired
DaysService daysService;
@Override
protected void doWork() {
this.beginTransaction();
@Override
protected void doWork() {
this.beginTransaction();
GeneralSystemSettings systemSettings = systemSettingsService.getGeneralSystemSettingsInstance();
try {
Iterator<FinalSeminar> it = finalSeminarService.findByStartDateAfter(new Date()).iterator();
try {
Iterator<FinalSeminar> it = finalSeminarService.findByStartDateAfter(new Date()).iterator();
while(it.hasNext()){
while (it.hasNext()) {
FinalSeminar fs = it.next();
FinalSeminar fs = it.next();
/**
* Take the startdate
*/
Date startDate = fs.getStartDate();
/**
* Take the comment deadline
*/
final int daysAhead = systemSettingsService.getFinalSeminarExaminerReviewUploadDaysAhead();
Date commentDeadline = daysService.workDaysAhead(fs.getStartDate(), daysAhead);
/**
* Make a cal from it and subtract as many days as the setting
*/
Calendar cal = Calendar.getInstance();
cal.setTime(startDate);
cal.add(Calendar.DATE, -systemSettings.getThesisCommentNoDaysAheadReminder());
Date minusDate = cal.getTime();
/**
* Take the remind date
*/
final int remindDaysAhead = systemSettings.getThesisCommentNoDaysAheadReminder();
Date remindDate = daysService.workDaysAhead(commentDeadline, remindDaysAhead);
/**
* Make a date for 00:00 today
*/
Date todayStart = new Date();
todayStart = SciProUtilities.setTimeOfDayTo0000(todayStart);
/**
* Make a date for 00:00 today
*/
Date todayStart = new Date();
todayStart = SciProUtilities.setTimeOfDayTo0000(todayStart);
/**
* Make a date for 23:59 today
*/
Date todayEnd = new Date();
todayEnd = SciProUtilities.setTimeOfDayTo2359(todayEnd);
/**
* Make a date for 23:59 today
*/
Date todayEnd = new Date();
todayEnd = SciProUtilities.setTimeOfDayTo2359(todayEnd);
/**
* If the subtracted date is today, then remind
*/
if (minusDate.after(todayStart) && minusDate.before(todayEnd) && systemSettings.isThesisReviewsMandatory()){
notificationController.notifySeminar(fs, SeminarEvent.Event.THESIS_COMMENT_REMIND, new NotificationSource());
}
/**
* If the remind date is today, then remind
*/
if (remindDate.after(todayStart) && remindDate.before(todayEnd) && systemSettings.isThesisReviewsMandatory()) {
notificationController.notifySeminar(fs, SeminarEvent.Event.THESIS_COMMENT_REMIND, new NotificationSource());
}
commitTransaction();
} catch (Exception e){
this.rollbackTransaction();
this.setSuccessfulWorker(false);
throw new RuntimeException(e);
}
commitTransaction();
} catch (Exception e) {
this.rollbackTransaction();
this.setSuccessfulWorker(false);
throw new RuntimeException(e);
}
}
}
}