1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.widget;
17
18 import com.google.common.collect.Maps;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.krad.bo.DataObjectRelationship;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
23 import org.kuali.rice.krad.datadictionary.parse.BeanTags;
24 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
25 import org.kuali.rice.krad.uif.UifParameters;
26 import org.kuali.rice.krad.uif.component.BindingInfo;
27 import org.kuali.rice.krad.uif.component.Component;
28 import org.kuali.rice.krad.uif.container.CollectionGroup;
29 import org.kuali.rice.krad.uif.element.Action;
30 import org.kuali.rice.krad.uif.field.InputField;
31 import org.kuali.rice.krad.uif.util.ViewModelUtils;
32 import org.kuali.rice.krad.uif.view.View;
33 import org.kuali.rice.krad.util.KRADConstants;
34 import org.kuali.rice.krad.util.KRADUtils;
35
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Map;
39
40
41
42
43
44
45 @BeanTags({@BeanTag(name = "quickFinder-bean", parent = "Uif-QuickFinder"),
46 @BeanTag(name = "quickFinderByScript-bean", parent = "Uif-QuickFinderByScript"),
47 @BeanTag(name = "collectionQuickFinder-bean", parent = "Uif-CollectionQuickFinder")})
48 public class QuickFinder extends WidgetBase {
49 private static final long serialVersionUID = 3302390972815386785L;
50
51
52 private String baseLookupUrl;
53 private String dataObjectClassName;
54 private String viewName;
55
56 private String referencesToRefresh;
57
58 private Map<String, String> fieldConversions;
59 private Map<String, String> lookupParameters;
60
61
62 private String readOnlySearchFields;
63
64 private Boolean hideReturnLink;
65 private Boolean suppressActions;
66 private Boolean autoSearch;
67 private Boolean renderLookupCriteria;
68 private Boolean supplementalActionsEnabled;
69 private Boolean renderSearchButtons;
70 private Boolean renderHeader;
71 private Boolean showMaintenanceLinks;
72
73 private Boolean multipleValuesSelect;
74 private String lookupCollectionName;
75
76 private Action quickfinderAction;
77 private LightBox lightBoxLookup;
78
79 public QuickFinder() {
80 super();
81
82 fieldConversions = new HashMap<String, String>();
83 lookupParameters = new HashMap<String, String>();
84 }
85
86
87
88
89
90
91
92
93
94
95
96 @Override
97 public void performInitialization(View view, Object model) {
98 super.performInitialization(view, model);
99
100 if (quickfinderAction != null && (lightBoxLookup != null && lightBoxLookup.isRender())) {
101 quickfinderAction.setActionScript("voidAction");
102 }
103 }
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125 @Override
126 public void performFinalize(View view, Object model, Component parent) {
127 super.performFinalize(view, model, parent);
128
129
130 if (parent.isReadOnly()) {
131 setRender(false);
132 }
133
134 if (!isRender()) {
135 return;
136 }
137
138 if (parent instanceof InputField) {
139 InputField field = (InputField) parent;
140
141
142
143 if (StringUtils.isBlank(dataObjectClassName)) {
144 DataObjectRelationship relationship = getRelationshipForField(view, model, field);
145
146
147 if (relationship == null) {
148 setRender(false);
149 return;
150 }
151
152 dataObjectClassName = relationship.getRelatedClass().getName();
153
154 if ((fieldConversions == null) || fieldConversions.isEmpty()) {
155 generateFieldConversions(field, relationship);
156 }
157
158 if ((lookupParameters == null) || lookupParameters.isEmpty()) {
159 generateLookupParameters(field, relationship);
160 }
161 }
162
163
164 updateFieldConversions(field.getBindingInfo());
165 updateLookupParameters(field.getBindingInfo());
166 updateReferencesToRefresh(field.getBindingInfo());
167 } else if (parent instanceof CollectionGroup) {
168 CollectionGroup collectionGroup = (CollectionGroup) parent;
169
170
171
172 if (StringUtils.isBlank(getDataObjectClassName())) {
173 Class<?> collectionObjectClass = collectionGroup.getCollectionObjectClass();
174 boolean isCollectionClassLookupable = KRADServiceLocatorWeb.getViewDictionaryService().isLookupable(
175 collectionObjectClass);
176 if (isCollectionClassLookupable) {
177 setDataObjectClassName(collectionObjectClass.getName());
178
179 if ((fieldConversions == null) || fieldConversions.isEmpty()) {
180
181 List<String> collectionObjectPKFields =
182 KRADServiceLocatorWeb.getDataObjectMetaDataService().listPrimaryKeyFieldNames(
183 collectionObjectClass);
184
185 for (String pkField : collectionObjectPKFields) {
186 fieldConversions.put(pkField, pkField);
187 }
188 }
189 } else {
190
191 setRender(false);
192 }
193 }
194
195
196 if (isRender() && StringUtils.isBlank(getLookupCollectionName())) {
197 setLookupCollectionName(collectionGroup.getBindingInfo().getBindingPath());
198 }
199 }
200
201 quickfinderAction.addActionParameter(UifParameters.BASE_LOOKUP_URL, baseLookupUrl);
202 quickfinderAction.addActionParameter(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClassName);
203
204 if (!fieldConversions.isEmpty()) {
205 quickfinderAction.addActionParameter(UifParameters.CONVERSION_FIELDS, KRADUtils.buildMapParameterString(
206 fieldConversions));
207 }
208
209 if (!lookupParameters.isEmpty()) {
210 quickfinderAction.addActionParameter(UifParameters.LOOKUP_PARAMETERS, KRADUtils.buildMapParameterString(
211 lookupParameters));
212 }
213
214 addActionParameterIfNotNull(UifParameters.VIEW_NAME, viewName);
215 addActionParameterIfNotNull(UifParameters.READ_ONLY_FIELDS, readOnlySearchFields);
216 addActionParameterIfNotNull(UifParameters.HIDE_RETURN_LINK, hideReturnLink);
217 addActionParameterIfNotNull(UifParameters.SUPPRESS_ACTIONS, suppressActions);
218 addActionParameterIfNotNull(UifParameters.REFERENCES_TO_REFRESH, referencesToRefresh);
219 addActionParameterIfNotNull(UifParameters.AUTO_SEARCH, autoSearch);
220 addActionParameterIfNotNull(UifParameters.RENDER_LOOKUP_CRITERIA, renderLookupCriteria);
221 addActionParameterIfNotNull(UifParameters.SUPPLEMENTAL_ACTIONS_ENABLED, supplementalActionsEnabled);
222 addActionParameterIfNotNull(UifParameters.RENDER_SEARCH_BUTTONS, renderSearchButtons);
223 addActionParameterIfNotNull(UifParameters.RENDER_HEADER, renderHeader);
224 addActionParameterIfNotNull(UifParameters.SHOW_MAINTENANCE_LINKS, showMaintenanceLinks);
225 addActionParameterIfNotNull(UifParameters.MULTIPLE_VALUES_SELECT, multipleValuesSelect);
226 addActionParameterIfNotNull(UifParameters.LOOKUP_COLLECTION_NAME, lookupCollectionName);
227
228
229
230
231 }
232
233 protected void addActionParameterIfNotNull(String parameterName, Object parameterValue) {
234 if ((parameterValue != null) && StringUtils.isNotBlank(parameterValue.toString())) {
235 quickfinderAction.addActionParameter(parameterName, parameterValue.toString());
236 }
237 }
238
239 protected DataObjectRelationship getRelationshipForField(View view, Object model, InputField field) {
240 String propertyName = field.getBindingInfo().getBindingName();
241
242
243 Object parentObject = ViewModelUtils.getParentObjectForMetadata(view, model, field);
244 Class<?> parentObjectClass = null;
245 if (parentObject != null) {
246 parentObjectClass = parentObject.getClass();
247 }
248
249
250 return KRADServiceLocatorWeb.getDataObjectMetaDataService().getDataObjectRelationship(parentObject,
251 parentObjectClass, propertyName, "", true, true, false);
252 }
253
254 protected void generateFieldConversions(InputField field, DataObjectRelationship relationship) {
255 fieldConversions = new HashMap<String, String>();
256 for (Map.Entry<String, String> entry : relationship.getParentToChildReferences().entrySet()) {
257 String fromField = entry.getValue();
258 String toField = entry.getKey();
259
260
261
262
263
264 fieldConversions.put(fromField, toField);
265 }
266 }
267
268 protected void generateLookupParameters(InputField field, DataObjectRelationship relationship) {
269 lookupParameters = new HashMap<String, String>();
270 for (Map.Entry<String, String> entry : relationship.getParentToChildReferences().entrySet()) {
271 String fromField = entry.getKey();
272 String toField = entry.getValue();
273
274
275
276
277
278 if (relationship.getUserVisibleIdentifierKey() == null || relationship.getUserVisibleIdentifierKey().equals(
279 fromField)) {
280 lookupParameters.put(fromField, toField);
281 }
282 }
283 }
284
285
286
287
288
289
290
291 public void updateFieldConversions(BindingInfo bindingInfo) {
292 Map<String, String> adjustedFieldConversions = new HashMap<String, String>();
293 for (String fromField : fieldConversions.keySet()) {
294 String toField = fieldConversions.get(fromField);
295 String adjustedToFieldPath = bindingInfo.getPropertyAdjustedBindingPath(toField);
296
297 adjustedFieldConversions.put(fromField, adjustedToFieldPath);
298 }
299
300 this.fieldConversions = adjustedFieldConversions;
301 }
302
303
304
305
306
307
308
309 public void updateLookupParameters(BindingInfo bindingInfo) {
310 Map<String, String> adjustedLookupParameters = new HashMap<String, String>();
311 for (String fromField : lookupParameters.keySet()) {
312 String toField = lookupParameters.get(fromField);
313 String adjustedFromFieldPath = bindingInfo.getPropertyAdjustedBindingPath(fromField);
314
315 adjustedLookupParameters.put(adjustedFromFieldPath, toField);
316 }
317
318 this.lookupParameters = adjustedLookupParameters;
319 }
320
321
322
323
324
325
326
327 public void updateReferencesToRefresh (BindingInfo bindingInfo) {
328 String adjustedReferencesToRefresh = new String();
329
330 if (referencesToRefresh == null) {
331 referencesToRefresh = adjustedReferencesToRefresh;
332 }
333
334 for (String reference : StringUtils.split(referencesToRefresh, KRADConstants.REFERENCES_TO_REFRESH_SEPARATOR )){
335
336
337 if (StringUtils.isNotBlank(adjustedReferencesToRefresh)) {
338 adjustedReferencesToRefresh = adjustedReferencesToRefresh + KRADConstants.REFERENCES_TO_REFRESH_SEPARATOR;
339 }
340
341 String adjustedReference = bindingInfo.getPropertyAdjustedBindingPath(reference);
342 adjustedReferencesToRefresh = adjustedReferencesToRefresh + adjustedReference;
343 }
344 this.referencesToRefresh = adjustedReferencesToRefresh;
345 }
346
347
348
349
350 @Override
351 public List<Component> getComponentsForLifecycle() {
352 List<Component> components = super.getComponentsForLifecycle();
353
354 components.add(quickfinderAction);
355 components.add(lightBoxLookup);
356
357 return components;
358 }
359
360
361
362
363
364
365
366
367
368
369
370
371
372 @BeanTagAttribute(name = "baseLookupUrl")
373 public String getBaseLookupUrl() {
374 return this.baseLookupUrl;
375 }
376
377
378
379
380
381
382 public void setBaseLookupUrl(String baseLookupUrl) {
383 this.baseLookupUrl = baseLookupUrl;
384 }
385
386
387
388
389
390
391
392
393
394
395
396
397 @BeanTagAttribute(name = "dataOjbectClassName")
398 public String getDataObjectClassName() {
399 return this.dataObjectClassName;
400 }
401
402
403
404
405
406
407 public void setDataObjectClassName(String dataObjectClassName) {
408 this.dataObjectClassName = dataObjectClassName;
409 }
410
411
412
413
414
415
416
417
418
419
420
421
422 @BeanTagAttribute(name = "viewName")
423 public String getViewName() {
424 return this.viewName;
425 }
426
427
428
429
430
431
432 public void setViewName(String viewName) {
433 this.viewName = viewName;
434 }
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453 @BeanTagAttribute(name = "referencesToRefresh")
454 public String getReferencesToRefresh() {
455 return this.referencesToRefresh;
456 }
457
458
459
460
461
462
463 public void setReferencesToRefresh(String referencesToRefresh) {
464 this.referencesToRefresh = referencesToRefresh;
465 }
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489 @BeanTagAttribute(name = "fieldConversions", type = BeanTagAttribute.AttributeType.MAPVALUE)
490 public Map<String, String> getFieldConversions() {
491 return this.fieldConversions;
492 }
493
494
495
496
497
498
499
500 public void setFieldConversions(Map<String, String> fieldConversions) {
501 this.fieldConversions = fieldConversions;
502 }
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518 @BeanTagAttribute(name = "lookupParameters", type = BeanTagAttribute.AttributeType.MAPVALUE)
519 public Map<String, String> getLookupParameters() {
520 return this.lookupParameters;
521 }
522
523
524
525
526
527
528
529 public void setLookupParameters(Map<String, String> lookupParameters) {
530 this.lookupParameters = lookupParameters;
531 }
532
533
534
535
536
537
538
539
540
541
542
543
544
545 @BeanTagAttribute(name = "readOnlySearchFields")
546 public String getReadOnlySearchFields() {
547 return this.readOnlySearchFields;
548 }
549
550
551
552
553
554
555
556 public void setReadOnlySearchFields(String readOnlySearchFields) {
557 this.readOnlySearchFields = readOnlySearchFields;
558 }
559
560
561
562
563
564
565
566
567
568
569
570
571 @BeanTagAttribute(name = "hideReturnLink")
572 public Boolean getHideReturnLink() {
573 return this.hideReturnLink;
574 }
575
576
577
578
579
580
581 public void setHideReturnLink(Boolean hideReturnLink) {
582 this.hideReturnLink = hideReturnLink;
583 }
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602 @BeanTagAttribute(name = "suppressActions")
603 public Boolean getSuppressActions() {
604 return suppressActions;
605 }
606
607
608
609
610
611
612 public void setSuppressActions(Boolean suppressActions) {
613 this.suppressActions = suppressActions;
614 }
615
616
617
618
619
620
621
622
623
624
625
626
627 @BeanTagAttribute(name = "autoSearch")
628 public Boolean getAutoSearch() {
629 return this.autoSearch;
630 }
631
632
633
634
635
636
637 public void setAutoSearch(Boolean autoSearch) {
638 this.autoSearch = autoSearch;
639 }
640
641
642
643
644
645
646
647
648
649
650
651 @BeanTagAttribute(name = "renderLookupCriteria")
652 public Boolean getRenderLookupCriteria() {
653 return this.renderLookupCriteria;
654 }
655
656
657
658
659
660
661 public void setRenderLookupCriteria(Boolean renderLookupCriteria) {
662 this.renderLookupCriteria = renderLookupCriteria;
663 }
664
665
666
667
668
669
670 @BeanTagAttribute(name = "supplementalActionsEnabled")
671 public Boolean getSupplementalActionsEnabled() {
672 return this.supplementalActionsEnabled;
673 }
674
675 public void setSupplementalActionsEnabled(Boolean supplementalActionsEnabled) {
676 this.supplementalActionsEnabled = supplementalActionsEnabled;
677 }
678
679
680
681
682
683
684 @BeanTagAttribute(name = "renderSearchButtons")
685 public Boolean getRenderSearchButtons() {
686 return this.renderSearchButtons;
687 }
688
689
690
691
692
693
694 public void setRenderSearchButtons(Boolean renderSearchButtons) {
695 this.renderSearchButtons = renderSearchButtons;
696 }
697
698
699
700
701
702
703
704
705
706
707 @BeanTagAttribute(name = "renderHeader")
708 public Boolean getRenderHeader() {
709 return this.renderHeader;
710 }
711
712
713
714
715
716
717 public void setRenderHeader(Boolean renderHeader) {
718 this.renderHeader = renderHeader;
719 }
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736 @BeanTagAttribute(name = "showMaintenanceLinks")
737 public Boolean getShowMaintenanceLinks() {
738 return this.showMaintenanceLinks;
739 }
740
741
742
743
744
745
746 public void setShowMaintenanceLinks(Boolean showMaintenanceLinks) {
747 this.showMaintenanceLinks = showMaintenanceLinks;
748 }
749
750
751
752
753
754
755
756
757
758
759
760
761 @BeanTagAttribute(name = "quickfinderAction", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
762 public Action getQuickfinderAction() {
763 return this.quickfinderAction;
764 }
765
766
767
768
769
770
771 public void setQuickfinderAction(Action quickfinderAction) {
772 this.quickfinderAction = quickfinderAction;
773 }
774
775
776
777
778
779
780 public void setLightBoxLookup(LightBox lightBoxLookup) {
781 this.lightBoxLookup = lightBoxLookup;
782 }
783
784
785
786
787
788
789
790
791
792
793
794 @BeanTagAttribute(name = "lightBoxLookup", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
795 public LightBox getLightBoxLookup() {
796 return lightBoxLookup;
797 }
798
799
800
801
802
803
804 @BeanTagAttribute(name = "MultipleValuesSelect")
805 public Boolean getMultipleValuesSelect() {
806 return multipleValuesSelect;
807 }
808
809
810
811
812
813
814 public void setMultipleValuesSelect(Boolean multipleValuesSelect) {
815 this.multipleValuesSelect = multipleValuesSelect;
816 }
817
818
819
820
821
822
823
824
825
826
827
828
829 @BeanTagAttribute(name = "lookupCollectionName")
830 public String getLookupCollectionName() {
831 return lookupCollectionName;
832 }
833
834
835
836
837
838
839 public void setLookupCollectionName(String lookupCollectionName) {
840 this.lookupCollectionName = lookupCollectionName;
841 }
842
843
844
845
846 @Override
847 protected <T> void copyProperties(T component) {
848 super.copyProperties(component);
849 QuickFinder quickFinderCopy = (QuickFinder) component;
850 quickFinderCopy.setBaseLookupUrl(this.getBaseLookupUrl());
851 quickFinderCopy.setDataObjectClassName(this.getDataObjectClassName());
852 quickFinderCopy.setViewName(this.getViewName());
853 quickFinderCopy.setReferencesToRefresh(this.getReferencesToRefresh());
854
855 if(fieldConversions != null) {
856 Map<String, String> fieldConversionsCopy = Maps.newHashMapWithExpectedSize(fieldConversions.size());
857 for(Map.Entry fieldConversion : fieldConversions.entrySet()) {
858 fieldConversionsCopy.put(fieldConversion.getKey().toString(),fieldConversion.getValue().toString());
859 }
860 quickFinderCopy.setFieldConversions(fieldConversionsCopy);
861 }
862
863 if(lookupParameters != null) {
864 Map<String, String> lookupParametersCopy = Maps.newHashMapWithExpectedSize(lookupParameters.size());
865 for(Map.Entry lookupParameter : lookupParameters.entrySet()) {
866 lookupParametersCopy.put(lookupParameter.getKey().toString(),lookupParameter.getValue().toString());
867 }
868 quickFinderCopy.setLookupParameters(lookupParametersCopy);
869 }
870
871 quickFinderCopy.setReadOnlySearchFields(this.getReadOnlySearchFields());
872 quickFinderCopy.setHideReturnLink(this.getHideReturnLink());
873 quickFinderCopy.setSuppressActions(this.getSuppressActions());
874 quickFinderCopy.setAutoSearch(this.getAutoSearch());
875 quickFinderCopy.setRenderLookupCriteria(this.getRenderLookupCriteria());
876 quickFinderCopy.setSupplementalActionsEnabled(this.getSupplementalActionsEnabled());
877 quickFinderCopy.setRenderSearchButtons(this.getRenderSearchButtons());
878 quickFinderCopy.setRenderHeader(this.getRenderHeader());
879 quickFinderCopy.setShowMaintenanceLinks(this.getShowMaintenanceLinks());
880 quickFinderCopy.setMultipleValuesSelect(this.getMultipleValuesSelect());
881 quickFinderCopy.setLookupCollectionName(this.getLookupCollectionName());
882
883 if(lightBoxLookup != null) {
884 quickFinderCopy.setLightBoxLookup((LightBox)this.getLightBoxLookup().copy());
885 }
886
887 if (this.quickfinderAction != null) {
888 quickFinderCopy.setQuickfinderAction((Action)this.quickfinderAction.copy());
889 }
890 }
891 }