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    /*
017     * Created on Apr 7, 2006
018     *
019     */
020    package org.kuali.kfs.gl.batch;
021    
022    import java.util.Date;
023    import java.util.Iterator;
024    import java.util.List;
025    
026    import org.kuali.kfs.coa.service.ChartService;
027    import org.kuali.kfs.gl.service.EntryService;
028    import org.kuali.kfs.sys.KFSConstants;
029    import org.kuali.kfs.sys.batch.AbstractStep;
030    
031    /**
032     * A step to remove old general ledger entries from the database.
033     */
034    public class PurgeEntryStep extends AbstractStep {
035        private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurgeEntryStep.class);
036        private ChartService chartService;
037        private EntryService entryService;
038    
039        /**
040         * This step will purge data from the gl_entry_t table older than a specified year. It purges the data one chart at a time each
041         * within their own transaction so database transaction logs don't get completely filled up when doing this. This step class
042         * should NOT be transactional.
043         * 
044         * @param jobName the name of the job this step is being run as part of
045         * @param jobRunDate the time/date the job was started
046         * @return true if the job completed successfully, false if otherwise
047         * @see org.kuali.kfs.sys.batch.Step#execute(String, Date)
048         */
049        public boolean execute(String jobName, Date jobRunDate) {
050            String yearStr = getParameterService().getParameterValue(PurgeEntryStep.class, KFSConstants.SystemGroupParameterNames.PURGE_GL_ENTRY_T_BEFORE_YEAR);
051            LOG.info("PurgeEntryStep was run with year = "+yearStr);
052            int year = Integer.parseInt(yearStr);
053            List charts = chartService.getAllChartCodes();
054            for (Iterator iter = charts.iterator(); iter.hasNext();) {
055                String chart = (String) iter.next();
056                entryService.purgeYearByChart(chart, year);
057            }
058            return true;
059        }
060    
061        /**
062         * Sets the entryService attribute, allowing the injection of an implementation of the service.
063         * 
064         * @param entryService the entryService implementation to set
065         * @see org.kuali.kfs.gl.service.EntryService
066         */
067        public void setEntryService(EntryService entryService) {
068            this.entryService = entryService;
069        }
070    
071        /**
072         * Sets the chartService attribute, allowing the injection of an implementation of the service.
073         * 
074         * @param chartService the chartService implementation to set
075         * @see org.kuali.kfs.coa.service.ChartService
076         */
077        public void setChartService(ChartService chartService) {
078            this.chartService = chartService;
079        }
080    }