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.Iterator;
020    import java.util.List;
021    
022    import org.kuali.kfs.coa.service.ChartService;
023    import org.kuali.kfs.gl.service.BalanceService;
024    import org.kuali.kfs.sys.KFSConstants;
025    import org.kuali.kfs.sys.batch.AbstractStep;
026    
027    /**
028     * A step to run the process of purging old balances
029     */
030    public class PurgeBalanceStep extends AbstractStep {
031        private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurgeBalanceStep.class);
032        private ChartService chartService;
033        private BalanceService balanceService;
034    
035        /**
036         * This step will purge data from the gl_encumbrance_t table older than a specified year. It purges the data one chart at a time
037         * each within their own transaction so database transaction logs don't get completely filled up when doing this. This step
038         * class should NOT be transactional.
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            String yearStr = getParameterService().getParameterValue(getClass(), KFSConstants.SystemGroupParameterNames.PURGE_GL_BALANCE_T_BEFORE_YEAR);
047            LOG.info("PurgeBalanceStep was run with year = "+yearStr);
048            int year = Integer.parseInt(yearStr);
049            List charts = chartService.getAllChartCodes();
050            for (Iterator iter = charts.iterator(); iter.hasNext();) {
051                String chart = (String) iter.next();
052                balanceService.purgeYearByChart(chart, year);
053            }
054            return true;
055        }
056    
057        /**
058         * Sets the balanceService attribute, allowing the injection of an implementation of the service.
059         * 
060         * @param chartService the balanceService implementation to set
061         * @see org.kuali.kfs.gl.service.BalanceService
062         */
063        public void setBalanceService(BalanceService balanceService) {
064            this.balanceService = balanceService;
065        }
066    
067        /**
068         * Sets the chartService attribute, allowing the injection of an implementation of the service.
069         * 
070         * @param chartService the chartService implementation to set
071         * @see org.kuali.kfs.coa.service.ChartService
072         */
073        public void setChartService(ChartService chartService) {
074            this.chartService = chartService;
075        }
076    }