1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.batch;
17
18 import java.util.Date;
19 import java.util.HashSet;
20 import java.util.List;
21 import java.util.Set;
22
23 import org.apache.commons.lang.SystemUtils;
24 import org.apache.commons.lang.time.DateUtils;
25 import org.kuali.hr.core.notification.service.KPMENotificationService;
26 import org.kuali.hr.lm.workflow.LeaveCalendarDocumentHeader;
27 import org.kuali.hr.lm.workflow.service.LeaveCalendarDocumentHeaderService;
28 import org.kuali.hr.time.calendar.CalendarEntries;
29 import org.kuali.hr.time.calendar.service.CalendarEntriesService;
30 import org.kuali.hr.time.principal.PrincipalHRAttributes;
31 import org.kuali.hr.time.principal.service.PrincipalHRAttributesService;
32 import org.kuali.hr.time.util.TKUtils;
33 import org.quartz.Job;
34 import org.quartz.JobExecutionContext;
35 import org.quartz.JobExecutionException;
36
37 public class LeaveCalendarDelinquencyJob implements Job {
38
39 private static int CALENDAR_ENTRIES_POLLING_WINDOW;
40
41 private static CalendarEntriesService CALENDAR_ENTRIES_SERVICE;
42 private static KPMENotificationService KPME_NOTIFICATION_SERVICE;
43 private static LeaveCalendarDocumentHeaderService LEAVE_CALENDAR_DOCUMENT_HEADER_SERVICE;
44 private static PrincipalHRAttributesService PRINCIPAL_HR_ATTRIBUTES_SERVICE;
45
46 @Override
47 public void execute(JobExecutionContext context) throws JobExecutionException {
48 Set<String> principalIds = new HashSet<String>();
49
50 Date asOfDate = TKUtils.getCurrentDate();
51 List<CalendarEntries> calendarEntries = getCalendarEntriesService().getCurrentCalendarEntryNeedsScheduled(getCalendarEntriesPollingWindow(), asOfDate);
52
53 for (CalendarEntries calendarEntry : calendarEntries) {
54 String hrCalendarId = calendarEntry.getHrCalendarId();
55 Date currentBeginDate = calendarEntry.getBeginPeriodDateTime();
56
57 if (currentBeginDate.before(asOfDate) || DateUtils.isSameDay(currentBeginDate, asOfDate)) {
58 CalendarEntries previousCalendarEntry = getCalendarEntriesService().getPreviousCalendarEntriesByCalendarId(hrCalendarId, calendarEntry);
59
60 if (previousCalendarEntry != null) {
61 String calendarName = previousCalendarEntry.getCalendarName();
62 Date previousBeginDate = previousCalendarEntry.getBeginPeriodDateTime();
63 List<PrincipalHRAttributes> principalHRAttributes = getPrincipalHRAttributesService().getActiveEmployeesForLeaveCalendar(calendarName, previousBeginDate);
64
65 for (PrincipalHRAttributes principalHRAttribute : principalHRAttributes) {
66 String principalId = principalHRAttribute.getPrincipalId();
67
68 if (!principalIds.contains(principalId)) {
69 List<LeaveCalendarDocumentHeader> leaveCalendarDocumentHeaders = getLeaveCalendarDocumentHeaderService().getSubmissionDelinquentDocumentHeaders(principalId, currentBeginDate);
70
71 if (!leaveCalendarDocumentHeaders.isEmpty()) {
72 principalIds.add(principalId);
73 }
74 }
75 }
76 }
77 }
78 }
79
80 for (String principalId : principalIds) {
81 String subject = "Delinquent Leave Calendar Reminder";
82 StringBuilder message = new StringBuilder();
83 message.append("You currently have one or more DELINQUENT Leave Calendars.");
84 message.append(SystemUtils.LINE_SEPARATOR);
85 message.append(SystemUtils.LINE_SEPARATOR);
86 message.append("Please review/enter your time-off for any prior unapproved months and submit your calendar(s).");
87
88 getKpmeNotificationService().sendNotification(subject, message.toString(), principalId);
89 }
90 }
91
92 public static int getCalendarEntriesPollingWindow() {
93 return CALENDAR_ENTRIES_POLLING_WINDOW;
94 }
95
96 public static void setCalendarEntriesPollingWindow(int calendarEntriesPollingWindow) {
97 CALENDAR_ENTRIES_POLLING_WINDOW = calendarEntriesPollingWindow;
98 }
99
100 public static CalendarEntriesService getCalendarEntriesService() {
101 return CALENDAR_ENTRIES_SERVICE;
102 }
103
104 public static void setCalendarEntriesService(CalendarEntriesService calendarEntriesService) {
105 CALENDAR_ENTRIES_SERVICE = calendarEntriesService;
106 }
107
108 public static KPMENotificationService getKpmeNotificationService() {
109 return KPME_NOTIFICATION_SERVICE;
110 }
111
112 public static void setKpmeNotificationService(KPMENotificationService kpmeNotificationService) {
113 KPME_NOTIFICATION_SERVICE = kpmeNotificationService;
114 }
115
116 public static LeaveCalendarDocumentHeaderService getLeaveCalendarDocumentHeaderService() {
117 return LEAVE_CALENDAR_DOCUMENT_HEADER_SERVICE;
118 }
119
120 public static void setLeaveCalendarDocumentHeaderService(LeaveCalendarDocumentHeaderService leaveCalendarDocumentHeaderService) {
121 LEAVE_CALENDAR_DOCUMENT_HEADER_SERVICE = leaveCalendarDocumentHeaderService;
122 }
123
124 public static PrincipalHRAttributesService getPrincipalHRAttributesService() {
125 return PRINCIPAL_HR_ATTRIBUTES_SERVICE;
126 }
127
128 public static void setPrincipalHRAttributesService(PrincipalHRAttributesService principalHRAttributesService) {
129 PRINCIPAL_HR_ATTRIBUTES_SERVICE = principalHRAttributesService;
130 }
131
132 }