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 private CalendarEntries calendarEntry;
34
35 public InitiateBatchJob(CalendarEntries calendarEntry) {
36 this.setBatchJobName(TkConstants.BATCH_JOB_NAMES.INITIATE);
37 this.setHrPyCalendarEntryId(calendarEntry.getHrCalendarEntriesId());
38 this.calendarEntry = calendarEntry;
39 }
40
41 @Override
42 public void doWork() {
43 Date asOfDate = TKUtils.getCurrentDate();
44 List<Assignment> lstAssignments = TkServiceLocator.getAssignmentService().getActiveAssignments(asOfDate);
45 for(Assignment assign : lstAssignments){
46 TimesheetDocumentHeader tkDocHeader = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeader(assign.getPrincipalId(), calendarEntry.getBeginPeriodDateTime(), calendarEntry.getEndPeriodDateTime());
47 if(tkDocHeader == null || StringUtils.equals(tkDocHeader.getDocumentStatus(),TkConstants.ROUTE_STATUS.CANCEL)){
48 populateBatchJobEntry(assign);
49 }
50 }
51 }
52
53
54 @Override
55 protected void populateBatchJobEntry(Object o) {
56 Assignment assign = (Assignment)o;
57 String ip = this.getNextIpAddressInCluster();
58 if(StringUtils.isNotBlank(ip)){
59
60 BatchJobEntry entry = this.createBatchJobEntry(this.getBatchJobName(), ip, assign.getPrincipalId(), null,null);
61 TkServiceLocator.getBatchJobEntryService().saveBatchJobEntry(entry);
62 } else {
63 LOG.info("No ip found in cluster to assign batch jobs");
64 }
65 }
66
67 }