1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kns.datadictionary; |
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.kuali.rice.kns.service.BusinessObjectMetaDataService; |
21 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
22 | |
import org.kuali.rice.krad.datadictionary.DataDictionary; |
23 | |
import org.kuali.rice.krad.datadictionary.DataDictionaryDefinitionBase; |
24 | |
import org.kuali.rice.krad.datadictionary.RelationshipDefinition; |
25 | |
import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException; |
26 | |
import org.kuali.rice.krad.datadictionary.exception.ClassValidationException; |
27 | |
import org.kuali.rice.krad.datadictionary.mask.Mask; |
28 | |
import org.kuali.rice.krad.valuefinder.ValueFinder; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
@Deprecated |
36 | |
public class FieldDefinition extends DataDictionaryDefinitionBase implements FieldDefinitionI { |
37 | |
private static final long serialVersionUID = -3426603523049661524L; |
38 | |
|
39 | |
protected String attributeName; |
40 | 0 | protected boolean required = false; |
41 | 0 | protected boolean forceInquiry = false; |
42 | 0 | protected boolean noInquiry = false; |
43 | 0 | protected boolean noDirectInquiry = false; |
44 | 0 | protected boolean forceLookup = false; |
45 | 0 | protected boolean noLookup = false; |
46 | 0 | protected boolean useShortLabel = false; |
47 | |
protected String defaultValue; |
48 | |
protected Class<? extends ValueFinder> defaultValueFinderClass; |
49 | |
protected String quickfinderParameterString; |
50 | |
protected Class<? extends ValueFinder> quickfinderParameterStringBuilderClass; |
51 | |
|
52 | 0 | protected Integer maxLength = null; |
53 | |
|
54 | |
protected String displayEditMode; |
55 | |
protected Mask displayMask; |
56 | |
|
57 | 0 | protected boolean hidden = false; |
58 | 0 | protected boolean readOnly = false; |
59 | |
|
60 | 0 | protected boolean treatWildcardsAndOperatorsAsLiteral = false; |
61 | |
|
62 | |
protected String alternateDisplayAttributeName; |
63 | |
protected String additionalDisplayAttributeName; |
64 | |
|
65 | |
protected boolean triggerOnChange; |
66 | 0 | protected boolean total = false; |
67 | |
|
68 | 0 | public FieldDefinition() { |
69 | 0 | } |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
public String getAttributeName() { |
76 | 0 | return attributeName; |
77 | |
} |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
public void setAttributeName(String attributeName) { |
86 | 0 | if (StringUtils.isBlank(attributeName)) { |
87 | 0 | throw new IllegalArgumentException("invalid (blank) attributeName"); |
88 | |
} |
89 | 0 | this.attributeName = attributeName; |
90 | 0 | } |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
public boolean isRequired() { |
97 | 0 | return required; |
98 | |
} |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
public void setRequired(boolean required) { |
106 | 0 | this.required = required; |
107 | 0 | } |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
public boolean isForceInquiry() { |
114 | 0 | return forceInquiry; |
115 | |
} |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
public void setForceInquiry(boolean forceInquiry) { |
123 | 0 | this.forceInquiry = forceInquiry; |
124 | 0 | } |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
public boolean isForceLookup() { |
130 | 0 | return forceLookup; |
131 | |
} |
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
public void setForceLookup(boolean forceLookup) { |
137 | 0 | this.forceLookup = forceLookup; |
138 | 0 | } |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
public boolean isNoInquiry() { |
144 | 0 | return noInquiry; |
145 | |
} |
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
public boolean isNoDirectInquiry() |
152 | |
{ |
153 | 0 | return noDirectInquiry; |
154 | |
} |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
public void setNoInquiry(boolean noInquiry) { |
160 | 0 | this.noInquiry = noInquiry; |
161 | 0 | } |
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
public void setNoDirectInquiry(boolean noDirectInquiry) { |
168 | 0 | this.noDirectInquiry = noDirectInquiry; |
169 | 0 | } |
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
public boolean isNoLookup() { |
175 | 0 | return noLookup; |
176 | |
} |
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
public void setNoLookup(boolean noLookup) { |
182 | 0 | this.noLookup = noLookup; |
183 | 0 | } |
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
public boolean isUseShortLabel() { |
190 | 0 | return this.useShortLabel; |
191 | |
} |
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
public void setUseShortLabel(boolean useShortLabel) { |
198 | 0 | this.useShortLabel = useShortLabel; |
199 | 0 | } |
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
public String getDefaultValue() { |
206 | 0 | return defaultValue; |
207 | |
} |
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
public void setDefaultValue(String defaultValue) { |
215 | 0 | this.defaultValue = defaultValue; |
216 | 0 | } |
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
public String getQuickfinderParameterString() { |
226 | 0 | return this.quickfinderParameterString; |
227 | |
} |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
public void setQuickfinderParameterString(String quickfinderParameterString) { |
233 | 0 | this.quickfinderParameterString = quickfinderParameterString; |
234 | 0 | } |
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
public Class<? extends ValueFinder> getQuickfinderParameterStringBuilderClass() { |
246 | 0 | return this.quickfinderParameterStringBuilderClass; |
247 | |
} |
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
public void setQuickfinderParameterStringBuilderClass( |
254 | |
Class<? extends ValueFinder> quickfinderParameterStringBuilderClass) { |
255 | 0 | if (quickfinderParameterStringBuilderClass == null) { |
256 | 0 | throw new IllegalArgumentException("invalid (null) quickfinderParameterStringBuilderClass"); |
257 | |
} |
258 | 0 | this.quickfinderParameterStringBuilderClass = quickfinderParameterStringBuilderClass; |
259 | 0 | } |
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) { |
267 | 0 | BusinessObjectMetaDataService boMetadataService = KNSServiceLocator.getBusinessObjectMetaDataService(); |
268 | |
|
269 | 0 | if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getAttributeName())) { |
270 | 0 | throw new AttributeValidationException("unable to find attribute '" + attributeName + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")"); |
271 | |
} |
272 | |
|
273 | 0 | if (StringUtils.isNotBlank(getAlternateDisplayAttributeName())) { |
274 | 0 | if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getAlternateDisplayAttributeName())) { |
275 | 0 | throw new AttributeValidationException("unable to find attribute named '" + getName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")"); |
276 | |
} |
277 | |
} |
278 | |
|
279 | 0 | if (StringUtils.isNotBlank(getAdditionalDisplayAttributeName())) { |
280 | 0 | if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getAdditionalDisplayAttributeName())) { |
281 | 0 | throw new AttributeValidationException("unable to find attribute named '" + getName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")"); |
282 | |
} |
283 | |
} |
284 | |
|
285 | 0 | if (defaultValueFinderClass != null && defaultValue != null) { |
286 | 0 | throw new AttributeValidationException("Both defaultValue and defaultValueFinderClass can not be specified on attribute " + getAttributeName() + " in rootBusinessObjectClass " + rootBusinessObjectClass.getName()); |
287 | |
} |
288 | |
|
289 | 0 | validateQuickfinderParameters(rootBusinessObjectClass, boMetadataService); |
290 | |
|
291 | 0 | if (forceInquiry == true && noInquiry == true) { |
292 | 0 | throw new AttributeValidationException("Both forceInquiry and noInquiry can not be set to true on attribute " + getAttributeName() + " in rootBusinessObjectClass " + rootBusinessObjectClass.getName()); |
293 | |
} |
294 | 0 | if (forceLookup == true && noLookup == true) { |
295 | 0 | throw new AttributeValidationException("Both forceLookup and noLookup can not be set to true on attribute " + getAttributeName() + " in rootBusinessObjectClass " + rootBusinessObjectClass.getName()); |
296 | |
} |
297 | 0 | } |
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | |
private void validateQuickfinderParameters(Class rootBusinessObjectClass, |
307 | |
BusinessObjectMetaDataService boMetadataService) { |
308 | 0 | if (quickfinderParameterStringBuilderClass != null && quickfinderParameterString != null) { |
309 | 0 | throw new AttributeValidationException("Both quickfinderParameterString and quickfinderParameterStringBuilderClass can not be specified on attribute " + getAttributeName() + " in rootBusinessObjectClass " + rootBusinessObjectClass.getName()); |
310 | |
} |
311 | |
|
312 | |
|
313 | 0 | String quickfinderParameterStringSource = "quickfinderParameterString"; |
314 | |
|
315 | 0 | if (quickfinderParameterStringBuilderClass != null) { |
316 | |
try { |
317 | 0 | quickfinderParameterStringSource = "quickfinderParameterStringBuilderClass " + quickfinderParameterStringBuilderClass.getCanonicalName(); |
318 | 0 | quickfinderParameterString = quickfinderParameterStringBuilderClass.newInstance().getValue(); |
319 | 0 | } catch (InstantiationException e) { |
320 | 0 | throw new ClassValidationException("unable to create new instance of "+ quickfinderParameterStringSource +" while validating rootBusinessObjectClass '"+ rootBusinessObjectClass.getName() +"'", e); |
321 | 0 | } catch (IllegalAccessException e) { |
322 | 0 | throw new ClassValidationException("unable to create new instance of "+ quickfinderParameterStringSource +" while validating rootBusinessObjectClass '"+ rootBusinessObjectClass.getName() +"'", e); |
323 | 0 | } |
324 | |
} |
325 | |
|
326 | 0 | if (!StringUtils.isEmpty(quickfinderParameterString)) { |
327 | |
|
328 | 0 | for (String quickfinderParam : quickfinderParameterString.split(",")) { |
329 | 0 | if (quickfinderParam.contains("=")) { |
330 | 0 | String propertyName = quickfinderParam.split("=")[0]; |
331 | 0 | RelationshipDefinition relationship = boMetadataService.getBusinessObjectRelationshipDefinition(rootBusinessObjectClass, attributeName); |
332 | 0 | Class targetClass = relationship.getTargetClass(); |
333 | |
|
334 | |
|
335 | 0 | if (!DataDictionary.isPropertyOf(targetClass, propertyName)) { |
336 | 0 | throw new ClassValidationException("malformed parameter string '"+ quickfinderParameterString +"' from "+ quickfinderParameterStringSource + |
337 | |
", '"+ propertyName +"' is not a property of "+ targetClass +"' for rootBusinessObjectClass '"+ rootBusinessObjectClass.getName() +"'"); |
338 | |
} |
339 | |
|
340 | 0 | } else { |
341 | 0 | throw new ClassValidationException("malformed parameter string '"+ quickfinderParameterString +"' from "+ quickfinderParameterStringSource + |
342 | |
" for rootBusinessObjectClass '"+ rootBusinessObjectClass.getName() +"'"); |
343 | |
} |
344 | |
} |
345 | |
} |
346 | 0 | } |
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | |
public String toString() { |
353 | 0 | return "FieldDefinition for attribute " + getAttributeName(); |
354 | |
} |
355 | |
|
356 | |
|
357 | |
public String getName() { |
358 | 0 | return attributeName; |
359 | |
} |
360 | |
|
361 | |
|
362 | |
public String getDisplayEditMode() { |
363 | 0 | return displayEditMode; |
364 | |
} |
365 | |
|
366 | |
|
367 | |
|
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
public void setDisplayEditMode(String displayEditMode) { |
380 | 0 | this.displayEditMode = displayEditMode; |
381 | 0 | } |
382 | |
|
383 | |
|
384 | |
public Mask getDisplayMask() { |
385 | 0 | return displayMask; |
386 | |
} |
387 | |
|
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | |
|
393 | |
public void setDisplayMask(Mask displayMask) { |
394 | 0 | this.displayMask = displayMask; |
395 | 0 | } |
396 | |
|
397 | |
|
398 | |
|
399 | |
public boolean isReadOnlyAfterAdd() { |
400 | 0 | return false; |
401 | |
} |
402 | |
|
403 | |
|
404 | |
|
405 | |
|
406 | |
|
407 | |
|
408 | |
public Integer getMaxLength() { |
409 | 0 | return maxLength; |
410 | |
} |
411 | |
|
412 | |
|
413 | |
|
414 | |
|
415 | |
|
416 | |
|
417 | |
public void setMaxLength(Integer maxLength) { |
418 | 0 | this.maxLength = maxLength; |
419 | 0 | } |
420 | |
|
421 | |
|
422 | |
|
423 | |
|
424 | |
public Class<? extends ValueFinder> getDefaultValueFinderClass() { |
425 | 0 | return this.defaultValueFinderClass; |
426 | |
} |
427 | |
|
428 | |
|
429 | |
|
430 | |
|
431 | |
|
432 | |
|
433 | |
public void setDefaultValueFinderClass(Class<? extends ValueFinder> defaultValueFinderClass) { |
434 | 0 | if (defaultValueFinderClass == null) { |
435 | 0 | throw new IllegalArgumentException("invalid (null) defaultValueFinderClass"); |
436 | |
} |
437 | 0 | this.defaultValueFinderClass = defaultValueFinderClass; |
438 | 0 | } |
439 | |
|
440 | |
|
441 | |
|
442 | |
|
443 | |
public boolean isHidden() { |
444 | 0 | return this.hidden; |
445 | |
} |
446 | |
|
447 | |
|
448 | |
|
449 | |
|
450 | |
|
451 | |
|
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
|
458 | |
public void setHidden(boolean hidden) { |
459 | 0 | this.hidden = hidden; |
460 | 0 | } |
461 | |
|
462 | |
|
463 | |
|
464 | |
|
465 | |
public boolean isReadOnly() { |
466 | 0 | return this.readOnly; |
467 | |
} |
468 | |
|
469 | |
|
470 | |
|
471 | |
|
472 | |
public void setReadOnly(boolean readOnly) { |
473 | 0 | this.readOnly = readOnly; |
474 | 0 | } |
475 | |
|
476 | |
public boolean isTriggerOnChange() { |
477 | 0 | return this.triggerOnChange; |
478 | |
} |
479 | |
|
480 | |
public void setTriggerOnChange(boolean triggerOnChange) { |
481 | 0 | this.triggerOnChange = triggerOnChange; |
482 | 0 | } |
483 | |
|
484 | |
|
485 | |
|
486 | |
|
487 | |
public boolean isTreatWildcardsAndOperatorsAsLiteral() { |
488 | 0 | return this.treatWildcardsAndOperatorsAsLiteral; |
489 | |
} |
490 | |
|
491 | |
|
492 | |
|
493 | |
|
494 | |
|
495 | |
public void setTreatWildcardsAndOperatorsAsLiteral( |
496 | |
boolean treatWildcardsAndOperatorsAsLiteralOnLookups) { |
497 | 0 | this.treatWildcardsAndOperatorsAsLiteral = treatWildcardsAndOperatorsAsLiteralOnLookups; |
498 | 0 | } |
499 | |
|
500 | |
|
501 | |
public String getAlternateDisplayAttributeName() { |
502 | 0 | return this.alternateDisplayAttributeName; |
503 | |
} |
504 | |
|
505 | |
|
506 | |
public void setAlternateDisplayAttributeName(String alternateDisplayAttributeName) { |
507 | 0 | this.alternateDisplayAttributeName = alternateDisplayAttributeName; |
508 | 0 | } |
509 | |
|
510 | |
|
511 | |
public String getAdditionalDisplayAttributeName() { |
512 | 0 | return this.additionalDisplayAttributeName; |
513 | |
} |
514 | |
|
515 | |
|
516 | |
public void setAdditionalDisplayAttributeName(String additionalDisplayAttributeName) { |
517 | 0 | this.additionalDisplayAttributeName = additionalDisplayAttributeName; |
518 | 0 | } |
519 | |
|
520 | |
|
521 | |
public boolean isTotal() { |
522 | 0 | return this.total; |
523 | |
} |
524 | |
|
525 | |
|
526 | |
public void setTotal(boolean total) { |
527 | 0 | this.total = total; |
528 | 0 | } |
529 | |
|
530 | |
} |