001: /*
002: * Copyright 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.chart.rules;
017:
018: import java.util.Iterator;
019: import java.util.List;
020:
021: import org.kuali.core.document.MaintenanceDocument;
022: import org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase;
023: import org.kuali.core.service.KeyValuesService;
024: import org.kuali.kfs.KFSKeyConstants;
025: import org.kuali.kfs.bo.Options;
026: import org.kuali.kfs.context.SpringContext;
027: import org.kuali.module.chart.bo.AccountingPeriod;
028:
029: /**
030: * Business rule(s) applicable to AccountingPeriodMaintence documents.
031: */
032: public class AccountingPeriodRule extends MaintenanceDocumentRuleBase {
033:
034: protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
035: .getLogger(AccountingPeriodRule.class);
036:
037: private static final String GENERAL_FUND_CD = "GF";
038: private static final String RESTRICTED_FUND_CD = "RF";
039: private static final String ENDOWMENT_FUND_CD = "EN";
040: private static final String PLANT_FUND_CD = "PF";
041:
042: private static final String RESTRICTED_CD_RESTRICTED = "R";
043: private static final String RESTRICTED_CD_UNRESTRICTED = "U";
044: private static final String RESTRICTED_CD_TEMPORARILY_RESTRICTED = "T";
045: private static final String SUB_FUND_GROUP_MEDICAL_PRACTICE_FUNDS = "MPRACT";
046: private static final String BUDGET_RECORDING_LEVEL_MIXED = "M";
047:
048: private AccountingPeriod oldAccountingPeriod;
049: private AccountingPeriod newAccountingPeriod;
050:
051: public AccountingPeriodRule() {
052: }
053:
054: /**
055: * This method sets the convenience objects like newAccount and oldAccount, so you have short and easy handles to the new and
056: * old objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load
057: * all sub-objects from the DB by their primary keys, if available.
058: *
059: * @param document - the maintenanceDocument being evaluated
060: */
061: public void setupConvenienceObjects() {
062:
063: // setup oldAccountingPeriod convenience objects, make sure all possible sub-objects are populated
064: oldAccountingPeriod = (AccountingPeriod) super .getOldBo();
065:
066: // setup newAccountingPeriod convenience objects, make sure all possible sub-objects are populated
067: newAccountingPeriod = (AccountingPeriod) super .getNewBo();
068: }
069:
070: /**
071: * This method checks the following rules: calls processCustomRouteDocumentBusinessRules but does not fail if any of them fail
072: * (this only happens on routing)
073: *
074: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
075: */
076: protected boolean processCustomSaveDocumentBusinessRules(
077: MaintenanceDocument document) {
078:
079: LOG.info("processCustomSaveDocumentBusinessRules called");
080: // call the route rules to report all of the messages, but ignore the result
081: processCustomRouteDocumentBusinessRules(document);
082:
083: // Save always succeeds, even if there are business rule failures
084: return true;
085: }
086:
087: /**
088: * This method checks to see if the fiscal year for any of {@link Options} is the same as the {@link AccountingPeriod}'s fiscal
089: * year
090: *
091: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
092: */
093: protected boolean processCustomRouteDocumentBusinessRules(
094: MaintenanceDocument document) {
095:
096: LOG.info("processCustomRouteDocumentBusinessRules called");
097: setupConvenienceObjects();
098:
099: Boolean foundYear = false;
100:
101: KeyValuesService boService = SpringContext
102: .getBean(KeyValuesService.class);
103: List optionList = (List) boService.findAll(Options.class);
104: for (Iterator iter = optionList.iterator(); iter.hasNext();) {
105: Options options = (Options) iter.next();
106: if (options.getUniversityFiscalYear().compareTo(
107: newAccountingPeriod.getUniversityFiscalYear()) == 0) {
108: foundYear = true;
109: break;
110: }
111: }
112:
113: if (!foundYear) {
114: // display an error
115: putFieldError(
116: "universityFiscalYear",
117: KFSKeyConstants.ERROR_DOCUMENT_FISCAL_PERIOD_YEAR_DOESNT_EXIST);
118: }
119:
120: return foundYear;
121: }
122:
123: }
|