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.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
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 }