View Javadoc
1   /**
2    * Copyright 2004-2015 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.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  //			throw new JobExecutionException("Failure to execute job due to WorkflowException", we);
54  		}
55  	}
56  	
57  }