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:
023: import org.kuali.kfs.batch.AbstractStep;
024: import org.kuali.kfs.service.impl.ParameterConstants;
025: import org.kuali.module.gl.GLConstants;
026: import org.kuali.module.gl.batch.closing.year.service.YearEndService;
027: import org.kuali.module.gl.batch.closing.year.service.impl.helper.BalanceForwardRuleHelper;
028: import org.kuali.module.gl.bo.OriginEntryGroup;
029: import org.kuali.module.gl.bo.OriginEntrySource;
030: import org.kuali.module.gl.service.OriginEntryGroupService;
031: import org.springframework.util.StopWatch;
032:
033: /**
034: * This step runs the balance forward year end process.
035: */
036: public class BalanceForwardStep extends AbstractStep {
037: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
038: .getLogger(BalanceForwardStep.class);
039:
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 balance forward service, specifically finding the parameters the job needs, creating the origin entry
047: * groups for the output origin entries, and creating the process's reports.
048: *
049: * @param jobName the name of the job that this step is a part of
050: * @return that the job finished successfully
051: * @see org.kuali.kfs.batch.Step#execute(java.lang.String)
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:
078: Integer varFiscalYear = new Integer(getParameterService()
079: .getParameterValue(
080: ParameterConstants.GENERAL_LEDGER_BATCH.class,
081: GLConstants.ANNUAL_CLOSING_FISCAL_YEAR_PARM));
082:
083: yearEndService.logAllMissingPriorYearAccounts(varFiscalYear);
084: yearEndService.logAllMissingSubFundGroups(varFiscalYear);
085:
086: OriginEntryGroup balanceForwardsUnclosedPriorYearAccountGroup = originEntryGroupService
087: .createGroup(varTransactionDate,
088: OriginEntrySource.YEAR_END_BEGINNING_BALANCE,
089: true, false, true);
090: OriginEntryGroup balanceForwardsClosedPriorYearAccountGroup = originEntryGroupService
091: .createGroup(
092: varTransactionDate,
093: OriginEntrySource.YEAR_END_BEGINNING_BALANCE_PRIOR_YEAR,
094: true, false, true);
095:
096: BalanceForwardRuleHelper balanceForwardRuleHelper = new BalanceForwardRuleHelper(
097: varFiscalYear, varTransactionDate,
098: balanceForwardsClosedPriorYearAccountGroup,
099: balanceForwardsUnclosedPriorYearAccountGroup);
100:
101: yearEndService.forwardBalances(
102: balanceForwardsUnclosedPriorYearAccountGroup,
103: balanceForwardsClosedPriorYearAccountGroup,
104: balanceForwardRuleHelper);
105:
106: yearEndService.generateForwardBalanceReports(
107: balanceForwardsUnclosedPriorYearAccountGroup,
108: balanceForwardsClosedPriorYearAccountGroup,
109: balanceForwardRuleHelper);
110:
111: stopWatch.stop();
112: LOG.info(jobName + " took "
113: + (stopWatch.getTotalTimeSeconds() / 60.0)
114: + " minutes to complete");
115:
116: return true;
117: }
118:
119: /**
120: * Sets the yearEndService attribute, allowing injection of an implementation of the service
121: *
122: * @param yearEndService an implementation of the yearEndService
123: * @see org.kuali.module.gl.service.yearEndService
124: */
125: public void setYearEndService(YearEndService yearEndService) {
126: this .yearEndService = yearEndService;
127: }
128:
129: /**
130: * Sets the originEntryGroupService attribute value.
131: *
132: * @param originEntryGroupService The originEntryGroupService to set.
133: * @see org.kuali.module.gl.service.OriginEntryGroupService
134: */
135: public void setOriginEntryGroupService(
136: OriginEntryGroupService originEntryGroupService) {
137: this.originEntryGroupService = originEntryGroupService;
138: }
139: }
|