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.time.batch;
17  
18  import org.joda.time.DateTime;
19  import org.kuali.kpme.core.api.calendar.entry.CalendarEntry;
20  import org.kuali.kpme.core.batch.BatchJob;
21  import org.kuali.kpme.core.service.HrServiceLocator;
22  import org.kuali.kpme.tklm.common.BatchJobService;
23  import org.kuali.kpme.tklm.time.service.TkServiceLocator;
24  import org.quartz.JobDataMap;
25  import org.quartz.JobExecutionContext;
26  import org.quartz.JobExecutionException;
27  
28  import java.text.DateFormat;
29  
30  public class EndReportingPeriodJob extends BatchJob {
31  
32  	public void execute(JobExecutionContext context) throws JobExecutionException {
33  		JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
34  		TkServiceLocator.getBatchJobService().updateStatus(context.getJobDetail(), BatchJobService.RUNNING_JOB_STATUS_CODE);
35  		String hrCalendarEntryId = jobDataMap.getString("hrCalendarEntryId");
36  		String principalId = jobDataMap.getString("principalId");
37  
38          CalendarEntry calendarEntry = HrServiceLocator.getCalendarEntryService().getCalendarEntry(hrCalendarEntryId);
39  		DateTime endPeriodDateTime = calendarEntry.getEndPeriodFullDateTime();
40  		
41  		String subject = "End of Reporting Period Reminder";
42  		StringBuilder message = new StringBuilder();
43  		message.append("Please submit your Leave Calendar for the period ending on ");
44  		message.append(DateFormat.getDateInstance(DateFormat.LONG).format(endPeriodDateTime.minusDays(1).toDate()));
45  		message.append(", so it can be reviewed and approved by your supervisor.");
46  		
47  		HrServiceLocator.getKPMENotificationService().sendNotification(subject, message.toString(), principalId);
48  		TkServiceLocator.getBatchJobService().updateStatus(context.getJobDetail(), BatchJobService.SUCCEEDED_JOB_STATUS_CODE);
49  	}
50  	
51  }