001    /**
002     * Copyright 2004-2012 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.Date;
019    import java.util.List;
020    
021    import org.apache.commons.lang.StringUtils;
022    import org.apache.log4j.Logger;
023    import org.kuali.hr.time.calendar.CalendarEntries;
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    
028    public class SupervisorApprovalBatchJob extends BatchJob {
029        private Logger LOG = Logger.getLogger(PayPeriodEndBatchJob.class);
030        private CalendarEntries payCalendarEntry;
031    
032        public SupervisorApprovalBatchJob(String hrPyCalendarEntryId) {
033            super();
034            this.setBatchJobName(TkConstants.BATCH_JOB_NAMES.SUPERVISOR_APPROVAL);
035            this.setHrPyCalendarEntryId(hrPyCalendarEntryId);
036            this.payCalendarEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntries(hrPyCalendarEntryId);
037        }
038    
039        @Override
040        public void doWork() {
041            Date payBeginDate = payCalendarEntry.getBatchEmployeeApprovalDate();
042            List<TimesheetDocumentHeader> documentHeaders = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeaders(payBeginDate);
043            for(TimesheetDocumentHeader timesheetDocumentHeader : documentHeaders){
044                populateBatchJobEntry(timesheetDocumentHeader);
045            }
046        }
047    
048    
049        @Override
050        protected void populateBatchJobEntry(Object o) {
051            TimesheetDocumentHeader tdh = (TimesheetDocumentHeader)o;
052            String ip = this.getNextIpAddressInCluster();
053            if(StringUtils.isNotBlank(ip)){
054                //insert a batch job entry here
055                BatchJobEntry entry = this.createBatchJobEntry(this.getBatchJobName(), ip, tdh.getPrincipalId(), tdh.getDocumentId(),null);
056                TkServiceLocator.getBatchJobEntryService().saveBatchJobEntry(entry);
057            } else {
058                LOG.info("No ip found in cluster to assign batch jobs");
059            }
060        }
061    
062    }