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.service.base.TkServiceLocator;
024 import org.kuali.hr.time.util.TkConstants;
025 import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
026
027
028 public class EmployeeApprovalBatchJob extends BatchJob {
029 private Logger LOG = Logger.getLogger(EmployeeApprovalBatchJob.class);
030 private CalendarEntries calendarEntry;
031
032 public EmployeeApprovalBatchJob(CalendarEntries calendarEntry) {
033 this.setBatchJobName(TkConstants.BATCH_JOB_NAMES.APPROVE);
034 this.setHrPyCalendarEntryId(calendarEntry.getHrCalendarEntriesId());
035 this.calendarEntry = calendarEntry;
036 }
037
038 @Override
039 public void doWork() {
040 List<TimesheetDocumentHeader> documentHeaders = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeaders(calendarEntry.getBatchEmployeeApprovalDate());
041 for(TimesheetDocumentHeader timesheetDocumentHeader : documentHeaders){
042 populateBatchJobEntry(timesheetDocumentHeader);
043 }
044 }
045
046 @Override
047 protected void populateBatchJobEntry(Object o) {
048 TimesheetDocumentHeader timesheetDocumentHeader = (TimesheetDocumentHeader)o;
049 String ip = this.getNextIpAddressInCluster();
050 if(StringUtils.isNotBlank(ip)){
051 //insert a batch job entry here
052 BatchJobEntry entry = this.createBatchJobEntry(this.getBatchJobName(), ip, timesheetDocumentHeader.getPrincipalId(), timesheetDocumentHeader.getDocumentId(),null);
053 TkServiceLocator.getBatchJobEntryService().saveBatchJobEntry(entry);
054 } else {
055 LOG.info("No ip found in cluster to assign batch jobs");
056 }
057 }
058
059 }