1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.time.batch;
17
18 import org.joda.time.DateTime;
19 import org.kuali.kpme.core.api.calendar.entry.CalendarEntry;
20 import org.kuali.kpme.core.batch.BatchJob;
21 import org.kuali.kpme.core.service.HrServiceLocator;
22 import org.kuali.kpme.tklm.common.BatchJobService;
23 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
24 import org.quartz.JobDataMap;
25 import org.quartz.JobExecutionContext;
26 import org.quartz.JobExecutionException;
27
28 import java.text.DateFormat;
29
30 public class EndReportingPeriodJob extends BatchJob {
31
32 public void execute(JobExecutionContext context) throws JobExecutionException {
33 JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
34 TkServiceLocator.getBatchJobService().updateStatus(context.getJobDetail(), BatchJobService.RUNNING_JOB_STATUS_CODE);
35 String hrCalendarEntryId = jobDataMap.getString("hrCalendarEntryId");
36 String principalId = jobDataMap.getString("principalId");
37
38 CalendarEntry calendarEntry = HrServiceLocator.getCalendarEntryService().getCalendarEntry(hrCalendarEntryId);
39 DateTime endPeriodDateTime = calendarEntry.getEndPeriodFullDateTime();
40
41 String subject = "End of Reporting Period Reminder";
42 StringBuilder message = new StringBuilder();
43 message.append("Please submit your Leave Calendar for the period ending on ");
44 message.append(DateFormat.getDateInstance(DateFormat.LONG).format(endPeriodDateTime.minusDays(1).toDate()));
45 message.append(", so it can be reviewed and approved by your supervisor.");
46
47 HrServiceLocator.getKPMENotificationService().sendNotification(subject, message.toString(), principalId);
48 TkServiceLocator.getBatchJobService().updateStatus(context.getJobDetail(), BatchJobService.SUCCEEDED_JOB_STATUS_CODE);
49 }
50
51 }