1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
29 public class EmployeeApprovalBatchJob extends BatchJob {
30 private Logger LOG = Logger.getLogger(EmployeeApprovalBatchJob.class);
31 private CalendarEntries payCalendarEntry;
32
33 public EmployeeApprovalBatchJob(CalendarEntries payCalendarEntry) {
34 this.payCalendarEntry = payCalendarEntry;
35 setBatchJobName(TkConstants.BATCH_JOB_NAMES.APPROVE);
36 }
37
38 @Override
39 public void doWork() {
40 Date payBeginDate = payCalendarEntry.getBatchEmployeeApprovalDate();
41
42 List<TimesheetDocumentHeader> documentHeaders = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeaders(payBeginDate);
43 for(TimesheetDocumentHeader timesheetDocumentHeader : documentHeaders){
44 populateBatchJobEntry(timesheetDocumentHeader);
45 }
46 }
47
48 @Override
49 protected void populateBatchJobEntry(Object o) {
50 TimesheetDocumentHeader timesheetDocumentHeader = (TimesheetDocumentHeader)o;
51 String ip = this.getNextIpAddressInCluster();
52 if(StringUtils.isNotBlank(ip)){
53
54 BatchJobEntry entry = this.createBatchJobEntry(this.getBatchJobName(), ip, timesheetDocumentHeader.getPrincipalId(), timesheetDocumentHeader.getDocumentId(),null);
55 TkServiceLocator.getBatchJobEntryService().saveBatchJobEntry(entry);
56 } else {
57 LOG.info("No ip found in cluster to assign batch jobs");
58 }
59 }
60
61 }