01: /*
02: * Copyright 2006-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.ObjLevel;
25: import org.kuali.module.chart.bo.ObjectCons;
26:
27: /**
28: *
29: * This class implements the business rules for {@link ObjLevel}
30: */
31: public class ObjectLevelRule extends MaintenanceDocumentRuleBase {
32: /**
33: * This performs rules checks on document save
34: * <ul>
35: * <li>{@link ObjectLevelRule#checkObjConsCode()}</li>
36: * </ul>
37: * This rule does not fail on business rule failures
38: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
39: */
40: @Override
41: protected boolean processCustomSaveDocumentBusinessRules(
42: MaintenanceDocument document) {
43: checkObjConsCode();
44: return true;
45: }
46:
47: /**
48: * This performs rules checks on document route
49: * <ul>
50: * <li>{@link ObjectLevelRule#checkObjConsCode()}</li>
51: * </ul>
52: * This rule fails on business rule failures
53: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
54: */
55: @Override
56: protected boolean processCustomRouteDocumentBusinessRules(
57: MaintenanceDocument document) {
58: boolean success = true;
59: success &= checkObjConsCode();
60: return success;
61: }
62:
63: /**
64: * This method checks to see if the Object Consolidation code matches a pre-existing Object Level code that is already entered.
65: * If it does it returns false with an error
66: *
67: * @param document
68: * @return false if Object Level Code already exists
69: */
70: private boolean checkObjConsCode() {
71: boolean success = true;
72: ObjLevel objLevel = (ObjLevel) super .getNewBo();
73: String chartOfAccountsCode = objLevel.getChartOfAccountsCode();
74: String finConsolidationObjectCode = objLevel
75: .getFinancialObjectLevelCode();
76: Map primaryKeys = new HashMap();
77: primaryKeys.put("chartOfAccountsCode", chartOfAccountsCode);
78: primaryKeys.put("finConsolidationObjectCode",
79: finConsolidationObjectCode);
80: ObjectCons objCons = (ObjectCons) getBoService()
81: .findByPrimaryKey(ObjectCons.class, primaryKeys);
82: if (objCons != null) {
83: success = false;
84: putFieldError(
85: "financialObjectLevelCode",
86: KFSKeyConstants.ERROR_DOCUMENT_OBJLEVELMAINT_ALREADY_EXISTS_AS_OBJCONS);
87: }
88: return success;
89: }
90: }
|