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.time.calendar.Calendar;
20  import org.kuali.hr.time.calendar.CalendarEntries;
21  import org.kuali.hr.time.service.base.TkServiceLocator;
22  import org.kuali.rice.kew.api.exception.WorkflowException;
23  import org.quartz.Job;
24  import org.quartz.JobDataMap;
25  import org.quartz.JobExecutionContext;
26  import org.quartz.JobExecutionException;
27  
28  public class InitiateJob implements Job {
29  	
30  	public void execute(JobExecutionContext context) throws JobExecutionException {
31  		JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
32  
33  		String hrCalendarEntriesId = jobDataMap.getString("hrCalendarEntriesId");
34  		String principalId = jobDataMap.getString("principalId");
35  		
36  		CalendarEntries calendarEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntries(hrCalendarEntriesId);
37  		Calendar calendar = TkServiceLocator.getCalendarService().getCalendar(calendarEntry.getHrCalendarId());
38  		
39  		try {
40  			if (StringUtils.equals(calendar.getCalendarTypes(), "Pay")) {
41  				TkServiceLocator.getTimesheetService().openTimesheetDocument(principalId, calendarEntry);
42  			} else if (StringUtils.equals(calendar.getCalendarTypes(), "Leave")) {
43  				TkServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument(principalId, calendarEntry);
44  			}
45  		} catch (WorkflowException we) {
46  			throw new JobExecutionException("Failure to execute job due to WorkflowException", we);
47  		}
48  	}
49  	
50  }