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