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.apache.commons.lang.StringUtils;
19 import org.apache.log4j.Logger;
20 import org.kuali.kpme.core.batch.BatchJob;
21 import org.kuali.kpme.core.calendar.Calendar;
22 import org.kuali.kpme.core.calendar.entry.CalendarEntry;
23 import org.kuali.kpme.core.service.HrServiceLocator;
24 import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
25 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
26 import org.kuali.rice.kew.api.exception.WorkflowException;
27 import org.quartz.Job;
28 import org.quartz.JobDataMap;
29 import org.quartz.JobExecutionContext;
30 import org.quartz.JobExecutionException;
31
32 public class InitiateJob extends BatchJob {
33
34 private static final Logger LOG = Logger.getLogger(InitiateJob.class);
35
36 public void execute(JobExecutionContext context) throws JobExecutionException {
37 JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
38
39 String hrCalendarEntryId = jobDataMap.getString("hrCalendarEntryId");
40 String principalId = jobDataMap.getString("principalId");
41
42 CalendarEntry calendarEntry = HrServiceLocator.getCalendarEntryService().getCalendarEntry(hrCalendarEntryId);
43 Calendar calendar = HrServiceLocator.getCalendarService().getCalendar(calendarEntry.getHrCalendarId());
44
45 try {
46 if (StringUtils.equals(calendar.getCalendarTypes(), "Pay")) {
47 TkServiceLocator.getTimesheetService().openTimesheetDocument(principalId, calendarEntry);
48 } else if (StringUtils.equals(calendar.getCalendarTypes(), "Leave")) {
49 LmServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument(principalId, calendarEntry);
50 }
51 } catch (WorkflowException we) {
52 LOG.error("Failure to execute job due to WorkflowException", we);
53
54 }
55 }
56
57 }