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: * A step to run the year end process of forwarding encumbrances into the next fiscal year
036: */
037: public class EncumbranceForwardStep extends AbstractStep {
038: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
039: .getLogger(EncumbranceForwardStep.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: * This step runs the forward encumbrance process, including retrieving the parameters needed to run the job, creating the
047: * origin entry group where output origin entries will go, and having the job's reports generated.
048: *
049: * @jobName the name of the job that 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: Map jobParameters = new HashMap();
058: Integer varFiscalYear = null;
059: Date varTransactionDate = null;
060:
061: String FIELD_FISCAL_YEAR = GLConstants.ColumnNames.UNIVERSITY_FISCAL_YEAR;
062: String FIELD_TRANSACTION_DATE = GLConstants.ColumnNames.TRANSACTION_DT;
063:
064: // Get the current fiscal year.
065: varFiscalYear = new Integer(getParameterService()
066: .getParameterValue(
067: ParameterConstants.GENERAL_LEDGER_BATCH.class,
068: GLConstants.ANNUAL_CLOSING_FISCAL_YEAR_PARM));
069:
070: // Get the current date (transaction date).
071: try {
072: DateFormat transactionDateFormat = new SimpleDateFormat(
073: TRANSACTION_DATE_FORMAT_STRING);
074: varTransactionDate = new Date(
075: transactionDateFormat
076: .parse(
077: getParameterService()
078: .getParameterValue(
079: ParameterConstants.GENERAL_LEDGER_BATCH.class,
080: GLConstants.ANNUAL_CLOSING_TRANSACTION_DATE_PARM))
081: .getTime());
082: } catch (ParseException pe) {
083: LOG
084: .error("Failed to parse TRANSACTION_DT from kualiConfigurationService");
085: throw new RuntimeException(
086: "Unable to get transaction date from kualiConfigurationService",
087: pe);
088: }
089:
090: jobParameters.put(
091: GLConstants.ColumnNames.UNIVERSITY_FISCAL_YEAR,
092: varFiscalYear);
093: jobParameters.put(GLConstants.ColumnNames.UNIV_DT,
094: varTransactionDate);
095:
096: OriginEntryGroup originEntryGroup = originEntryGroupService
097: .createGroup(varTransactionDate,
098: OriginEntrySource.YEAR_END_ENCUMBRANCE_CLOSING,
099: true, false, true);
100: Map<String, Integer> forwardEncumbranceCounts = new HashMap<String, Integer>();
101:
102: yearEndService.forwardEncumbrances(originEntryGroup,
103: jobParameters, forwardEncumbranceCounts);
104:
105: yearEndService.generateForwardEncumbrancesReports(
106: originEntryGroup, jobParameters,
107: forwardEncumbranceCounts);
108:
109: stopWatch.stop();
110: LOG.info(jobName + " took "
111: + (stopWatch.getTotalTimeSeconds() / 60.0)
112: + " minutes to complete");
113:
114: return true;
115: }
116:
117: /**
118: * Sets the yearEndService attribute, allowing the injection of an implementation of that service
119: *
120: * @param yearEndService the yearEndService to set
121: * @see org.kuali.module.gl.service.YearEndService
122: */
123: public void setYearEndService(YearEndService yearEndService) {
124: this .yearEndService = yearEndService;
125: }
126:
127: /**
128: * Sets the originEntryGroupService attribute value.
129: *
130: * @param originEntryGroupService The originEntryGroupService to set.
131: * @see org.kuali.module.gl.service.OriginEntryGroupService
132: */
133: public void setOriginEntryGroupService(
134: OriginEntryGroupService originEntryGroupService) {
135: this.originEntryGroupService = originEntryGroupService;
136: }
137:
138: }
|