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.businessobject.OriginEntryFieldUtil;
025    import org.kuali.kfs.sys.KFSPropertyConstants;
026    import org.kuali.kfs.sys.batch.AbstractStep;
027    import org.springframework.util.StopWatch;
028    import org.kuali.kfs.gl.batch.ScrubberSortComparator;
029    
030    /**
031     * A step to run the scrubber process.
032     */
033    public class ScrubberSortStep extends AbstractStep {
034        protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ScrubberSortStep.class);
035        protected String batchFileDirectoryName;
036        
037        /**
038         * Runs the scrubber process.
039         * 
040         * @param jobName the name of the job this step is being run as part of
041         * @param jobRunDate the time/date the job was started
042         * @return true if the job completed successfully, false if otherwise
043         * @see org.kuali.kfs.sys.batch.Step#execute(java.lang.String)
044         */
045        public boolean execute(String jobName, Date jobRunDate) {
046            StopWatch stopWatch = new StopWatch();
047            stopWatch.start(jobName);
048            String inputFile = batchFileDirectoryName + File.separator + GeneralLedgerConstants.BatchFileSystem.PRE_SCRUBBER_FILE + GeneralLedgerConstants.BatchFileSystem.EXTENSION;
049            String outputFile = batchFileDirectoryName + File.separator + GeneralLedgerConstants.BatchFileSystem.SCRUBBER_INPUT_FILE + GeneralLedgerConstants.BatchFileSystem.EXTENSION;
050            if ( new File( inputFile ).exists() ) {
051                BatchSortUtil.sortTextFileWithFields(inputFile, outputFile, new ScrubberSortComparator());
052            } else {
053                LOG.warn( "Unable to find " + inputFile + ", sorting skipped.  No output file created." );
054            }
055            stopWatch.stop();
056            if (LOG.isDebugEnabled()) {
057                LOG.debug("scrubber step of " + jobName + " took " + (stopWatch.getTotalTimeSeconds() / 60.0) + " minutes to complete");
058            }
059            return true;
060        }
061       
062        public void setBatchFileDirectoryName(String batchFileDirectoryName) {
063            this.batchFileDirectoryName = batchFileDirectoryName;
064        }
065    
066    }