1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.batch;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.select.batch.service.RequisitionLoadTransactionsService;
20 import org.kuali.ole.sys.batch.AbstractStep;
21 import org.kuali.ole.sys.batch.BatchInputFileType;
22 import org.kuali.ole.sys.batch.service.BatchInputFileService;
23
24 import java.io.File;
25 import java.util.ArrayList;
26 import java.util.Date;
27 import java.util.List;
28
29
30
31
32
33 public class RequisitionLoadStep extends AbstractStep {
34 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RequisitionLoadStep.class);
35
36 private BatchInputFileService batchInputFileService;
37 private RequisitionLoadTransactionsService requisitionLoadTransactionsService;
38 private BatchInputFileType requisitionInputFileType;
39
40
41
42
43 public boolean execute(String jobName, Date jobRunDate) {
44
45 List<String> fileNamesToLoad = batchInputFileService.listInputFileNamesWithDoneFile(requisitionInputFileType);
46 boolean processSuccess = true;
47 List<String> processedFiles = new ArrayList();
48 for (String inputFileName : fileNamesToLoad) {
49 processSuccess = requisitionLoadTransactionsService.loadRequisitionFile(inputFileName);
50 if (processSuccess) {
51 processedFiles.add(inputFileName);
52 }
53 }
54
55 removeDoneFiles(processedFiles);
56
57 return processSuccess;
58 }
59
60
61
62
63 private void removeDoneFiles(List<String> dataFileNames) {
64
65 for (String dataFileName : dataFileNames) {
66 File doneFile = new File(StringUtils.substringBeforeLast(dataFileName, ".") + ".done");
67 if (doneFile.exists()) {
68 doneFile.delete();
69 }
70 }
71
72 }
73
74 public BatchInputFileService getBatchInputFileService() {
75 return batchInputFileService;
76 }
77
78 public void setBatchInputFileService(BatchInputFileService batchInputFileService) {
79 this.batchInputFileService = batchInputFileService;
80 }
81
82 public RequisitionLoadTransactionsService getRequisitionLoadTransactionsService() {
83 return requisitionLoadTransactionsService;
84 }
85
86 public void setRequisitionLoadTransactionsService(RequisitionLoadTransactionsService requisitionLoadTransactionsService) {
87 this.requisitionLoadTransactionsService = requisitionLoadTransactionsService;
88 }
89
90 public BatchInputFileType getRequisitionInputFileType() {
91 return requisitionInputFileType;
92 }
93
94 public void setRequisitionInputFileType(BatchInputFileType requisitionInputFileType) {
95 this.requisitionInputFileType = requisitionInputFileType;
96 }
97
98 }