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 java.util.List;
19
20 import org.kuali.ole.coa.businessobject.OrganizationReversion;
21 import org.kuali.ole.coa.businessobject.OrganizationReversionDetail;
22 import org.kuali.ole.sys.OLEKeyConstants;
23 import org.kuali.rice.kns.document.MaintenanceDocument;
24 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
25 import org.kuali.rice.krad.util.GlobalVariables;
26 import org.kuali.rice.krad.util.ObjectUtils;
27
28
29
30
31 public class OrganizationReversionRule extends MaintenanceDocumentRuleBase {
32
33 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OrganizationReversionRule.class);
34
35 protected OrganizationReversion oldOrgReversion;
36 protected OrganizationReversion newOrgReversion;
37
38
39
40
41 public OrganizationReversionRule() {
42
43 }
44
45
46
47
48
49
50
51
52
53 @Override
54 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
55
56 boolean success = true;
57
58
59 if (!isCorrectMaintenanceClass(document, OrganizationReversion.class)) {
60 throw new IllegalArgumentException("Maintenance Document passed in was of the incorrect type. Expected " + "'" + OrganizationReversion.class.toString() + "', received " + "'" + document.getOldMaintainableObject().getBoClass().toString() + "'.");
61 }
62
63
64 newOrgReversion = (OrganizationReversion) document.getNewMaintainableObject().getBusinessObject();
65
66
67 success &= validateDetailBusinessObjects(newOrgReversion);
68
69 return success;
70 }
71
72
73
74
75
76
77
78 protected boolean validateDetailBusinessObjects(OrganizationReversion orgReversion) {
79 GlobalVariables.getMessageMap().addToErrorPath("document.newMaintainableObject");
80 List<OrganizationReversionDetail> details = orgReversion.getOrganizationReversionDetail();
81 int index = 0;
82 int originalErrorCount = GlobalVariables.getMessageMap().getErrorCount();
83 for (OrganizationReversionDetail dtl : details) {
84 String errorPath = "organizationReversionDetail[" + index + "]";
85 GlobalVariables.getMessageMap().addToErrorPath(errorPath);
86 validateOrganizationReversionDetail(dtl);
87 validateOrganizationReversionCode(orgReversion, dtl);
88 GlobalVariables.getMessageMap().removeFromErrorPath(errorPath);
89 index++;
90 }
91 GlobalVariables.getMessageMap().removeFromErrorPath("document.newMaintainableObject");
92 return GlobalVariables.getMessageMap().getErrorCount() == originalErrorCount;
93 }
94
95
96
97
98
99
100
101 protected boolean validateOrganizationReversionDetail(OrganizationReversionDetail detail) {
102
103
104 boolean result = true;
105
106
107 detail.refreshReferenceObject("organizationReversionObject");
108 if (ObjectUtils.isNull(detail.getOrganizationReversionObject())) {
109 LOG.debug("organization reversion finanical object = null");
110 result = false;
111 GlobalVariables.getMessageMap().putError("organizationReversionObjectCode", OLEKeyConstants.ERROR_EXISTENCE, new String[] { "Financial Object Code: " + detail.getOrganizationReversionObjectCode() });
112 } else {
113 if (LOG.isDebugEnabled()) {
114 LOG.debug("organization reversion finanical object = " + detail.getOrganizationReversionObject().getName());
115 }
116 }
117 return result;
118 }
119
120
121
122
123
124
125
126
127
128
129
130
131 protected boolean validateOrganizationReversionCode(OrganizationReversion reversion, OrganizationReversionDetail detail) {
132
133
134
135
136 boolean result = true;
137
138
139
140
141
142 if (reversion.isCarryForwardByObjectCodeIndicator()) {
143 if (ObjectUtils.isNull(detail.getOrganizationReversionCode())) {
144 result = false;
145 GlobalVariables.getMessageMap().putError("organizationReversionCode", OLEKeyConstants.ERROR_DOCUMENT_GLOBAL_ORG_REVERSION_NO_REVERSION_CODE);
146 }
147 }
148 return result;
149 }
150 }