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.missedpunch.MissedPunchDocument;
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  import org.kuali.rice.kew.api.document.DocumentStatus;
28  
29  public class BatchApproveMissedPunchJob extends BatchJob {
30  	private Logger LOG = Logger.getLogger(BatchApproveMissedPunchJob.class);
31  	private CalendarEntries calendarEntry;
32  	
33     public BatchApproveMissedPunchJob(CalendarEntries calendarEntry) {
34          this.setBatchJobName(TkConstants.BATCH_JOB_NAMES.BATCH_APPROVE_MISSED_PUNCH);
35          this.setHrPyCalendarEntryId(calendarEntry.getHrCalendarEntriesId());
36          this.calendarEntry = calendarEntry;
37      }
38     
39     @Override
40     public void doWork() {
41  	   List<TimesheetDocumentHeader> timesheetDocumentHeaders = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeaders(calendarEntry.getBeginPeriodDateTime(), calendarEntry.getEndPeriodDateTime());
42         for (TimesheetDocumentHeader timesheetDocumentHeader : timesheetDocumentHeaders) {
43  		   List<MissedPunchDocument> missedPunchDocuments = TkServiceLocator.getMissedPunchService().getMissedPunchDocsByTimesheetDocumentId(timesheetDocumentHeader.getDocumentId());
44  	       for (MissedPunchDocument missedPunchDocument : missedPunchDocuments) {
45  	    	   if (StringUtils.equals(missedPunchDocument.getDocumentStatus(), DocumentStatus.ENROUTE.getCode())) {
46  	    		   populateBatchJobEntry(missedPunchDocument);
47  	    	   }
48  	       }
49         }
50     }
51     
52     @Override
53     protected void populateBatchJobEntry(Object o) {
54         MissedPunchDocument mp = (MissedPunchDocument)o;
55         String ip = this.getNextIpAddressInCluster();
56         if(StringUtils.isNotBlank(ip)){
57             //insert a batch job entry here
58             BatchJobEntry entry = this.createBatchJobEntry(this.getBatchJobName(), ip, mp.getPrincipalId(), null, null);
59             TkServiceLocator.getBatchJobEntryService().saveBatchJobEntry(entry);
60         } else {
61             LOG.info("No ip found in cluster to assign batch jobs");
62         }
63     }
64  
65  }