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.EncumbranceService;
028 import org.kuali.kfs.sys.KFSConstants;
029 import org.kuali.kfs.sys.batch.AbstractStep;
030
031 /**
032 * A step to remove old encumbrances from the database.
033 */
034 public class PurgeEncumbranceStep extends AbstractStep {
035 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurgeEncumbranceStep.class);
036 private ChartService chartService;
037 private EncumbranceService encumbranceService;
038
039 /**
040 * 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
041 * each within their own transaction so database transaction logs don't get completely filled up when doing this. This step
042 * class 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 step completed successfully, false if otherwise
047 * @see org.kuali.kfs.sys.batch.Step#execute(String, java.util.Date)
048 */
049 public boolean execute(String jobName, Date jobRunDate) {
050 String yearStr = getParameterService().getParameterValue(getClass(), KFSConstants.SystemGroupParameterNames.PURGE_GL_ENCUMBRANCE_T_BEFORE_YEAR);
051 LOG.info("PurgeEncumbranceStep 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 encumbranceService.purgeYearByChart(chart, year);
057 }
058 return true;
059 }
060
061 /**
062 * Sets the encumbranceService attribute, allowing the injection of an implementation of the service.
063 *
064 * @param encumbranceService the encumbranceService implementation to set
065 * @see org.kuali.kfs.gl.service.EncumbranceService
066 */
067 public void setEncumbranceService(EncumbranceService encumbranceService) {
068 this.encumbranceService = encumbranceService;
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 }