1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.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.apache.commons.lang.StringUtils;
24 import org.kuali.ole.fp.batch.service.ProcurementCardLoadTransactionsService;
25 import org.kuali.ole.sys.batch.AbstractStep;
26 import org.kuali.ole.sys.batch.BatchInputFileType;
27 import org.kuali.ole.sys.batch.service.BatchInputFileService;
28 import org.kuali.ole.sys.batch.service.WrappingBatchService;
29 import org.kuali.ole.sys.service.ReportWriterService;
30
31
32
33
34
35
36
37
38 public class ProcurementCardLoadStep extends AbstractStep {
39 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ProcurementCardLoadStep.class);
40
41 private ProcurementCardLoadTransactionsService procurementCardLoadTransactionsService;
42 private BatchInputFileService batchInputFileService;
43 private BatchInputFileType procurementCardInputFileType;
44 private ReportWriterService reportWriterService;
45
46
47
48
49
50
51 @Override
52 public List<String> getRequiredDirectoryNames() {
53 setBatchInputFileType(procurementCardInputFileType);
54 return super.getRequiredDirectoryNames();
55 }
56
57
58
59
60 public boolean execute(String jobName, Date jobRunDate) {
61 procurementCardLoadTransactionsService.cleanTransactionsTable();
62
63 List<String> fileNamesToLoad = batchInputFileService.listInputFileNamesWithDoneFile(procurementCardInputFileType);
64 ((WrappingBatchService) reportWriterService).initialize();
65
66 boolean processSuccess = true;
67 List<String> processedFiles = new ArrayList();
68 for (String inputFileName : fileNamesToLoad) {
69 processSuccess = procurementCardLoadTransactionsService.loadProcurementCardFile(inputFileName, reportWriterService);
70 if (processSuccess) {
71 processedFiles.add(inputFileName);
72 }
73 }
74 ((WrappingBatchService) reportWriterService).destroy();
75
76 removeDoneFiles(fileNamesToLoad);
77
78 return processSuccess;
79 }
80
81
82
83
84 private void removeDoneFiles(List<String> dataFileNames) {
85 for (String dataFileName : dataFileNames) {
86 File doneFile = new File(StringUtils.substringBeforeLast(dataFileName, ".") + ".done");
87 if (doneFile.exists()) {
88 doneFile.delete();
89 }
90 }
91 }
92
93
94
95
96 public void setBatchInputFileService(BatchInputFileService batchInputFileService) {
97 this.batchInputFileService = batchInputFileService;
98 }
99
100
101
102
103 public void setProcurementCardInputFileType(BatchInputFileType procurementCardInputFileType) {
104 this.procurementCardInputFileType = procurementCardInputFileType;
105 }
106
107
108
109
110 public void setProcurementCardLoadTransactionsService(ProcurementCardLoadTransactionsService procurementCardLoadTransactionsService) {
111 this.procurementCardLoadTransactionsService = procurementCardLoadTransactionsService;
112 }
113
114
115
116
117
118 public ReportWriterService getReportWriterService() {
119 return reportWriterService;
120 }
121
122
123
124
125
126 public void setReportWriterService(ReportWriterService reportWriterService) {
127 this.reportWriterService = reportWriterService;
128 }
129 }