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