1 /*
2 * Copyright 2006 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.ole.coa.document.validation.impl;
17
18 import org.kuali.ole.coa.businessobject.OffsetDefinition;
19 import org.kuali.ole.sys.OLEConstants;
20 import org.kuali.ole.sys.OLEKeyConstants;
21 import org.kuali.ole.sys.context.SpringContext;
22 import org.kuali.rice.core.api.parameter.ParameterEvaluator;
23 import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
24 import org.kuali.rice.kns.document.MaintenanceDocument;
25 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
26 import org.kuali.rice.krad.util.ObjectUtils;
27
28 /**
29 *
30 * This class implements the business rules for {@link OffsetDefinition}
31 */
32 public class OffsetDefinitionRule extends MaintenanceDocumentRuleBase {
33 protected OffsetDefinition oldDefinition;
34 protected OffsetDefinition newDefinition;
35
36
37 /**
38 * This method sets the convenience objects like newDefinition and oldDefinition, so you have short and easy handles to the new and
39 * old objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load
40 * all sub-objects from the DB by their primary keys, if available.
41 * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#setupConvenienceObjects()
42 */
43 @Override
44 public void setupConvenienceObjects() {
45
46 // setup oldAccount convenience objects, make sure all possible sub-objects are populated
47 oldDefinition = (OffsetDefinition) super.getOldBo();
48
49 // setup newAccount convenience objects, make sure all possible sub-objects are populated
50 newDefinition = (OffsetDefinition) super.getNewBo();
51 }
52
53 /**
54 * This performs rules checks on document save
55 * <ul>
56 * <li>{@link OffsetDefinitionRule#checkDocTypeActiveFinancialObjCode(MaintenanceDocument)}</li>
57 * </ul>
58 * This rule does not fail on business rule failures
59 * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
60 */
61 @Override
62 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
63 return checkDocTypeActiveFinancialObjCode(document);
64 }
65
66 /**
67 * This performs rules checks on document route
68 * <ul>
69 * <li>{@link OffsetDefinitionRule#checkDocTypeActiveFinancialObjCode(MaintenanceDocument)}</li>
70 * </ul>
71 * This rule fails on business rule failures
72 * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
73 */
74 @Override
75 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
76 return checkDocTypeActiveFinancialObjCode(document);
77 }
78
79 /**
80 *
81 * This checks that the doctype used for this {@link OffsetDefinition} is valid and active
82 * @param document
83 * @return false if the {@link org.kuali.rice.core.api.parameter.Parameter} evaluation fails and the financial object code is either null or inactive
84 */
85 protected boolean checkDocTypeActiveFinancialObjCode(MaintenanceDocument document) {
86 boolean success = true;
87 ParameterEvaluator evaluator = /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(OffsetDefinition.class, OLEConstants.ChartApcParms.DOCTYPE_AND_OBJ_CODE_ACTIVE, newDefinition.getFinancialDocumentTypeCode());
88 if (!evaluator.evaluationSucceeds()) {
89 if ((ObjectUtils.isNotNull(newDefinition.getFinancialObject()) && !newDefinition.getFinancialObject().isFinancialObjectActiveCode()) || ObjectUtils.isNull(newDefinition.getFinancialObject())) {
90 putFieldError("financialObjectCode", OLEKeyConstants.ERROR_DOCUMENT_OFFSETDEFMAINT_INACTIVE_OBJ_CODE_FOR_DOCTYPE, new String[] { newDefinition.getFinancialObjectCode(), evaluator.getParameterValuesForMessage() });
91 success &= false;
92 }
93
94 }
95 return success;
96 }
97 }