View Javadoc

1   /**
2    * Copyright 2004-2014 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.common;
17  
18  import java.util.List;
19  
20  import org.apache.log4j.Logger;
21  import org.joda.time.DateTime;
22  import org.joda.time.LocalDate;
23  import org.kuali.kpme.core.calendar.entry.CalendarEntry;
24  import org.kuali.kpme.core.service.HrServiceLocator;
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 final Logger LOG = Logger.getLogger(CalendarEntrySchedulerJob.class);
33  	private static int CALENDAR_ENTRIES_POLLING_WINDOW;
34  	
35  	private static BatchJobService batchJobService;
36  
37  	@Override
38  	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
39  		DateTime asOfDate = new LocalDate().toDateTimeAtStartOfDay();
40          List<CalendarEntry> calendarEntries = HrServiceLocator.getCalendarEntryService().getCurrentCalendarEntriesNeedsScheduled(getCalendarEntriesPollingWindow(), asOfDate);
41  
42          try {
43  	        for (CalendarEntry calendarEntry : calendarEntries) {
44  	            if (calendarEntry.getEndPeriodDateTime() != null) {
45  	            	getBatchJobService().scheduleEndReportingPeriodJobs(calendarEntry);
46  	            }
47  	        	
48  	            if (calendarEntry.getBatchInitiateDateTime() != null) {
49  	            	getBatchJobService().scheduleInitiateJobs(calendarEntry);
50  	            }
51  	            
52  	            if (calendarEntry.getBatchEndPayPeriodDateTime() != null) {
53  	            	getBatchJobService().scheduleEndPayPeriodJobs(calendarEntry);
54  	            }
55  	            
56  	            if (calendarEntry.getBatchEmployeeApprovalDateTime() != null) {
57  	            	getBatchJobService().scheduleEmployeeApprovalJobs(calendarEntry);
58  	            }
59  	            
60  //	            if (calendarEntry.getBatchSupervisorApprovalDateTime() != null) {
61  //	            	getBatchJobService().scheduleMissedPunchApprovalJobs(calendarEntry);
62  //	            }
63  	            
64  	            if (calendarEntry.getBatchSupervisorApprovalDateTime() != null) {
65  	            	getBatchJobService().scheduleSupervisorApprovalJobs(calendarEntry);
66  	            }
67  	        }
68          } catch (SchedulerException se) {
69          	LOG.error("Exception thrown during job scheduling", se);
70  //        	throw new JobExecutionException("Exception thrown during job scheduling", se);
71          }
72  	}
73  	
74  	public int getCalendarEntriesPollingWindow() {
75  		return CALENDAR_ENTRIES_POLLING_WINDOW;
76  	}
77  
78  	public void setCalendarEntriesPollingWindow(int calendarEntriesPollingWindow) {
79  		CALENDAR_ENTRIES_POLLING_WINDOW = calendarEntriesPollingWindow;
80  	}
81  
82  	public static BatchJobService getBatchJobService() {
83  		return CalendarEntrySchedulerJob.batchJobService;
84  	}
85  
86  	public void setBatchJobService(BatchJobService batchJobService) {
87  		CalendarEntrySchedulerJob.batchJobService = batchJobService;
88  	}
89  
90  }