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.module.ld.batch;
017    
018    import java.util.Date;
019    import java.util.List;
020    
021    import org.apache.commons.lang.StringUtils;
022    import org.kuali.kfs.coa.service.ChartService;
023    import org.kuali.kfs.module.ld.LaborConstants;
024    import org.kuali.kfs.module.ld.service.LaborLedgerEntryService;
025    import org.kuali.kfs.sys.batch.AbstractStep;
026    
027    /**
028     * The step is used to remove the labor ledger entries posted before the given year from database
029     */
030    public class LaborPurgeEntryStep extends AbstractStep {
031        private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LaborPurgeEntryStep.class);
032    
033        private ChartService chartService;
034        private LaborLedgerEntryService laborLedgerEntryService;
035    
036        /**
037         * @see org.kuali.kfs.sys.batch.Step#execute(java.lang.String, java.util.Date)
038         */
039        public boolean execute(String jobName, Date jobRunDate) throws InterruptedException {
040            String fiscalYearAsString = getParameterService().getParameterValue(getClass(), LaborConstants.PurgeJob.PURGE_LEDGER_ENTRY_YEAR);
041            LOG.info("Purge labor entries posted before the year: " + fiscalYearAsString);
042    
043            Integer fiscalYear = Integer.parseInt(StringUtils.trim(fiscalYearAsString));
044            
045            List<String> allChartOfAccountsCode = chartService.getAllChartCodes();
046            for (String chartOfAccountsCode : allChartOfAccountsCode) {
047                laborLedgerEntryService.deleteLedgerEntriesPriorToYear(fiscalYear, chartOfAccountsCode);
048            }
049    
050            return true;
051        }
052    
053        /**
054         * Sets the chartService attribute value.
055         * 
056         * @param chartService The chartService to set.
057         */
058        public void setChartService(ChartService chartService) {
059            this.chartService = chartService;
060        }
061    
062        /**
063         * Sets the laborLedgerEntryService attribute value.
064         * 
065         * @param laborLedgerEntryService The laborLedgerEntryService to set.
066         */
067        public void setLaborLedgerEntryService(LaborLedgerEntryService laborLedgerEntryService) {
068            this.laborLedgerEntryService = laborLedgerEntryService;
069        }
070    }