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.LaborLedgerBalanceService; 025 import org.kuali.kfs.sys.batch.AbstractStep; 026 027 /** 028 * The step is used to remove the labor ledger balances posted before the given year from database 029 */ 030 public class LaborPurgeBalanceStep extends AbstractStep { 031 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LaborPurgeBalanceStep.class); 032 033 private ChartService chartService; 034 private LaborLedgerBalanceService laborLedgerBalanceService; 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_BALANCE_YEAR); 041 LOG.info("Purge labor balances 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 laborLedgerBalanceService.deleteLedgerBalancesPriorToYear(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 laborLedgerBalanceService attribute value. 064 * 065 * @param laborLedgerBalanceService The laborLedgerBalanceService to set. 066 */ 067 public void setLaborLedgerBalanceService(LaborLedgerBalanceService laborLedgerBalanceService) { 068 this.laborLedgerBalanceService = laborLedgerBalanceService; 069 } 070 }