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   * The step that runs the year end nominal activity closing process.
34   */
35  public class NominalActivityClosingStep extends AbstractWrappedBatchStep {
36      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(NominalActivityClosingStep.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               * Runs the nominal activity process, including retrieving system parameters for the process, creating the origin entry group
49               * for output origin entries, and generating reports based on the run
50               * @return true if the step completed successfully, false if otherwise
51               * @see org.kuali.ole.sys.batch.Step#performStep()
52               */
53              public boolean execute() {
54                  StopWatch stopWatch = new StopWatch();
55                  stopWatch.start("NominalActivityClosingStep");
56  
57                  Date varTransactionDate;
58                  try {
59                      DateFormat transactionDateFormat = new SimpleDateFormat(TRANSACTION_DATE_FORMAT_STRING);
60                      varTransactionDate = new Date(transactionDateFormat.parse(getParameterService().getParameterValueAsString(OleParameterConstants.GENERAL_LEDGER_BATCH.class, GeneralLedgerConstants.ANNUAL_CLOSING_TRANSACTION_DATE_PARM)).getTime());
61                  }
62                  catch (ParseException e) {
63                      LOG.error("forwardBalances() Unable to parse transaction date", e);
64                      throw new IllegalArgumentException("Unable to parse transaction date");
65                  }
66                  Integer varFiscalYear = new Integer(getParameterService().getParameterValueAsString(OleParameterConstants.GENERAL_LEDGER_BATCH.class, GeneralLedgerConstants.ANNUAL_CLOSING_FISCAL_YEAR_PARM));
67                  String nominalClosingFileName = GeneralLedgerConstants.BatchFileSystem.CLOSE_NOMINAL_ACTIVITY_FILE + GeneralLedgerConstants.BatchFileSystem.EXTENSION;
68                  
69                  Map nominalClosingJobParameters = new HashMap();
70                  nominalClosingJobParameters.put(GeneralLedgerConstants.ColumnNames.UNIV_DT, varTransactionDate);
71                  nominalClosingJobParameters.put(GeneralLedgerConstants.ColumnNames.UNIVERSITY_FISCAL_YEAR, varFiscalYear);
72                  Map<String, Integer> nominalActivityClosingCounts = new HashMap<String, Integer>();
73  
74                  yearEndService.closeNominalActivity(nominalClosingFileName, nominalClosingJobParameters);
75                  stopWatch.stop();
76                  LOG.info("NominalActivityClosingStep took " + (stopWatch.getTotalTimeSeconds() / 60.0) + " minutes to complete");
77  
78                  return true;
79              }
80          };
81      }
82  
83      /**
84       * Sets the yearEndService attribute, allowing the injection of an implementation of the service
85       * 
86       * @param yearEndService the year end service to set
87       * @see org.kuali.module.gl.service.YearEndService
88       */
89      public void setYearEndService(YearEndService yearEndService) {
90          this.yearEndService = yearEndService;
91      }
92  
93      /**
94       * This method returns the YearEndService object associated with this step
95       * 
96       * @return the yearEndService this step is using to complete its process
97       * @see org.kuali.module.gl.service.YearEndSErvice
98       */
99      public YearEndService getYearEndService() {
100         return yearEndService;
101     }
102 }