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 end of year version of the process is supposed to be run before the
033     * end of a fiscal year for reporting purposes; therefore, it uses current year accounts instead of prior year accounts.
034     */
035    public class OrganizationReversionPriorYearAccountStep extends AbstractWrappedBatchStep {
036        private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OrganizationReversionPriorYearAccountStep.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(java.lang.String)
051                 */
052                public boolean execute() {
053                    StopWatch stopWatch = new StopWatch();
054                    stopWatch.start("OrganizationReversionPriorYearAccountStep");
055    
056                    Map jobParameters = organizationReversionProcessService.getJobParameters();
057                    Map<String, Integer> organizationReversionCounts = new HashMap<String, Integer>();
058                    
059                    getYearEndService().logAllMissingPriorYearAccounts((Integer) jobParameters.get(KFSConstants.UNIV_FISCAL_YR));
060                    getYearEndService().logAllMissingSubFundGroups((Integer) jobParameters.get(KFSConstants.UNIV_FISCAL_YR));
061    
062                    getOrganizationReversionProcessService().organizationReversionPriorYearAccountProcess(jobParameters, organizationReversionCounts);
063                    
064                    stopWatch.stop();
065                    LOG.info("OrganizationReversionPriorYearAccountStep took " + (stopWatch.getTotalTimeSeconds() / 60.0) + " minutes to complete");
066                    return true;
067                }
068            };
069        }
070    
071        /**
072         * Sets the organizationREversionProcessService (not to be confused with the OrganizationReversionService, which doesn't do a
073         * process, but which does all the database stuff associated with OrganizationReversion records; it's off in Chart), which
074         * allows the injection of an implementation of the service.
075         * 
076         * @param organizationReversionProcessService the implementation of the organizationReversionProcessService to set
077         * @see org.kuali.kfs.gl.batch.service.OrganizationReversionProcessService
078         */
079        public void setOrganizationReversionProcessService(OrganizationReversionProcessService organizationReversionProcessService) {
080            this.organizationReversionProcessService = organizationReversionProcessService;
081        }
082    
083        /**
084         * Gets the yearEndService attribute. 
085         * @return Returns the yearEndService.
086         */
087        public YearEndService getYearEndService() {
088            return yearEndService;
089        }
090    
091        /**
092         * Sets the yearEndService attribute value.
093         * @param yearEndService The yearEndService to set.
094         */
095        public void setYearEndService(YearEndService yearEndService) {
096            this.yearEndService = yearEndService;
097        }
098    
099        /**
100         * Gets the organizationReversionProcessService attribute. 
101         * @return Returns the organizationReversionProcessService.
102         */
103        public OrganizationReversionProcessService getOrganizationReversionProcessService() {
104            return organizationReversionProcessService;
105        }
106        
107    }