1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.common;
17
18 import java.util.List;
19
20 import org.apache.log4j.Logger;
21 import org.joda.time.DateTime;
22 import org.joda.time.LocalDate;
23 import org.kuali.kpme.core.calendar.entry.CalendarEntry;
24 import org.kuali.kpme.core.service.HrServiceLocator;
25 import org.quartz.JobExecutionContext;
26 import org.quartz.JobExecutionException;
27 import org.quartz.SchedulerException;
28 import org.springframework.scheduling.quartz.QuartzJobBean;
29
30 public class CalendarEntrySchedulerJob extends QuartzJobBean {
31
32 private static final Logger LOG = Logger.getLogger(CalendarEntrySchedulerJob.class);
33 private static int CALENDAR_ENTRIES_POLLING_WINDOW;
34
35 private static BatchJobService batchJobService;
36
37 @Override
38 protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
39 DateTime asOfDate = new LocalDate().toDateTimeAtStartOfDay();
40 List<CalendarEntry> calendarEntries = HrServiceLocator.getCalendarEntryService().getCurrentCalendarEntriesNeedsScheduled(getCalendarEntriesPollingWindow(), asOfDate);
41
42 try {
43 for (CalendarEntry calendarEntry : calendarEntries) {
44 if (calendarEntry.getEndPeriodDateTime() != null) {
45 getBatchJobService().scheduleEndReportingPeriodJobs(calendarEntry);
46 }
47
48 if (calendarEntry.getBatchInitiateDateTime() != null) {
49 getBatchJobService().scheduleInitiateJobs(calendarEntry);
50 }
51
52 if (calendarEntry.getBatchEndPayPeriodDateTime() != null) {
53 getBatchJobService().scheduleEndPayPeriodJobs(calendarEntry);
54 }
55
56 if (calendarEntry.getBatchEmployeeApprovalDateTime() != null) {
57 getBatchJobService().scheduleEmployeeApprovalJobs(calendarEntry);
58 }
59
60
61
62
63
64 if (calendarEntry.getBatchSupervisorApprovalDateTime() != null) {
65 getBatchJobService().scheduleSupervisorApprovalJobs(calendarEntry);
66 }
67
68 if (calendarEntry.getBatchPayrollApprovalDateTime() != null) {
69 getBatchJobService().schedulePayrollApprovalJobs(calendarEntry);
70 }
71 }
72 } catch (SchedulerException se) {
73 LOG.error("Exception thrown during job scheduling", se);
74
75 }
76 }
77
78 public int getCalendarEntriesPollingWindow() {
79 return CALENDAR_ENTRIES_POLLING_WINDOW;
80 }
81
82 public void setCalendarEntriesPollingWindow(int calendarEntriesPollingWindow) {
83 CALENDAR_ENTRIES_POLLING_WINDOW = calendarEntriesPollingWindow;
84 }
85
86 public static BatchJobService getBatchJobService() {
87 return CalendarEntrySchedulerJob.batchJobService;
88 }
89
90 public void setBatchJobService(BatchJobService batchJobService) {
91 CalendarEntrySchedulerJob.batchJobService = batchJobService;
92 }
93
94 }