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 org.kuali.ole.coa.businessobject.ObjectConsolidation;
19  import org.kuali.ole.coa.businessobject.ObjectLevel;
20  import org.kuali.ole.coa.service.ChartService;
21  import org.kuali.ole.coa.service.ObjectCodeService;
22  import org.kuali.ole.coa.service.ObjectLevelService;
23  import org.kuali.ole.sys.OLEKeyConstants;
24  import org.kuali.ole.sys.context.SpringContext;
25  import org.kuali.rice.kns.document.MaintenanceDocument;
26  import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
27  /**
28   * 
29   * This class implements the business rules for {@link ObjectCons}
30   */
31  public class ObjectConsRule extends MaintenanceDocumentRuleBase {
32  
33      protected static ChartService chartService;
34      protected static ObjectLevelService objectLevelService;
35      protected static ObjectCodeService objectCodeService;
36      
37      /**
38       * 
39       * Constructs a {@link ObjectConsRule}
40       * Pseudo-injects some services
41       */
42      public ObjectConsRule() {
43          if (chartService == null) {
44              objectLevelService = SpringContext.getBean(ObjectLevelService.class);
45              objectCodeService = SpringContext.getBean(ObjectCodeService.class);
46              chartService = SpringContext.getBean(ChartService.class);
47          }
48      }
49  
50      /**
51       * This performs rules checks on document save
52       * <ul>
53       * <li>{@link ObjectConsRule#checkObjLevelCode(ObjectCons)}</li>
54       * </ul>
55       * This rule does not fail on business rule failures
56       * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
57       */
58      @Override
59      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
60          ObjectConsolidation objConsolidation = (ObjectConsolidation) getNewBo();
61  
62          checkObjLevelCode(objConsolidation);
63          return true;
64      }
65  
66      /**
67       * This performs rules checks on document route
68       * <ul>
69       * <li>{@link ObjectConsRule#checkObjLevelCode(ObjectCons)}</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          boolean success = true;
77          ObjectConsolidation objConsolidation = (ObjectConsolidation) getNewBo();
78  
79          success &= checkObjLevelCode(objConsolidation);
80          return success;
81      }
82  
83      /**
84       * This method checks to see if the Object Consolidation code matches a pre-existing Object Level code that is already entered.
85       * If it does it returns false with an error
86       * 
87       * @param document
88       * @return false if Object Level Code already exists
89       */
90      protected boolean checkObjLevelCode(ObjectConsolidation objConsolidation) {
91          boolean success = true;
92  
93          ObjectLevel objLevel = objectLevelService.getByPrimaryId(objConsolidation.getChartOfAccountsCode(), objConsolidation.getFinConsolidationObjectCode());
94          if (objLevel != null) {
95              success = false;
96              putFieldError("finConsolidationObjectCode", OLEKeyConstants.ERROR_DOCUMENT_OBJCONSMAINT_ALREADY_EXISTS_AS_OBJLEVEL);
97          }
98          return success;
99      }
100 }