1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.validation.impl;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.ole.sys.businessobject.AccountingLine;
23 import org.kuali.ole.sys.document.AccountingDocument;
24 import org.kuali.ole.sys.document.validation.Validation;
25 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26 import org.kuali.rice.krad.util.ObjectUtils;
27
28
29
30
31
32
33
34 public class AccountingLineValuesAllowedValidationHutch implements Validation {
35 protected Validation objectCodeAllowedValidation;
36 protected Validation objectTypeAllowedValidation;
37 protected Validation fundGroupAllowedValidation;
38 protected Validation subFundGroupAllowedValidation;
39 protected Validation objectSubTypeAllowedValidation;
40 protected Validation objectLevelAllowedValidation;
41 protected Validation objectConsolidationAllowedValidation;
42
43 protected String accountingDocumentParameterPropertyName;
44 protected String accountingLineParameterPropertyName;
45 protected AccountingDocument accountingDocumentForValidation;
46 protected AccountingLine accountingLineForValidation;
47
48 protected boolean quitOnFail;
49
50
51
52
53 public boolean shouldQuitOnFail() {
54 return quitOnFail;
55 }
56
57
58
59
60
61 public void setQuitOnFail(boolean b) {
62 quitOnFail = b;
63 }
64
65
66
67
68 public boolean stageValidation(AttributedDocumentEvent event) {
69 grabDocumentAndLineForValidationFromEvent(event);
70 updateValidationsWithParameters();
71 return validate(event);
72 }
73
74
75
76
77
78 protected List<Validation> getValidationGauntlet() {
79 List<Validation> gauntlet = new ArrayList<Validation>();
80 if (objectCodeAllowedValidation != null) {
81 gauntlet.add(objectCodeAllowedValidation);
82 }
83 if (objectTypeAllowedValidation != null) {
84 gauntlet.add(objectTypeAllowedValidation);
85 }
86 if (fundGroupAllowedValidation != null) {
87 gauntlet.add(fundGroupAllowedValidation);
88 }
89 if (subFundGroupAllowedValidation != null) {
90 gauntlet.add(subFundGroupAllowedValidation);
91 }
92 if (objectSubTypeAllowedValidation != null) {
93 gauntlet.add(objectSubTypeAllowedValidation);
94 }
95 if (objectLevelAllowedValidation != null) {
96 gauntlet.add(objectLevelAllowedValidation);
97 }
98 if (objectConsolidationAllowedValidation != null) {
99 gauntlet.add(objectConsolidationAllowedValidation);
100 }
101 return gauntlet;
102 }
103
104
105
106
107
108
109 protected void grabDocumentAndLineForValidationFromEvent(AttributedDocumentEvent event) {
110 if (StringUtils.isNotBlank(accountingDocumentParameterPropertyName)) {
111 accountingDocumentForValidation = (AccountingDocument)ObjectUtils.getPropertyValue(event, accountingDocumentParameterPropertyName);
112 }
113 if (StringUtils.isNotBlank(accountingLineParameterPropertyName)) {
114 accountingLineForValidation = (AccountingLine)ObjectUtils.getPropertyValue(event, accountingLineParameterPropertyName);
115 }
116 }
117
118
119
120
121 protected void updateValidationsWithParameters() {
122 for (Validation v: getValidationGauntlet()) {
123 if (v instanceof AccountingLineValueAllowedValidation) {
124 addParametersToValidation((AccountingLineValueAllowedValidation)v);
125 } else if (v instanceof CompositeValidation) {
126 addParametersToValidation((CompositeValidation)v);
127 } else {
128 throw new IllegalStateException("Validations in the AccountingLineValuesAllowedValidationHutch must either extend AccountingLineValueAllowedValidation or be a CompositeValidation made up of AccountingLineValueAllowedValidation instances");
129 }
130 }
131 }
132
133
134
135
136
137 protected void addParametersToValidation(AccountingLineValueAllowedValidation validation) {
138 validation.setAccountingDocumentForValidation(accountingDocumentForValidation);
139 validation.setAccountingLineForValidation(accountingLineForValidation);
140 }
141
142
143
144
145
146 protected void addParametersToValidation(CompositeValidation validation) {
147 for (Validation val : validation.getValidations()) {
148 if (val instanceof CompositeValidation) {
149 addParametersToValidation((CompositeValidation)val);
150 } else if (val instanceof AccountingLineValueAllowedValidation) {
151 addParametersToValidation((AccountingLineValueAllowedValidation)val);
152 } else {
153 throw new IllegalStateException("Validations in the AccountingLineValuesAllowedValidationHutch must either extend AccountingLineValueAllowedValidation or be a CompositeValidation made up of AccountingLineValueAllowedValidation instances");
154 }
155 }
156 }
157
158
159
160
161
162 public boolean validate(AttributedDocumentEvent event) {
163 boolean result = true;
164 for (Validation validation : getValidationGauntlet()) {
165 result &= validation.validate(event);
166 }
167 return result;
168 }
169
170
171
172
173
174 public Validation getFundGroupAllowedValidation() {
175 return fundGroupAllowedValidation;
176 }
177
178
179
180
181
182 public void setFundGroupAllowedValidation(Validation fundGroupAllowedValidation) {
183 this.fundGroupAllowedValidation = fundGroupAllowedValidation;
184 }
185
186
187
188
189
190 public Validation getObjectCodeAllowedValidation() {
191 return objectCodeAllowedValidation;
192 }
193
194
195
196
197
198 public void setObjectCodeAllowedValidation(Validation objectCodeAllowedValidation) {
199 this.objectCodeAllowedValidation = objectCodeAllowedValidation;
200 }
201
202
203
204
205
206 public Validation getObjectConsolidationAllowedValidation() {
207 return objectConsolidationAllowedValidation;
208 }
209
210
211
212
213
214 public void setObjectConsolidationAllowedValidation(Validation objectConsolidationAllowedValidation) {
215 this.objectConsolidationAllowedValidation = objectConsolidationAllowedValidation;
216 }
217
218
219
220
221
222 public Validation getObjectLevelAllowedValidation() {
223 return objectLevelAllowedValidation;
224 }
225
226
227
228
229
230 public void setObjectLevelAllowedValidation(Validation objectLevelAllowedValidation) {
231 this.objectLevelAllowedValidation = objectLevelAllowedValidation;
232 }
233
234
235
236
237
238 public Validation getObjectSubTypeAllowedValidation() {
239 return objectSubTypeAllowedValidation;
240 }
241
242
243
244
245
246 public void setObjectSubTypeAllowedValidation(Validation objectSubTypeAllowedValidation) {
247 this.objectSubTypeAllowedValidation = objectSubTypeAllowedValidation;
248 }
249
250
251
252
253
254 public Validation getObjectTypeAllowedValidation() {
255 return objectTypeAllowedValidation;
256 }
257
258
259
260
261
262 public void setObjectTypeAllowedValidation(Validation objectTypeAllowedValidation) {
263 this.objectTypeAllowedValidation = objectTypeAllowedValidation;
264 }
265
266
267
268
269
270 public Validation getSubFundGroupAllowedValidation() {
271 return subFundGroupAllowedValidation;
272 }
273
274
275
276
277
278 public void setSubFundGroupAllowedValidation(Validation subFundGroupAllowedValidation) {
279 this.subFundGroupAllowedValidation = subFundGroupAllowedValidation;
280 }
281
282
283
284
285
286 public String getAccountingDocumentParameterPropertyName() {
287 return accountingDocumentParameterPropertyName;
288 }
289
290
291
292
293
294 public void setAccountingDocumentParameterPropertyName(String accountingDocumentParameterPropertyName) {
295 this.accountingDocumentParameterPropertyName = accountingDocumentParameterPropertyName;
296 }
297
298
299
300
301
302 public String getAccountingLineParameterPropertyName() {
303 return accountingLineParameterPropertyName;
304 }
305
306
307
308
309
310 public void setAccountingLineParameterPropertyName(String accountingLineParameterPropertyName) {
311 this.accountingLineParameterPropertyName = accountingLineParameterPropertyName;
312 }
313
314 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
315 this.accountingDocumentForValidation = accountingDocumentForValidation;
316 }
317
318 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
319 this.accountingLineForValidation = accountingLineForValidation;
320 }
321
322 public AccountingDocument getAccountingDocumentForValidation() {
323 return accountingDocumentForValidation;
324 }
325
326 public AccountingLine getAccountingLineForValidation() {
327 return accountingLineForValidation;
328 }
329 }