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 org.apache.commons.lang.StringUtils;
19 import org.kuali.hr.lm.leavecalendar.LeaveCalendarDocument;
20 import org.kuali.hr.lm.workflow.LeaveCalendarDocumentHeader;
21 import org.kuali.hr.time.calendar.Calendar;
22 import org.kuali.hr.time.calendar.CalendarEntries;
23 import org.kuali.hr.time.service.base.TkServiceLocator;
24 import org.kuali.hr.time.timesheet.TimesheetDocument;
25 import org.kuali.hr.time.util.TkConstants;
26 import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
27 import org.kuali.rice.kew.api.document.DocumentStatus;
28 import org.kuali.rice.kew.service.KEWServiceLocator;
29 import org.quartz.Job;
30 import org.quartz.JobDataMap;
31 import org.quartz.JobExecutionContext;
32 import org.quartz.JobExecutionException;
33
34 public class EmployeeApprovalJob implements Job {
35
36 public void execute(JobExecutionContext context) throws JobExecutionException {
37 JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
38
39 String hrCalendarEntriesId = jobDataMap.getString("hrCalendarEntriesId");
40 String documentId = jobDataMap.getString("documentId");
41
42 CalendarEntries calendarEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntries(hrCalendarEntriesId);
43 Calendar calendar = TkServiceLocator.getCalendarService().getCalendar(calendarEntry.getHrCalendarId());
44
45 if (StringUtils.equals(calendar.getCalendarTypes(), "Pay")) {
46 TimesheetDocumentHeader timesheetDocumentHeader = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeader(documentId);
47 if (timesheetDocumentHeader != null) {
48 TimesheetDocument timesheetDocument = TkServiceLocator.getTimesheetService().getTimesheetDocument(documentId);
49 String documentStatus = KEWServiceLocator.getRouteHeaderService().getDocumentStatus(timesheetDocument.getDocumentId());
50 String principalId = timesheetDocument == null ? null : timesheetDocument.getPrincipalId();
51
52 if (DocumentStatus.INITIATED.getCode().equals(documentStatus) || DocumentStatus.SAVED.getCode().equals(documentStatus)) {
53 TkServiceLocator.getTimesheetService().routeTimesheet(principalId, timesheetDocument, TkConstants.BATCH_JOB_ACTIONS.BATCH_JOB_ROUTE);
54 }
55 }
56 } else if (StringUtils.equals(calendar.getCalendarTypes(), "Leave")) {
57 LeaveCalendarDocumentHeader leaveCalendarDocumentHeader = TkServiceLocator.getLeaveCalendarDocumentHeaderService().getDocumentHeader(documentId);
58 if (leaveCalendarDocumentHeader != null) {
59 LeaveCalendarDocument leaveCalendarDocument = TkServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(documentId);
60 String documentStatus = KEWServiceLocator.getRouteHeaderService().getDocumentStatus(leaveCalendarDocument.getDocumentId());
61 String principalId = leaveCalendarDocument.getPrincipalId();
62
63 if (DocumentStatus.INITIATED.getCode().equals(documentStatus) || DocumentStatus.SAVED.getCode().equals(documentStatus)) {
64 TkServiceLocator.getLeaveCalendarService().routeLeaveCalendar(principalId, leaveCalendarDocument, TkConstants.BATCH_JOB_ACTIONS.BATCH_JOB_ROUTE);
65 }
66 }
67 }
68 }
69
70 }