View Javadoc

1   /**
2    * Copyright 2004-2012 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.apache.commons.lang.StringUtils;
22  import org.apache.log4j.Logger;
23  import org.kuali.hr.time.calendar.CalendarEntries;
24  import org.kuali.hr.time.service.base.TkServiceLocator;
25  import org.kuali.hr.time.util.TkConstants;
26  import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
27  
28  public class SupervisorApprovalBatchJob extends BatchJob {
29      private Logger LOG = Logger.getLogger(PayPeriodEndBatchJob.class);
30      private CalendarEntries payCalendarEntry;
31  
32      public SupervisorApprovalBatchJob(String hrPyCalendarEntryId) {
33          super();
34          this.setBatchJobName(TkConstants.BATCH_JOB_NAMES.SUPERVISOR_APPROVAL);
35          this.setHrPyCalendarEntryId(hrPyCalendarEntryId);
36          this.payCalendarEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntries(hrPyCalendarEntryId);
37      }
38  
39      @Override
40      public void doWork() {
41          Date payBeginDate = payCalendarEntry.getBatchEmployeeApprovalDate();
42          List<TimesheetDocumentHeader> documentHeaders = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeaders(payBeginDate);
43          for(TimesheetDocumentHeader timesheetDocumentHeader : documentHeaders){
44              populateBatchJobEntry(timesheetDocumentHeader);
45          }
46      }
47  
48  
49      @Override
50      protected void populateBatchJobEntry(Object o) {
51          TimesheetDocumentHeader tdh = (TimesheetDocumentHeader)o;
52          String ip = this.getNextIpAddressInCluster();
53          if(StringUtils.isNotBlank(ip)){
54              //insert a batch job entry here
55              BatchJobEntry entry = this.createBatchJobEntry(this.getBatchJobName(), ip, tdh.getPrincipalId(), tdh.getDocumentId(),null);
56              TkServiceLocator.getBatchJobEntryService().saveBatchJobEntry(entry);
57          } else {
58              LOG.info("No ip found in cluster to assign batch jobs");
59          }
60      }
61  
62  }