001 /*
002 * Copyright 2011 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.kfs.module.ld.batch;
017
018 import java.io.File;
019 import java.util.ArrayList;
020 import java.util.Date;
021 import java.util.List;
022
023 import org.kuali.kfs.gl.GeneralLedgerConstants;
024 import org.kuali.kfs.module.ld.LaborConstants;
025 import org.kuali.kfs.sys.batch.AbstractStep;
026 import org.springframework.util.StopWatch;
027
028 /**
029 * A step to run the scrubber process.
030 */
031 public class LaborFileRenameStep extends AbstractStep {
032 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LaborFileRenameStep.class);
033 private String batchFileDirectoryName;
034
035 public boolean execute(String jobName, Date jobRunDate) {
036 StopWatch stopWatch = new StopWatch();
037 stopWatch.start(jobName);
038 String filePath = batchFileDirectoryName + File.separator;
039 List<String> fileNameList = new ArrayList<String>();
040 fileNameList.add(LaborConstants.BatchFileSystem.NIGHTLY_OUT_FILE);
041 fileNameList.add(LaborConstants.BatchFileSystem.BACKUP_FILE);
042 fileNameList.add(LaborConstants.BatchFileSystem.PRE_SCRUBBER_FILE);
043 fileNameList.add(LaborConstants.BatchFileSystem.SCRUBBER_INPUT_FILE);
044 fileNameList.add(LaborConstants.BatchFileSystem.SCRUBBER_VALID_OUTPUT_FILE);
045 fileNameList.add(LaborConstants.BatchFileSystem.SCRUBBER_ERROR_OUTPUT_FILE);
046 fileNameList.add(LaborConstants.BatchFileSystem.SCRUBBER_EXPIRED_OUTPUT_FILE);
047 fileNameList.add(LaborConstants.BatchFileSystem.SCRUBBER_ERROR_SORTED_FILE);
048 fileNameList.add(LaborConstants.BatchFileSystem.DEMERGER_VAILD_OUTPUT_FILE);
049 fileNameList.add(LaborConstants.BatchFileSystem.DEMERGER_ERROR_OUTPUT_FILE);
050 fileNameList.add(LaborConstants.BatchFileSystem.POSTER_INPUT_FILE);
051 fileNameList.add(LaborConstants.BatchFileSystem.POSTER_VALID_OUTPUT_FILE);
052 fileNameList.add(LaborConstants.BatchFileSystem.POSTER_ERROR_OUTPUT_FILE);
053
054 for (String fileName : fileNameList){
055 File file = new File(filePath + fileName + GeneralLedgerConstants.BatchFileSystem.EXTENSION);
056 if (file.exists()) {
057 String changedFileName = filePath + fileName + "." + getDateTimeService().toDateTimeStringForFilename(jobRunDate);
058 file.renameTo(new File(changedFileName + GeneralLedgerConstants.BatchFileSystem.EXTENSION));
059 }
060 }
061
062
063 stopWatch.stop();
064 if (LOG.isDebugEnabled()) {
065 LOG.debug("LaborFileRenameStep of " + jobName + " took " + (stopWatch.getTotalTimeSeconds() / 60.0) + " minutes to complete");
066 }
067 return true;
068 }
069
070 public void setBatchFileDirectoryName(String batchFileDirectoryName) {
071 this.batchFileDirectoryName = batchFileDirectoryName;
072 }
073
074 }