1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.web.struts.form;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.kns.lookup.LookupUtils;
20 import org.kuali.rice.kns.lookup.Lookupable;
21 import org.kuali.rice.kns.service.KNSServiceLocator;
22 import org.kuali.rice.kns.web.ui.Field;
23 import org.kuali.rice.kns.web.ui.Row;
24 import org.kuali.rice.krad.service.DataDictionaryService;
25 import org.kuali.rice.krad.service.KRADServiceLocator;
26 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
27 import org.kuali.rice.krad.util.ExternalizableBusinessObjectUtils;
28 import org.kuali.rice.krad.util.KRADConstants;
29
30 import javax.servlet.http.HttpServletRequest;
31 import java.util.HashMap;
32 import java.util.Iterator;
33 import java.util.List;
34 import java.util.Map;
35
36
37
38
39 public class LookupForm extends KualiForm {
40 private static final long serialVersionUID = 1L;
41
42 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LookupForm.class);
43
44 private String formKey;
45 private Map<String, String> fields;
46 private Map fieldsForLookup;
47 private String lookupableImplServiceName;
48 private String conversionFields;
49 private Map fieldConversions;
50 private String businessObjectClassName;
51 private Lookupable lookupable;
52 private boolean hideReturnLink = false;
53 private boolean suppressActions = false;
54 private boolean multipleValues = false;
55 private String lookupAnchor;
56 private String readOnlyFields;
57 private List readOnlyFieldsList;
58 private String referencesToRefresh;
59 private boolean searchUsingOnlyPrimaryKeyValues;
60 private String primaryKeyFieldLabels;
61 private boolean showMaintenanceLinks = false;
62 private String docNum;
63 private String htmlDataType;
64 private String lookupObjectId;
65 private boolean lookupCriteriaEnabled = true;
66 private boolean supplementalActionsEnabled = false;
67 private boolean actionUrlsExist = false;
68 private boolean ddExtraButton = false;
69 private boolean headerBarEnabled = true;
70 private boolean disableSearchButtons = false;
71
72
73
74
75 public void addRequiredNonEditableProperties(){
76 super.addRequiredNonEditableProperties();
77 registerRequiredNonEditableProperty(KRADConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME);
78 registerRequiredNonEditableProperty(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE);
79 registerRequiredNonEditableProperty(KRADConstants.DISPATCH_REQUEST_PARAMETER);
80 registerRequiredNonEditableProperty(KRADConstants.DOC_FORM_KEY);
81 registerRequiredNonEditableProperty(KRADConstants.REFRESH_CALLER);
82 registerRequiredNonEditableProperty(KRADConstants.DOC_NUM);
83 registerRequiredNonEditableProperty(KRADConstants.REFERENCES_TO_REFRESH);
84 registerRequiredNonEditableProperty(KRADConstants.FORM_KEY);
85 registerRequiredNonEditableProperty(KRADConstants.CONVERSION_FIELDS_PARAMETER);
86 registerRequiredNonEditableProperty(KRADConstants.FIELDS_CONVERSION_PARAMETER);
87 registerRequiredNonEditableProperty(KRADConstants.HIDE_LOOKUP_RETURN_LINK);
88 registerRequiredNonEditableProperty(KRADConstants.MULTIPLE_VALUE);
89 registerRequiredNonEditableProperty(KRADConstants.BACK_LOCATION);
90 registerRequiredNonEditableProperty(KRADConstants.LOOKUP_ANCHOR);
91 registerRequiredNonEditableProperty("searchUsingOnlyPrimaryKeyValues");
92 registerRequiredNonEditableProperty(KRADConstants.MULTIPLE_VALUE_LOOKUP_PREVIOUSLY_SELECTED_OBJ_IDS_PARAM);
93 registerRequiredNonEditableProperty(KRADConstants.TableRenderConstants.VIEWED_PAGE_NUMBER);
94 }
95
96
97
98
99 public String getHtmlDataType() {
100 return this.htmlDataType;
101 }
102
103
104
105
106 public void setHtmlDataType(String htmlDataType) {
107 this.htmlDataType = htmlDataType;
108 }
109
110
111
112
113 public String getDocNum() {
114 return this.docNum;
115 }
116
117
118
119
120 public void setDocNum(String docNum) {
121 this.docNum = docNum;
122 }
123
124
125
126
127 private boolean hasReturnableRow;
128
129
130
131 private Map requestParameters;
132
133
134
135
136 @Override
137 public void postprocessRequestParameters(Map requestParameters) {
138 this.requestParameters = requestParameters;
139 super.postprocessRequestParameters(requestParameters);
140 }
141
142
143
144
145 public void populate(HttpServletRequest request) {
146 super.populate(request);
147
148 DataDictionaryService ddService = KRADServiceLocatorWeb.getDataDictionaryService();
149
150 try {
151 Lookupable localLookupable = null;
152 if (StringUtils.isBlank(getParameter(request, KRADConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME)) && StringUtils.isBlank(getLookupableImplServiceName())) {
153
154 String localBusinessObjectClassName = getParameter(request, KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE);
155 if ( ExternalizableBusinessObjectUtils.isExternalizableBusinessObjectInterface(localBusinessObjectClassName) ) {
156 Class localBusinessObjectClass = Class.forName(localBusinessObjectClassName);
157 localBusinessObjectClassName = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(localBusinessObjectClass).getExternalizableBusinessObjectImplementation(localBusinessObjectClass).getName();
158 }
159 setBusinessObjectClassName(localBusinessObjectClassName);
160 if (StringUtils.isBlank(localBusinessObjectClassName)) {
161 LOG.error("Business object class not passed to lookup.");
162 throw new RuntimeException("Business object class not passed to lookup.");
163 }
164
165
166 String lookupImplID = KRADServiceLocatorWeb.getBusinessObjectDictionaryService().getLookupableID(Class.forName(localBusinessObjectClassName));
167 if (lookupImplID == null) {
168 lookupImplID = "kualiLookupable";
169 }
170
171 setLookupableImplServiceName(lookupImplID);
172 }
173 localLookupable = KNSServiceLocator.getLookupable(getLookupableImplServiceName());
174
175 if (localLookupable == null) {
176 LOG.error("Lookup impl not found for lookup impl name " + getLookupableImplServiceName());
177 throw new RuntimeException("Lookup impl not found for lookup impl name " + getLookupableImplServiceName());
178 }
179
180
181 localLookupable.setParameters(requestParameters);
182 requestParameters = null;
183
184 if (getParameter(request, KRADConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME) != null) {
185 setLookupableImplServiceName(getParameter(request, KRADConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME));
186 }
187
188 if (getParameter(request, KRADConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME) != null) {
189 setLookupableImplServiceName(getParameter(request, KRADConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME));
190 }
191
192
193 if (request.getAttribute(KRADConstants.DOC_FORM_KEY) != null && StringUtils.isBlank(this.getFormKey())) {
194 setFormKey((String) request.getAttribute(KRADConstants.DOC_FORM_KEY));
195 }
196 else if (getParameter(request, KRADConstants.DOC_FORM_KEY) != null && StringUtils.isBlank(this.getFormKey())) {
197 setFormKey(getParameter(request, KRADConstants.DOC_FORM_KEY));
198 }
199
200 if (getParameter(request, KRADConstants.DOC_NUM) != null) {
201 setDocNum(getParameter(request, KRADConstants.DOC_NUM));
202 }
203
204 String returnLocation = getParameter(request, "returnLocation");
205 if (StringUtils.isNotBlank(returnLocation)) {
206 setBackLocation(returnLocation);
207 localLookupable.getLookupableHelperService().setBackLocation(returnLocation);
208 }
209
210 if (getParameter(request, "conversionFields") != null) {
211 setConversionFields(getParameter(request, "conversionFields"));
212 }
213 if (getParameter(request, KRADConstants.EXTRA_BUTTON_SOURCE) != null) {
214
215 ddExtraButton=false;
216 setExtraButtonSource(getParameter(request, KRADConstants.EXTRA_BUTTON_SOURCE));
217 }
218 if (getParameter(request, KRADConstants.EXTRA_BUTTON_PARAMS) != null) {
219 setExtraButtonParams(getParameter(request, KRADConstants.EXTRA_BUTTON_PARAMS));
220 }
221 String value = getParameter(request, "multipleValues");
222 if (value != null) {
223 if ("YES".equals(value.toUpperCase())) {
224 setMultipleValues(true);
225 }
226 else {
227 setMultipleValues(new Boolean(getParameter(request, "multipleValues")).booleanValue());
228 }
229 }
230 if (getParameter(request, KRADConstants.REFERENCES_TO_REFRESH) != null) {
231 setReferencesToRefresh(getParameter(request, KRADConstants.REFERENCES_TO_REFRESH));
232 }
233
234 if (getParameter(request, "readOnlyFields") != null) {
235 setReadOnlyFields(getParameter(request, "readOnlyFields"));
236 setReadOnlyFieldsList(LookupUtils.translateReadOnlyFieldsToList(this.readOnlyFields));
237 localLookupable.setReadOnlyFieldsList(getReadOnlyFieldsList());
238 }
239
240
241 localLookupable.setBusinessObjectClass(Class.forName(getBusinessObjectClassName()));
242 Map<String, String> fieldValues = new HashMap<String, String>();
243 Map<String, String> formFields = getFields();
244 Class boClass = Class.forName(getBusinessObjectClassName());
245
246 for (Iterator iter = localLookupable.getRows().iterator(); iter.hasNext();) {
247 Row row = (Row) iter.next();
248
249 for (Iterator iterator = row.getFields().iterator(); iterator.hasNext();) {
250 Field field = (Field) iterator.next();
251
252
253 if (formFields != null && formFields.containsKey(field.getPropertyName())) {
254 field.setPropertyValue(formFields.get(field.getPropertyName()));
255 }
256
257
258 if (getParameter(request, field.getPropertyName()) != null) {
259 if(!Field.MULTI_VALUE_FIELD_TYPES.contains(field.getFieldType())) {
260 field.setPropertyValue(getParameter(request, field.getPropertyName()).trim());
261 } else {
262
263 field.setPropertyValues(getParameterValues(request, field.getPropertyName()));
264 }
265 }
266
267 field.setPropertyValue(org.kuali.rice.krad.lookup.LookupUtils
268 .forceUppercase(boClass, field.getPropertyName(), field.getPropertyValue()));
269 fieldValues.put(field.getPropertyName(), field.getPropertyValue());
270
271 localLookupable.applyFieldAuthorizationsFromNestedLookups(field);
272 }
273 }
274
275 if (localLookupable.checkForAdditionalFields(fieldValues)) {
276 for (Iterator iter = localLookupable.getRows().iterator(); iter.hasNext();) {
277 Row row = (Row) iter.next();
278
279 for (Iterator iterator = row.getFields().iterator(); iterator.hasNext();) {
280 Field field = (Field) iterator.next();
281
282
283 if (formFields != null && formFields.containsKey(field.getPropertyName())) {
284 field.setPropertyValue(formFields.get(field.getPropertyName()));
285 }
286
287
288 if (getParameter(request, field.getPropertyName()) != null) {
289 if(!Field.MULTI_VALUE_FIELD_TYPES.contains(field.getFieldType())) {
290 field.setPropertyValue(getParameter(request, field.getPropertyName()).trim());
291 } else {
292
293 field.setPropertyValues(getParameterValues(request, field.getPropertyName()));
294 }
295 }
296 fieldValues.put(field.getPropertyName(), field.getPropertyValue());
297 }
298 }
299
300 }
301 fieldValues.put(KRADConstants.DOC_FORM_KEY, this.getFormKey());
302 fieldValues.put(KRADConstants.BACK_LOCATION, this.getBackLocation());
303 if(this.getDocNum() != null){
304 fieldValues.put(KRADConstants.DOC_NUM, this.getDocNum());
305 }
306 if (StringUtils.isNotBlank(getReferencesToRefresh())) {
307 fieldValues.put(KRADConstants.REFERENCES_TO_REFRESH, this.getReferencesToRefresh());
308 }
309
310 this.setFields(fieldValues);
311
312 setFieldConversions(LookupUtils.translateFieldConversions(this.conversionFields));
313 localLookupable.setFieldConversions(getFieldConversions());
314 if(StringUtils.isNotEmpty(localLookupable.getExtraButtonSource())) {
315 setExtraButtonSource(localLookupable.getExtraButtonSource());
316
317 ddExtraButton=true;
318 }
319 if(StringUtils.isNotEmpty(localLookupable.getExtraButtonParams())) {
320 setExtraButtonParams(localLookupable.getExtraButtonParams());
321 }
322 setLookupable(localLookupable);
323 setFieldsForLookup(fieldValues);
324
325
326 if (!isShowMaintenanceLinks()) {
327 if (StringUtils.contains(getBackLocation(), "/"+ KRADConstants.PORTAL_ACTION)
328 || StringUtils.contains(getBackLocation(), "/index.html")) {
329 showMaintenanceLinks = true;
330 }
331 }
332 }
333 catch (ClassNotFoundException e) {
334 LOG.error("Business Object class " + getBusinessObjectClassName() + " not found");
335 throw new RuntimeException("Business Object class " + getBusinessObjectClassName() + " not found", e);
336 }
337 }
338
339
340
341
342 public String getLookupableImplServiceName() {
343 return lookupableImplServiceName;
344 }
345
346
347
348
349 public void setLookupableImplServiceName(String lookupableImplServiceName) {
350 this.lookupableImplServiceName = lookupableImplServiceName;
351 }
352
353
354
355
356 public String getFormKey() {
357 return formKey;
358 }
359
360
361
362
363 public void setFormKey(String formKey) {
364 this.formKey = formKey;
365 }
366
367
368
369
370 public Map<String, String> getFields() {
371 return fields;
372 }
373
374
375
376
377 public void setFields(Map<String, String> fields) {
378 this.fields = fields;
379 }
380
381
382
383
384 public String getConversionFields() {
385 return conversionFields;
386 }
387
388
389
390
391 public void setConversionFields(String conversionFields) {
392 this.conversionFields = conversionFields;
393 }
394
395
396
397
398 public Map getFieldConversions() {
399 return fieldConversions;
400 }
401
402
403
404
405 public void setFieldConversions(Map fieldConversions) {
406 this.fieldConversions = fieldConversions;
407 }
408
409
410
411
412 public String getBusinessObjectClassName() {
413 return businessObjectClassName;
414 }
415
416
417
418
419 public void setBusinessObjectClassName(String businessObjectClassName) {
420 this.businessObjectClassName = businessObjectClassName;
421 }
422
423
424
425
426
427 public Lookupable getLookupable() {
428 return lookupable;
429 }
430
431
432
433
434
435 public void setLookupable(Lookupable lookupable) {
436 this.lookupable = lookupable;
437 }
438
439
440
441
442
443 public boolean isHideReturnLink() {
444 return hideReturnLink;
445 }
446
447
448
449
450 public void setSuppressActions(boolean suppressActions) {
451 this.suppressActions = suppressActions;
452 }
453
454
455
456
457 public boolean isSuppressActions() {
458 return suppressActions;
459 }
460
461
462
463
464
465 public void setHideReturnLink(boolean hideReturnLink) {
466 this.hideReturnLink = hideReturnLink;
467 }
468
469
470 public String getExtraButtonParams() {
471 return extraButtons.get(0).getExtraButtonParams();
472 }
473
474
475 public void setExtraButtonParams(String extraButtonParams) {
476 extraButtons.get(0).setExtraButtonParams( extraButtonParams );
477 }
478
479
480 public String getExtraButtonSource() {
481 return extraButtons.get(0).getExtraButtonSource();
482 }
483
484
485 public void setExtraButtonSource(String extraButtonSource) {
486 extraButtons.get(0).setExtraButtonSource( extraButtonSource );
487 }
488
489
490
491
492
493
494 public boolean isMultipleValues() {
495 return multipleValues;
496 }
497
498
499
500
501
502 public void setMultipleValues(boolean multipleValues) {
503 this.multipleValues = multipleValues;
504 }
505
506 public String getLookupAnchor() {
507 return lookupAnchor;
508 }
509
510 public void setLookupAnchor(String lookupAnchor) {
511 this.lookupAnchor = lookupAnchor;
512 }
513
514
515
516
517
518 public Map getFieldsForLookup() {
519 return fieldsForLookup;
520 }
521
522
523
524
525
526 public void setFieldsForLookup(Map fieldsForLookup) {
527 this.fieldsForLookup = fieldsForLookup;
528 }
529
530
531
532
533
534 public String getReadOnlyFields() {
535 return readOnlyFields;
536 }
537
538
539
540
541
542 public void setReadOnlyFields(String readOnlyFields) {
543 this.readOnlyFields = readOnlyFields;
544 }
545
546
547
548
549
550 public List getReadOnlyFieldsList() {
551 return readOnlyFieldsList;
552 }
553
554
555
556
557
558 public void setReadOnlyFieldsList(List readOnlyFieldsList) {
559 this.readOnlyFieldsList = readOnlyFieldsList;
560 }
561
562 public String getReferencesToRefresh() {
563 return referencesToRefresh;
564 }
565
566 public void setReferencesToRefresh(String referencesToRefresh) {
567 this.referencesToRefresh = referencesToRefresh;
568 }
569
570 public String getPrimaryKeyFieldLabels() {
571 return primaryKeyFieldLabels;
572 }
573
574 public void setPrimaryKeyFieldLabels(String primaryKeyFieldLabels) {
575 this.primaryKeyFieldLabels = primaryKeyFieldLabels;
576 }
577
578 public boolean isSearchUsingOnlyPrimaryKeyValues() {
579 return searchUsingOnlyPrimaryKeyValues;
580 }
581
582 public void setSearchUsingOnlyPrimaryKeyValues(boolean searchUsingOnlyPrimaryKeyValues) {
583 this.searchUsingOnlyPrimaryKeyValues = searchUsingOnlyPrimaryKeyValues;
584 }
585
586
587
588
589
590 public boolean isShowMaintenanceLinks() {
591 return showMaintenanceLinks;
592 }
593
594
595
596
597
598 public void setShowMaintenanceLinks(boolean showMaintenanceLinks) {
599 this.showMaintenanceLinks = showMaintenanceLinks;
600 }
601
602
603
604
605
606
607 public boolean isHasReturnableRow() {
608 return this.hasReturnableRow;
609 }
610
611
612
613
614
615
616 public void setHasReturnableRow(boolean hasReturnableRow) {
617 this.hasReturnableRow = hasReturnableRow;
618 }
619
620
621
622
623 public String getLookupObjectId() {
624 return this.lookupObjectId;
625 }
626
627
628
629
630 public void setLookupObjectId(String lookupObjectId) {
631 this.lookupObjectId = lookupObjectId;
632 }
633
634
635
636
637 public boolean isLookupCriteriaEnabled() {
638 return this.lookupCriteriaEnabled;
639 }
640
641
642
643
644 public void setLookupCriteriaEnabled(boolean lookupCriteriaEnabled) {
645 this.lookupCriteriaEnabled = lookupCriteriaEnabled;
646 }
647
648
649
650
651 public boolean isSupplementalActionsEnabled() {
652 return this.supplementalActionsEnabled;
653 }
654
655
656
657
658 public void setSupplementalActionsEnabled(boolean supplementalActionsEnabled) {
659 this.supplementalActionsEnabled = supplementalActionsEnabled;
660 }
661
662
663
664
665
666 public void setActionUrlsExist(boolean actionUrlsExist) {
667 this.actionUrlsExist = actionUrlsExist;
668 }
669
670
671
672
673 public boolean isActionUrlsExist() {
674 return actionUrlsExist;
675 }
676
677
678
679
680 public boolean isDdExtraButton() {
681 return this.ddExtraButton;
682 }
683
684
685
686
687 public void setDdExtraButton(boolean ddExtraButton) {
688 this.ddExtraButton = ddExtraButton;
689 }
690
691 public boolean isHeaderBarEnabled() {
692 return headerBarEnabled;
693 }
694
695 public void setHeaderBarEnabled(boolean headerBarEnabled) {
696 this.headerBarEnabled = headerBarEnabled;
697 }
698
699 public boolean isDisableSearchButtons() {
700 return this.disableSearchButtons;
701 }
702
703 public void setDisableSearchButtons(boolean disableSearchButtons) {
704 this.disableSearchButtons = disableSearchButtons;
705 }
706
707
708
709
710
711
712
713 public boolean getRenderSearchButtons() {
714 boolean renderSearchButtons = true;
715
716 if (disableSearchButtons
717 || KRADServiceLocatorWeb.getBusinessObjectDictionaryService().disableSearchButtonsInLookup(
718 getLookupable().getBusinessObjectClass())) {
719 renderSearchButtons = false;
720 }
721
722 return renderSearchButtons;
723 }
724 }