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