1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.field;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.exception.RiceRuntimeException;
20 import org.kuali.rice.krad.bo.DataObjectRelationship;
21 import org.kuali.rice.krad.bo.KualiCode;
22 import org.kuali.rice.krad.datadictionary.AttributeDefinition;
23 import org.kuali.rice.krad.datadictionary.mask.MaskFormatter;
24 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
25 import org.kuali.rice.krad.uif.component.BindingInfo;
26 import org.kuali.rice.krad.uif.component.Component;
27 import org.kuali.rice.krad.uif.component.ComponentSecurity;
28 import org.kuali.rice.krad.uif.component.DataBinding;
29 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
30 import org.kuali.rice.krad.uif.util.ViewModelUtils;
31 import org.kuali.rice.krad.uif.view.View;
32 import org.kuali.rice.krad.uif.widget.Inquiry;
33 import org.kuali.rice.krad.util.KRADPropertyConstants;
34 import org.kuali.rice.krad.util.ObjectUtils;
35 import org.kuali.rice.krad.valuefinder.ValueFinder;
36
37 import java.beans.PropertyEditor;
38 import java.util.ArrayList;
39 import java.util.List;
40
41
42
43
44
45
46 public class DataField extends FieldBase implements DataBinding {
47 private static final long serialVersionUID = -4129678891948564724L;
48
49
50 private String propertyName;
51 private BindingInfo bindingInfo;
52
53 private String dictionaryAttributeName;
54 private String dictionaryObjectEntry;
55
56
57 private String defaultValue;
58 private Class<? extends ValueFinder> defaultValueFinderClass;
59
60 private PropertyEditor propertyEditor;
61
62 private boolean readOnlyHidden;
63
64
65 protected String alternateDisplayPropertyName;
66 protected String additionalDisplayPropertyName;
67
68 private String alternateDisplayValue;
69 private String additionalDisplayValue;
70
71 private boolean applyValueMask;
72 private MaskFormatter maskFormatter;
73
74 private List<String> hiddenPropertyNames;
75 private List<String> informationalDisplayPropertyNames;
76
77 private boolean escapeHtmlInPropertyValue;
78
79 private String helpSummary;
80 private String helpDescription;
81
82
83 private Inquiry fieldInquiry;
84
85 public DataField() {
86 super();
87
88 readOnlyHidden = false;
89 applyValueMask = false;
90
91 hiddenPropertyNames = new ArrayList<String>();
92 informationalDisplayPropertyNames = new ArrayList<String>();
93 }
94
95
96
97
98
99
100
101
102
103
104
105
106 @Override
107 public void performInitialization(View view, Object model) {
108 super.performInitialization(view, model);
109
110 if (bindingInfo != null) {
111 bindingInfo.setDefaults(view, getPropertyName());
112 }
113 }
114
115
116
117
118
119
120
121
122 public void performApplyModel(View view, Object model, Component parent) {
123 super.performApplyModel(view, model, parent);
124
125 if (isReadOnlyHidden()) {
126 setReadOnly(true);
127 getHiddenPropertyNames().add(getPropertyName());
128 }
129 }
130
131
132
133
134
135
136
137
138
139
140
141
142
143 @Override
144 public void performFinalize(View view, Object model, Component parent) {
145 super.performFinalize(view, model, parent);
146
147
148
149 List<String> hiddenPropertyPaths = new ArrayList<String>();
150 for (String hiddenPropertyName : getHiddenPropertyNames()) {
151 String hiddenPropertyPath = getBindingInfo().getPropertyAdjustedBindingPath(hiddenPropertyName);
152 hiddenPropertyPaths.add(hiddenPropertyPath);
153 }
154 this.hiddenPropertyNames = hiddenPropertyPaths;
155
156
157 List<String> informationalPropertyPaths = new ArrayList<String>();
158 for (String infoPropertyName : getInformationalDisplayPropertyNames()) {
159 String infoPropertyPath = getBindingInfo().getPropertyAdjustedBindingPath(infoPropertyName);
160 informationalPropertyPaths.add(infoPropertyPath);
161 }
162 this.informationalDisplayPropertyNames = informationalPropertyPaths;
163
164
165 setAlternateAndAdditionalDisplayValue(view, model);
166 }
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191 protected void setAlternateAndAdditionalDisplayValue(View view, Object model) {
192
193 if (StringUtils.isNotBlank(alternateDisplayValue) || StringUtils.isNotBlank(additionalDisplayValue)) {
194 return;
195 }
196
197
198 if (isApplyValueMask()) {
199 Object fieldValue = ObjectPropertyUtils.getPropertyValue(model, getBindingInfo().getBindingPath());
200 alternateDisplayValue = getMaskFormatter().maskValue(fieldValue);
201
202
203 setReadOnly(true);
204 return;
205 }
206
207
208 if (!isReadOnly()) {
209 return;
210 }
211
212
213 if (StringUtils.isNotBlank(getAlternateDisplayPropertyName())) {
214 String alternateDisplayPropertyPath = getBindingInfo().getPropertyAdjustedBindingPath(
215 getAlternateDisplayPropertyName());
216
217 Object alternateFieldValue = ObjectPropertyUtils.getPropertyValue(model, alternateDisplayPropertyPath);
218 if (alternateFieldValue != null) {
219
220 alternateDisplayValue = alternateFieldValue.toString();
221 }
222 }
223
224
225 if (StringUtils.isBlank(getAdditionalDisplayPropertyName()) && view.isTranslateCodes()) {
226
227 Class<?> parentObjectClass = ViewModelUtils.getParentObjectClassForMetadata(view, model, this);
228 DataObjectRelationship relationship =
229 KRADServiceLocatorWeb.getDataObjectMetaDataService().getDataObjectRelationship(null,
230 parentObjectClass, getBindingInfo().getBindingName(), "", true, false, false);
231
232 if (relationship != null
233 && getPropertyName().startsWith(relationship.getParentAttributeName())
234 && KualiCode.class.isAssignableFrom(relationship.getRelatedClass())) {
235 additionalDisplayPropertyName =
236 relationship.getParentAttributeName() + "." + KRADPropertyConstants.NAME;
237 }
238 }
239
240
241 if (StringUtils.isNotBlank(getAdditionalDisplayPropertyName())) {
242 String additionalDisplayPropertyPath = getBindingInfo().getPropertyAdjustedBindingPath(
243 getAdditionalDisplayPropertyName());
244
245 Object additionalFieldValue = ObjectPropertyUtils.getPropertyValue(model, additionalDisplayPropertyPath);
246 if (additionalFieldValue != null) {
247
248 additionalDisplayValue = additionalFieldValue.toString();
249 }
250 }
251 }
252
253
254
255
256
257
258
259
260
261
262
263
264 public void copyFromAttributeDefinition(View view, AttributeDefinition attributeDefinition) {
265
266 if (StringUtils.isEmpty(getLabel())) {
267 setLabel(attributeDefinition.getLabel());
268 }
269
270
271 if (StringUtils.isEmpty(getShortLabel())) {
272 setShortLabel(attributeDefinition.getShortLabel());
273 }
274
275
276 if (StringUtils.isEmpty(getHelpSummary())) {
277 setHelpSummary(attributeDefinition.getSummary());
278 }
279
280
281 if (StringUtils.isEmpty(getHelpDescription())) {
282 setHelpDescription(attributeDefinition.getDescription());
283 }
284
285
286 if (getComponentSecurity().getAttributeSecurity() == null) {
287 getComponentSecurity().setAttributeSecurity(attributeDefinition.getAttributeSecurity());
288 }
289
290
291 if (getAlternateDisplayPropertyName() == null && StringUtils.isNotBlank(
292 attributeDefinition.getAlternateDisplayAttributeName())) {
293 setAlternateDisplayPropertyName(attributeDefinition.getAlternateDisplayAttributeName());
294 }
295
296
297 if (getAdditionalDisplayPropertyName() == null && StringUtils.isNotBlank(
298 attributeDefinition.getAdditionalDisplayAttributeName())) {
299 setAdditionalDisplayPropertyName(attributeDefinition.getAdditionalDisplayAttributeName());
300 }
301
302
303 if (getPropertyEditor() == null) {
304 setPropertyEditor(attributeDefinition.getPropertyEditor());
305 }
306 }
307
308
309
310
311 @Override
312 public List<Component> getComponentsForLifecycle() {
313 List<Component> components = super.getComponentsForLifecycle();
314
315 components.add(fieldInquiry);
316
317 return components;
318 }
319
320
321
322
323
324
325
326 public boolean isInputAllowed() {
327 return false;
328 }
329
330
331
332
333 public String getPropertyName() {
334 return this.propertyName;
335 }
336
337
338
339
340
341
342 public void setPropertyName(String propertyName) {
343 this.propertyName = propertyName;
344 }
345
346
347
348
349
350
351
352
353
354
355
356
357
358 public PropertyEditor getPropertyEditor() {
359 return propertyEditor;
360 }
361
362
363
364
365
366
367 public void setPropertyEditor(PropertyEditor propertyEditor) {
368 this.propertyEditor = propertyEditor;
369 }
370
371
372
373
374
375
376 public void setPropertyEditorClass(Class<? extends PropertyEditor> propertyEditorClass) {
377 this.propertyEditor = ObjectUtils.newInstance(propertyEditorClass);
378 }
379
380
381
382
383 public BindingInfo getBindingInfo() {
384 return this.bindingInfo;
385 }
386
387
388
389
390
391
392 public void setBindingInfo(BindingInfo bindingInfo) {
393 this.bindingInfo = bindingInfo;
394 }
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417 public String getDictionaryAttributeName() {
418 return this.dictionaryAttributeName;
419 }
420
421
422
423
424
425
426 public void setDictionaryAttributeName(String dictionaryAttributeName) {
427 this.dictionaryAttributeName = dictionaryAttributeName;
428 }
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450 public String getDictionaryObjectEntry() {
451 return this.dictionaryObjectEntry;
452 }
453
454
455
456
457
458
459 public void setDictionaryObjectEntry(String dictionaryObjectEntry) {
460 this.dictionaryObjectEntry = dictionaryObjectEntry;
461 }
462
463
464
465
466
467
468
469
470
471
472
473
474 public String getDefaultValue() {
475 return this.defaultValue;
476 }
477
478
479
480
481
482
483 public void setDefaultValue(String defaultValue) {
484 this.defaultValue = defaultValue;
485 }
486
487
488
489
490
491
492
493 public Class<? extends ValueFinder> getDefaultValueFinderClass() {
494 return this.defaultValueFinderClass;
495 }
496
497
498
499
500
501
502 public void setDefaultValueFinderClass(Class<? extends ValueFinder> defaultValueFinderClass) {
503 this.defaultValueFinderClass = defaultValueFinderClass;
504 }
505
506
507
508
509
510
511 public String getHelpSummary() {
512 return helpSummary;
513 }
514
515
516
517
518
519
520 public void setHelpSummary(String helpSummary) {
521 this.helpSummary = helpSummary;
522 }
523
524
525
526
527
528
529 public String getHelpDescription() {
530 return this.helpDescription;
531 }
532
533
534
535
536
537
538 public void setHelpDescription(String helpDescription) {
539 this.helpDescription = helpDescription;
540 }
541
542
543
544
545
546
547 @Override
548 public DataFieldSecurity getComponentSecurity() {
549 return (DataFieldSecurity) super.getComponentSecurity();
550 }
551
552
553
554
555
556
557 @Override
558 public void setComponentSecurity(ComponentSecurity componentSecurity) {
559 if (!(componentSecurity instanceof DataFieldSecurity)) {
560 throw new RiceRuntimeException("Component security for DataField should be instance of DataFieldSecurity");
561 }
562
563 super.setComponentSecurity(componentSecurity);
564 }
565
566 @Override
567 protected Class<? extends ComponentSecurity> getComponentSecurityClass() {
568 return DataFieldSecurity.class;
569 }
570
571
572
573
574
575
576
577
578
579
580 public boolean isReadOnlyHidden() {
581 return readOnlyHidden;
582 }
583
584
585
586
587
588
589 public void setReadOnlyHidden(boolean readOnlyHidden) {
590 this.readOnlyHidden = readOnlyHidden;
591 }
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606 public Inquiry getFieldInquiry() {
607 return this.fieldInquiry;
608 }
609
610
611
612
613
614
615 public void setFieldInquiry(Inquiry fieldInquiry) {
616 this.fieldInquiry = fieldInquiry;
617 }
618
619
620
621
622
623
624
625 public void setAdditionalDisplayPropertyName(String additionalDisplayPropertyName) {
626 this.additionalDisplayPropertyName = additionalDisplayPropertyName;
627 }
628
629
630
631
632
633
634 public String getAdditionalDisplayPropertyName() {
635 return this.additionalDisplayPropertyName;
636 }
637
638
639
640
641
642
643
644 public void setAlternateDisplayPropertyName(String alternateDisplayPropertyName) {
645 this.alternateDisplayPropertyName = alternateDisplayPropertyName;
646 }
647
648
649
650
651
652
653 public String getAlternateDisplayPropertyName() {
654 return this.alternateDisplayPropertyName;
655 }
656
657
658
659
660
661
662 public String getAlternateDisplayValue() {
663 return alternateDisplayValue;
664 }
665
666
667
668
669
670
671 public void setAlternateDisplayValue(String value) {
672 this.alternateDisplayValue = value;
673 }
674
675
676
677
678
679
680 public String getAdditionalDisplayValue() {
681 return additionalDisplayValue;
682 }
683
684
685
686
687
688
689 public void setAdditionalDisplayValue(String value) {
690 this.additionalDisplayValue = value;
691 }
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710 public boolean isApplyValueMask() {
711 return applyValueMask;
712 }
713
714
715
716
717
718
719 public void setApplyValueMask(boolean applyValueMask) {
720 this.applyValueMask = applyValueMask;
721 }
722
723
724
725
726
727
728
729
730
731
732
733 public MaskFormatter getMaskFormatter() {
734 return maskFormatter;
735 }
736
737
738
739
740
741
742 public void setMaskFormatter(MaskFormatter maskFormatter) {
743 this.maskFormatter = maskFormatter;
744 }
745
746
747
748
749
750
751
752 public List<String> getHiddenPropertyNames() {
753 return hiddenPropertyNames;
754 }
755
756
757
758
759
760
761 public void setHiddenPropertyNames(List<String> hiddenPropertyNames) {
762 this.hiddenPropertyNames = hiddenPropertyNames;
763 }
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783 public List<String> getInformationalDisplayPropertyNames() {
784 return informationalDisplayPropertyNames;
785 }
786
787
788
789
790
791
792 public void setInformationalDisplayPropertyNames(List<String> informationalDisplayPropertyNames) {
793 this.informationalDisplayPropertyNames = informationalDisplayPropertyNames;
794 }
795
796
797
798
799
800 public void setEscapeHtmlInPropertyValue(boolean escapeHtmlInPropertyValue) {
801 this.escapeHtmlInPropertyValue = escapeHtmlInPropertyValue;
802 }
803
804
805
806
807
808
809 public boolean isEscapeHtmlInPropertyValue() {
810 return this.escapeHtmlInPropertyValue;
811 }
812
813
814
815
816
817
818
819
820
821
822
823 public boolean hasSecureValue() {
824 return isApplyValueMask() || ((getComponentSecurity().isViewAuthz()
825 || getComponentSecurity().isViewInLineAuthz()
826 || ((getComponentSecurity().getAttributeSecurity() != null) && getComponentSecurity()
827 .getAttributeSecurity().isHide())) && isHidden());
828 }
829
830 }