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