001    /**
002     * Copyright 2004-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.hr.time.batch;
017    
018    import java.util.Date;
019    import java.util.List;
020    
021    import org.kuali.hr.time.batch.service.BatchJobService;
022    import org.kuali.hr.time.calendar.CalendarEntries;
023    import org.kuali.hr.time.service.base.TkServiceLocator;
024    import org.kuali.hr.time.util.TKUtils;
025    import org.quartz.JobExecutionContext;
026    import org.quartz.JobExecutionException;
027    import org.quartz.SchedulerException;
028    import org.springframework.scheduling.quartz.QuartzJobBean;
029    
030    public class CalendarEntrySchedulerJob extends QuartzJobBean {
031    
032            private static int CALENDAR_ENTRIES_POLLING_WINDOW;
033            
034            private static BatchJobService batchJobService;
035    
036            @Override
037            protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
038                    Date asOfDate = TKUtils.getCurrentDate();
039            List<CalendarEntries> calendarEntries = TkServiceLocator.getCalendarEntriesService().getCurrentCalendarEntryNeedsScheduled(getCalendarEntriesPollingWindow(), asOfDate);
040    
041            try {
042                    for (CalendarEntries calendarEntry : calendarEntries) {
043                        if (calendarEntry.getEndPeriodDateTime() != null) {
044                            getBatchJobService().scheduleEndReportingPeriodJobs(calendarEntry);
045                        }
046                            
047                        if (calendarEntry.getBatchInitiateDateTime() != null) {
048                            getBatchJobService().scheduleInitiateJobs(calendarEntry);
049                        }
050                        
051                        if (calendarEntry.getBatchEndPayPeriodDateTime() != null) {
052                            getBatchJobService().scheduleEndPayPeriodJobs(calendarEntry);
053                        }
054                        
055                        if (calendarEntry.getBatchEmployeeApprovalDateTime() != null) {
056                            getBatchJobService().scheduleEmployeeApprovalJobs(calendarEntry);
057                        }
058                        
059                        if (calendarEntry.getBatchSupervisorApprovalDateTime() != null) {
060                            getBatchJobService().scheduleMissedPunchApprovalJobs(calendarEntry);
061                        }
062                        
063                        if (calendarEntry.getBatchSupervisorApprovalDateTime() != null) {
064                            getBatchJobService().scheduleSupervisorApprovalJobs(calendarEntry);
065                        }
066                    }
067            } catch (SchedulerException se) {
068                    throw new JobExecutionException("Exception thrown during job scheduling", se);
069            }
070            }
071            
072            public int getCalendarEntriesPollingWindow() {
073                    return CALENDAR_ENTRIES_POLLING_WINDOW;
074            }
075    
076            public void setCalendarEntriesPollingWindow(int calendarEntriesPollingWindow) {
077                    CALENDAR_ENTRIES_POLLING_WINDOW = calendarEntriesPollingWindow;
078            }
079    
080            public static BatchJobService getBatchJobService() {
081                    return CalendarEntrySchedulerJob.batchJobService;
082            }
083    
084            public void setBatchJobService(BatchJobService batchJobService) {
085                    CalendarEntrySchedulerJob.batchJobService = batchJobService;
086            }
087    
088    }