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.Chart;
19  import org.kuali.ole.coa.service.ChartService;
20  import org.kuali.ole.sys.OLEKeyConstants;
21  import org.kuali.ole.sys.context.SpringContext;
22  import org.kuali.ole.sys.service.FinancialSystemUserService;
23  import org.kuali.rice.kim.api.identity.Person;
24  import org.kuali.rice.kim.api.identity.PersonService;
25  import org.kuali.rice.kns.document.MaintenanceDocument;
26  import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
27  
28  /**
29   * Business rule(s) applicable to {@link ChartMaintenance} documents.
30   */
31  public class ChartRule extends MaintenanceDocumentRuleBase {
32  
33      /**
34       * This method calls specific rules for routing on Chart Maintenance documents Specifically it checks to make sure that
35       * reportsToChart exists if it is not the same code as the newly created Chart and it checks to make sure that the chart manager
36       * is valid for the Chart Module
37       *
38       * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
39       * @return false if reports to chart code doesn't exist or user is invalid for this module
40       */
41      @Override
42      protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
43  
44          boolean result = true;
45  
46          Chart chart = (Chart) document.getNewMaintainableObject().getBusinessObject();
47          ChartService chartService = SpringContext.getBean(ChartService.class);
48          PersonService personService = SpringContext.getBean(PersonService.class);
49  
50  
51          String chartCode = chart.getChartOfAccountsCode();
52  
53          String reportsToChartCode = chart.getReportsToChartOfAccountsCode();
54  
55          if (chartCode != null && !chartCode.equals(reportsToChartCode)) { // if not equal to this newly created chart, then must
56                                                                              // exist
57              Chart reportsToChart = chartService.getByPrimaryId(reportsToChartCode);
58              if (reportsToChart == null) {
59                  result = false;
60                  putFieldError("reportsToChartOfAccountsCode", OLEKeyConstants.ERROR_DOCUMENT_CHART_REPORTS_TO_CHART_MUST_EXIST);
61              }
62          }
63  
64          Person chartManager = personService.getPerson(chart.getFinCoaManagerPrincipalId());
65          if ( chartManager == null ) {
66              result = false;
67              putFieldError("finCoaManagerUniversal.principalName", OLEKeyConstants.ERROR_DOCUMENT_CHART_MANAGER_MUST_EXIST);
68          }
69  
70          if (chartManager != null && !SpringContext.getBean(FinancialSystemUserService.class).isActiveFinancialSystemUser(chartManager)) {
71              result = false;
72              putFieldError("finCoaManagerUniversal.principalName", OLEKeyConstants.ERROR_DOCUMENT_CHART_MANAGER_MUST_BE_KUALI_USER);
73          }
74  
75  
76          return result;
77  
78      }
79  
80  }
81