001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.financial.batch.pcard;
017:
018: import java.io.File;
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import org.apache.commons.lang.StringUtils;
023: import org.kuali.kfs.batch.AbstractStep;
024: import org.kuali.kfs.batch.BatchInputFileType;
025: import org.kuali.kfs.service.BatchInputFileService;
026: import org.kuali.module.financial.service.ProcurementCardLoadTransactionsService;
027:
028: /**
029: * This step will call a service method to load the kuali pcard xml file into the transaction table. Validates the data before the
030: * load. Functions performed by this step: 1) Lookup path and filename from APC for the pcard input file 2) Load the pcard xml file
031: * 3) Parse each transaction and validate against the data dictionary 4) Clean fp_prcrmnt_card_trn_t from the previous run 5) Load
032: * new transactions into fp_prcrmnt_card_trn_t 6) Rename input file using the current date (backup) RESTART: All functions performed
033: * withing a single transaction. Step can be restarted as needed.
034: */
035: public class ProcurementCardLoadStep extends AbstractStep {
036: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
037: .getLogger(ProcurementCardLoadStep.class);
038:
039: private ProcurementCardLoadTransactionsService procurementCardLoadTransactionsService;
040: private BatchInputFileService batchInputFileService;
041: private BatchInputFileType procurementCardInputFileType;
042:
043: /**
044: * Controls the procurement card process.
045: */
046: public boolean execute(String jobName) {
047: procurementCardLoadTransactionsService.cleanTransactionsTable();
048:
049: List<String> fileNamesToLoad = batchInputFileService
050: .listInputFileNamesWithDoneFile(procurementCardInputFileType);
051:
052: boolean processSuccess = true;
053: List<String> processedFiles = new ArrayList();
054: for (String inputFileName : fileNamesToLoad) {
055: processSuccess = procurementCardLoadTransactionsService
056: .loadProcurementCardFile(inputFileName);
057: if (processSuccess) {
058: processedFiles.add(inputFileName);
059: }
060: }
061:
062: removeDoneFiles(processedFiles);
063:
064: return processSuccess;
065: }
066:
067: /**
068: * Clears out associated .done files for the processed data files.
069: */
070: private void removeDoneFiles(List<String> dataFileNames) {
071: for (String dataFileName : dataFileNames) {
072: File doneFile = new File(StringUtils.substringBeforeLast(
073: dataFileName, ".")
074: + ".done");
075: if (doneFile.exists()) {
076: doneFile.delete();
077: }
078: }
079: }
080:
081: /**
082: * Sets the batchInputFileService attribute value.
083: */
084: public void setBatchInputFileService(
085: BatchInputFileService batchInputFileService) {
086: this .batchInputFileService = batchInputFileService;
087: }
088:
089: /**
090: * Sets the procurementCardInputFileType attribute value.
091: */
092: public void setProcurementCardInputFileType(
093: BatchInputFileType procurementCardInputFileType) {
094: this .procurementCardInputFileType = procurementCardInputFileType;
095: }
096:
097: /**
098: * Sets the procurementCardLoadTransactionsService attribute value.
099: */
100: public void setProcurementCardLoadTransactionsService(
101: ProcurementCardLoadTransactionsService procurementCardLoadTransactionsService) {
102: this.procurementCardLoadTransactionsService = procurementCardLoadTransactionsService;
103: }
104: }
|