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.apache.commons.lang.StringUtils;
19 import org.kuali.ole.coa.businessobject.ReportingCode;
20 import org.kuali.ole.sys.OLEKeyConstants;
21 import org.kuali.ole.sys.context.SpringContext;
22 import org.kuali.rice.kns.document.MaintenanceDocument;
23 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
24 import org.kuali.rice.krad.bo.PersistableBusinessObject;
25 import org.kuali.rice.krad.service.BusinessObjectService;
26 import org.kuali.rice.krad.util.ObjectUtils;
27
28
29
30
31
32 public class ReportingCodesRule extends MaintenanceDocumentRuleBase {
33
34 protected ReportingCode oldReportingCode;
35 protected ReportingCode newReportingCode;
36
37 protected BusinessObjectService businessObjectService;
38
39
40
41
42
43 public ReportingCodesRule() {
44 super();
45 setBusinessObjectService((BusinessObjectService) SpringContext.getBean(BusinessObjectService.class));
46 }
47
48
49
50
51
52
53
54
55
56 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
57 boolean success = true;
58 setupConvenienceObjects(document);
59 success &= checkReportsToReportingCode();
60 return success;
61 }
62
63
64
65
66
67
68
69
70
71 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
72 boolean success = true;
73 setupConvenienceObjects(document);
74 checkReportsToReportingCode();
75 return success;
76 }
77
78
79
80
81
82
83
84
85
86 protected void setupConvenienceObjects(MaintenanceDocument document) {
87
88
89 oldReportingCode = (ReportingCode) super.getOldBo();
90
91
92 newReportingCode = (ReportingCode) super.getNewBo();
93 }
94
95
96
97
98
99
100
101
102 protected boolean checkReportsToReportingCode() {
103 boolean success = true;
104 boolean oneMissing = false;
105 boolean bothMissing = false;
106 boolean doExistenceTest = false;
107
108
109
110 if (StringUtils.isBlank(newReportingCode.getFinancialReportingCode()) && StringUtils.isBlank(newReportingCode.getFinancialReportsToReportingCode())) {
111 bothMissing = true;
112 }
113 else if (StringUtils.isBlank(newReportingCode.getFinancialReportingCode()) || StringUtils.isBlank(newReportingCode.getFinancialReportsToReportingCode())) {
114 oneMissing = true;
115 }
116 if (oneMissing && !bothMissing) {
117 doExistenceTest = true;
118 }
119
120
121 if (StringUtils.isNotBlank(newReportingCode.getFinancialReportingCode())) {
122 if (!newReportingCode.getFinancialReportingCode().equalsIgnoreCase(newReportingCode.getFinancialReportsToReportingCode())) {
123 doExistenceTest = true;
124 }
125 }
126
127
128 if (doExistenceTest) {
129
130
131 PersistableBusinessObject referenceBo;
132 referenceBo = (PersistableBusinessObject)businessObjectService.getReferenceIfExists((PersistableBusinessObject) newReportingCode, "reportingCodes");
133 if (!ObjectUtils.isNotNull(referenceBo)) {
134 putFieldError("financialReportsToReportingCode", OLEKeyConstants.ERROR_EXISTENCE, "Reports To Reporting Code");
135 success &= false;
136 }
137 }
138 return success;
139 }
140
141 protected void setBusinessObjectService(BusinessObjectService boService) {
142 businessObjectService = boService;
143 }
144
145 }