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  import java.util.HashMap;
23  import java.util.Map;
24  
25  import org.kuali.ole.gl.GeneralLedgerConstants;
26  import org.kuali.ole.gl.batch.service.YearEndService;
27  import org.kuali.ole.sys.batch.AbstractWrappedBatchStep;
28  import org.kuali.ole.sys.batch.service.WrappedBatchExecutorService.CustomBatchExecutor;
29  import org.kuali.ole.sys.service.impl.OleParameterConstants;
30  import org.springframework.util.StopWatch;
31  
32  /**
33   * A step to run the year end process of forwarding encumbrances into the next fiscal year
34   */
35  public class EncumbranceForwardStep extends AbstractWrappedBatchStep {
36      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(EncumbranceForwardStep.class);
37      private YearEndService yearEndService;
38  
39      public static final String TRANSACTION_DATE_FORMAT_STRING = "yyyy-MM-dd";
40  
41      /**
42       * @see org.kuali.ole.sys.batch.AbstractWrappedBatchStep#getCustomBatchExecutor()
43       */
44      @Override
45      protected CustomBatchExecutor getCustomBatchExecutor() {
46          return new CustomBatchExecutor() {
47              /**
48               * This step runs the forward encumbrance process, including retrieving the parameters needed to run the job, creating the
49               * origin entry group where output origin entries will go, and having the job's reports generated.
50               * 
51               * @return true if the step completed successfully, false if otherwise
52               * @see org.kuali.ole.sys.batch.Step#performStep()
53               */
54              public boolean execute() {
55                  StopWatch stopWatch = new StopWatch();
56                  stopWatch.start("EncumbranceForwardStep");
57  
58                  Map jobParameters = new HashMap();
59                  Integer varFiscalYear = null;
60                  Date varTransactionDate = null;
61  
62                  String FIELD_FISCAL_YEAR = GeneralLedgerConstants.ColumnNames.UNIVERSITY_FISCAL_YEAR;
63                  String FIELD_TRANSACTION_DATE = GeneralLedgerConstants.ColumnNames.TRANSACTION_DT;
64  
65                  // Get the current fiscal year.
66                  varFiscalYear = new Integer(getParameterService().getParameterValueAsString(OleParameterConstants.GENERAL_LEDGER_BATCH.class, GeneralLedgerConstants.ANNUAL_CLOSING_FISCAL_YEAR_PARM));
67  
68                  // Get the current date (transaction date).
69                  try {
70                      DateFormat transactionDateFormat = new SimpleDateFormat(TRANSACTION_DATE_FORMAT_STRING);
71                      varTransactionDate = new Date(transactionDateFormat.parse(getParameterService().getParameterValueAsString(OleParameterConstants.GENERAL_LEDGER_BATCH.class, GeneralLedgerConstants.ANNUAL_CLOSING_TRANSACTION_DATE_PARM)).getTime());
72                  }
73                  catch (ParseException pe) {
74                      LOG.error("Failed to parse TRANSACTION_DT from kualiConfigurationService");
75                      throw new RuntimeException("Unable to get transaction date from kualiConfigurationService", pe);
76                  }
77  
78                  jobParameters.put(GeneralLedgerConstants.ColumnNames.UNIVERSITY_FISCAL_YEAR, varFiscalYear);
79                  jobParameters.put(GeneralLedgerConstants.ColumnNames.UNIV_DT, varTransactionDate);
80  
81                  String encumbranceForwardFileName = GeneralLedgerConstants.BatchFileSystem.ENCUMBRANCE_FORWARD_FILE + GeneralLedgerConstants.BatchFileSystem.EXTENSION;
82                  Map<String, Integer> forwardEncumbranceCounts = new HashMap<String, Integer>();
83  
84                  yearEndService.forwardEncumbrances(encumbranceForwardFileName, jobParameters, forwardEncumbranceCounts);
85  
86                  stopWatch.stop();
87                  LOG.info("EncumbranceForwardStep took " + (stopWatch.getTotalTimeSeconds() / 60.0) + " minutes to complete");
88  
89                  return true;
90              }
91          };
92      }
93  
94      /**
95       * Sets the yearEndService attribute, allowing the injection of an implementation of that service
96       * 
97       * @param yearEndService the yearEndService to set
98       * @see org.kuali.module.gl.service.YearEndService
99       */
100     public void setYearEndService(YearEndService yearEndService) {
101         this.yearEndService = yearEndService;
102     }
103 }