View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * This step will call a service method to load the vendor  xml file into the transaction table. Validates the data before the
31   * load.
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       * Controls the procurement card process.
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       * Clears out associated .done files for the processed data files.
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  }