View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.gl.batch;
20  
21  import java.sql.Date;
22  import java.text.DateFormat;
23  import java.text.ParseException;
24  import java.text.SimpleDateFormat;
25  import java.util.HashMap;
26  import java.util.Map;
27  
28  import org.kuali.kfs.gl.GeneralLedgerConstants;
29  import org.kuali.kfs.gl.batch.service.YearEndService;
30  import org.kuali.kfs.sys.batch.AbstractWrappedBatchStep;
31  import org.kuali.kfs.sys.batch.service.WrappedBatchExecutorService.CustomBatchExecutor;
32  import org.kuali.kfs.sys.service.impl.KfsParameterConstants;
33  import org.springframework.util.StopWatch;
34  
35  /**
36   * The step that runs the year end nominal activity closing process.
37   */
38  public class NominalActivityClosingStep extends AbstractWrappedBatchStep {
39      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(NominalActivityClosingStep.class);
40      private YearEndService yearEndService;
41  
42      public static final String TRANSACTION_DATE_FORMAT_STRING = "yyyy-MM-dd";
43  
44      /**
45       * @see org.kuali.kfs.sys.batch.AbstractWrappedBatchStep#getCustomBatchExecutor()
46       */
47      @Override
48      protected CustomBatchExecutor getCustomBatchExecutor() {
49          return new CustomBatchExecutor() {
50              /**
51               * Runs the nominal activity process, including retrieving system parameters for the process, creating the origin entry group
52               * for output origin entries, and generating reports based on the run
53               * @return true if the step completed successfully, false if otherwise
54               * @see org.kuali.kfs.sys.batch.Step#performStep()
55               */
56              public boolean execute() {
57                  StopWatch stopWatch = new StopWatch();
58                  stopWatch.start("NominalActivityClosingStep");
59  
60                  Date varTransactionDate;
61                  try {
62                      DateFormat transactionDateFormat = new SimpleDateFormat(TRANSACTION_DATE_FORMAT_STRING);
63                      varTransactionDate = new Date(transactionDateFormat.parse(getParameterService().getParameterValueAsString(KfsParameterConstants.GENERAL_LEDGER_BATCH.class, GeneralLedgerConstants.ANNUAL_CLOSING_TRANSACTION_DATE_PARM)).getTime());
64                  }
65                  catch (ParseException e) {
66                      LOG.error("forwardBalances() Unable to parse transaction date", e);
67                      throw new IllegalArgumentException("Unable to parse transaction date");
68                  }
69                  Integer varFiscalYear = new Integer(getParameterService().getParameterValueAsString(KfsParameterConstants.GENERAL_LEDGER_BATCH.class, GeneralLedgerConstants.ANNUAL_CLOSING_FISCAL_YEAR_PARM));
70                  String nominalClosingFileName = GeneralLedgerConstants.BatchFileSystem.CLOSE_NOMINAL_ACTIVITY_FILE + GeneralLedgerConstants.BatchFileSystem.EXTENSION;
71                  
72                  Map nominalClosingJobParameters = new HashMap();
73                  nominalClosingJobParameters.put(GeneralLedgerConstants.ColumnNames.UNIV_DT, varTransactionDate);
74                  nominalClosingJobParameters.put(GeneralLedgerConstants.ColumnNames.UNIVERSITY_FISCAL_YEAR, varFiscalYear);
75                  Map<String, Integer> nominalActivityClosingCounts = new HashMap<String, Integer>();
76  
77                  yearEndService.closeNominalActivity(nominalClosingFileName, nominalClosingJobParameters);
78                  stopWatch.stop();
79                  LOG.info("NominalActivityClosingStep took " + (stopWatch.getTotalTimeSeconds() / 60.0) + " minutes to complete");
80  
81                  return true;
82              }
83          };
84      }
85  
86      /**
87       * Sets the yearEndService attribute, allowing the injection of an implementation of the service
88       * 
89       * @param yearEndService the year end service to set
90       * @see org.kuali.module.gl.service.YearEndService
91       */
92      public void setYearEndService(YearEndService yearEndService) {
93          this.yearEndService = yearEndService;
94      }
95  
96      /**
97       * This method returns the YearEndService object associated with this step
98       * 
99       * @return the yearEndService this step is using to complete its process
100      * @see org.kuali.module.gl.service.YearEndSErvice
101      */
102     public YearEndService getYearEndService() {
103         return yearEndService;
104     }
105 }