1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
30
31 public class ChartRule extends MaintenanceDocumentRuleBase {
32
33
34
35
36
37
38
39
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)) {
56
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