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