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.chart.rules;
017:
018: import org.kuali.core.document.MaintenanceDocument;
019: import org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase;
020: import org.kuali.core.util.ObjectUtils;
021: import org.kuali.kfs.KFSConstants;
022: import org.kuali.kfs.KFSKeyConstants;
023: import org.kuali.kfs.context.SpringContext;
024: import org.kuali.kfs.service.ParameterEvaluator;
025: import org.kuali.kfs.service.ParameterService;
026: import org.kuali.module.chart.bo.OffsetDefinition;
027:
028: /**
029: *
030: * This class implements the business rules for {@link OffsetDefinition}
031: */
032: public class OffsetDefinitionRule extends MaintenanceDocumentRuleBase {
033: private OffsetDefinition oldDefinition;
034: private OffsetDefinition newDefinition;
035:
036: /**
037: * This method sets the convenience objects like newDefinition and oldDefinition, so you have short and easy handles to the new and
038: * old objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load
039: * all sub-objects from the DB by their primary keys, if available.
040: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#setupConvenienceObjects()
041: */
042: @Override
043: public void setupConvenienceObjects() {
044:
045: // setup oldAccount convenience objects, make sure all possible sub-objects are populated
046: oldDefinition = (OffsetDefinition) super .getOldBo();
047:
048: // setup newAccount convenience objects, make sure all possible sub-objects are populated
049: newDefinition = (OffsetDefinition) super .getNewBo();
050: }
051:
052: /**
053: * This performs rules checks on document save
054: * <ul>
055: * <li>{@link OffsetDefinitionRule#checkDocTypeActiveFinancialObjCode(MaintenanceDocument)}</li>
056: * </ul>
057: * This rule does not fail on business rule failures
058: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
059: */
060: @Override
061: protected boolean processCustomSaveDocumentBusinessRules(
062: MaintenanceDocument document) {
063: return checkDocTypeActiveFinancialObjCode(document);
064: }
065:
066: /**
067: * This performs rules checks on document route
068: * <ul>
069: * <li>{@link OffsetDefinitionRule#checkDocTypeActiveFinancialObjCode(MaintenanceDocument)}</li>
070: * </ul>
071: * This rule fails on business rule failures
072: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
073: */
074: @Override
075: protected boolean processCustomRouteDocumentBusinessRules(
076: MaintenanceDocument document) {
077: return checkDocTypeActiveFinancialObjCode(document);
078: }
079:
080: /**
081: *
082: * This checks that the doctype used for this {@link OffsetDefinition} is valid and active
083: * @param document
084: * @return false if the {@link org.kuali.core.bo.Parameter} evaluation fails and the financial object code is either null or inactive
085: */
086: private boolean checkDocTypeActiveFinancialObjCode(
087: MaintenanceDocument document) {
088: boolean success = true;
089: ParameterEvaluator evaluator = SpringContext.getBean(
090: ParameterService.class).getParameterEvaluator(
091: OffsetDefinition.class,
092: KFSConstants.ChartApcParms.DOCTYPE_AND_OBJ_CODE_ACTIVE,
093: newDefinition.getFinancialDocumentTypeCode());
094: if (!evaluator.evaluationSucceeds()) {
095: if ((ObjectUtils.isNotNull(newDefinition
096: .getFinancialObject()) && !newDefinition
097: .getFinancialObject().isFinancialObjectActiveCode())
098: || ObjectUtils.isNull(newDefinition
099: .getFinancialObject())) {
100: putFieldError(
101: "financialObjectCode",
102: KFSKeyConstants.ERROR_DOCUMENT_OFFSETDEFMAINT_INACTIVE_OBJ_CODE_FOR_DOCTYPE,
103: new String[] {
104: newDefinition.getFinancialObjectCode(),
105: evaluator
106: .getParameterValuesForMessage() });
107: success &= false;
108: }
109:
110: }
111: return success;
112: }
113: }
|