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 java.util.Date;
19  import java.util.List;
20  
21  import org.kuali.hr.time.batch.service.BatchJobService;
22  import org.kuali.hr.time.calendar.CalendarEntries;
23  import org.kuali.hr.time.service.base.TkServiceLocator;
24  import org.kuali.hr.time.util.TKUtils;
25  import org.quartz.JobExecutionContext;
26  import org.quartz.JobExecutionException;
27  import org.quartz.SchedulerException;
28  import org.springframework.scheduling.quartz.QuartzJobBean;
29  
30  public class CalendarEntrySchedulerJob extends QuartzJobBean {
31  
32  	private static int CALENDAR_ENTRIES_POLLING_WINDOW;
33  	
34  	private static BatchJobService batchJobService;
35  
36  	@Override
37  	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
38  		Date asOfDate = TKUtils.getCurrentDate();
39          List<CalendarEntries> calendarEntries = TkServiceLocator.getCalendarEntriesService().getCurrentCalendarEntryNeedsScheduled(getCalendarEntriesPollingWindow(), asOfDate);
40  
41          try {
42  	        for (CalendarEntries calendarEntry : calendarEntries) {
43  	            if (calendarEntry.getEndPeriodDateTime() != null) {
44  	            	getBatchJobService().scheduleEndReportingPeriodJobs(calendarEntry);
45  	            }
46  	        	
47  	            if (calendarEntry.getBatchInitiateDateTime() != null) {
48  	            	getBatchJobService().scheduleInitiateJobs(calendarEntry);
49  	            }
50  	            
51  	            if (calendarEntry.getBatchEndPayPeriodDateTime() != null) {
52  	            	getBatchJobService().scheduleEndPayPeriodJobs(calendarEntry);
53  	            }
54  	            
55  	            if (calendarEntry.getBatchEmployeeApprovalDateTime() != null) {
56  	            	getBatchJobService().scheduleEmployeeApprovalJobs(calendarEntry);
57  	            }
58  	            
59  	            if (calendarEntry.getBatchSupervisorApprovalDateTime() != null) {
60  	            	getBatchJobService().scheduleMissedPunchApprovalJobs(calendarEntry);
61  	            }
62  	            
63  	            if (calendarEntry.getBatchSupervisorApprovalDateTime() != null) {
64  	            	getBatchJobService().scheduleSupervisorApprovalJobs(calendarEntry);
65  	            }
66  	        }
67          } catch (SchedulerException se) {
68          	throw new JobExecutionException("Exception thrown during job scheduling", se);
69          }
70  	}
71  	
72  	public int getCalendarEntriesPollingWindow() {
73  		return CALENDAR_ENTRIES_POLLING_WINDOW;
74  	}
75  
76  	public void setCalendarEntriesPollingWindow(int calendarEntriesPollingWindow) {
77  		CALENDAR_ENTRIES_POLLING_WINDOW = calendarEntriesPollingWindow;
78  	}
79  
80  	public static BatchJobService getBatchJobService() {
81  		return CalendarEntrySchedulerJob.batchJobService;
82  	}
83  
84  	public void setBatchJobService(BatchJobService batchJobService) {
85  		CalendarEntrySchedulerJob.batchJobService = batchJobService;
86  	}
87  
88  }