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.Date;
019    import java.util.HashMap;
020    import java.util.Map;
021    
022    import org.kuali.kfs.gl.GeneralLedgerConstants;
023    import org.kuali.kfs.gl.batch.service.OrganizationReversionProcessService;
024    import org.kuali.kfs.gl.batch.service.YearEndService;
025    import org.kuali.kfs.sys.KFSConstants;
026    import org.kuali.kfs.sys.batch.AbstractWrappedBatchStep;
027    import org.kuali.kfs.sys.batch.service.WrappedBatchExecutorService.CustomBatchExecutor;
028    import org.kuali.kfs.sys.context.SpringContext;
029    import org.springframework.util.StopWatch;
030    
031    /**
032     * A step that runs the reversion and carry forward process. The beginning of year version of the process is supposed to be run at
033     * the beginning of a fiscal year, and therefore, it uses prior year accounts instead of current year accounts.
034     */
035    public class OrganizationReversionCurrentYearAccountStep extends AbstractWrappedBatchStep {
036        private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OrganizationReversionCurrentYearAccountStep.class);
037        private OrganizationReversionProcessService organizationReversionProcessService;
038        private YearEndService yearEndService;
039    
040        /**
041         * @see org.kuali.kfs.sys.batch.AbstractWrappedBatchStep#getCustomBatchExecutor()
042         */
043        @Override
044        protected CustomBatchExecutor getCustomBatchExecutor() {
045            return new CustomBatchExecutor() {
046                /**
047                 * Runs the organization reversion process, retrieving parameter, creating the origin entry group for output entries, and
048                 * generating the reports on the process.
049                 * @return true if the job completed successfully, false if otherwise
050                 * @see org.kuali.kfs.sys.batch.Step#execute(String, java.util.Date)
051                 */
052                public boolean execute() {
053                    StopWatch stopWatch = new StopWatch();
054                    stopWatch.start("OrganizationReversionCurrentYearAccountStep");
055    
056                    Map jobParameters = organizationReversionProcessService.getJobParameters();
057                    Map<String, Integer> organizationReversionCounts = new HashMap<String, Integer>();
058    
059                    getYearEndService().logAllMissingSubFundGroups((Integer) jobParameters.get(KFSConstants.UNIV_FISCAL_YR));
060    
061                    getOrganizationReversionProcessService().organizationReversionCurrentYearAccountProcess(jobParameters, organizationReversionCounts);
062    
063                    stopWatch.stop();
064                    LOG.info("OrganizationReversionCurrentYearAccountStep took " + (stopWatch.getTotalTimeSeconds() / 60.0) + " minutes to complete");
065                    return true;
066                }
067            };
068        }
069        
070        /**
071         * Sets the organizationReversionProcessService (not to be confused with the OrganizationReversionService, which doesn't do a
072         * process, but which does all the database stuff associated with OrganizationReversion records; it's off in Chart), which
073         * allows the injection of an implementation of the service.
074         * 
075         * @param organizationReversionProcessService the implementation of the organizationReversionProcessService to set
076         * @see org.kuali.kfs.gl.batch.service.OrganizationReversionProcessService
077         */
078        public void setOrganizationReversionProcessService(OrganizationReversionProcessService organizationReversionProcessService) {
079            this.organizationReversionProcessService = organizationReversionProcessService;
080        }
081        
082        /**
083         * Gets the yearEndService attribute. 
084         * @return Returns the yearEndService.
085         */
086        public YearEndService getYearEndService() {
087            return yearEndService;
088        }
089    
090        /**
091         * Sets the yearEndService attribute value.
092         * @param yearEndService The yearEndService to set.
093         */
094        public void setYearEndService(YearEndService yearEndService) {
095            this.yearEndService = yearEndService;
096        }
097    
098        /**
099         * Gets the organizationReversionProcessService attribute. 
100         * @return Returns the organizationReversionProcessService.
101         */
102        public OrganizationReversionProcessService getOrganizationReversionProcessService() {
103            return organizationReversionProcessService;
104        }
105    }