001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.time.batch;
017
018 import java.util.List;
019
020 import org.apache.commons.lang.StringUtils;
021 import org.apache.log4j.Logger;
022 import org.kuali.hr.time.calendar.CalendarEntries;
023 import org.kuali.hr.time.missedpunch.MissedPunchDocument;
024 import org.kuali.hr.time.service.base.TkServiceLocator;
025 import org.kuali.hr.time.util.TkConstants;
026 import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
027 import org.kuali.rice.kew.api.document.DocumentStatus;
028
029 public class BatchApproveMissedPunchJob extends BatchJob {
030 private Logger LOG = Logger.getLogger(BatchApproveMissedPunchJob.class);
031 private CalendarEntries calendarEntry;
032
033 public BatchApproveMissedPunchJob(CalendarEntries calendarEntry) {
034 this.setBatchJobName(TkConstants.BATCH_JOB_NAMES.BATCH_APPROVE_MISSED_PUNCH);
035 this.setHrPyCalendarEntryId(calendarEntry.getHrCalendarEntriesId());
036 this.calendarEntry = calendarEntry;
037 }
038
039 @Override
040 public void doWork() {
041 List<TimesheetDocumentHeader> timesheetDocumentHeaders = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeaders(calendarEntry.getBeginPeriodDateTime(), calendarEntry.getEndPeriodDateTime());
042 for (TimesheetDocumentHeader timesheetDocumentHeader : timesheetDocumentHeaders) {
043 List<MissedPunchDocument> missedPunchDocuments = TkServiceLocator.getMissedPunchService().getMissedPunchDocsByTimesheetDocumentId(timesheetDocumentHeader.getDocumentId());
044 for (MissedPunchDocument missedPunchDocument : missedPunchDocuments) {
045 if (StringUtils.equals(missedPunchDocument.getDocumentStatus(), DocumentStatus.ENROUTE.getCode())) {
046 populateBatchJobEntry(missedPunchDocument);
047 }
048 }
049 }
050 }
051
052 @Override
053 protected void populateBatchJobEntry(Object o) {
054 MissedPunchDocument mp = (MissedPunchDocument)o;
055 String ip = this.getNextIpAddressInCluster();
056 if(StringUtils.isNotBlank(ip)){
057 //insert a batch job entry here
058 BatchJobEntry entry = this.createBatchJobEntry(this.getBatchJobName(), ip, mp.getPrincipalId(), null, null);
059 TkServiceLocator.getBatchJobEntryService().saveBatchJobEntry(entry);
060 } else {
061 LOG.info("No ip found in cluster to assign batch jobs");
062 }
063 }
064
065 }