01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.module.chart.rules;
17:
18: import java.util.HashMap;
19: import java.util.Map;
20:
21: import org.kuali.core.document.MaintenanceDocument;
22: import org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase;
23: import org.kuali.kfs.KFSKeyConstants;
24: import org.kuali.module.chart.bo.BasicAccountingCategory;
25: import org.kuali.module.chart.bo.ObjectType;
26:
27: /**
28: *
29: * This class implements the business rules for {@link ObjectType}
30: */
31: public class ObjectTypeRule extends MaintenanceDocumentRuleBase {
32:
33: /**
34: * This performs rules checks on document save
35: * <ul>
36: * <li>{@link ObjectTypeRule#checkAccountingCategory(MaintenanceDocument)}</li>
37: * </ul>
38: * This rule does not fail on business rule failures
39: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
40: */
41: @Override
42: protected boolean processCustomSaveDocumentBusinessRules(
43: MaintenanceDocument document) {
44: checkAccountingCategory(document);
45: return true; // it's a save, always return true
46: }
47:
48: /**
49: * This performs rules checks on document route
50: * <ul>
51: * <li>{@link ObjectTypeRule#checkAccountingCategory(MaintenanceDocument)}</li>
52: * </ul>
53: * This rule fails on business rule failures
54: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
55: */
56: @Override
57: protected boolean processCustomRouteDocumentBusinessRules(
58: MaintenanceDocument document) {
59: boolean success = true;
60: success &= checkAccountingCategory(document);
61: return success;
62: }
63:
64: /**
65: *
66: * This checks that the accounting category exists in the system
67: * @param document
68: * @return false if category does not exist
69: */
70: protected boolean checkAccountingCategory(
71: MaintenanceDocument document) {
72: boolean result = true;
73: ObjectType objectType = (ObjectType) document
74: .getNewMaintainableObject().getBusinessObject();
75: Map pkMap = new HashMap();
76: pkMap.put("code", objectType.getBasicAccountingCategoryCode());
77: BasicAccountingCategory basicAccountingCategory = (BasicAccountingCategory) this
78: .getBoService().findByPrimaryKey(
79: BasicAccountingCategory.class, pkMap);
80: if (basicAccountingCategory == null) {
81: result = false;
82: putFieldError(
83: "basicAccountingCategoryCode",
84: KFSKeyConstants.ERROR_DOCUMENT_OBJTYPE_INVALID_ACCT_CTGRY,
85: new String[] { objectType
86: .getBasicAccountingCategoryCode() });
87: }
88: return result;
89: }
90: }
|