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