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  
28  public class EmployeeApprovalBatchJob extends BatchJob {
29      private Logger LOG = Logger.getLogger(EmployeeApprovalBatchJob.class);
30      private CalendarEntries calendarEntry;
31  
32      public EmployeeApprovalBatchJob(CalendarEntries calendarEntry) {
33          this.setBatchJobName(TkConstants.BATCH_JOB_NAMES.APPROVE);
34          this.setHrPyCalendarEntryId(calendarEntry.getHrCalendarEntriesId());
35          this.calendarEntry = calendarEntry;
36      }
37  
38      @Override
39      public void doWork() {
40          List<TimesheetDocumentHeader> documentHeaders = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeaders(calendarEntry.getBatchEmployeeApprovalDate());
41          for(TimesheetDocumentHeader timesheetDocumentHeader : documentHeaders){
42              populateBatchJobEntry(timesheetDocumentHeader);
43          }
44      }
45  
46      @Override
47      protected void populateBatchJobEntry(Object o) {
48          TimesheetDocumentHeader timesheetDocumentHeader = (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, timesheetDocumentHeader.getPrincipalId(), timesheetDocumentHeader.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  }