001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.gl.batch;
017:
018: import java.sql.Date;
019: import java.text.DateFormat;
020: import java.text.ParseException;
021: import java.text.SimpleDateFormat;
022: import java.util.HashMap;
023: import java.util.Map;
024:
025: import org.kuali.kfs.batch.AbstractStep;
026: import org.kuali.kfs.service.impl.ParameterConstants;
027: import org.kuali.module.gl.GLConstants;
028: import org.kuali.module.gl.batch.closing.year.service.YearEndService;
029: import org.kuali.module.gl.bo.OriginEntryGroup;
030: import org.kuali.module.gl.bo.OriginEntrySource;
031: import org.kuali.module.gl.service.OriginEntryGroupService;
032: import org.springframework.util.StopWatch;
033:
034: /**
035: * The step tha truns the year end nominal activity closing process.
036: */
037: public class NominalActivityClosingStep extends AbstractStep {
038: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
039: .getLogger(NominalActivityClosingStep.class);
040: private YearEndService yearEndService;
041: private OriginEntryGroupService originEntryGroupService;
042:
043: public static final String TRANSACTION_DATE_FORMAT_STRING = "yyyy-MM-dd";
044:
045: /**
046: * Runs the nominal activity process, including retrieving system parameters for the process, creating the origin entry group
047: * for output origin entries, and generating reports based on the run
048: *
049: * @param jobName the name of the job this step is being run as part of
050: * @return true if the job completed successfully, false if otherwise
051: * @see org.kuali.kfs.batch.Step#performStep()
052: */
053: public boolean execute(String jobName) {
054: StopWatch stopWatch = new StopWatch();
055: stopWatch.start(jobName);
056:
057: Date varTransactionDate;
058: try {
059: DateFormat transactionDateFormat = new SimpleDateFormat(
060: TRANSACTION_DATE_FORMAT_STRING);
061: varTransactionDate = new Date(
062: transactionDateFormat
063: .parse(
064: getParameterService()
065: .getParameterValue(
066: ParameterConstants.GENERAL_LEDGER_BATCH.class,
067: GLConstants.ANNUAL_CLOSING_TRANSACTION_DATE_PARM))
068: .getTime());
069: } catch (ParseException e) {
070: LOG
071: .error(
072: "forwardBalances() Unable to parse transaction date",
073: e);
074: throw new IllegalArgumentException(
075: "Unable to parse transaction date");
076: }
077: Integer varFiscalYear = new Integer(getParameterService()
078: .getParameterValue(
079: ParameterConstants.GENERAL_LEDGER_BATCH.class,
080: GLConstants.ANNUAL_CLOSING_FISCAL_YEAR_PARM));
081: OriginEntryGroup nominalClosingOriginEntryGroup = originEntryGroupService
082: .createGroup(
083: varTransactionDate,
084: OriginEntrySource.YEAR_END_CLOSE_NOMINAL_BALANCES,
085: true, false, true);
086: Map nominalClosingJobParameters = new HashMap();
087: nominalClosingJobParameters.put(
088: GLConstants.ColumnNames.UNIV_DT, varTransactionDate);
089: nominalClosingJobParameters.put(
090: GLConstants.ColumnNames.UNIVERSITY_FISCAL_YEAR,
091: varFiscalYear);
092: Map<String, Integer> nominalActivityClosingCounts = new HashMap<String, Integer>();
093:
094: yearEndService.closeNominalActivity(
095: nominalClosingOriginEntryGroup,
096: nominalClosingJobParameters,
097: nominalActivityClosingCounts);
098:
099: yearEndService.generateCloseNominalActivityReports(
100: nominalClosingOriginEntryGroup,
101: nominalClosingJobParameters,
102: nominalActivityClosingCounts);
103:
104: stopWatch.stop();
105: LOG.info(jobName + " took "
106: + (stopWatch.getTotalTimeSeconds() / 60.0)
107: + " minutes to complete");
108:
109: return true;
110: }
111:
112: /**
113: * Sets the yearEndService attribute, allowing the injection of an implementation of the service
114: *
115: * @param yearEndService the year end service to set
116: * @see org.kuali.module.gl.service.YearEndService
117: */
118: public void setYearEndService(YearEndService yearEndService) {
119: this .yearEndService = yearEndService;
120: }
121:
122: /**
123: * This method returns the YearEndService object associated with this step
124: *
125: * @return the yearEndService this step is using to complete its process
126: * @see org.kuali.module.gl.service.YearEndSErvice
127: */
128: public YearEndService getYearEndService() {
129: return yearEndService;
130: }
131:
132: /**
133: * Sets the originEntryGroupService attribute value.
134: *
135: * @param originEntryGroupService The originEntryGroupService to set.
136: * @see org.kuali.module.gl.service.OriginEntryGroupService
137: */
138: public void setOriginEntryGroupService(
139: OriginEntryGroupService originEntryGroupService) {
140: this.originEntryGroupService = originEntryGroupService;
141: }
142: }
|