1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.util;
17
18 import java.lang.reflect.InvocationTargetException;
19 import java.security.GeneralSecurityException;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.Iterator;
25 import java.util.LinkedHashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.apache.commons.beanutils.NestedNullException;
30 import org.apache.commons.beanutils.PropertyUtils;
31 import org.apache.commons.lang.StringUtils;
32 import org.kuali.rice.core.api.CoreApiServiceLocator;
33 import org.kuali.rice.core.api.data.DataType;
34 import org.kuali.rice.core.api.encryption.EncryptionService;
35 import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
36 import org.kuali.rice.core.api.uif.AttributeLookupSettings;
37 import org.kuali.rice.core.api.uif.RemotableAbstractControl;
38 import org.kuali.rice.core.api.uif.RemotableAbstractWidget;
39 import org.kuali.rice.core.api.uif.RemotableAttributeField;
40 import org.kuali.rice.core.api.uif.RemotableAttributeLookupSettings;
41 import org.kuali.rice.core.api.uif.RemotableCheckbox;
42 import org.kuali.rice.core.api.uif.RemotableCheckboxGroup;
43 import org.kuali.rice.core.api.uif.RemotableControlContract;
44 import org.kuali.rice.core.api.uif.RemotableDatepicker;
45 import org.kuali.rice.core.api.uif.RemotableHiddenInput;
46 import org.kuali.rice.core.api.uif.RemotablePasswordInput;
47 import org.kuali.rice.core.api.uif.RemotableQuickFinder;
48 import org.kuali.rice.core.api.uif.RemotableRadioButtonGroup;
49 import org.kuali.rice.core.api.uif.RemotableSelect;
50 import org.kuali.rice.core.api.uif.RemotableTextExpand;
51 import org.kuali.rice.core.api.uif.RemotableTextInput;
52 import org.kuali.rice.core.api.uif.RemotableTextarea;
53 import org.kuali.rice.core.api.util.ClassLoaderUtils;
54 import org.kuali.rice.core.api.util.ConcreteKeyValue;
55 import org.kuali.rice.core.api.util.KeyValue;
56 import org.kuali.rice.core.api.util.io.SerializationUtils;
57 import org.kuali.rice.core.web.format.FormatException;
58 import org.kuali.rice.core.web.format.Formatter;
59 import org.kuali.rice.kew.api.KewApiConstants;
60 import org.kuali.rice.kim.api.identity.Person;
61 import org.kuali.rice.kns.datadictionary.BusinessObjectEntry;
62 import org.kuali.rice.kns.datadictionary.FieldDefinition;
63 import org.kuali.rice.kns.datadictionary.MaintainableCollectionDefinition;
64 import org.kuali.rice.kns.datadictionary.control.ButtonControlDefinition;
65 import org.kuali.rice.kns.datadictionary.control.CurrencyControlDefinition;
66 import org.kuali.rice.kns.datadictionary.control.KualiUserControlDefinition;
67 import org.kuali.rice.kns.datadictionary.control.LinkControlDefinition;
68 import org.kuali.rice.kns.document.authorization.FieldRestriction;
69 import org.kuali.rice.kns.document.authorization.MaintenanceDocumentRestrictions;
70 import org.kuali.rice.kns.inquiry.Inquirable;
71 import org.kuali.rice.kns.lookup.HtmlData;
72 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
73 import org.kuali.rice.kns.lookup.LookupUtils;
74 import org.kuali.rice.kns.service.BusinessObjectDictionaryService;
75 import org.kuali.rice.kns.service.BusinessObjectMetaDataService;
76 import org.kuali.rice.kns.service.KNSServiceLocator;
77 import org.kuali.rice.kns.web.comparator.CellComparatorHelper;
78 import org.kuali.rice.kns.web.ui.Column;
79 import org.kuali.rice.kns.web.ui.Field;
80 import org.kuali.rice.kns.web.ui.PropertyRenderingConfigElement;
81 import org.kuali.rice.kns.web.ui.Row;
82 import org.kuali.rice.kns.web.ui.Section;
83 import org.kuali.rice.krad.bo.BusinessObject;
84 import org.kuali.rice.krad.bo.DataObjectRelationship;
85 import org.kuali.rice.krad.bo.KualiCode;
86 import org.kuali.rice.krad.bo.PersistableBusinessObject;
87 import org.kuali.rice.krad.datadictionary.control.ControlDefinition;
88 import org.kuali.rice.krad.datadictionary.exception.UnknownBusinessClassAttributeException;
89 import org.kuali.rice.krad.datadictionary.mask.MaskFormatter;
90 import org.kuali.rice.krad.keyvalues.IndicatorValuesFinder;
91 import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
92 import org.kuali.rice.krad.keyvalues.PersistableBusinessObjectValuesFinder;
93 import org.kuali.rice.krad.service.DataDictionaryService;
94 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
95 import org.kuali.rice.krad.service.KualiModuleService;
96 import org.kuali.rice.krad.service.ModuleService;
97 import org.kuali.rice.krad.util.ExternalizableBusinessObjectUtils;
98 import org.kuali.rice.krad.util.GlobalVariables;
99 import org.kuali.rice.krad.util.KRADConstants;
100 import org.kuali.rice.krad.util.KRADPropertyConstants;
101 import org.kuali.rice.krad.util.MessageMap;
102 import org.kuali.rice.krad.util.ObjectUtils;
103 import org.kuali.rice.krad.valuefinder.ValueFinder;
104
105
106
107
108
109 public final class FieldUtils {
110 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(FieldUtils.class);
111 private static DataDictionaryService dataDictionaryService = null;
112 private static BusinessObjectMetaDataService businessObjectMetaDataService = null;
113 private static BusinessObjectDictionaryService businessObjectDictionaryService = null;
114 private static KualiModuleService kualiModuleService = null;
115
116 private FieldUtils() {
117 throw new UnsupportedOperationException("do not call");
118 }
119
120 public static void setInquiryURL(Field field, BusinessObject bo, String propertyName) {
121 HtmlData inquiryHref = new AnchorHtmlData(KRADConstants.EMPTY_STRING, KRADConstants.EMPTY_STRING);
122
123 Boolean b = getBusinessObjectDictionaryService().noInquiryFieldInquiry(bo.getClass(), propertyName);
124 if (b == null || !b.booleanValue()) {
125 Class<Inquirable> inquirableClass = getBusinessObjectDictionaryService().getInquirableClass(bo.getClass());
126 Boolean b2 = getBusinessObjectDictionaryService().forceLookupResultFieldInquiry(bo.getClass(), propertyName);
127 Inquirable inq = null;
128 try {
129 if ( inquirableClass != null ) {
130 inq = inquirableClass.newInstance();
131 } else {
132 inq = KNSServiceLocator.getKualiInquirable();
133 if ( LOG.isDebugEnabled() ) {
134 LOG.debug( "Default Inquirable Class: " + inq.getClass() );
135 }
136 }
137
138 inquiryHref = inq.getInquiryUrl(bo, propertyName, null == b2 ? false : b2.booleanValue() );
139
140 } catch ( Exception ex ) {
141 LOG.error("unable to create inquirable to get inquiry URL", ex );
142 }
143 }
144
145 field.setInquiryURL(inquiryHref);
146 }
147
148
149
150
151
152
153
154
155
156
157
158
159
160 public static void setFieldControl(Class businessObjectClass, String attributeName, boolean convertForLookup,
161 Field field) {
162 ControlDefinition control = getDataDictionaryService().getAttributeControlDefinition(businessObjectClass,
163 attributeName);
164 String fieldType = Field.TEXT;
165
166 if (control != null) {
167 if (control.isSelect()) {
168 if (control.getScript() != null && control.getScript().length() > 0) {
169 fieldType = Field.DROPDOWN_SCRIPT;
170 field.setScript(control.getScript());
171 } else {
172 fieldType = Field.DROPDOWN;
173 }
174 }
175
176 if (control.isMultiselect()) {
177 fieldType = Field.MULTISELECT;
178 }
179
180 if (control.isCheckbox()) {
181 fieldType = Field.CHECKBOX;
182 }
183
184 if (control.isRadio()) {
185 fieldType = Field.RADIO;
186 }
187
188 if (control.isHidden()) {
189 fieldType = Field.HIDDEN;
190 }
191
192 if (control.isKualiUser()) {
193 fieldType = Field.KUALIUSER;
194 KualiUserControlDefinition kualiUserControl = (KualiUserControlDefinition) control;
195 field.setUniversalIdAttributeName(kualiUserControl.getUniversalIdAttributeName());
196 field.setUserIdAttributeName(kualiUserControl.getUserIdAttributeName());
197 field.setPersonNameAttributeName(kualiUserControl.getPersonNameAttributeName());
198 }
199
200 if (control.isWorkflowWorkgroup()) {
201 fieldType = Field.WORKFLOW_WORKGROUP;
202 }
203
204 if (control.isFile()) {
205 fieldType = Field.FILE;
206 }
207
208 if (control.isTextarea() && !convertForLookup) {
209 fieldType = Field.TEXT_AREA;
210 }
211
212 if (control.isLookupHidden()) {
213 fieldType = Field.LOOKUP_HIDDEN;
214 }
215
216 if (control.isLookupReadonly()) {
217 fieldType = Field.LOOKUP_READONLY;
218 }
219
220 if (control.isCurrency()) {
221 fieldType = Field.CURRENCY;
222 }
223
224 if (control.isButton()) {
225 fieldType = Field.BUTTON;
226 }
227
228 if (control.isLink()) {
229 fieldType = Field.LINK;
230 }
231
232 if (Field.CURRENCY.equals(fieldType) && control instanceof CurrencyControlDefinition) {
233 CurrencyControlDefinition currencyControl = (CurrencyControlDefinition) control;
234 field.setStyleClass("amount");
235 field.setSize(currencyControl.getSize());
236 field.setFormattedMaxLength(currencyControl.getFormattedMaxLength());
237 }
238
239
240 if (Field.TEXT.equals(fieldType)) {
241 Integer size = control.getSize();
242 if (size != null) {
243 field.setSize(size.intValue());
244 } else {
245 field.setSize(30);
246 }
247 field.setDatePicker(control.isDatePicker());
248 field.setRanged(control.isRanged());
249 }
250
251 if (Field.WORKFLOW_WORKGROUP.equals(fieldType)) {
252 Integer size = control.getSize();
253 if (size != null) {
254 field.setSize(size.intValue());
255 } else {
256 field.setSize(30);
257 }
258 }
259
260
261 if (Field.TEXT_AREA.equals(fieldType)) {
262 Integer rows = control.getRows();
263 if (rows != null) {
264 field.setRows(rows.intValue());
265 } else {
266 field.setRows(3);
267 }
268
269 Integer cols = control.getCols();
270 if (cols != null) {
271 field.setCols(cols.intValue());
272 } else {
273 field.setCols(40);
274 }
275 field.setExpandedTextArea(control.isExpandedTextArea());
276 }
277
278 if (Field.MULTISELECT.equals(fieldType)) {
279 Integer size = control.getSize();
280 if (size != null) {
281 field.setSize(size.intValue());
282 }
283 }
284
285
286 if (Field.DROPDOWN.equals(fieldType) || Field.RADIO.equals(fieldType)
287 || Field.DROPDOWN_SCRIPT.equals(fieldType)
288 || Field.MULTISELECT.equals(fieldType)) {
289 String keyFinderClassName = control.getValuesFinderClass();
290
291 if (StringUtils.isNotBlank(keyFinderClassName)) {
292 try {
293 Class keyFinderClass = ClassLoaderUtils.getClass(keyFinderClassName);
294 KeyValuesFinder finder = (KeyValuesFinder) keyFinderClass.newInstance();
295
296 if (finder != null) {
297 if (finder instanceof PersistableBusinessObjectValuesFinder) {
298 ((PersistableBusinessObjectValuesFinder) finder)
299 .setBusinessObjectClass(ClassLoaderUtils.getClass(control
300 .getBusinessObjectClass()));
301 ((PersistableBusinessObjectValuesFinder) finder).setKeyAttributeName(control
302 .getKeyAttribute());
303 ((PersistableBusinessObjectValuesFinder) finder).setLabelAttributeName(control
304 .getLabelAttribute());
305 if (control.getIncludeBlankRow() != null) {
306 ((PersistableBusinessObjectValuesFinder) finder).setIncludeBlankRow(control
307 .getIncludeBlankRow());
308 }
309 ((PersistableBusinessObjectValuesFinder) finder).setIncludeKeyInDescription(control
310 .getIncludeKeyInLabel());
311 }
312 field.setFieldValidValues(finder.getKeyValues());
313 field.setFieldInactiveValidValues(finder.getKeyValues(false));
314 }
315 } catch (InstantiationException e) {
316 LOG.error("Unable to get new instance of finder class: " + keyFinderClassName);
317 throw new RuntimeException("Unable to get new instance of finder class: " + keyFinderClassName);
318 } catch (IllegalAccessException e) {
319 LOG.error("Unable to get new instance of finder class: " + keyFinderClassName);
320 throw new RuntimeException("Unable to get new instance of finder class: " + keyFinderClassName);
321 }
322 }
323 }
324
325 if (Field.CHECKBOX.equals(fieldType) && convertForLookup) {
326 fieldType = Field.RADIO;
327 field.setFieldValidValues(IndicatorValuesFinder.INSTANCE.getKeyValues());
328 }
329
330
331 if (Field.BUTTON.equals(fieldType)) {
332 ButtonControlDefinition buttonControl = (ButtonControlDefinition) control;
333 field.setImageSrc(buttonControl.getImageSrc());
334 field.setStyleClass(buttonControl.getStyleClass());
335 }
336
337
338 if (Field.LINK.equals(fieldType)) {
339 LinkControlDefinition linkControl = (LinkControlDefinition) control;
340 field.setStyleClass(linkControl.getStyleClass());
341 field.setTarget(linkControl.getTarget());
342 field.setHrefText(linkControl.getHrefText());
343 }
344
345 }
346
347 field.setFieldType(fieldType);
348 }
349
350
351
352
353
354
355
356
357 public static Field getPropertyField(Class businessObjectClass, String attributeName, boolean convertForLookup) {
358 Field field = new Field();
359 field.setPropertyName(attributeName);
360
361
362 if (ExternalizableBusinessObjectUtils.isExternalizableBusinessObject(businessObjectClass)) {
363 ModuleService moduleService = getKualiModuleService().getResponsibleModuleService(businessObjectClass);
364 businessObjectClass = moduleService.getExternalizableBusinessObjectDictionaryEntry(businessObjectClass).getDataObjectClass();
365 }
366
367 field.setFieldLabel(getDataDictionaryService().getAttributeLabel(businessObjectClass, attributeName));
368
369 setFieldControl(businessObjectClass, attributeName, convertForLookup, field);
370
371 Boolean fieldRequired = getBusinessObjectDictionaryService().getLookupAttributeRequired(businessObjectClass, attributeName);
372 if (fieldRequired != null) {
373 field.setFieldRequired(fieldRequired.booleanValue());
374 }
375
376 Integer maxLength = getDataDictionaryService().getAttributeMaxLength(businessObjectClass, attributeName);
377 if (maxLength != null) {
378 field.setMaxLength(maxLength.intValue());
379 }
380
381 Boolean upperCase = null;
382 try {
383 upperCase = getDataDictionaryService().getAttributeForceUppercase(businessObjectClass, attributeName);
384 }
385 catch (UnknownBusinessClassAttributeException t) {
386
387 LOG.warn( "UnknownBusinessClassAttributeException in fieldUtils.getPropertyField() : " + t.getMessage() );
388 }
389 if (upperCase != null) {
390 field.setUpperCase(upperCase.booleanValue());
391 }
392
393 if (!businessObjectClass.isInterface()) {
394 try {
395 field.setFormatter(
396 ObjectUtils.getFormatterWithDataDictionary(businessObjectClass.newInstance(), attributeName));
397 } catch (InstantiationException e) {
398 LOG.info("Unable to get new instance of business object class: " + businessObjectClass.getName(), e);
399
400 } catch (IllegalAccessException e) {
401 LOG.info("Unable to get new instance of business object class: " + businessObjectClass.getName(), e);
402
403 }
404 }
405
406
407 field.setBusinessObjectClassName(businessObjectClass.getName());
408 field.setFieldHelpName(attributeName);
409 field.setFieldHelpSummary(getDataDictionaryService().getAttributeSummary(businessObjectClass, attributeName));
410
411 return field;
412 }
413
414
415
416
417
418
419
420
421
422
423
424
425
426 public static void setAdditionalDisplayPropertyForCodes(Class businessObjectClass, String attributeName, PropertyRenderingConfigElement field) {
427 try {
428 DataObjectRelationship relationship = getBusinessObjectMetaDataService().getBusinessObjectRelationship(
429 (BusinessObject) businessObjectClass.newInstance(), attributeName);
430
431 if (relationship != null && attributeName.startsWith(relationship.getParentAttributeName())
432 && KualiCode.class.isAssignableFrom(relationship.getRelatedClass())) {
433 field.setAdditionalDisplayPropertyName(relationship.getParentAttributeName() + "."
434 + KRADPropertyConstants.NAME);
435 }
436 } catch (Exception e) {
437 throw new RuntimeException("Cannot get new instance of class to check for KualiCode references: "
438 + e.getMessage());
439 }
440 }
441
442
443
444
445
446
447
448
449 public static List wrapFields(List fields) {
450 return wrapFields(fields, KRADConstants.DEFAULT_NUM_OF_COLUMNS);
451 }
452
453
454
455
456
457
458
459
460 public static List<Row> wrapFields(List<Field> fields, int numberOfColumns) {
461
462 List<Row> rows = new ArrayList();
463 List<Field> fieldOnlyList = new ArrayList();
464
465 List<Field> visableFields = getVisibleFields(fields);
466 List<Field> nonVisableFields = getNonVisibleFields(fields);
467
468 int fieldsPosition = 0;
469 for (Field element : visableFields) {
470 if (Field.SUB_SECTION_SEPARATOR.equals(element.getFieldType()) || Field.CONTAINER.equals(element.getFieldType())) {
471 fieldsPosition = createBlankSpace(fieldOnlyList, rows, numberOfColumns, fieldsPosition);
472 List fieldList = new ArrayList();
473 fieldList.add(element);
474 rows.add(new Row(fieldList));
475 }
476 else {
477 if (fieldsPosition < numberOfColumns) {
478 fieldOnlyList.add(element);
479 fieldsPosition++;
480 }
481 else {
482 rows.add(new Row(new ArrayList(fieldOnlyList)));
483 fieldOnlyList.clear();
484 fieldOnlyList.add(element);
485 fieldsPosition = 1;
486 }
487 }
488 }
489 createBlankSpace(fieldOnlyList, rows, numberOfColumns, fieldsPosition);
490
491
492 if(nonVisableFields != null && !nonVisableFields.isEmpty()){
493 Row nonVisRow = new Row();
494 nonVisRow.setFields(nonVisableFields);
495 rows.add(nonVisRow);
496 }
497
498
499 return rows;
500 }
501
502 private static List<Field> getVisibleFields(List<Field> fields){
503 List<Field> rList = new ArrayList<Field>();
504
505 for(Field f: fields){
506 if(!Field.HIDDEN.equals(f.getFieldType()) && !Field.BLANK_SPACE.equals(f.getFieldType())){
507 rList.add(f);
508 }
509 }
510
511 return rList;
512 }
513
514 private static List<Field> getNonVisibleFields(List<Field> fields){
515 List<Field> rList = new ArrayList<Field>();
516
517 for(Field f: fields){
518 if(Field.HIDDEN.equals(f.getFieldType()) || Field.BLANK_SPACE.equals(f.getFieldType())){
519 rList.add(f);
520 }
521 }
522
523 return rList;
524 }
525
526
527
528
529
530
531
532
533
534 private static int createBlankSpace(List<Field> fieldOnlyList, List<Row> rows, int numberOfColumns, int fieldsPosition) {
535 int fieldOnlySize = fieldOnlyList.size();
536 if (fieldOnlySize > 0) {
537 for (int i = 0; i < (numberOfColumns - fieldOnlySize); i++) {
538 Field empty = new Field();
539 empty.setFieldType(Field.BLANK_SPACE);
540
541 empty.setPropertyName(Field.BLANK_SPACE);
542 fieldOnlyList.add(empty);
543 }
544 rows.add(new Row(new ArrayList(fieldOnlyList)));
545 fieldOnlyList.clear();
546 fieldsPosition = 0;
547 }
548 return fieldsPosition;
549 }
550
551
552
553
554
555
556
557
558
559 public static Field constructContainerField(String name, String label, List fields) {
560 return constructContainerField(name, label, fields, KRADConstants.DEFAULT_NUM_OF_COLUMNS);
561 }
562
563
564
565
566
567
568
569
570
571
572 public static Field constructContainerField(String name, String label, List fields, int numberOfColumns) {
573 Field containerField = new Field();
574 containerField.setPropertyName(name);
575 containerField.setFieldLabel(label);
576 containerField.setFieldType(Field.CONTAINER);
577 containerField.setNumberOfColumnsForCollection(numberOfColumns);
578
579 List rows = wrapFields(fields, numberOfColumns);
580 containerField.setContainerRows(rows);
581
582 return containerField;
583 }
584
585
586
587
588
589
590
591
592
593 public static List<Field> populateFieldsFromBusinessObject(List<Field> fields, BusinessObject bo) {
594 List<Field> populatedFields = new ArrayList<Field>();
595
596 if (bo instanceof PersistableBusinessObject) {
597 ((PersistableBusinessObject) bo).refreshNonUpdateableReferences();
598 }
599
600 for (Iterator<Field> iter = fields.iterator(); iter.hasNext();) {
601 Field element = iter.next();
602 if (element.containsBOData()) {
603 String propertyName = element.getPropertyName();
604
605
606
607
608 if (isPropertyNested(propertyName) && !isObjectTreeNonNullAllTheWayDown(bo, propertyName) && ((!element.getFieldType().equals(Field.IMAGE_SUBMIT)) && !(element.getFieldType().equals(Field.CONTAINER)) && (!element.getFieldType().equals(Field.QUICKFINDER)))) {
609 element.setPropertyValue(null);
610 }
611 else if (isPropertyReadable(bo, propertyName)) {
612 populateReadableField(element, bo);
613 }
614
615 if (StringUtils.isNotBlank(element.getAlternateDisplayPropertyName())) {
616 String alternatePropertyValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(bo, element
617 .getAlternateDisplayPropertyName());
618 element.setAlternateDisplayPropertyValue(alternatePropertyValue);
619 }
620
621 if (StringUtils.isNotBlank(element.getAdditionalDisplayPropertyName())) {
622 String additionalPropertyValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(bo, element
623 .getAdditionalDisplayPropertyName());
624 element.setAdditionalDisplayPropertyValue(additionalPropertyValue);
625 }
626 }
627 populatedFields.add(element);
628 }
629
630 return populatedFields;
631 }
632
633 private static boolean isPropertyReadable(Object bean, String name) {
634 try {
635 return PropertyUtils.isReadable(bean, name);
636 } catch (NestedNullException e) {
637 return false;
638 }
639 }
640
641 private static boolean isPropertyWritable(Object bean, String name) {
642 try {
643 return PropertyUtils.isWriteable(bean, name);
644 } catch (NestedNullException e) {
645 return false;
646 }
647 }
648
649 public static void populateReadableField(Field field, BusinessObject businessObject){
650 Object obj = ObjectUtils.getNestedValue(businessObject, field.getPropertyName());
651
652
653
654 if (Field.FILE.equals(field.getFieldType())) {
655 Object fileName = ObjectUtils.getNestedValue(businessObject, KRADConstants.BO_ATTACHMENT_FILE_NAME);
656 Object fileType = ObjectUtils.getNestedValue(businessObject, KRADConstants.BO_ATTACHMENT_FILE_CONTENT_TYPE);
657 field.setImageSrc(WebUtils.getAttachmentImageForUrl((String)fileType));
658 field.setPropertyValue(fileName);
659 }
660
661 if (obj != null) {
662 String formattedValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(businessObject, field.getPropertyName());
663 field.setPropertyValue(formattedValue);
664
665
666 if ( field.getFieldType().equals(Field.KUALIUSER) ) {
667
668 try {
669 if ( StringUtils.isNotBlank(field.getUniversalIdAttributeName()) ) {
670 Object principalId = ObjectUtils.getNestedValue(businessObject, field.getUniversalIdAttributeName());
671 if ( principalId != null ) {
672 field.setUniversalIdValue(principalId.toString());
673 }
674 }
675 if ( StringUtils.isNotBlank(field.getPersonNameAttributeName()) ) {
676 Object personName = ObjectUtils.getNestedValue(businessObject, field.getPersonNameAttributeName());
677 if ( personName != null ) {
678 field.setPersonNameValue( personName.toString() );
679 }
680 }
681 } catch ( Exception ex ) {
682 LOG.warn( "Unable to get principal ID or person name property in FieldBridge.", ex );
683 }
684 }
685 }
686
687 populateSecureField(field, obj);
688 }
689
690 public static void populateSecureField(Field field, Object fieldValue){
691
692
693 if (field.isSecure()) {
694 try {
695 if (fieldValue != null && fieldValue.toString().endsWith(EncryptionService.HASH_POST_PREFIX)) {
696 field.setEncryptedValue(fieldValue.toString());
697 }
698 else {
699 if(CoreApiServiceLocator.getEncryptionService().isEnabled()) {
700 field.setEncryptedValue(CoreApiServiceLocator.getEncryptionService().encrypt(fieldValue) + EncryptionService.ENCRYPTION_POST_PREFIX);
701 }
702 }
703 }
704 catch (GeneralSecurityException e) {
705 throw new RuntimeException("Unable to encrypt secure field " + e.getMessage());
706 }
707
708 }
709 }
710
711
712
713
714
715
716
717 static private boolean isPropertyNested(String propertyName) {
718 return -1 != propertyName.indexOf('.');
719 }
720
721
722
723
724
725
726
727
728
729 static private boolean isObjectTreeNonNullAllTheWayDown(BusinessObject bo, String propertyName) {
730 String[] propertyParts = propertyName.split("\\.");
731
732 StringBuffer property = new StringBuffer();
733 for (int i = 0; i < propertyParts.length - 1; i++) {
734
735 property.append((0 == property.length()) ? "" : ".").append(propertyParts[i]);
736 try {
737 if (null == PropertyUtils.getNestedProperty(bo, property.toString())) {
738 return false;
739 }
740 }
741 catch (Throwable t) {
742 LOG.debug("Either getter or setter not specified for property \"" + property.toString() + "\"", t);
743 return false;
744 }
745 }
746
747 return true;
748
749 }
750
751
752
753
754
755
756 private static boolean containsIntermediateNull(Object bo, String propertyName) {
757 boolean containsNull = false;
758
759 if (StringUtils.contains(propertyName, ".")) {
760 String prefix = StringUtils.substringBefore(propertyName, ".");
761 Object propertyValue = ObjectUtils.getPropertyValue(bo, prefix);
762
763 if (propertyValue == null) {
764 containsNull = true;
765 }
766 else {
767 String suffix = StringUtils.substringAfter(propertyName, ".");
768 containsNull = containsIntermediateNull(propertyValue, suffix);
769 }
770 }
771
772 return containsNull;
773 }
774
775
776
777
778
779
780
781
782
783 public static Map populateBusinessObjectFromMap(BusinessObject bo, Map fieldValues) {
784 return populateBusinessObjectFromMap(bo, fieldValues, "");
785 }
786
787
788
789
790
791
792
793
794
795
796 public static Map populateBusinessObjectFromMap(BusinessObject bo, Map<String, ?> fieldValues, String propertyNamePrefix) {
797 Map cachedValues = new HashMap();
798 MessageMap errorMap = GlobalVariables.getMessageMap();
799
800 try {
801 for (Iterator<String> iter = fieldValues.keySet().iterator(); iter.hasNext();) {
802 String propertyName = iter.next();
803
804 if (propertyName.endsWith(KRADConstants.CHECKBOX_PRESENT_ON_FORM_ANNOTATION)) {
805
806
807 if (StringUtils.isNotBlank((String) fieldValues.get(propertyName))) {
808 String checkboxName = StringUtils.removeEnd(propertyName, KRADConstants.CHECKBOX_PRESENT_ON_FORM_ANNOTATION);
809 String checkboxValue = (String) fieldValues.get(checkboxName);
810 if (checkboxValue == null) {
811
812 if (isPropertyWritable(bo, checkboxName)) {
813 Class type = ObjectUtils.easyGetPropertyType(bo, checkboxName);
814 if (type == Boolean.TYPE || type == Boolean.class) {
815
816 ObjectUtils.setObjectProperty(bo, checkboxName, type, "false");
817 }
818 }
819 }
820 }
821
822
823 }
824 else if (isPropertyWritable(bo, propertyName) && fieldValues.get(propertyName) != null ) {
825
826 Class type = ObjectUtils.easyGetPropertyType(bo, propertyName);
827 try {
828 Object fieldValue = fieldValues.get(propertyName);
829 ObjectUtils.setObjectProperty(bo, propertyName, type, fieldValue);
830 }
831 catch (FormatException e) {
832 cachedValues.put(propertyNamePrefix + propertyName, fieldValues.get(propertyName));
833 errorMap.putError(propertyNamePrefix + propertyName, e.getErrorKey(), e.getErrorArgs());
834 }
835 }
836 }
837 }
838 catch (IllegalAccessException e) {
839 LOG.error("unable to populate business object" + e.getMessage());
840 throw new RuntimeException(e.getMessage(), e);
841 }
842 catch (InvocationTargetException e) {
843 LOG.error("unable to populate business object" + e.getMessage());
844 throw new RuntimeException(e.getMessage(), e);
845 }
846 catch (NoSuchMethodException e) {
847 LOG.error("unable to populate business object" + e.getMessage());
848 throw new RuntimeException(e.getMessage(), e);
849 }
850
851 return cachedValues;
852 }
853
854
855
856
857
858
859
860
861
862
863
864 public static Field fixFieldForForm(Field field, List keyFieldNames, String namePrefix, String maintenanceAction, boolean readOnly, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) {
865 String propertyName = field.getPropertyName();
866
867 if (field.containsBOData()) {
868
869
870 if (!propertyName.startsWith(KRADConstants.DISPATCH_REQUEST_PARAMETER)) {
871
872 if (field.getPropertyPrefix() == null || field.getPropertyPrefix().equals("")) {
873 field.setPropertyName(namePrefix + propertyName);
874 }
875 else {
876 field.setPropertyName(field.getPropertyPrefix() + "." + propertyName);
877 }
878 }
879
880 if (readOnly) {
881 field.setReadOnly(true);
882 }
883
884
885 if ( KRADConstants.MAINTENANCE_EDIT_ACTION.equals(maintenanceAction) ) {
886 if (keyFieldNames.contains(propertyName) ) {
887 field.setReadOnly(true);
888 field.setKeyField(true);
889 } else if ( StringUtils.isNotBlank( field.getUniversalIdAttributeName() )
890 && keyFieldNames.contains(field.getUniversalIdAttributeName() ) ) {
891
892
893 field.setReadOnly(true);
894 field.setKeyField(true);
895 }
896 }
897
898
899 applyAuthorization(field, maintenanceAction, auths, documentStatus, documentInitiatorPrincipalId);
900
901
902 if (StringUtils.isNotBlank(field.getFieldConversions())) {
903 String fieldConversions = field.getFieldConversions();
904 String newFieldConversions = KRADConstants.EMPTY_STRING;
905 String[] conversions = StringUtils.split(fieldConversions, KRADConstants.FIELD_CONVERSIONS_SEPARATOR);
906
907 for (int l = 0; l < conversions.length; l++) {
908 String conversion = conversions[l];
909
910 String[] conversionPair = StringUtils.split(conversion, KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR, 2);
911 String conversionFrom = conversionPair[0];
912 String conversionTo = conversionPair[1];
913 conversionTo = KRADConstants.MAINTENANCE_NEW_MAINTAINABLE + conversionTo;
914 newFieldConversions += (conversionFrom + KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR + conversionTo);
915
916 if (l < conversions.length) {
917 newFieldConversions += KRADConstants.FIELD_CONVERSIONS_SEPARATOR;
918 }
919 }
920
921 field.setFieldConversions(newFieldConversions);
922 }
923
924
925 if (StringUtils.isNotBlank(field.getInquiryParameters())) {
926 String inquiryParameters = field.getInquiryParameters();
927 StringBuilder newInquiryParameters = new StringBuilder();
928 String[] parameters = StringUtils.split(inquiryParameters, KRADConstants.FIELD_CONVERSIONS_SEPARATOR);
929
930 for (int l = 0; l < parameters.length; l++) {
931 String parameter = parameters[l];
932
933 String[] parameterPair = StringUtils.split(parameter, KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR, 2);
934 String conversionFrom = parameterPair[0];
935 String conversionTo = parameterPair[1];
936
937
938 newInquiryParameters.append(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE).append(conversionFrom);
939
940 newInquiryParameters.append(KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR).append(conversionTo);
941
942 if (l < parameters.length - 1) {
943 newInquiryParameters.append(KRADConstants.FIELD_CONVERSIONS_SEPARATOR);
944 }
945 }
946
947 field.setInquiryParameters(newInquiryParameters.toString());
948 }
949
950 if (Field.KUALIUSER.equals(field.getFieldType())) {
951
952 int suffixIndex = field.getPropertyName().indexOf( field.getUserIdAttributeName() );
953 if ( suffixIndex != -1 ) {
954 field.setPersonNameAttributeName( field.getPropertyName().substring( 0, suffixIndex ) + field.getPersonNameAttributeName() );
955 field.setUniversalIdAttributeName( field.getPropertyName().substring( 0, suffixIndex ) + field.getUniversalIdAttributeName() );
956 } else {
957 field.setPersonNameAttributeName(namePrefix + field.getPersonNameAttributeName());
958 field.setUniversalIdAttributeName(namePrefix + field.getUniversalIdAttributeName());
959 }
960
961
962 }
963
964
965 if (StringUtils.isNotBlank(field.getLookupParameters())) {
966 String lookupParameters = field.getLookupParameters();
967 String newLookupParameters = KRADConstants.EMPTY_STRING;
968 String[] conversions = StringUtils.split(lookupParameters, KRADConstants.FIELD_CONVERSIONS_SEPARATOR);
969
970 for (int m = 0; m < conversions.length; m++) {
971 String conversion = conversions[m];
972
973 String[] conversionPair = StringUtils.split(conversion, KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR, 2);
974 String conversionFrom = conversionPair[0];
975 String conversionTo = conversionPair[1];
976 conversionFrom = KRADConstants.MAINTENANCE_NEW_MAINTAINABLE + conversionFrom;
977 newLookupParameters += (conversionFrom + KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR + conversionTo);
978
979 if (m < conversions.length) {
980 newLookupParameters += KRADConstants.FIELD_CONVERSIONS_SEPARATOR;
981 }
982 }
983
984 field.setLookupParameters(newLookupParameters);
985 }
986
987
988 if (Field.CONTAINER.equals(field.getFieldType())) {
989 List containerRows = field.getContainerRows();
990 List fixedRows = new ArrayList();
991
992 for (Iterator iter = containerRows.iterator(); iter.hasNext();) {
993 Row containerRow = (Row) iter.next();
994 List containerFields = containerRow.getFields();
995 List fixedFields = new ArrayList();
996
997 for (Iterator iterator = containerFields.iterator(); iterator.hasNext();) {
998 Field containerField = (Field) iterator.next();
999 containerField = fixFieldForForm(containerField, keyFieldNames, namePrefix, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId);
1000 fixedFields.add(containerField);
1001 }
1002
1003 fixedRows.add(new Row(fixedFields));
1004 }
1005
1006 field.setContainerRows(fixedRows);
1007 }
1008 }
1009 return field;
1010 }
1011
1012 public static void applyAuthorization(Field field, String maintenanceAction, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) {
1013 String fieldName = "";
1014 FieldRestriction fieldAuth = null;
1015 Person user = GlobalVariables.getUserSession().getPerson();
1016
1017 if (field.getPropertyName().startsWith(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE)) {
1018
1019 fieldName = field.getPropertyName().substring(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE.length());
1020
1021
1022 if (auths.hasRestriction(fieldName)) {
1023 fieldAuth = auths.getFieldRestriction(fieldName);
1024 if(KRADConstants.MAINTENANCE_NEW_ACTION.equals(maintenanceAction) || KRADConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceAction)){
1025 if((KewApiConstants.ROUTE_HEADER_SAVED_CD.equals(documentStatus) || KewApiConstants.ROUTE_HEADER_INITIATED_CD.equals(documentStatus))
1026 && user.getPrincipalId().equals(documentInitiatorPrincipalId)){
1027
1028
1029 }else{
1030 if(fieldAuth.isPartiallyMasked()){
1031 field.setSecure(true);
1032 fieldAuth.setShouldBeEncrypted(true);
1033 MaskFormatter maskFormatter = fieldAuth.getMaskFormatter();
1034 String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue());
1035 field.setDisplayMaskValue(displayMaskValue);
1036 populateSecureField(field, field.getPropertyValue());
1037 }
1038 else if(fieldAuth.isMasked()){
1039 field.setSecure(true);
1040 fieldAuth.setShouldBeEncrypted(true);
1041 MaskFormatter maskFormatter = fieldAuth.getMaskFormatter();
1042 String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue());
1043 field.setDisplayMaskValue(displayMaskValue);
1044 populateSecureField(field, field.getPropertyValue());
1045 }
1046 }
1047 }
1048
1049 if (KRADConstants.MAINTENANCE_EDIT_ACTION.equals(maintenanceAction) || KRADConstants.MAINTENANCE_NEWWITHEXISTING_ACTION.equals(maintenanceAction)) {
1050
1051 if(fieldAuth.isPartiallyMasked()){
1052 field.setSecure(true);
1053 fieldAuth.setShouldBeEncrypted(true);
1054 MaskFormatter maskFormatter = fieldAuth.getMaskFormatter();
1055 String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue());
1056 field.setDisplayMaskValue(displayMaskValue);
1057 populateSecureField(field, field.getPropertyValue());
1058 }
1059 else if(fieldAuth.isMasked()){
1060 field.setSecure(true);
1061 fieldAuth.setShouldBeEncrypted(true);
1062 MaskFormatter maskFormatter = fieldAuth.getMaskFormatter();
1063 String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue());
1064 field.setDisplayMaskValue(displayMaskValue);
1065 populateSecureField(field, field.getPropertyValue());
1066 }
1067 }
1068
1069 if (Field.isInputField(field.getFieldType()) || field.getFieldType().equalsIgnoreCase(Field.CHECKBOX)) {
1070
1071
1072 if (fieldAuth.isReadOnly()) {
1073 if (!field.isReadOnly() && !fieldAuth.isMasked() && !fieldAuth.isPartiallyMasked()) {
1074 field.setReadOnly(true);
1075 }
1076 }
1077 else if (fieldAuth.isHidden()) {
1078 if (field.getFieldType() != Field.HIDDEN) {
1079 field.setFieldType(Field.HIDDEN);
1080 }
1081 }
1082 }
1083
1084 if(Field.BUTTON.equalsIgnoreCase(field.getFieldType()) && fieldAuth.isHidden()){
1085 field.setFieldType(Field.HIDDEN);
1086 }
1087
1088
1089
1090 if (field.isReadOnly() && fieldAuth.isHidden()) {
1091 field.setFieldType(Field.HIDDEN);
1092 }
1093
1094 }
1095
1096
1097 }
1098 else if (field.getPropertyName().startsWith(KRADConstants.MAINTENANCE_OLD_MAINTAINABLE)) {
1099
1100 fieldName = field.getPropertyName().substring(KRADConstants.MAINTENANCE_OLD_MAINTAINABLE.length());
1101
1102 if (auths.hasRestriction(fieldName)) {
1103 fieldAuth = auths.getFieldRestriction(fieldName);
1104 if(fieldAuth.isPartiallyMasked()){
1105 field.setSecure(true);
1106 MaskFormatter maskFormatter = fieldAuth.getMaskFormatter();
1107 String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue());
1108 field.setDisplayMaskValue(displayMaskValue);
1109 field.setPropertyValue(displayMaskValue);
1110 populateSecureField(field, field.getPropertyValue());
1111
1112 }
1113
1114 if(fieldAuth.isMasked()){
1115 field.setSecure(true);
1116 MaskFormatter maskFormatter = fieldAuth.getMaskFormatter();
1117 String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue());
1118 field.setDisplayMaskValue(displayMaskValue);
1119 field.setPropertyValue(displayMaskValue);
1120 populateSecureField(field, field.getPropertyValue());
1121 }
1122
1123 if (fieldAuth.isHidden()) {
1124 field.setFieldType(Field.HIDDEN);
1125 }
1126 }
1127 }
1128 }
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140 public static List meshSections(List oldSections, List newSections, List keyFieldNames, String maintenanceAction, boolean readOnly, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) {
1141 List meshedSections = new ArrayList();
1142
1143 for (int i = 0; i < newSections.size(); i++) {
1144 Section maintSection = (Section) newSections.get(i);
1145 List sectionRows = maintSection.getRows();
1146 Section oldMaintSection = (Section) oldSections.get(i);
1147 List oldSectionRows = oldMaintSection.getRows();
1148 List<Row> meshedRows = new ArrayList();
1149 meshedRows = meshRows(oldSectionRows, sectionRows, keyFieldNames, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId);
1150 maintSection.setRows(meshedRows);
1151 if (StringUtils.isBlank(maintSection.getErrorKey())) {
1152 maintSection.setErrorKey(MaintenanceUtils.generateErrorKeyForSection(maintSection));
1153 }
1154 meshedSections.add(maintSection);
1155 }
1156
1157 return meshedSections;
1158 }
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170 public static List meshRows(List oldRows, List newRows, List keyFieldNames, String maintenanceAction, boolean readOnly, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) {
1171 List<Row> meshedRows = new ArrayList<Row>();
1172
1173 for (int j = 0; j < newRows.size(); j++) {
1174 Row sectionRow = (Row) newRows.get(j);
1175 List rowFields = sectionRow.getFields();
1176 Row oldSectionRow = null;
1177 List oldRowFields = new ArrayList();
1178
1179 if (null != oldRows && oldRows.size() > j) {
1180 oldSectionRow = (Row) oldRows.get(j);
1181 oldRowFields = oldSectionRow.getFields();
1182 }
1183
1184 List meshedFields = meshFields(oldRowFields, rowFields, keyFieldNames, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId);
1185 if (meshedFields.size() > 0) {
1186 Row meshedRow = new Row(meshedFields);
1187 if (sectionRow.isHidden()) {
1188 meshedRow.setHidden(true);
1189 }
1190
1191 meshedRows.add(meshedRow);
1192 }
1193 }
1194
1195 return meshedRows;
1196 }
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209 public static List meshFields(List oldFields, List newFields, List keyFieldNames, String maintenanceAction, boolean readOnly, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) {
1210 List meshedFields = new ArrayList();
1211
1212 List newFieldsToMerge = new ArrayList();
1213 List oldFieldsToMerge = new ArrayList();
1214
1215 for (int k = 0; k < newFields.size(); k++) {
1216 Field newMaintField = (Field) newFields.get(k);
1217 String propertyName = newMaintField.getPropertyName();
1218
1219 if (Field.IMAGE_SUBMIT.equals(newMaintField.getFieldType())) {
1220 meshedFields.add(newMaintField);
1221 }
1222 else if (Field.CONTAINER.equals(newMaintField.getFieldType())) {
1223 if (oldFields.size() > k) {
1224 Field oldMaintField = (Field) oldFields.get(k);
1225 newMaintField = meshContainerFields(oldMaintField, newMaintField, keyFieldNames, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId);
1226 }
1227 else {
1228 newMaintField = meshContainerFields(newMaintField, newMaintField, keyFieldNames, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId);
1229 }
1230 meshedFields.add(newMaintField);
1231 }
1232 else {
1233 newMaintField = FieldUtils.fixFieldForForm(newMaintField, keyFieldNames, KRADConstants.MAINTENANCE_NEW_MAINTAINABLE, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId);
1234
1235 if (KRADConstants.MAINTENANCE_EDIT_ACTION.equals(maintenanceAction) || KRADConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceAction)) {
1236 Field oldMaintField = (Field) oldFields.get(k);
1237
1238
1239
1240 if (!StringUtils.equalsIgnoreCase(newMaintField.getPropertyValue(), oldMaintField.getPropertyValue())
1241 && !Field.HIDDEN.equals(newMaintField.getFieldType())) {
1242 newMaintField.setHighlightField(true);
1243 }
1244
1245 oldMaintField = FieldUtils.fixFieldForForm(oldMaintField, keyFieldNames, KRADConstants.MAINTENANCE_OLD_MAINTAINABLE, maintenanceAction, true, auths, documentStatus, documentInitiatorPrincipalId);
1246 oldFieldsToMerge.add(oldMaintField);
1247 }
1248
1249 newFieldsToMerge.add(newMaintField);
1250
1251 for (Iterator iter = oldFieldsToMerge.iterator(); iter.hasNext();) {
1252 Field element = (Field) iter.next();
1253 meshedFields.add(element);
1254 }
1255
1256 for (Iterator iter = newFieldsToMerge.iterator(); iter.hasNext();) {
1257 Field element = (Field) iter.next();
1258 meshedFields.add(element);
1259 }
1260 }
1261 }
1262 return meshedFields;
1263 }
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277 protected static boolean isLookupFieldLevelHelpEnabled(Class businessObjectClass, String attributeName) {
1278 return false;
1279 }
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293 protected static boolean isLookupFieldLevelHelpDisabled(Class businessObjectClass, String attributeName) {
1294 return false;
1295 }
1296
1297 public static List<Field> createAndPopulateFieldsForLookup(List<String> lookupFieldAttributeList, List<String> readOnlyFieldsList, Class businessObjectClass) throws InstantiationException, IllegalAccessException {
1298 List<Field> fields = new ArrayList<Field>();
1299 BusinessObjectEntry boe = (BusinessObjectEntry) getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(businessObjectClass.getName());
1300
1301 Map<String, Boolean> isHiddenMap = new HashMap<String, Boolean>();
1302 Map<String, Boolean> isReadOnlyMap = new HashMap<String, Boolean>();
1303
1304
1305
1306
1307
1308 if(boe.hasLookupDefinition()){
1309 List<FieldDefinition> fieldDefs = boe.getLookupDefinition().getLookupFields();
1310 for(FieldDefinition field : fieldDefs){
1311 isReadOnlyMap.put(field.getAttributeName(), Boolean.valueOf(field.isReadOnly()));
1312 isHiddenMap.put(field.getAttributeName(), Boolean.valueOf(field.isHidden()));
1313 }
1314 }
1315
1316 for( String attributeName : lookupFieldAttributeList )
1317 {
1318 Field field = FieldUtils.getPropertyField(businessObjectClass, attributeName, true);
1319
1320 if(field.isDatePicker() && field.isRanged()) {
1321
1322 Field newDate = createRangeDateField(field);
1323 fields.add(newDate);
1324 }
1325
1326 BusinessObject newBusinessObjectInstance;
1327 if (ExternalizableBusinessObjectUtils.isExternalizableBusinessObjectInterface(businessObjectClass)) {
1328 ModuleService moduleService = getKualiModuleService().getResponsibleModuleService(businessObjectClass);
1329 newBusinessObjectInstance = (BusinessObject) moduleService.createNewObjectFromExternalizableClass(businessObjectClass);
1330 }
1331 else {
1332 newBusinessObjectInstance = (BusinessObject) businessObjectClass.newInstance();
1333 }
1334
1335 field = LookupUtils.setFieldQuickfinder(newBusinessObjectInstance, attributeName, field, lookupFieldAttributeList);
1336 field = LookupUtils.setFieldDirectInquiry(newBusinessObjectInstance, attributeName, field);
1337
1338
1339 if (!Field.MULTISELECT.equals(field.getFieldType())) {
1340 field.setMaxLength(100);
1341 }
1342
1343
1344 if (attributeName.equals(KRADPropertyConstants.ACTIVE) && MutableInactivatable.class.isAssignableFrom(businessObjectClass)) {
1345 field.setPropertyValue(KRADConstants.YES_INDICATOR_VALUE);
1346 field.setDefaultValue(KRADConstants.YES_INDICATOR_VALUE);
1347 }
1348
1349 String defaultValue = getBusinessObjectMetaDataService().getLookupFieldDefaultValue(businessObjectClass, attributeName);
1350 if (defaultValue != null) {
1351 field.setPropertyValue(defaultValue);
1352 field.setDefaultValue(defaultValue);
1353 }
1354
1355 Class defaultValueFinderClass = getBusinessObjectMetaDataService().getLookupFieldDefaultValueFinderClass(businessObjectClass, attributeName);
1356
1357 if (defaultValueFinderClass != null) {
1358 field.setPropertyValue(((ValueFinder) defaultValueFinderClass.newInstance()).getValue());
1359 field.setDefaultValue(((ValueFinder) defaultValueFinderClass.newInstance()).getValue());
1360 }
1361 if ( (readOnlyFieldsList != null && readOnlyFieldsList.contains(field.getPropertyName()))
1362 || ( isReadOnlyMap.containsKey(field.getPropertyName()) && isReadOnlyMap.get(field.getPropertyName()).booleanValue())
1363 ) {
1364 field.setReadOnly(true);
1365 }
1366
1367 populateQuickfinderDefaultsForLookup(businessObjectClass, attributeName, field);
1368
1369 if ((isHiddenMap.containsKey(field.getPropertyName()) && isHiddenMap.get(field.getPropertyName()).booleanValue())) {
1370 field.setFieldType(Field.HIDDEN);
1371 }
1372
1373 boolean triggerOnChange = getBusinessObjectDictionaryService().isLookupFieldTriggerOnChange(businessObjectClass, attributeName);
1374 field.setTriggerOnChange(triggerOnChange);
1375
1376 field.setFieldLevelHelpEnabled(isLookupFieldLevelHelpEnabled(businessObjectClass, attributeName));
1377 field.setFieldLevelHelpDisabled(isLookupFieldLevelHelpDisabled(businessObjectClass, attributeName));
1378
1379 fields.add(field);
1380 }
1381 return fields;
1382 }
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394 private static void populateQuickfinderDefaultsForLookup(
1395 Class businessObjectClass, String attributeName, Field field)
1396 throws InstantiationException, IllegalAccessException {
1397
1398 String quickfinderParamString = getBusinessObjectMetaDataService().getLookupFieldQuickfinderParameterString(businessObjectClass, attributeName);
1399 Class<? extends ValueFinder> quickfinderParameterFinderClass =
1400 getBusinessObjectMetaDataService().getLookupFieldQuickfinderParameterStringBuilderClass(businessObjectClass, attributeName);
1401 if (quickfinderParameterFinderClass != null) {
1402 quickfinderParamString = quickfinderParameterFinderClass.newInstance().getValue();
1403 }
1404
1405 if (!StringUtils.isEmpty(quickfinderParamString)) {
1406 String [] params = quickfinderParamString.split(",");
1407 if (params != null) for (String param : params) {
1408 if (param.contains(KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER)) {
1409 String[] paramChunks = param.split(KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER, 2);
1410 field.appendLookupParameters(
1411 KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX+KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER+
1412 paramChunks[1]+":"+paramChunks[0]);
1413 }
1414 }
1415 }
1416 }
1417
1418
1419
1420
1421
1422
1423
1424 public static Field createRangeDateField(Field field) {
1425 Field newDate = (Field) SerializationUtils.deepCopy(field);
1426 newDate.setFieldLabel(newDate.getFieldLabel()+" "+KRADConstants.LOOKUP_DEFAULT_RANGE_SEARCH_LOWER_BOUND_LABEL);
1427 field.setFieldLabel(field.getFieldLabel()+" "+KRADConstants.LOOKUP_DEFAULT_RANGE_SEARCH_UPPER_BOUND_LABEL);
1428 newDate.setPropertyName(KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX+newDate.getPropertyName());
1429 return newDate;
1430 }
1431
1432 private static Field meshContainerFields(Field oldMaintField, Field newMaintField, List keyFieldNames, String maintenanceAction, boolean readOnly, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) {
1433 List resultingRows = new ArrayList();
1434 resultingRows.addAll(meshRows(oldMaintField.getContainerRows(), newMaintField.getContainerRows(), keyFieldNames, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId));
1435 Field resultingField = newMaintField;
1436 resultingField.setFieldType(Field.CONTAINER);
1437
1438
1439 resultingField.setContainerElementName(newMaintField.getContainerElementName());
1440 resultingField.setContainerDisplayFields(newMaintField.getContainerDisplayFields());
1441 resultingField.setNumberOfColumnsForCollection(newMaintField.getNumberOfColumnsForCollection());
1442
1443 resultingField.setContainerRows(resultingRows);
1444 List resultingRowsList = newMaintField.getContainerRows();
1445 if (resultingRowsList.size() > 0) {
1446 List resultingFieldsList = ((Row) resultingRowsList.get(0)).getFields();
1447 if (resultingFieldsList.size() > 0) {
1448
1449
1450 String containedFieldName = ((Field) (resultingFieldsList.get(0))).getPropertyName();
1451 resultingField.setPropertyName(containedFieldName.substring(0, containedFieldName.lastIndexOf('.')));
1452 }
1453 }
1454 else {
1455 resultingField.setPropertyName(oldMaintField.getPropertyName());
1456 }
1457 return resultingField;
1458 }
1459
1460
1461
1462
1463
1464
1465
1466
1467 static final public void modifyFieldToSupportMultipleValueLookups(Field field, String parents, MaintainableCollectionDefinition definition) {
1468 field.setMultipleValueLookedUpCollectionName(parents + definition.getName());
1469 field.setMultipleValueLookupClassName(definition.getSourceClassName().getName());
1470 field.setMultipleValueLookupClassLabel(getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(definition.getSourceClassName().getName()).getObjectLabel());
1471 }
1472
1473
1474
1475
1476
1477
1478
1479
1480 static final public boolean isCollectionMultipleLookupEnabled(MaintainableCollectionDefinition definition) {
1481 return definition.getSourceClassName() != null && definition.isIncludeMultipleLookupLine();
1482 }
1483
1484
1485
1486
1487
1488
1489
1490
1491 public static String scrubWhitespace(String s) {
1492 return s.replaceAll("(\\s)(\\s+)", " ");
1493 }
1494
1495 public static List<Row> convertRemotableAttributeFields(List<RemotableAttributeField> remotableAttributeFields) {
1496 List<Row> rows = new ArrayList<Row>();
1497 for (RemotableAttributeField remotableAttributeField : remotableAttributeFields) {
1498 List<Field> fields = convertRemotableAttributeField(remotableAttributeField);
1499
1500 for (Field field : fields) {
1501 Row row = new Row(field);
1502 rows.add(row);
1503 }
1504 }
1505 return rows;
1506 }
1507
1508 public static List<Field> convertRemotableAttributeField(RemotableAttributeField remotableAttributeField) {
1509
1510 List<Field> fields = constructFieldsForAttributeDefinition(remotableAttributeField);
1511 for (Field field : fields) {
1512 applyControlAttributes(remotableAttributeField, field);
1513 applyLookupAttributes(remotableAttributeField, field);
1514 applyWidgetAttributes(remotableAttributeField, field);
1515 }
1516 return fields;
1517 }
1518
1519 private static List<Field> constructFieldsForAttributeDefinition(RemotableAttributeField remotableAttributeField) {
1520 List<Field> fields = new ArrayList<Field>();
1521 if (remotableAttributeField.getAttributeLookupSettings() != null
1522 && remotableAttributeField.getAttributeLookupSettings().isRanged()) {
1523
1524 AttributeLookupSettings lookupSettings = remotableAttributeField.getAttributeLookupSettings();
1525
1526
1527 String attrLabel;
1528 if (StringUtils.isBlank(remotableAttributeField.getLongLabel())) {
1529 attrLabel = remotableAttributeField.getShortLabel();
1530 } else {
1531 attrLabel = remotableAttributeField.getLongLabel();
1532 }
1533 String label = StringUtils.defaultString(lookupSettings.getLowerLabel(), attrLabel
1534 + " " + KewApiConstants.SearchableAttributeConstants.DEFAULT_RANGE_SEARCH_LOWER_BOUND_LABEL);
1535 Field lowerField = new Field(KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX + remotableAttributeField.getName(), label);
1536 lowerField.setMemberOfRange(true);
1537 lowerField.setAllowInlineRange(false);
1538 lowerField.setRangeFieldInclusive(lookupSettings.isLowerBoundInclusive());
1539 if (lookupSettings.isLowerDatePicker() != null) {
1540 lowerField.setDatePicker(lookupSettings.isLowerDatePicker());
1541 }
1542 if (!remotableAttributeField.getDataType().equals(DataType.CURRENCY)) {
1543 lowerField.setFieldDataType(remotableAttributeField.getDataType().name().toLowerCase());
1544 }
1545 fields.add(lowerField);
1546
1547 label = StringUtils.defaultString(lookupSettings.getUpperLabel(), attrLabel
1548 + " " + KewApiConstants.SearchableAttributeConstants.DEFAULT_RANGE_SEARCH_UPPER_BOUND_LABEL);
1549 Field upperField = new Field(remotableAttributeField.getName(), label);
1550 upperField.setMemberOfRange(true);
1551 upperField.setAllowInlineRange(false);
1552 upperField.setRangeFieldInclusive(lookupSettings.isUpperBoundInclusive());
1553 if (lookupSettings.isUpperDatePicker() != null) {
1554 upperField.setDatePicker(lookupSettings.isUpperDatePicker());
1555 }
1556 if (!remotableAttributeField.getDataType().equals(DataType.CURRENCY)) {
1557 upperField.setFieldDataType(remotableAttributeField.getDataType().name().toLowerCase());
1558 }
1559 fields.add(upperField);
1560 } else {
1561
1562 Field tempField = new Field(remotableAttributeField.getName(), remotableAttributeField.getLongLabel());
1563 if (remotableAttributeField.getMaxLength() != null) {
1564 tempField.setMaxLength(remotableAttributeField.getMaxLength());
1565 }
1566
1567 if (remotableAttributeField.getShortLabel() != null) {
1568 tempField.setFieldLabel(remotableAttributeField.getShortLabel());
1569 }
1570
1571 if (!remotableAttributeField.getDataType().equals(DataType.CURRENCY)) {
1572 tempField.setFieldDataType(remotableAttributeField.getDataType().name().toLowerCase());
1573 } else {
1574 tempField.setFieldDataType(KewApiConstants.SearchableAttributeConstants.DATA_TYPE_FLOAT);
1575 }
1576
1577 tempField.setMainFieldLabel(remotableAttributeField.getLongLabel());
1578 tempField.setFieldHelpSummary(remotableAttributeField.getHelpSummary());
1579 tempField.setUpperCase(remotableAttributeField.isForceUpperCase());
1580 if (remotableAttributeField.getMaxLength() != null) {
1581 if (remotableAttributeField.getMaxLength().intValue() > 0) {
1582 tempField.setMaxLength(remotableAttributeField.getMaxLength().intValue());
1583 } else {
1584 tempField.setMaxLength(100);
1585 }
1586 }
1587 tempField.setFieldRequired(remotableAttributeField.isRequired());
1588
1589 fields.add(tempField);
1590 }
1591 return fields;
1592 }
1593
1594 public static List<RemotableAttributeField> convertRowsToAttributeFields(List<Row> rows) {
1595 List<RemotableAttributeField> attributeFields = new ArrayList<RemotableAttributeField>();
1596 for (Row row : rows) {
1597 attributeFields.addAll(convertRowToAttributeFields(row));
1598 }
1599 return attributeFields;
1600 }
1601
1602 public static List<RemotableAttributeField> convertRowToAttributeFields(Row row) {
1603 List<RemotableAttributeField> attributeFields = new ArrayList<RemotableAttributeField>();
1604 for (Field field : row.getFields()) {
1605 RemotableAttributeField remotableAttributeField = convertFieldToAttributeField(field);
1606 if (remotableAttributeField != null) {
1607 attributeFields.add(remotableAttributeField);
1608 }
1609 }
1610 return attributeFields;
1611 }
1612
1613 public static RemotableAttributeField convertFieldToAttributeField(Field field) {
1614 RemotableAttributeField.Builder builder = RemotableAttributeField.Builder.create(field.getPropertyName());
1615
1616 List<RemotableAbstractWidget.Builder> widgets = new ArrayList<RemotableAbstractWidget.Builder>();
1617 builder.setDataType(DataType.valueOf(field.getFieldDataType().toUpperCase()));
1618 builder.setShortLabel(field.getFieldLabel());
1619 builder.setLongLabel(field.getMainFieldLabel());
1620 builder.setHelpSummary(field.getFieldHelpSummary());
1621
1622
1623 builder.setForceUpperCase(field.isUpperCase());
1624
1625 if (field.getMaxLength() > 0) {
1626 builder.setMaxLength(new Integer(field.getMaxLength()));
1627 } else {
1628 builder.setMaxLength(new Integer(100));
1629 }
1630
1631
1632
1633
1634 builder.setRequired(field.isFieldRequired());
1635 builder.setDefaultValues(Collections.singletonList(field.getDefaultValue()));
1636 builder.setControl(FieldUtils.constructControl(field, field.getFieldValidValues()));
1637 if (field.getHasLookupable()) {
1638 builder.setAttributeLookupSettings(RemotableAttributeLookupSettings.Builder.create());
1639 RemotableQuickFinder.Builder quickfinder =
1640 RemotableQuickFinder.Builder.create(field.getBaseLookupUrl(), field.getQuickFinderClassNameImpl());
1641 quickfinder.setFieldConversions(toMap(field.getFieldConversions()));
1642 quickfinder.setLookupParameters(toMap(field.getLookupParameters()));
1643 widgets.add(quickfinder);
1644 }
1645 RemotableAttributeLookupSettings.Builder lookupSettings = null;
1646 if (builder.getDataType().equals(DataType.DATETIME)
1647 || builder.getDataType().equals(DataType.DATE)) {
1648 if (field.isRanged()) {
1649 lookupSettings = RemotableAttributeLookupSettings.Builder.create();
1650 lookupSettings.setRanged(field.isRanged());
1651 if (field.isDatePicker()) {
1652 lookupSettings.setLowerDatePicker(Boolean.TRUE);
1653 lookupSettings.setUpperDatePicker(Boolean.TRUE);
1654 }
1655 if (ObjectUtils.isNull(field.getRangeFieldInclusive())) {
1656 lookupSettings.setUpperBoundInclusive(true);
1657 lookupSettings.setLowerBoundInclusive(true);
1658 }
1659 }
1660 }
1661
1662 if (!field.isColumnVisible()) {
1663 if (ObjectUtils.isNull(lookupSettings)) {
1664 lookupSettings = RemotableAttributeLookupSettings.Builder.create();
1665 }
1666 lookupSettings.setInResults(field.isColumnVisible());
1667 }
1668
1669 if (ObjectUtils.isNotNull(lookupSettings)) {
1670 builder.setAttributeLookupSettings(lookupSettings);
1671 }
1672
1673 if (field.getFieldType().equals(Field.CURRENCY)) {
1674 builder.setDataType(DataType.CURRENCY);
1675 builder.setMaxLength(field.getFormattedMaxLength());
1676 }
1677 if (field.isDatePicker()) {
1678 widgets.add(RemotableDatepicker.Builder.create());
1679 }
1680 if (field.isExpandedTextArea()) {
1681 widgets.add(RemotableTextExpand.Builder.create());
1682 }
1683 builder.setWidgets(widgets);
1684
1685 return builder.build();
1686 }
1687
1688 private static RemotableAbstractControl.Builder constructControl(Field field, List<KeyValue> options) {
1689
1690
1691 Map<String, String> optionMap = new LinkedHashMap<String, String>();
1692 if (options != null) {
1693 for (KeyValue option : options) {
1694 optionMap.put(option.getKey(), option.getValue());
1695 }
1696 }
1697 String type = field.getFieldType();
1698 if (Field.TEXT.equals(type) || Field.DATEPICKER.equals(type)) {
1699 RemotableTextInput.Builder control = RemotableTextInput.Builder.create();
1700 control.setSize(field.getSize());
1701 return control;
1702 } else if (Field.TEXT_AREA.equals(type)) {
1703 RemotableTextarea.Builder control = RemotableTextarea.Builder.create();
1704 control.setCols(field.getCols());
1705 control.setRows(field.getRows());
1706 return control;
1707 } else if (Field.DROPDOWN.equals(type)) {
1708 return RemotableSelect.Builder.create(optionMap);
1709 } else if (Field.DROPDOWN_REFRESH.equals(type)) {
1710 RemotableSelect.Builder control = RemotableSelect.Builder.create(optionMap);
1711 control.setRefreshOnChange(true);
1712 return control;
1713 } else if (Field.CHECKBOX.equals(type)) {
1714 return RemotableCheckbox.Builder.create();
1715 } else if (Field.RADIO.equals(type)) {
1716 return RemotableRadioButtonGroup.Builder.create(optionMap);
1717 } else if (Field.HIDDEN.equals(type)) {
1718 return RemotableHiddenInput.Builder.create();
1719 } else if (Field.MULTIBOX.equals(type)) {
1720 RemotableSelect.Builder control = RemotableSelect.Builder.create(optionMap);
1721 control.setMultiple(true);
1722 return control;
1723 } else if (Field.MULTISELECT.equals(type)) {
1724 RemotableSelect.Builder control = RemotableSelect.Builder.create(optionMap);
1725 control.setMultiple(true);
1726 return control;
1727 } else if (Field.CURRENCY.equals(type)) {
1728 RemotableTextInput.Builder control = RemotableTextInput.Builder.create();
1729 control.setSize(field.getSize());
1730 return control;
1731 } else {
1732 throw new IllegalArgumentException("Illegal field type found: " + type);
1733 }
1734
1735 }
1736
1737 private static void applyControlAttributes(RemotableAttributeField remotableField, Field field) {
1738 RemotableControlContract control = remotableField.getControl();
1739 String fieldType = null;
1740
1741 if (control == null) {
1742 throw new IllegalStateException("Given attribute field with the following name has a null control: " + remotableField.getName());
1743 }
1744 if (control == null || control instanceof RemotableTextInput) {
1745 fieldType = Field.TEXT;
1746 if (((RemotableTextInput)remotableField.getControl()).getSize() != null) {
1747 field.setSize(((RemotableTextInput)remotableField.getControl()).getSize().intValue());
1748 }
1749 if (((RemotableTextInput)remotableField.getControl()).getSize() != null) {
1750 field.setFormattedMaxLength(((RemotableTextInput)remotableField.getControl()).getSize().intValue());
1751 }
1752 } else if (control instanceof RemotableCheckboxGroup) {
1753 RemotableCheckboxGroup checkbox = (RemotableCheckboxGroup)control;
1754 fieldType = Field.CHECKBOX;
1755 field.setFieldValidValues(FieldUtils.convertMapToKeyValueList(checkbox.getKeyLabels()));
1756 } else if (control instanceof RemotableCheckbox) {
1757 fieldType = Field.CHECKBOX;
1758 } else if (control instanceof RemotableHiddenInput) {
1759 fieldType = Field.HIDDEN;
1760 } else if (control instanceof RemotablePasswordInput) {
1761 throw new IllegalStateException("Password control not currently supported.");
1762 } else if (control instanceof RemotableRadioButtonGroup) {
1763 fieldType = Field.RADIO;
1764 RemotableRadioButtonGroup radioControl = (RemotableRadioButtonGroup)control;
1765 field.setFieldValidValues(FieldUtils.convertMapToKeyValueList(radioControl.getKeyLabels()));
1766 } else if (control instanceof RemotableSelect) {
1767 RemotableSelect selectControl = (RemotableSelect)control;
1768
1769 field.setFieldValidValues(FieldUtils.convertMapToKeyValueList(selectControl.getKeyLabels()));
1770 if (selectControl.isMultiple()) {
1771 fieldType = Field.MULTISELECT;
1772 } else if (selectControl.isRefreshOnChange()) {
1773 fieldType = Field.DROPDOWN_REFRESH;
1774 } else {
1775 fieldType = Field.DROPDOWN;
1776 }
1777 } else if (control instanceof RemotableTextarea) {
1778 fieldType = Field.TEXT_AREA;
1779 if (((RemotableTextarea)remotableField.getControl()).getCols() != null
1780 && ((RemotableTextarea)remotableField.getControl()).getRows() != null) {
1781 field.setCols(((RemotableTextarea)remotableField.getControl()).getCols().intValue());
1782 field.setSize(((RemotableTextarea)remotableField.getControl()).getRows().intValue());
1783 }
1784 } else {
1785 throw new IllegalArgumentException("Given control type is not supported: " + control.getClass());
1786 }
1787
1788 if (!remotableField.getDefaultValues().isEmpty()) {
1789 field.setDefaultValue(remotableField.getDefaultValues().iterator().next());
1790
1791 field.setPropertyValues(remotableField.getDefaultValues().toArray(new String[remotableField.getDefaultValues().size()]));
1792 field.setPropertyValue(field.getDefaultValue());
1793 }
1794 field.setFieldType(fieldType);
1795 }
1796
1797 private static List<KeyValue> convertMapToKeyValueList(Map<String, String> values) {
1798 ArrayList<KeyValue> validValues = new ArrayList<KeyValue>(values.size());
1799 for (Map.Entry<String, String> entry : values.entrySet()) {
1800 validValues.add(new ConcreteKeyValue(entry.getKey(), entry.getValue()));
1801 }
1802 return validValues;
1803 }
1804
1805 private static void applyLookupAttributes(RemotableAttributeField remotableField, Field field) {
1806 AttributeLookupSettings lookupSettings = remotableField.getAttributeLookupSettings();
1807 if (lookupSettings != null) {
1808 field.setColumnVisible(lookupSettings.isInResults());
1809 if (!lookupSettings.isInCriteria()) {
1810 field.setFieldType(Field.HIDDEN);
1811 }
1812 field.setRanged(lookupSettings.isRanged());
1813 boolean datePickerLow = lookupSettings.isLowerDatePicker() == null ? false : lookupSettings.isLowerDatePicker().booleanValue();
1814 boolean datePickerUpper = lookupSettings.isUpperDatePicker() == null ? false : lookupSettings.isUpperDatePicker().booleanValue();
1815 field.setDatePicker(datePickerLow || datePickerUpper);
1816 }
1817 }
1818
1819 private static void applyWidgetAttributes(RemotableAttributeField remotableField, Field field) {
1820 Collection<? extends RemotableAbstractWidget> widgets = remotableField.getWidgets();
1821
1822 for (RemotableAbstractWidget widget : widgets) {
1823
1824 if (widget instanceof RemotableQuickFinder) {
1825 field.setQuickFinderClassNameImpl(((RemotableQuickFinder)widget).getDataObjectClass());
1826 field.setBaseLookupUrl(((RemotableQuickFinder)widget).getBaseLookupUrl());
1827 field.setLookupParameters(((RemotableQuickFinder)widget).getLookupParameters());
1828 field.setFieldConversions(((RemotableQuickFinder)widget).getFieldConversions());
1829
1830
1831
1832
1833
1834 } else if (widget instanceof RemotableTextExpand) {
1835 field.setExpandedTextArea(true);
1836 }
1837
1838 }
1839 }
1840
1841 public static Column constructColumnFromAttributeField(RemotableAttributeField attributeField) {
1842 if (attributeField == null) {
1843 throw new IllegalArgumentException("attributeField was null");
1844 }
1845 DataType dataType = DataType.STRING;
1846 if (attributeField.getDataType() != null) {
1847 dataType = attributeField.getDataType();
1848 }
1849 Column column = new Column();
1850 String columnTitle = "";
1851 if (StringUtils.isBlank(attributeField.getShortLabel())) {
1852 if (StringUtils.isBlank(attributeField.getLongLabel())) {
1853 columnTitle = attributeField.getName();
1854 } else {
1855 columnTitle = attributeField.getLongLabel();
1856 }
1857 } else {
1858 columnTitle = attributeField.getShortLabel();
1859 }
1860 column.setColumnTitle(columnTitle);
1861 column.setSortable(Boolean.TRUE.toString());
1862
1863 if (attributeField.getMaxLength() != null) {
1864 column.setMaxLength(attributeField.getMaxLength());
1865 }
1866 column.setPropertyName(attributeField.getName());
1867 if (attributeField.getDataType() == DataType.MARKUP) {
1868 column.setEscapeXMLValue(false);
1869
1870 column.setColumnAnchor(new AnchorHtmlData());
1871 } else {
1872 column.setEscapeXMLValue(true);
1873 }
1874 column.setComparator(CellComparatorHelper.getAppropriateComparatorForPropertyClass(dataType.getType()));
1875 column.setValueComparator(CellComparatorHelper.getAppropriateValueComparatorForPropertyClass(dataType.getType()));
1876
1877 if(StringUtils.isNotEmpty(attributeField.getFormatterName())) {
1878 try {
1879 column.setFormatter(Formatter.getFormatter(Class.forName(attributeField.getFormatterName())));
1880 } catch (ClassNotFoundException e) {
1881 LOG.error("Unable to find formatter class: " + attributeField.getFormatterName());
1882
1883 column.setFormatter(FieldUtils.getFormatterForDataType(dataType));
1884 }
1885 } else {
1886 column.setFormatter(FieldUtils.getFormatterForDataType(dataType));
1887 }
1888
1889 return column;
1890 }
1891
1892 public static List<Column> constructColumnsFromAttributeFields(List<RemotableAttributeField> attributeFields) {
1893 List<Column> attributeColumns = new ArrayList<Column>();
1894 if (attributeFields != null) {
1895 for (RemotableAttributeField attributeField : attributeFields) {
1896 attributeColumns.add(constructColumnFromAttributeField(attributeField));
1897 }
1898 }
1899 return attributeColumns;
1900 }
1901
1902 public static Formatter getFormatterForDataType(DataType dataType) {
1903 return Formatter.getFormatter(dataType.getType());
1904 }
1905
1906
1907
1908
1909
1910
1911
1912 public static String generateCollectionSubTabName(Field field) {
1913 final String containerName = field.getContainerElementName();
1914 final String cleanedContainerName =
1915 (containerName == null) ?
1916 "" :
1917 containerName.replaceAll("\\d+", "");
1918 StringBuilder subTabName = new StringBuilder(cleanedContainerName);
1919 if (field.getContainerDisplayFields() != null) {
1920 for (Field containerField : field.getContainerDisplayFields()) {
1921 subTabName.append(containerField.getPropertyValue());
1922 }
1923 }
1924 return subTabName.toString();
1925 }
1926
1927 private static Map<String, String> toMap(String s) {
1928 if (StringUtils.isBlank(s)) {
1929 return Collections.emptyMap();
1930 }
1931 final Map<String, String> map = new HashMap<String, String>();
1932 for (String string : s.split(",")) {
1933 String [] keyVal = string.split(":");
1934 map.put(keyVal[0], keyVal[1]);
1935 }
1936 return Collections.unmodifiableMap(map);
1937 }
1938
1939 private static DataDictionaryService getDataDictionaryService() {
1940 if (dataDictionaryService == null) {
1941 dataDictionaryService = KRADServiceLocatorWeb.getDataDictionaryService();
1942 }
1943 return dataDictionaryService;
1944 }
1945
1946 private static BusinessObjectMetaDataService getBusinessObjectMetaDataService() {
1947 if (businessObjectMetaDataService == null) {
1948 businessObjectMetaDataService = KNSServiceLocator.getBusinessObjectMetaDataService();
1949 }
1950 return businessObjectMetaDataService;
1951 }
1952
1953 private static BusinessObjectDictionaryService getBusinessObjectDictionaryService() {
1954 if (businessObjectDictionaryService == null) {
1955 businessObjectDictionaryService = KNSServiceLocator.getBusinessObjectDictionaryService();
1956 }
1957 return businessObjectDictionaryService;
1958 }
1959
1960 private static KualiModuleService getKualiModuleService() {
1961 if (kualiModuleService == null) {
1962 kualiModuleService = KRADServiceLocatorWeb.getKualiModuleService();
1963 }
1964 return kualiModuleService;
1965 }
1966 }