View Javadoc
1   /*
2    * Copyright 2006 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.gl.batch;
17  
18  import java.util.Date;
19  import java.util.Iterator;
20  import java.util.List;
21  
22  import org.kuali.ole.coa.service.ChartService;
23  import org.kuali.ole.gl.service.AccountBalanceService;
24  import org.kuali.ole.sys.OLEConstants;
25  import org.kuali.ole.sys.batch.AbstractStep;
26  
27  /**
28   * A step to run the process that purges old data from gl_acct_balances_t.
29   */
30  public class PurgeAccountBalancesStep extends AbstractStep {
31      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurgeAccountBalancesStep.class);
32      private ChartService chartService;
33      private AccountBalanceService accountBalanceService;
34  
35      /**
36       * This step will purge data from the gl_acct_balances_t table older than a specified year. It purges the data one chart at a
37       * time each within their own transaction so database transaction logs don't get completely filled up when doing this. This step
38       * class should NOT be transactional.
39       * 
40       * @param jobName the name of the job this step is being run as part of
41       * @param jobRunDate the time/date the job was started
42       * @return true if the job completed successfully, false if otherwise
43       * @see org.kuali.ole.sys.batch.Step#execute(java.lang.String)
44       */
45      public boolean execute(String jobName, Date jobRunDate) {
46          String yearStr = getParameterService().getParameterValueAsString(getClass(), OLEConstants.SystemGroupParameterNames.PURGE_GL_ACCT_BALANCES_T_BEFORE_YEAR);
47          LOG.info("PurgeAccountBalancesStep was run with year = "+yearStr);
48          int year = Integer.parseInt(yearStr);
49          List charts = chartService.getAllChartCodes();
50          for (Iterator iter = charts.iterator(); iter.hasNext();) {
51              String chart = (String) iter.next();
52              accountBalanceService.purgeYearByChart(chart, year);
53          }
54          return true;
55      }
56  
57      /**
58       * Sets the accountBalanceService attribute, allowing the injection of an implementation of the service.
59       * 
60       * @param accountBalanceService the accountBalanceService implementation to set
61       * @see org.kuali.ole.gl.service.AccountBalanceService
62       */
63      public void setAccountBalanceService(AccountBalanceService accountBalanceService) {
64          this.accountBalanceService = accountBalanceService;
65      }
66  
67      /**
68       * Sets the chartService attribute, allowing the injection of an implementation of the service.
69       * 
70       * @param chartService the chartService implementation to set
71       * @see org.kuali.ole.coa.service.ChartService
72       */
73      public void setChartService(ChartService chartService) {
74          this.chartService = chartService;
75      }
76  }