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.sql.Date;
19  import java.text.DateFormat;
20  import java.text.ParseException;
21  import java.text.SimpleDateFormat;
22  
23  import org.kuali.ole.gl.GeneralLedgerConstants;
24  import org.kuali.ole.gl.batch.service.YearEndService;
25  import org.kuali.ole.sys.batch.AbstractWrappedBatchStep;
26  import org.kuali.ole.sys.batch.service.WrappedBatchExecutorService.CustomBatchExecutor;
27  import org.kuali.ole.sys.service.impl.OleParameterConstants;
28  import org.springframework.util.StopWatch;
29  
30  /**
31   * This step runs the balance forward year end process.
32   */
33  public class BalanceForwardStep extends AbstractWrappedBatchStep {
34      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BalanceForwardStep.class);
35  
36      private YearEndService yearEndService;
37  
38      public static final String TRANSACTION_DATE_FORMAT_STRING = "yyyy-MM-dd";
39  
40      /**
41       * @see org.kuali.ole.sys.batch.AbstractWrappedBatchStep#getCustomBatchExecutor()
42       */
43      @Override
44      protected CustomBatchExecutor getCustomBatchExecutor() {
45          return new CustomBatchExecutor() {
46              /**
47               * This step runs the balance forward service, specifically finding the parameters the job needs, creating the origin entry
48               * groups for the output origin entries, and creating the process's reports.
49               * @return that the job finished successfully
50               * @see org.kuali.ole.sys.batch.Step#execute(String, java.util.Date)
51               */
52              public boolean execute() {
53                  StopWatch stopWatch = new StopWatch();
54                  stopWatch.start("Balance Forward Step");
55  
56                  Date varTransactionDate;
57                  try {
58                      DateFormat transactionDateFormat = new SimpleDateFormat(TRANSACTION_DATE_FORMAT_STRING);
59                      varTransactionDate = new Date(transactionDateFormat.parse(getParameterService().getParameterValueAsString(OleParameterConstants.GENERAL_LEDGER_BATCH.class, GeneralLedgerConstants.ANNUAL_CLOSING_TRANSACTION_DATE_PARM)).getTime());
60                  }
61                  catch (ParseException e) {
62                      LOG.error("forwardBalances() Unable to parse transaction date", e);
63                      throw new IllegalArgumentException("Unable to parse transaction date");
64                  }
65  
66                  Integer varFiscalYear = new Integer(getParameterService().getParameterValueAsString(OleParameterConstants.GENERAL_LEDGER_BATCH.class, GeneralLedgerConstants.ANNUAL_CLOSING_FISCAL_YEAR_PARM));
67  
68                  yearEndService.logAllMissingPriorYearAccounts(varFiscalYear);
69                  yearEndService.logAllMissingSubFundGroups(varFiscalYear);
70  
71                  String balanceForwardsUnclosedFileName = GeneralLedgerConstants.BatchFileSystem.BALANCE_FORWARDS_FILE + GeneralLedgerConstants.BatchFileSystem.EXTENSION; 
72                  String balanceForwardsclosedFileName = GeneralLedgerConstants.BatchFileSystem.BALANCE_FORWARDS_CLOSED_FILE + GeneralLedgerConstants.BatchFileSystem.EXTENSION;
73                  
74                  BalanceForwardRuleHelper balanceForwardRuleHelper = new BalanceForwardRuleHelper(varFiscalYear, varTransactionDate, balanceForwardsclosedFileName, balanceForwardsUnclosedFileName);
75  
76                  yearEndService.forwardBalances(balanceForwardsUnclosedFileName, balanceForwardsclosedFileName, balanceForwardRuleHelper);
77  
78                  stopWatch.stop();
79                  LOG.info("Balance Forward Step took " + (stopWatch.getTotalTimeSeconds() / 60.0) + " minutes to complete");
80  
81                  return true;
82              }
83          };
84      }
85  
86      /**
87       * Sets the yearEndService attribute, allowing injection of an implementation of the service
88       * 
89       * @param yearEndService an implementation of the yearEndService
90       * @see org.kuali.module.gl.service.yearEndService
91       */
92      public void setYearEndService(YearEndService yearEndService) {
93          this.yearEndService = yearEndService;
94      }
95  }