1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary;
17
18 import java.beans.PropertyEditor;
19 import java.util.List;
20
21 import org.apache.commons.lang.ClassUtils;
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.rice.core.api.data.DataType;
24 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
25 import org.kuali.rice.core.api.util.ClassLoaderUtils;
26 import org.kuali.rice.core.web.format.Formatter;
27 import org.kuali.rice.krad.datadictionary.control.ControlDefinition;
28 import org.kuali.rice.krad.datadictionary.mask.MaskFormatterLiteral;
29 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
30 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
31 import org.kuali.rice.krad.datadictionary.validation.ValidationPattern;
32 import org.kuali.rice.krad.datadictionary.validation.capability.CaseConstrainable;
33 import org.kuali.rice.krad.datadictionary.validation.capability.Formatable;
34 import org.kuali.rice.krad.datadictionary.validation.capability.HierarchicallyConstrainable;
35 import org.kuali.rice.krad.datadictionary.validation.capability.MustOccurConstrainable;
36 import org.kuali.rice.krad.datadictionary.validation.capability.PrerequisiteConstrainable;
37 import org.kuali.rice.krad.datadictionary.validation.capability.ValidCharactersConstrainable;
38 import org.kuali.rice.krad.datadictionary.validation.constraint.CaseConstraint;
39 import org.kuali.rice.krad.datadictionary.validation.constraint.MustOccurConstraint;
40 import org.kuali.rice.krad.datadictionary.validation.constraint.PrerequisiteConstraint;
41 import org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersConstraint;
42 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
43 import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
44 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
45 import org.kuali.rice.krad.uif.control.Control;
46 import org.kuali.rice.krad.util.KRADUtils;
47
48
49
50
51
52
53
54
55 @BeanTag(name = "attributeDefinition")
56 public class AttributeDefinition extends AttributeDefinitionBase implements CaseConstrainable, PrerequisiteConstrainable, Formatable, HierarchicallyConstrainable, MustOccurConstrainable, ValidCharactersConstrainable {
57 private static final long serialVersionUID = -2490613377818442742L;
58 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AttributeDefinition.class);
59
60 protected Boolean forceUppercase;
61
62 protected Boolean unique;
63
64
65 @Deprecated
66 protected ValidationPattern validationPattern;
67
68 @Deprecated
69 protected ControlDefinition control;
70
71
72 protected Control controlField;
73 protected Control cachedDerivedControl = null;
74
75 @Deprecated
76 protected String formatterClass;
77 protected PropertyEditor propertyEditor;
78
79 protected AttributeSecurity attributeSecurity;
80
81 protected Boolean dynamic;
82
83
84 protected String customValidatorClass;
85 protected ValidCharactersConstraint validCharactersConstraint;
86 protected CaseConstraint caseConstraint;
87 protected List<PrerequisiteConstraint> dependencyConstraints;
88 protected List<MustOccurConstraint> mustOccurConstraints;
89
90
91 protected String childEntryName;
92
93 private KeyValuesFinder optionsFinder;
94
95 protected String alternateDisplayAttributeName;
96 protected String additionalDisplayAttributeName;
97
98 public AttributeDefinition() {
99 super();
100 }
101
102
103
104
105
106
107 public void setForceUppercase(Boolean forceUppercase) {
108 this.forceUppercase = forceUppercase;
109 }
110
111
112
113
114
115
116
117
118
119
120
121
122
123 @BeanTagAttribute
124 public Boolean getForceUppercase() {
125 if ( forceUppercase != null ) {
126 return forceUppercase;
127 }
128 if ( getDataObjectAttribute() != null ) {
129 return getDataObjectAttribute().isForceUppercase();
130 }
131 return Boolean.FALSE;
132 }
133
134
135
136
137
138
139
140 @BeanTagAttribute
141 public Integer getMaxLength() {
142 if ( getSimpleConstraint().getMaxLength() != null ) {
143 return getSimpleConstraint().getMaxLength();
144 }
145 if ( getDataObjectAttribute() != null ) {
146 if ( getDataObjectAttribute().getMaxLength() != null ) {
147 return new Integer( getDataObjectAttribute().getMaxLength().intValue() );
148 }
149 }
150 return null;
151 }
152
153
154
155
156
157
158 public void setMaxLength(Integer maxLength) {
159 this.getSimpleConstraint().setMaxLength(maxLength);
160 }
161
162
163
164
165 @BeanTagAttribute
166 public String getExclusiveMin() {
167 return this.getSimpleConstraint().getExclusiveMin();
168 }
169
170
171
172
173
174
175 public void setExclusiveMin(String exclusiveMin) {
176 this.getSimpleConstraint().setExclusiveMin(exclusiveMin);
177 }
178
179
180
181
182 @BeanTagAttribute
183 public String getInclusiveMax() {
184 return this.getSimpleConstraint().getInclusiveMax();
185 }
186
187
188
189
190
191
192 public void setInclusiveMax(String inclusiveMax) {
193 this.getSimpleConstraint().setInclusiveMax(inclusiveMax);
194 }
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233 @Deprecated
234 public void setValidationPattern(ValidationPattern validationPattern) {
235 this.validationPattern = validationPattern;
236 }
237
238
239
240
241
242 @Deprecated
243 public boolean hasValidationPattern() {
244 return (validationPattern != null);
245 }
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287 @Deprecated
288 public ValidationPattern getValidationPattern() {
289 return this.validationPattern;
290 }
291
292
293
294
295 @BeanTagAttribute(name = "oldControl", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
296 @Deprecated
297 public ControlDefinition getControl() {
298 return control;
299 }
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340 @Deprecated
341 public void setControl(ControlDefinition control) {
342 if (control == null) {
343 throw new IllegalArgumentException("invalid (null) control");
344 }
345 this.control = control;
346 }
347
348 @Deprecated
349 public boolean hasFormatterClass() {
350 return (formatterClass != null);
351 }
352
353 @Override
354 @BeanTagAttribute
355 @Deprecated
356 public String getFormatterClass() {
357 return formatterClass;
358 }
359
360
361
362
363
364
365
366
367 @Deprecated
368 public void setFormatterClass(String formatterClass) {
369 if (formatterClass == null) {
370 throw new IllegalArgumentException("invalid (null) formatterClass");
371 }
372 this.formatterClass = formatterClass;
373 }
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389 @BeanTagAttribute
390 public PropertyEditor getPropertyEditor() {
391 if ( propertyEditor != null ) {
392 return propertyEditor;
393 }
394 if ( getDataObjectAttribute() != null ) {
395 return getDataObjectAttribute().getPropertyEditor();
396 }
397 return null;
398 }
399
400
401
402
403
404
405 public void setPropertyEditor(PropertyEditor propertyEditor) {
406 this.propertyEditor = propertyEditor;
407 }
408
409
410
411
412
413
414 public void setPropertyEditorClass(Class<? extends PropertyEditor> propertyEditorClass) {
415 this.propertyEditor = KRADUtils.createNewObjectFromClass(propertyEditorClass);
416 }
417
418
419
420
421
422
423 @Override
424 public void dataDictionaryPostProcessing() {
425 super.dataDictionaryPostProcessing();
426 if ( getAttributeSecurity() != null ) {
427 getAttributeSecurity().dataDictionaryPostProcessing();
428 }
429 }
430
431
432
433
434
435
436
437 @Override
438 @Deprecated
439 public void completeValidation(Class<?> rootObjectClass, Class<?> otherObjectClass) {
440 completeValidation(rootObjectClass, otherObjectClass, new ValidationTrace());
441 }
442
443
444
445
446
447
448
449 @Override
450 public void completeValidation(Class rootObjectClass, Class otherObjectClass, ValidationTrace tracer) {
451 tracer.addBean(this.getClass().getSimpleName(), "id: " + getId());
452 try {
453 if (StringUtils.isBlank(getName())) {
454 String currentValues[] = {"id = " + getId(), "class = " + rootObjectClass.getName()};
455 tracer.createError("AttributeDefinition missing name", currentValues);
456 }
457 if (!DataDictionary.isPropertyOf(rootObjectClass, getName())) {
458 String currentValues[] = {"property = " + getName(), "class = " + rootObjectClass.getName()};
459 tracer.createError("Property is not found in class. Ensure that the property is defined on the class and that there is at least a public 'getter' for it.", currentValues);
460 }
461
462 if (getControl() == null && getControlField() == null) {
463 String currentValues[] = {"property = " + getName(), "class = " + rootObjectClass.getName()};
464 tracer.createError("Property does not have a control defined in the class", currentValues);
465 }
466
467 if (getAttributeSecurity() != null) {
468 getAttributeSecurity().completeValidation(rootObjectClass, otherObjectClass, tracer.getCopy());
469 }
470
471
472 if (getControl() != null) {
473 getControl().completeValidation(rootObjectClass, otherObjectClass);
474 }
475 if (validationPattern != null) {
476 validationPattern.completeValidation();
477 }
478
479 if (getFormatterClass() != null) {
480 try {
481 Class formatterClassObject = ClassUtils.getClass(ClassLoaderUtils.getDefaultClassLoader(),
482 getFormatterClass());
483 if (!Formatter.class.isAssignableFrom(formatterClassObject)) {
484 String currentValues[] = {"formatterClassObject = " + formatterClassObject.getName()};
485 tracer.createError("FormatterClass is not a valid instance", currentValues);
486 }
487 } catch (ClassNotFoundException e) {
488 String currentValues[] = {"class = " + getFormatterClass()};
489 tracer.createError("FormatterClass could not be found", currentValues);
490 }
491 }
492 } catch (RuntimeException ex) {
493 String currentValues[] =
494 {"attribute = " + rootObjectClass + "." + getName(), "Exception = " + ex.getMessage()};
495 tracer.createError("Unable to validate attribute", currentValues);
496 LOG.error("Exception while validating AttributeDefinition: " + getId(), ex );
497 }
498 }
499
500 @BeanTagAttribute(name = "attributeSecurity", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
501 public AttributeSecurity getAttributeSecurity() {
502 if ( attributeSecurity != null ) {
503 return attributeSecurity;
504 }
505
506
507
508 if ( getDataObjectAttribute() != null ) {
509 if ( getDataObjectAttribute().isSensitive() ) {
510 AttributeSecurity attrSec = new AttributeSecurity();
511 attrSec.setMask(true);
512 attrSec.setMaskFormatter(new MaskFormatterLiteral());
513 attributeSecurity = attrSec;
514 }
515 }
516
517 return attributeSecurity;
518 }
519
520 public void setAttributeSecurity(AttributeSecurity attributeSecurity) {
521 this.attributeSecurity = attributeSecurity;
522 }
523
524 public boolean hasAttributeSecurity() {
525 return (getAttributeSecurity() != null);
526 }
527
528
529
530
531 public Boolean getUnique() {
532 return this.unique;
533 }
534
535
536
537
538 public void setUnique(Boolean unique) {
539 this.unique = unique;
540 }
541
542
543
544
545
546
547
548
549
550
551 @BeanTagAttribute(name = "control", type = BeanTagAttribute.AttributeType.BYTYPE)
552 public Control getControlField() {
553 if ( controlField != null ) {
554 return controlField;
555 }
556 if ( cachedDerivedControl == null ) {
557 if ( GlobalResourceLoader.isInitialized() ) {
558 cachedDerivedControl = KRADServiceLocatorWeb.getUifDefaultingService().deriveControlAttributeFromMetadata(this);
559 }
560 }
561 return cachedDerivedControl;
562 }
563
564
565
566
567
568
569 public void setControlField(Control controlField) {
570 this.controlField = controlField;
571 }
572
573
574
575
576 @BeanTagAttribute
577 public Integer getMinLength() {
578 if ( getSimpleConstraint().getMinLength() != null ) {
579 return getSimpleConstraint().getMinLength();
580 }
581 if ( getDataObjectAttribute() != null ) {
582 if ( getDataObjectAttribute().getMinLength() != null ) {
583 return new Integer( getDataObjectAttribute().getMinLength().intValue() );
584 }
585 }
586 return null;
587 }
588
589
590
591
592
593
594 public void setMinLength(Integer minLength) {
595 this.getSimpleConstraint().setMinLength(minLength);
596 }
597
598
599
600
601
602
603
604
605 @BeanTagAttribute(type = BeanTagAttribute.AttributeType.SINGLEBEAN)
606 public DataType getDataType() {
607 if ( simpleConstraint.getDataType() != null ) {
608 return simpleConstraint.getDataType();
609 }
610 if ( getDataObjectAttribute() != null ) {
611 return getDataObjectAttribute().getDataType();
612 }
613 return DataType.STRING;
614 }
615
616
617
618
619 public void setDataType(DataType dataType) {
620 simpleConstraint.setDataType(dataType);
621 }
622
623 public void setDataType(String dataType) {
624 simpleConstraint.setDataType(DataType.valueOf(dataType));
625 }
626
627
628
629
630 @BeanTagAttribute
631 public String getCustomValidatorClass() {
632 return this.customValidatorClass;
633 }
634
635
636
637
638 public void setCustomValidatorClass(String customValidatorClass) {
639 this.customValidatorClass = customValidatorClass;
640 }
641
642
643
644
645 @Override
646 @BeanTagAttribute(type = BeanTagAttribute.AttributeType.DIRECTORBYTYPE)
647 public ValidCharactersConstraint getValidCharactersConstraint() {
648 if ( validCharactersConstraint == null ) {
649
650 if ( GlobalResourceLoader.isInitialized() ) {
651
652 if ( getControlField() != null && !getControlField().isHidden() && !Boolean.TRUE.equals(getControlField().getReadOnly()) ) {
653 validCharactersConstraint = KRADServiceLocatorWeb.getUifDefaultingService().deriveValidCharactersConstraint( this );
654 }
655 }
656 }
657 return validCharactersConstraint;
658 }
659
660
661
662
663 public void setValidCharactersConstraint(ValidCharactersConstraint validCharactersConstraint) {
664 this.validCharactersConstraint = validCharactersConstraint;
665 }
666
667
668
669
670 @Override
671 @BeanTagAttribute(type = BeanTagAttribute.AttributeType.DIRECTORBYTYPE)
672 public CaseConstraint getCaseConstraint() {
673 return this.caseConstraint;
674 }
675
676
677
678
679 public void setCaseConstraint(CaseConstraint caseConstraint) {
680 this.caseConstraint = caseConstraint;
681 }
682
683
684
685
686 @Override
687 @BeanTagAttribute
688 public List<PrerequisiteConstraint> getPrerequisiteConstraints() {
689 return this.dependencyConstraints;
690 }
691
692
693
694
695 public void setPrerequisiteConstraints(List<PrerequisiteConstraint> dependencyConstraints) {
696 this.dependencyConstraints = dependencyConstraints;
697 }
698
699
700
701
702 @Override
703 @BeanTagAttribute
704 public List<MustOccurConstraint> getMustOccurConstraints() {
705 return this.mustOccurConstraints;
706 }
707
708
709
710
711 public void setMustOccurConstraints(List<MustOccurConstraint> mustOccurConstraints) {
712 this.mustOccurConstraints = mustOccurConstraints;
713 }
714
715
716
717
718 @Override
719 @BeanTagAttribute
720 public String getChildEntryName() {
721 return this.childEntryName;
722 }
723
724
725
726
727 public void setChildEntryName(String childEntryName) {
728 this.childEntryName = childEntryName;
729 }
730
731
732
733
734
735
736
737
738
739 @BeanTagAttribute
740 public KeyValuesFinder getOptionsFinder() {
741 if ( optionsFinder == null ) {
742 if ( getDataObjectAttribute() != null && getDataObjectAttribute().getValidValues() != null ) {
743 return getDataObjectAttribute().getValidValues();
744 }
745 }
746 return optionsFinder;
747 }
748
749
750
751
752
753
754 public void setOptionsFinder(KeyValuesFinder optionsFinder) {
755 this.optionsFinder = optionsFinder;
756 }
757
758
759
760
761
762
763
764 public void setOptionsFinderClass(Class<? extends KeyValuesFinder> optionsFinderClass) {
765 this.optionsFinder = KRADUtils.createNewObjectFromClass(optionsFinderClass);
766 }
767
768 public void setAdditionalDisplayAttributeName(String additionalDisplayAttributeName) {
769 this.additionalDisplayAttributeName = additionalDisplayAttributeName;
770 }
771
772 @BeanTagAttribute
773 public String getAdditionalDisplayAttributeName() {
774 return this.additionalDisplayAttributeName;
775 }
776
777 public void setAlternateDisplayAttributeName(String alternateDisplayAttributeName) {
778 this.alternateDisplayAttributeName = alternateDisplayAttributeName;
779 }
780
781 @BeanTagAttribute
782 public String getAlternateDisplayAttributeName() {
783 return this.alternateDisplayAttributeName;
784 }
785
786
787
788
789
790
791 public List<PrerequisiteConstraint> getDependencyConstraints() {
792 return dependencyConstraints;
793 }
794
795
796
797
798
799
800 public void setDependencyConstraints(List<PrerequisiteConstraint> dependencyConstraints) {
801 this.dependencyConstraints = dependencyConstraints;
802 }
803
804 }