1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.gl.batch;
17
18 import java.io.File;
19 import java.util.ArrayList;
20 import java.util.Date;
21 import java.util.List;
22
23 import org.kuali.ole.gl.GeneralLedgerConstants;
24 import org.kuali.ole.sys.batch.AbstractStep;
25 import org.springframework.util.StopWatch;
26
27
28
29
30 public class FileRenameStep extends AbstractStep {
31 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(FileRenameStep.class);
32
33 private String batchFileDirectoryName;
34
35 public boolean execute(String jobName, Date jobRunDate) {
36 StopWatch stopWatch = new StopWatch();
37 stopWatch.start(jobName);
38 String filePath = batchFileDirectoryName + File.separator;
39 List<String> fileNameList = new ArrayList<String>();
40 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.NIGHTLY_OUT_FILE);
41 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.COLLECTOR_SCRUBBER_INPUT_FILE);
42 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.COLLECTOR_SCRUBBER_VALID_OUTPUT_FILE);
43 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.COLLECTOR_SCRUBBER_ERROR_OUTPUT_FILE);
44 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.COLLECTOR_SCRUBBER_EXPIRED_OUTPUT_FILE);
45 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.COLLECTOR_SCRUBBER_ERROR_SORTED_FILE);
46 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.BACKUP_FILE);
47 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.PRE_SCRUBBER_FILE);
48 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.SCRUBBER_INPUT_FILE);
49 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.SCRUBBER_VALID_OUTPUT_FILE);
50 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.SCRUBBER_ERROR_OUTPUT_FILE);
51 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.SCRUBBER_EXPIRED_OUTPUT_FILE);
52 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.SCRUBBER_ERROR_SORTED_FILE);
53 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.DEMERGER_VAILD_OUTPUT_FILE);
54 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.DEMERGER_ERROR_OUTPUT_FILE);
55 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE);
56 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.REVERSAL_POSTER_VALID_OUTPUT_FILE);
57 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.REVERSAL_POSTER_ERROR_OUTPUT_FILE);
58 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.POSTER_VALID_OUTPUT_FILE);
59 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.POSTER_ERROR_OUTPUT_FILE);
60 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.ICR_TRANSACTIONS_OUTPUT_FILE);
61 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.ICR_POSTER_INPUT_FILE);
62 fileNameList.add(GeneralLedgerConstants.BatchFileSystem.ICR_POSTER_ERROR_OUTPUT_FILE);
63
64 for (String fileName : fileNameList){
65 File file = new File(filePath + fileName + GeneralLedgerConstants.BatchFileSystem.EXTENSION);
66 if (file.exists()) {
67 String changedFileName = filePath + fileName + "." + getDateTimeService().toDateTimeStringForFilename(jobRunDate);
68 file.renameTo(new File(changedFileName + GeneralLedgerConstants.BatchFileSystem.EXTENSION));
69 }
70 }
71
72
73 stopWatch.stop();
74 if (LOG.isDebugEnabled()) {
75 LOG.debug("FileRenameStep of " + jobName + " took " + (stopWatch.getTotalTimeSeconds() / 60.0) + " minutes to complete");
76 }
77 return true;
78 }
79
80 public void setBatchFileDirectoryName(String batchFileDirectoryName) {
81 this.batchFileDirectoryName = batchFileDirectoryName;
82 }
83
84 }