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.sql.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.assignment.Assignment;
24 import org.kuali.hr.time.calendar.CalendarEntries;
25 import org.kuali.hr.time.service.base.TkServiceLocator;
26 import org.kuali.hr.time.util.TKUtils;
27 import org.kuali.hr.time.util.TkConstants;
28 import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
29
30
31 public class InitiateBatchJob extends BatchJob {
32 private Logger LOG = Logger.getLogger(InitiateBatchJob.class);
33
34
35 public InitiateBatchJob(String hrPyCalendarEntryId) {
36 super();
37 this.setBatchJobName(TkConstants.BATCH_JOB_NAMES.INITIATE);
38 this.setHrPyCalendarEntryId(hrPyCalendarEntryId);
39 }
40
41 @Override
42 public void doWork() {
43 Date asOfDate = TKUtils.getCurrentDate();
44 List<Assignment> lstAssignments = TkServiceLocator.getAssignmentService().getActiveAssignments(asOfDate);
45 CalendarEntries payCalendarEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntries(this.getHrPyCalendarEntryId());
46 for(Assignment assign : lstAssignments){
47 TimesheetDocumentHeader tkDocHeader = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeader(assign.getPrincipalId(), payCalendarEntry.getBeginPeriodDateTime(), payCalendarEntry.getEndPeriodDateTime());
48 if(tkDocHeader == null || StringUtils.equals(tkDocHeader.getDocumentStatus(),TkConstants.ROUTE_STATUS.CANCEL)){
49 populateBatchJobEntry(assign);
50 }
51 }
52 }
53
54
55 @Override
56 protected void populateBatchJobEntry(Object o) {
57 Assignment assign = (Assignment)o;
58 String ip = this.getNextIpAddressInCluster();
59 if(StringUtils.isNotBlank(ip)){
60
61 BatchJobEntry entry = this.createBatchJobEntry(this.getBatchJobName(), ip, assign.getPrincipalId(), null,null);
62 TkServiceLocator.getBatchJobEntryService().saveBatchJobEntry(entry);
63 } else {
64 LOG.info("No ip found in cluster to assign batch jobs");
65 }
66 }
67
68 }