1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.validation.impl;
17
18 import org.kuali.ole.coa.businessobject.Chart;
19 import org.kuali.ole.coa.businessobject.Organization;
20 import org.kuali.ole.coa.service.ChartService;
21 import org.kuali.ole.coa.service.OrganizationService;
22 import org.kuali.ole.module.purap.PurapKeyConstants;
23 import org.kuali.ole.module.purap.businessobject.OrganizationParameter;
24 import org.kuali.ole.sys.OLEPropertyConstants;
25 import org.kuali.ole.sys.context.SpringContext;
26 import org.kuali.rice.kns.document.MaintenanceDocument;
27 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
28 import org.kuali.rice.krad.service.BusinessObjectService;
29 import org.kuali.rice.krad.util.GlobalVariables;
30 import org.kuali.rice.krad.util.MessageMap;
31 import org.kuali.rice.krad.util.ObjectUtils;
32
33
34
35
36 public class OrganizationParameterRule extends MaintenanceDocumentRuleBase {
37
38 protected OrganizationParameter newOrganizationParameter;
39 protected BusinessObjectService boService;
40
41
42
43
44 @Override
45 public void setupConvenienceObjects() {
46
47 newOrganizationParameter = (OrganizationParameter) super.getNewBo();
48 boService = (BusinessObjectService) super.getBoService();
49 super.setupConvenienceObjects();
50 }
51
52
53
54
55 protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
56 LOG.info("processCustomApproveDocumentBusinessRules called");
57 this.setupConvenienceObjects();
58 boolean success = true;
59 success &= this.checkChartOfAccountsCode();
60 success &= this.checkOrganizationCode();
61 return success && super.processCustomApproveDocumentBusinessRules(document);
62 }
63
64
65
66
67 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
68 LOG.info("processCustomRouteDocumentBusinessRules called");
69 this.setupConvenienceObjects();
70 boolean success = true;
71 success &= this.checkChartOfAccountsCode();
72 success &= this.checkOrganizationCode();
73 return success && super.processCustomRouteDocumentBusinessRules(document);
74 }
75
76
77
78
79 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
80 LOG.info("processCustomSaveDocumentBusinessRules called");
81 this.setupConvenienceObjects();
82 boolean success = true;
83 success &= this.checkChartOfAccountsCode();
84 success &= this.checkOrganizationCode();
85 return success && super.processCustomSaveDocumentBusinessRules(document);
86 }
87
88
89
90
91
92
93 protected boolean checkChartOfAccountsCode() {
94 LOG.info("checkChartOfAccountsCode called");
95 MessageMap errorMap = GlobalVariables.getMessageMap();
96 boolean success = true;
97 Chart chart = SpringContext.getBean(ChartService.class).getByPrimaryId(newOrganizationParameter.getChartOfAccountsCode());
98 if (ObjectUtils.isNull(chart)) {
99 success &= false;
100 errorMap.putError(OLEPropertyConstants.DOCUMENT + "." + OLEPropertyConstants.NEW_MAINTAINABLE_OBJECT + "." + OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, PurapKeyConstants.ERROR_INVALID_CHART_OF_ACCOUNTS_CODE);
101 }
102 return success;
103 }
104
105
106
107
108
109
110 protected boolean checkOrganizationCode() {
111 LOG.info("checkOrganizationCode called");
112 MessageMap errorMap = GlobalVariables.getMessageMap();
113 boolean success = true;
114 Organization org = SpringContext.getBean(OrganizationService.class).getByPrimaryId(newOrganizationParameter.getChartOfAccountsCode(), newOrganizationParameter.getOrganizationCode());
115 if (ObjectUtils.isNull(org)) {
116 success &= false;
117 errorMap.putError(OLEPropertyConstants.DOCUMENT + "." + OLEPropertyConstants.NEW_MAINTAINABLE_OBJECT + "." + OLEPropertyConstants.ORGANIZATION_CODE, PurapKeyConstants.ERROR_INVALID_ORGANIZATION_CODE);
118 }
119 return success;
120 }
121
122 }