View Javadoc
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 java.util.HashMap;
19  import java.util.Map;
20  
21  import org.kuali.ole.coa.businessobject.ObjectConsolidation;
22  import org.kuali.ole.coa.businessobject.ObjectLevel;
23  import org.kuali.ole.sys.OLEKeyConstants;
24  import org.kuali.rice.kns.document.MaintenanceDocument;
25  import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
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.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
39       */
40      @Override
41      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
42          checkObjConsCode();
43          return true;
44      }
45  
46      /**
47       * This performs rules checks on document route
48       * <ul>
49       * <li>{@link ObjectLevelRule#checkObjConsCode()}</li>
50       * </ul>
51       * This rule fails on business rule failures
52       * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
53       */
54      @Override
55      protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
56          boolean success = true;
57          success &= checkObjConsCode();
58          return success;
59      }
60  
61      /**
62       * This method checks to see if the Object Consolidation code matches a pre-existing Object Level code that is already entered.
63       * If it does it returns false with an error
64       * 
65       * @param document
66       * @return false if Object Level Code already exists
67       */
68      protected boolean checkObjConsCode() {
69          boolean success = true;
70          ObjectLevel objLevel = (ObjectLevel) super.getNewBo();
71          String chartOfAccountsCode = objLevel.getChartOfAccountsCode();
72          String finConsolidationObjectCode = objLevel.getFinancialObjectLevelCode();
73          Map primaryKeys = new HashMap();
74          primaryKeys.put("chartOfAccountsCode", chartOfAccountsCode);
75          primaryKeys.put("finConsolidationObjectCode", finConsolidationObjectCode);
76          ObjectConsolidation objCons = (ObjectConsolidation) getBoService().findByPrimaryKey(ObjectConsolidation.class, primaryKeys);
77          if (objCons != null) {
78              success = false;
79              putFieldError("financialObjectLevelCode", OLEKeyConstants.ERROR_DOCUMENT_OBJLEVELMAINT_ALREADY_EXISTS_AS_OBJCONS);
80          }
81          return success;
82      }
83  }