View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.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  }