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.util.Comparator;
019    import java.util.Date;
020    
021    import org.kuali.kfs.gl.GeneralLedgerConstants;
022    import org.kuali.kfs.gl.batch.service.BatchSortService;
023    import org.kuali.kfs.gl.exception.LoadException;
024    import org.kuali.kfs.gl.service.ScrubberService;
025    import org.kuali.kfs.sys.KFSKeyConstants;
026    import org.kuali.kfs.sys.batch.AbstractStep;
027    import org.kuali.kfs.sys.batch.AbstractWrappedBatchStep;
028    import org.kuali.kfs.sys.batch.service.WrappedBatchExecutorService.CustomBatchExecutor;
029    import org.kuali.rice.kns.util.GlobalVariables;
030    import org.springframework.util.StopWatch;
031    
032    /**
033     * A step to run the scrubber process.
034     */
035    public class DemergerStep extends AbstractWrappedBatchStep {
036        private ScrubberService scrubberService;
037        private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DemergerStep.class);
038        
039        /**
040         * Overridden to run the scrubber demerger process.
041         * @see org.kuali.kfs.batch.Step#execute(java.lang.String)
042         */
043        @Override
044        protected CustomBatchExecutor getCustomBatchExecutor() {
045            return new CustomBatchExecutor() {
046                public boolean execute() {
047                    final String jobName = "demerger";
048                    StopWatch stopWatch = new StopWatch();
049                    stopWatch.start(jobName);
050                    scrubberService.performDemerger();
051    
052                    stopWatch.stop();
053                    LOG.info("scrubber step of " + jobName + " took " + (stopWatch.getTotalTimeSeconds() / 60.0) + " minutes to complete");
054                    if (LOG.isDebugEnabled()) {
055                        LOG.debug("scrubber step of " + jobName + " took " + (stopWatch.getTotalTimeSeconds() / 60.0) + " minutes to complete");
056                    }
057                    return true;
058                }
059            };
060        }
061    
062          /**
063           * Sets the scrubberSerivce, allowing the injection of an implementation of that service
064           * 
065           * @param scrubberService the scrubberServiceService implementation to set
066           * @see org.kuali.module.gl.service.ScrubberService
067           */
068          public void setScrubberService(ScrubberService ss) {
069              scrubberService = ss;
070          }
071    }