001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.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/ecl2.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.kfs.gl.batch;
017    
018    import java.io.File;
019    import java.util.Comparator;
020    import java.util.Date;
021    import java.util.Map;
022    
023    import org.kuali.kfs.gl.GeneralLedgerConstants;
024    import org.kuali.kfs.gl.batch.service.BatchSortService;
025    import org.kuali.kfs.gl.businessobject.OriginEntryFieldUtil;
026    import org.kuali.kfs.gl.exception.LoadException;
027    import org.kuali.kfs.gl.service.ScrubberService;
028    import org.kuali.kfs.sys.KFSKeyConstants;
029    import org.kuali.kfs.sys.KFSPropertyConstants;
030    import org.kuali.kfs.sys.batch.AbstractStep;
031    import org.kuali.rice.kns.util.GlobalVariables;
032    import org.springframework.util.StopWatch;
033    import org.kuali.kfs.gl.batch.PosterSortComparator;
034    
035    /**
036     * A step to run the scrubber process.
037     */
038    public class PosterSortStep extends AbstractStep {
039        protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PosterSortStep.class);
040        protected String batchFileDirectoryName;
041        
042        /**
043         * Runs the scrubber process.
044         * 
045         * @param jobName the name of the job this step is being run as part of
046         * @param jobRunDate the time/date the job was started
047         * @return true if the job completed successfully, false if otherwise
048         * @see org.kuali.kfs.sys.batch.Step#execute(java.lang.String)
049         */
050        public boolean execute(String jobName, Date jobRunDate) {
051            StopWatch stopWatch = new StopWatch();
052            stopWatch.start(jobName);
053            String inputFile = batchFileDirectoryName + File.separator + GeneralLedgerConstants.BatchFileSystem.DEMERGER_VAILD_OUTPUT_FILE + GeneralLedgerConstants.BatchFileSystem.EXTENSION;
054            String outputFile = batchFileDirectoryName + File.separator + GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE + GeneralLedgerConstants.BatchFileSystem.EXTENSION; 
055            
056            BatchSortUtil.sortTextFileWithFields(inputFile, outputFile, new PosterSortComparator());
057    
058            stopWatch.stop();
059            if (LOG.isDebugEnabled()) {
060                LOG.debug("scrubber step of " + jobName + " took " + (stopWatch.getTotalTimeSeconds() / 60.0) + " minutes to complete");
061            }
062            return true;
063        }
064        
065        public void setBatchFileDirectoryName(String batchFileDirectoryName) {
066            this.batchFileDirectoryName = batchFileDirectoryName;
067        }
068    
069    }