Coverage Report - org.kuali.rice.krad.web.ui.FieldBridge
 
Classes in this File Line Coverage Branch Coverage Complexity
FieldBridge
0%
0/204
0%
0/114
5.438
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.krad.web.ui;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.util.ClassLoaderUtils;
 20  
 import org.kuali.rice.core.util.KeyValue;
 21  
 import org.kuali.rice.core.web.format.Formatter;
 22  
 import org.kuali.rice.krad.bo.BusinessObject;
 23  
 import org.kuali.rice.krad.datadictionary.*;
 24  
 import org.kuali.rice.krad.datadictionary.control.ControlDefinition;
 25  
 import org.kuali.rice.krad.lookup.LookupUtils;
 26  
 import org.kuali.rice.krad.lookup.keyvalues.KeyValuesFinder;
 27  
 import org.kuali.rice.krad.lookup.keyvalues.PersistableBusinessObjectValuesFinder;
 28  
 import org.kuali.rice.krad.maintenance.Maintainable;
 29  
 import org.kuali.rice.krad.service.*;
 30  
 import org.kuali.rice.krad.util.FieldUtils;
 31  
 import org.kuali.rice.krad.util.KRADConstants;
 32  
 import org.kuali.rice.krad.util.MaintenanceUtils;
 33  
 import org.kuali.rice.krad.util.ObjectUtils;
 34  
 
 35  
 import java.util.ArrayList;
 36  
 import java.util.Collection;
 37  
 import java.util.List;
 38  
 import java.util.Set;
 39  
 
 40  0
 public class FieldBridge {
 41  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(FieldBridge.class);
 42  
     private static DataDictionaryService dataDictionaryService;
 43  
     private static PersistenceStructureService persistenceStructureService;
 44  
     private static BusinessObjectDictionaryService businessObjectDictionaryService;
 45  
     private static MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService;
 46  
 
 47  
     /**
 48  
      * Sets additional properties for MaintainableField(s)
 49  
      *
 50  
      * @param field The field to populate.
 51  
      * @param definition The DD specification for the field.
 52  
      */
 53  
     public static final void setupField(Field field, FieldDefinitionI definition, Set<String> conditionallyRequiredMaintenanceFields) {
 54  0
         if (definition instanceof MaintainableFieldDefinition) {
 55  0
             MaintainableFieldDefinition maintainableFieldDefinition = ((MaintainableFieldDefinition) definition);
 56  
             
 57  0
             field.setFieldRequired(maintainableFieldDefinition.isRequired());
 58  0
             field.setReadOnly(maintainableFieldDefinition.isUnconditionallyReadOnly());
 59  0
             if (maintainableFieldDefinition.isLookupReadOnly()) {
 60  0
                     field.setFieldType(Field.LOOKUP_READONLY);
 61  
             }
 62  
 
 63  
             // set onblur and callback functions
 64  0
             if (StringUtils.isNotBlank(maintainableFieldDefinition.getWebUILeaveFieldFunction())) {
 65  0
                 field.setWebOnBlurHandler(maintainableFieldDefinition.getWebUILeaveFieldFunction());
 66  
             }
 67  
 
 68  0
             if (StringUtils.isNotBlank(maintainableFieldDefinition.getWebUILeaveFieldCallbackFunction())) {
 69  0
                 field.setWebOnBlurHandlerCallback(maintainableFieldDefinition.getWebUILeaveFieldCallbackFunction());
 70  
             }
 71  
 
 72  0
             if (maintainableFieldDefinition.getWebUILeaveFieldFunctionParameters()!=null) {
 73  0
                 field.setWebUILeaveFieldFunctionParameters(maintainableFieldDefinition.getWebUILeaveFieldFunctionParameters());
 74  
             }
 75  
             
 76  0
                         if (StringUtils.isNotBlank(maintainableFieldDefinition.getAlternateDisplayAttributeName())) {
 77  0
                                 field.setAlternateDisplayPropertyName(maintainableFieldDefinition.getAlternateDisplayAttributeName());
 78  
                         }
 79  
 
 80  0
                         if (StringUtils.isNotBlank(maintainableFieldDefinition.getAdditionalDisplayAttributeName())) {
 81  0
                                 field.setAdditionalDisplayPropertyName(maintainableFieldDefinition.getAdditionalDisplayAttributeName());
 82  
                         }
 83  
             
 84  0
             if (conditionallyRequiredMaintenanceFields != null && conditionallyRequiredMaintenanceFields.contains(field.getPropertyName())) {
 85  0
                     field.setFieldRequired(true);
 86  
             }
 87  
             
 88  0
             if (((MaintainableFieldDefinition) definition).isTriggerOnChange()) {
 89  0
                     field.setTriggerOnChange(true);
 90  
             }
 91  
         }
 92  0
     }
 93  
 
 94  
     /**
 95  
          * Uses reflection to populate the rows of the inquiry from the business
 96  
          * object value. Also formats if needed.
 97  
      *
 98  
          * @param field
 99  
          *            The Field to populate.
 100  
          * @param bo
 101  
          *            The BusinessObject from which the Field will be popualated.
 102  
      */
 103  
     public static final void populateFieldFromBusinessObject(Field field, BusinessObject bo) {
 104  0
         if (bo == null) {
 105  0
             throw new RuntimeException("Inquiry Business object is null.");
 106  
         }
 107  
 
 108  0
         field.setReadOnly(true); // inquiry fields are always read only
 109  
 
 110  0
         Formatter formatter = field.getFormatter();
 111  0
         String propertyName = field.getPropertyName();
 112  
 
 113  
         // get the field type for the property
 114  0
                 ControlDefinition fieldControl = getDataDictionaryService().getAttributeControlDefinition(bo.getClass(),
 115  
                                 propertyName);
 116  
         try {
 117  0
             Object prop = ObjectUtils.getPropertyValue(bo, field.getPropertyName());
 118  
 
 119  
                         // for select fields, display the associated label (unless we are
 120  
                         // already display an additonal attribute)
 121  0
                         String propValue = KRADConstants.EMPTY_STRING;
 122  0
                         if (fieldControl != null && fieldControl.isSelect()
 123  
                                         && StringUtils.isBlank(field.getAdditionalDisplayPropertyName())
 124  
                                         && StringUtils.isBlank(field.getAlternateDisplayPropertyName())) {
 125  0
                                 Class<? extends KeyValuesFinder> keyValuesFinderName = ClassLoaderUtils.getClass(fieldControl.getValuesFinderClass(), KeyValuesFinder.class);
 126  0
                 KeyValuesFinder finder = keyValuesFinderName.newInstance();
 127  
 
 128  0
                 propValue = lookupFinderValue(fieldControl, prop, finder);
 129  0
             } else {
 130  0
                                 propValue = ObjectUtils.getFormattedPropertyValue(bo, field.getPropertyName(), formatter);
 131  
                     }
 132  0
                         field.setPropertyValue(propValue);
 133  
                         
 134  
                         // set additional or alternate display property values if property
 135  
                         // name is specified
 136  0
                         if (StringUtils.isNotBlank(field.getAlternateDisplayPropertyName())) {
 137  0
                                 String alternatePropertyValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(bo, field
 138  
                                                 .getAlternateDisplayPropertyName());
 139  0
                                 field.setAlternateDisplayPropertyValue(alternatePropertyValue);
 140  
                 }
 141  
 
 142  0
                         if (StringUtils.isNotBlank(field.getAdditionalDisplayPropertyName())) {
 143  0
                                 String additionalPropertyValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(bo, field
 144  
                                                 .getAdditionalDisplayPropertyName());
 145  0
                                 field.setAdditionalDisplayPropertyValue(additionalPropertyValue);
 146  
             }
 147  
 
 148  
                         // for user fields, attempt to pull the principal ID and person's
 149  
                         // name from the source object
 150  0
             if ( fieldControl != null && fieldControl.isKualiUser() ) {
 151  
                     // this is supplemental, so catch and log any errors 
 152  
                     try {
 153  0
                             if ( StringUtils.isNotBlank(field.getUniversalIdAttributeName()) ) {
 154  0
                                     Object principalId = ObjectUtils.getNestedValue(bo, field.getUniversalIdAttributeName());
 155  0
                                     if ( principalId != null ) {
 156  0
                                             field.setUniversalIdValue(principalId.toString());
 157  
                                     }
 158  
                             }
 159  0
                             if ( StringUtils.isNotBlank(field.getPersonNameAttributeName()) ) {
 160  0
                                     Object personName = ObjectUtils.getNestedValue(bo, field.getPersonNameAttributeName());
 161  0
                                     if ( personName != null ) {
 162  0
                                             field.setPersonNameValue( personName.toString() );
 163  
                                     }
 164  
                             }
 165  0
                     } catch ( Exception ex ) {
 166  0
                             LOG.warn( "Unable to get principal ID or person name property in FieldBridge.", ex );
 167  0
                     }
 168  
             }
 169  0
             FieldUtils.setInquiryURL(field, bo, propertyName);
 170  0
                 } catch (InstantiationException e) {
 171  0
             LOG.error("Unable to get instance of KeyValuesFinder: " + e.getMessage());
 172  0
             throw new RuntimeException("Unable to get instance of KeyValuesFinder: " + e.getMessage());
 173  0
                 } catch (ClassNotFoundException e) {
 174  0
                         LOG.error("Unable to get instance of KeyValuesFinder: " + e.getMessage());
 175  0
             throw new RuntimeException("Unable to get instance of KeyValuesFinder: " + e.getMessage());
 176  0
                 } catch (IllegalAccessException e) {
 177  0
             LOG.error("Unable to set columns: " + e.getMessage());
 178  0
             throw new RuntimeException("Unable to set columns: " + e.getMessage());
 179  0
         }
 180  
 
 181  0
     }
 182  
 
 183  
     /**
 184  
      * This method looks up a value in a finder class.
 185  
      * @param fieldControl the type of web control that is associated with this field.
 186  
      * @param prop the property to look up - either a property name as a String, or a referenced object
 187  
      * @param finder finder to look the value up in
 188  
      * @return the value that was returned from the lookup
 189  
      */
 190  
     private static String lookupFinderValue(ControlDefinition fieldControl, Object prop, KeyValuesFinder finder) {
 191  0
         String propValue = null;
 192  
 
 193  
         // KULRICE-1808 : PersistableBusinessObjectValuesFinder is not working for inquiries that have child objects with ValuesFinder populated select lists
 194  0
         if (finder instanceof PersistableBusinessObjectValuesFinder) {
 195  0
             ((PersistableBusinessObjectValuesFinder) finder).setBusinessObjectClass(ClassLoaderUtils.getClass(fieldControl.getBusinessObjectClass()));
 196  0
             ((PersistableBusinessObjectValuesFinder) finder).setKeyAttributeName(fieldControl.getKeyAttribute());
 197  0
             ((PersistableBusinessObjectValuesFinder) finder).setLabelAttributeName(fieldControl.getLabelAttribute());
 198  0
             if (fieldControl.getIncludeBlankRow() != null) {
 199  0
                     ((PersistableBusinessObjectValuesFinder) finder).setIncludeBlankRow(fieldControl.getIncludeBlankRow());
 200  
             }
 201  0
             ((PersistableBusinessObjectValuesFinder) finder).setIncludeKeyInDescription(fieldControl.getIncludeKeyInLabel());
 202  
         }
 203  0
         List<KeyValue> keyValues = finder.getKeyValues();
 204  0
         propValue = getPropertyValueFromList(prop, keyValues);
 205  0
         if(propValue==null) {
 206  0
                         propValue = lookupInactiveFinderValue(prop, finder);
 207  
                 }
 208  0
         return propValue;
 209  
     }
 210  
     
 211  
     private static String lookupInactiveFinderValue(Object property, KeyValuesFinder finder){
 212  0
             List<KeyValue> keyValues = finder.getKeyValues(false);
 213  0
             return getPropertyValueFromList(property, keyValues);
 214  
             
 215  
     }
 216  
     
 217  
     private static String getPropertyValueFromList(Object property, List<KeyValue> keyValues){
 218  0
             String propertyValue = null;
 219  0
         if (property != null) {
 220  0
             for (Object element2 : keyValues) {
 221  0
                 KeyValue element = (KeyValue) element2;
 222  0
                 if (element.getKey().toString().equals(property.toString())) {
 223  0
                     propertyValue = element.getValue();
 224  0
                     break;
 225  
                 }
 226  0
             }
 227  
         }
 228  0
         return propertyValue;
 229  
     }
 230  
     
 231  
     /**
 232  
      * Determines whether field level help is enabled for the field corresponding to the businessObjectClass and attribute name
 233  
      *
 234  
      * If this value is true, then the field level help will be enabled.
 235  
      * If false, then whether a field is enabled is determined by the value returned by {@link #isMaintenanceFieldLevelHelpDisabled(Maintainable, MaintainableFieldDefinition)}
 236  
      * and the system-wide parameter setting.  Note that if a field is read-only, that may cause field-level help to not be rendered.
 237  
      *
 238  
      * @param businessObjectClass the looked up class
 239  
      * @param attributeName the attribute for the field
 240  
      * @return true if field level help is enabled, false if the value of this method should NOT be used to determine whether this method's return value
 241  
      * affects the enablement of field level help
 242  
      */
 243  
     protected static boolean isMaintenanceFieldLevelHelpEnabled(Maintainable m, MaintainableFieldDefinition fieldDefinition) {
 244  0
         if ( fieldDefinition != null ) {
 245  0
             if ( fieldDefinition.isShowFieldLevelHelp() != null && fieldDefinition.isShowFieldLevelHelp() ) {
 246  0
                 return true;
 247  
             }
 248  
         }
 249  0
         return false;
 250  
     }
 251  
 
 252  
     /**
 253  
      * Determines whether field level help is disabled for the field corresponding to the businessObjectClass and attribute name
 254  
      *
 255  
      * If this value is true and {@link #isMaintenanceFieldLevelHelpEnabled(Maintainable, MaintainableFieldDefinition)} returns false,
 256  
      * then the field level help will not be rendered.  If both this and {@link #isMaintenanceFieldLevelHelpEnabled(Maintainable, MaintainableFieldDefinition)} return false,
 257  
      * then the system-wide setting will determine whether field level help is enabled.  Note that if a field is read-only, that may cause
 258  
      * field-level help to not be rendered.
 259  
      *
 260  
      * @param businessObjectClass the looked up class
 261  
      * @param attributeName the attribute for the field
 262  
      * @return true if field level help is disabled, false if the value of this method should NOT be used to determine whether this method's return value
 263  
      * affects the enablement of field level help
 264  
      */
 265  
     protected static boolean isMaintenanceFieldLevelHelpDisabled(Maintainable m, MaintainableFieldDefinition fieldDefinition) {
 266  0
         if ( fieldDefinition != null ) {
 267  0
             if ( fieldDefinition.isShowFieldLevelHelp() != null && !fieldDefinition.isShowFieldLevelHelp() ) {
 268  0
                 return true;
 269  
             }
 270  
         }
 271  0
         return false;
 272  
     }
 273  
 
 274  
     /**
 275  
      * This method creates a Field for display on a Maintenance Document.
 276  
      *
 277  
      * @param id The DD definition for the Field (can be a Collection).
 278  
      * @param sd The DD definition for the Section in which the field will be displayed.
 279  
      * @param o The BusinessObject will be populated from this BO.
 280  
      * @param m
 281  
      * @param s The Section in which the Field will be displayed.
 282  
      * @param autoFillDefaultValues Should default values be filled in?
 283  
      * @param autoFillBlankRequiredValues Should values be filled in for fields that are required but which were left blank when submitting the form from the UI?
 284  
      * @param displayedFieldNames What fields are being displayed on the form in the UI?
 285  
      *
 286  
      * @return
 287  
      *
 288  
      * @throws InstantiationException
 289  
      * @throws IllegalAccessException
 290  
      */
 291  
     public static final Field toField(MaintainableItemDefinition id, MaintainableSectionDefinition sd, BusinessObject o, Maintainable m, Section s, List<String> displayedFieldNames, Set<String> conditionallyRequiredMaintenanceFields) throws InstantiationException, IllegalAccessException {
 292  0
         Field field = new Field();
 293  
 
 294  
         // if FieldDefiniton, simply add a Field UI object
 295  0
         if (id instanceof MaintainableFieldDefinition) {
 296  0
             MaintainableFieldDefinition maintainableFieldDefinition = (MaintainableFieldDefinition) id;
 297  0
             field = FieldUtils.getPropertyField(o.getClass(), maintainableFieldDefinition.getName(), false);
 298  
 
 299  0
                         boolean translateCodes = getMaintenanceDocumentDictionaryService().translateCodes(o.getClass());
 300  0
                         if (translateCodes) {
 301  0
                                 FieldUtils.setAdditionalDisplayPropertyForCodes(o.getClass(), field.getPropertyName(), field);
 302  
                         }
 303  
 
 304  0
             setupField(field, maintainableFieldDefinition, conditionallyRequiredMaintenanceFields);
 305  
 
 306  0
             MaintenanceUtils.setFieldQuickfinder(o, field.getPropertyName(), maintainableFieldDefinition, field, displayedFieldNames, m);
 307  0
             MaintenanceUtils.setFieldDirectInquiry(o, field.getPropertyName(), maintainableFieldDefinition, field, displayedFieldNames);
 308  
 
 309  
             // set default value
 310  
             //TODO St. Ailish says review this. A question was raised on 11-16-2006 Tuscon meeting as to why this is done here and not in the formatter.
 311  
             /*if (autoFillDefaultValues) {
 312  
                 Object defaultValue = maintainableFieldDefinition.getDefaultValue();
 313  
                 if (defaultValue != null) {
 314  
                     if (defaultValue.toString().equals("true")) {
 315  
                         defaultValue = "Yes";
 316  
                     }
 317  
                     else if (defaultValue.toString().equals("false")) {
 318  
                         defaultValue = "No";
 319  
                     }
 320  
                     field.setPropertyValue(defaultValue);
 321  
                 }
 322  
 
 323  
                 Class defaultValueFinderClass = maintainableFieldDefinition.getDefaultValueFinderClass();
 324  
                 if (defaultValueFinderClass != null) {
 325  
                     field.setPropertyValue(((ValueFinder) defaultValueFinderClass.newInstance()).getValue());
 326  
                 }
 327  
             }
 328  
 
 329  
             // if this flag is set, and the current field is required, and readonly, and blank, use the
 330  
             // defaultValueFinder if one exists
 331  
             if (autoFillBlankRequiredValues) {
 332  
                 if ( maintainableFieldDefinition.isRequired() && maintainableFieldDefinition.isUnconditionallyReadOnly() ) {
 333  
                     if ( StringUtils.isBlank( field.getPropertyValue() ) ) {
 334  
                         Class defaultValueFinderClass = maintainableFieldDefinition.getDefaultValueFinderClass();
 335  
                         if (defaultValueFinderClass != null) {
 336  
                             field.setPropertyValue(((ValueFinder) defaultValueFinderClass.newInstance()).getValue());
 337  
                         }
 338  
                     }
 339  
                 }
 340  
             }
 341  
                         */
 342  0
             field.setFieldLevelHelpEnabled(isMaintenanceFieldLevelHelpEnabled(m, maintainableFieldDefinition));
 343  0
             field.setFieldLevelHelpDisabled(isMaintenanceFieldLevelHelpDisabled(m, maintainableFieldDefinition));
 344  0
             field.setFieldLevelHelpUrl(maintainableFieldDefinition.getFieldLevelHelpUrl());
 345  
         }
 346  
 
 347  0
         return field;
 348  
 
 349  
     }
 350  
 
 351  
     /**
 352  
      * This method will return a new form for adding in a BO for a collection.
 353  
      * This should be customized in a subclass so the default behavior is to return nothing.
 354  
      *
 355  
      * @param collectionDefinition The DD definition for the Collection.
 356  
      * @param o The BusinessObject form which the new Fields will be populated.
 357  
      * @param document MaintenanceDocument instance which we ar building fields for
 358  
      * @param m
 359  
      * @param displayedFieldNames What Fields are being displayed on the form in the UI?
 360  
      * @param containerRowErrorKey The error key for the Container/Collection used for displaying error messages.
 361  
      * @param parents
 362  
      * @param hideAdd Should the add line be hidden when displaying this Collection/Container in the UI?
 363  
      * @param numberOfColumns How many columns the Fields in the Collection will be split into when displaying them in the UI.
 364  
      *
 365  
      * @return The List of new Fields.
 366  
      */
 367  
     public static final List<Field> getNewFormFields(CollectionDefinitionI collectionDefinition, BusinessObject o, Maintainable m, List<String> displayedFieldNames, Set<String> conditionallyRequiredMaintenanceFields, StringBuffer containerRowErrorKey, String parents, boolean hideAdd, int numberOfColumns) {
 368  0
         LOG.debug( "getNewFormFields" );
 369  0
         String collName = collectionDefinition.getName();
 370  
 
 371  0
         List<Field> collFields = new ArrayList<Field>();
 372  
         Collection<? extends FieldDefinitionI> collectionFields;
 373  
         //Class boClass = collectionDefinition.getBusinessObjectClass();
 374  0
         BusinessObject collBO = null;
 375  
         try {
 376  0
             collectionFields = collectionDefinition.getFields();
 377  0
             collBO = m.getNewCollectionLine(parents + collName);
 378  
 
 379  0
             if ( LOG.isDebugEnabled() ) {
 380  0
                 LOG.debug( "newBO for add line: " + collBO );
 381  
             }
 382  
 
 383  0
             for ( FieldDefinitionI fieldDefinition : collectionFields  ) {
 384  
                 // construct Field UI object from definition
 385  0
                 Field collField = FieldUtils.getPropertyField(collectionDefinition.getBusinessObjectClass(), fieldDefinition.getName(), false);
 386  
 
 387  0
                 if (fieldDefinition instanceof MaintainableFieldDefinition) {
 388  0
                     setupField(collField, fieldDefinition, conditionallyRequiredMaintenanceFields);
 389  
                 }
 390  
                 //generate the error key for the add row
 391  0
                 String[] nameParts = StringUtils.split(collField.getPropertyName(), ".");
 392  0
                 String fieldErrorKey = KRADConstants.MAINTENANCE_NEW_MAINTAINABLE + KRADConstants.ADD_PREFIX + ".";
 393  0
                 fieldErrorKey += collName + ".";
 394  0
                 for (int i = 0; i < nameParts.length; i++) {
 395  0
                     fieldErrorKey += nameParts[i];
 396  0
                     containerRowErrorKey.append(fieldErrorKey);
 397  0
                     if (i < nameParts.length) {
 398  0
                         fieldErrorKey += ".";
 399  0
                         containerRowErrorKey.append(",");
 400  
                     }
 401  
                 }
 402  
 
 403  
                 //  set the QuickFinderClass
 404  0
                 BusinessObject collectionBoInstance = collectionDefinition.getBusinessObjectClass().newInstance();
 405  0
                 FieldUtils.setInquiryURL(collField, collectionBoInstance, fieldDefinition.getName());
 406  0
                 if (collectionDefinition instanceof MaintainableCollectionDefinition) {
 407  0
                     MaintenanceUtils.setFieldQuickfinder(collectionBoInstance, parents+collectionDefinition.getName(), true, 0, fieldDefinition.getName(), collField, displayedFieldNames, m, (MaintainableFieldDefinition) fieldDefinition);
 408  0
                     MaintenanceUtils.setFieldDirectInquiry(collectionBoInstance, parents+collectionDefinition.getName(), true, 0, fieldDefinition.getName(), collField, displayedFieldNames, m, (MaintainableFieldDefinition) fieldDefinition);
 409  
                 }
 410  
                 else {
 411  0
                     LookupUtils.setFieldQuickfinder(collectionBoInstance, parents+collectionDefinition.getName(), true, 0, fieldDefinition.getName(), collField, displayedFieldNames, m);
 412  0
                     LookupUtils.setFieldDirectInquiry(collectionBoInstance, fieldDefinition.getName(), collField);
 413  
                 }
 414  
 
 415  0
                 collFields.add(collField);
 416  0
             }
 417  
 
 418  0
         } catch (InstantiationException e) {
 419  0
             LOG.error("Unable to create instance of object class" + e.getMessage());
 420  0
             throw new RuntimeException("Unable to create instance of object class" + e.getMessage());
 421  0
         } catch (IllegalAccessException e) {
 422  0
             LOG.error("Unable to create instance of object class" + e.getMessage());
 423  0
             throw new RuntimeException("Unable to create instance of object class" + e.getMessage());
 424  0
         }
 425  
 
 426  
         // populate field values from business object
 427  0
         collFields = FieldUtils.populateFieldsFromBusinessObject(collFields,collBO);
 428  
 
 429  
         // need to append the prefix afterwards since the population command (above)
 430  
         // does not handle the prefixes on the property names
 431  0
         for ( Field field : collFields ) {
 432  
             // prefix name for add line
 433  0
             field.setPropertyName(KRADConstants.MAINTENANCE_ADD_PREFIX + parents + collectionDefinition.getName() + "." + field.getPropertyName());
 434  
         }
 435  0
         LOG.debug("Error Key for section " + collectionDefinition.getName() + " : " + containerRowErrorKey.toString());
 436  
 
 437  
         
 438  0
         collFields = constructContainerField(collectionDefinition, parents, o, hideAdd, numberOfColumns, collName, collFields);
 439  
 
 440  0
         return collFields;
 441  
     }
 442  
 
 443  
     /**
 444  
      * 
 445  
      * This method handles setting up a container field not including the add fields
 446  
      * 
 447  
      * @param collectionDefinition
 448  
      * @param parents
 449  
      * @param o
 450  
      * @param hideAdd
 451  
      * @param numberOfColumns
 452  
      * @param collName
 453  
      * @param collFields
 454  
      * @return
 455  
      */
 456  
     public static List<Field> constructContainerField(CollectionDefinitionI collectionDefinition, String parents, BusinessObject o, boolean hideAdd, int numberOfColumns, String collName, List<Field> collFields) {
 457  
         // get label for collection
 458  0
         String collectionLabel = getDataDictionaryService().getCollectionLabel(o.getClass(), collectionDefinition.getName());
 459  
 
 460  
         // retrieve the summary label either from the override or from the DD
 461  0
         String collectionElementLabel = collectionDefinition.getSummaryTitle();
 462  0
         if(StringUtils.isEmpty(collectionElementLabel)){
 463  0
             collectionElementLabel = getDataDictionaryService().getCollectionElementLabel(o.getClass().getName(), collectionDefinition.getName(),collectionDefinition.getBusinessObjectClass());
 464  
         }
 465  
 
 466  
         // container field
 467  
         Field containerField;
 468  0
         containerField = FieldUtils.constructContainerField(collName, collectionLabel, collFields, numberOfColumns);
 469  0
         if(StringUtils.isNotEmpty(collectionElementLabel)) {
 470  0
             containerField.setContainerElementName(collectionElementLabel);
 471  
         }
 472  0
         collFields = new ArrayList();
 473  0
         collFields.add(containerField);
 474  
 
 475  
         // field button for adding lines
 476  0
         if(!hideAdd  && collectionDefinition.getIncludeAddLine()) {
 477  0
             Field field = new Field();
 478  
 
 479  0
             String addButtonName = KRADConstants.DISPATCH_REQUEST_PARAMETER + "." + KRADConstants.ADD_LINE_METHOD + "." + parents + collectionDefinition.getName() + "." + KRADConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL + collectionDefinition.getBusinessObjectClass().getName() + KRADConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL;
 480  0
             field.setPropertyName(addButtonName);
 481  0
             field.setFieldType(Field.IMAGE_SUBMIT);
 482  0
             field.setPropertyValue("images/tinybutton-add1.gif");
 483  
             // collFields.add(field);
 484  0
             containerField.getContainerRows().add(new Row(field));
 485  
         }
 486  
 
 487  0
         if (collectionDefinition instanceof MaintainableCollectionDefinition) {
 488  0
             if (FieldUtils.isCollectionMultipleLookupEnabled((MaintainableCollectionDefinition) collectionDefinition)) {
 489  0
                 FieldUtils.modifyFieldToSupportMultipleValueLookups(containerField, parents, (MaintainableCollectionDefinition) collectionDefinition);
 490  
             }
 491  
         }
 492  
 
 493  0
         return collFields;
 494  
     }
 495  
 
 496  
     /**
 497  
      * Call getNewFormFields with no parents.
 498  
      *
 499  
      * @see #getNewFormFields(CollectionDefinitionI, BusinessObject, Maintainable, List, StringBuffer, String, boolean, int)
 500  
      */
 501  
     public static final List<Field> getNewFormFields(MaintainableCollectionDefinition collectionDefinition, BusinessObject o, Maintainable m, List<String> displayedFieldNames, Set<String> conditionallyRequiredMaintenanceFields, StringBuffer containerRowErrorKey, int numberOfColumns) {
 502  0
         String parent = "";
 503  0
         return getNewFormFields(collectionDefinition, o, m, displayedFieldNames, conditionallyRequiredMaintenanceFields, containerRowErrorKey, parent, false, numberOfColumns);
 504  
     }
 505  
 
 506  
     /**
 507  
      * Create a Field for display on an Inquiry screen.
 508  
      *
 509  
      * @param d The DD definition for the Field.
 510  
      * @param o The BusinessObject from which the Field will be populated.
 511  
      * @param s The Section in which the Field will be displayed.
 512  
      *
 513  
      * @return The populated Field.
 514  
      */
 515  
     public static Field toField(FieldDefinition d, BusinessObject o, Section s) {
 516  0
         Field field = FieldUtils.getPropertyField(o.getClass(), d.getAttributeName(), false);
 517  
         
 518  0
         FieldUtils.setInquiryURL(field, o, field.getPropertyName());
 519  
 
 520  0
                 String alternateDisplayPropertyName = getBusinessObjectDictionaryService()
 521  
                                 .getInquiryFieldAlternateDisplayAttributeName(o.getClass(), d.getAttributeName());
 522  0
                 if (StringUtils.isNotBlank(alternateDisplayPropertyName)) {
 523  0
                         field.setAlternateDisplayPropertyName(alternateDisplayPropertyName);
 524  
                 }
 525  
 
 526  0
                 String additionalDisplayPropertyName = getBusinessObjectDictionaryService()
 527  
                                 .getInquiryFieldAdditionalDisplayAttributeName(o.getClass(), d.getAttributeName());
 528  0
                 if (StringUtils.isNotBlank(additionalDisplayPropertyName)) {
 529  0
                         field.setAdditionalDisplayPropertyName(additionalDisplayPropertyName);
 530  
                 }
 531  
                 else {
 532  0
                         boolean translateCodes = getBusinessObjectDictionaryService().tranlateCodesInInquiry(o.getClass());
 533  0
                         if (translateCodes) {
 534  0
                                 FieldUtils.setAdditionalDisplayPropertyForCodes(o.getClass(), d.getAttributeName(), field);
 535  
                         }
 536  
                 }
 537  
 
 538  0
         populateFieldFromBusinessObject(field, o);
 539  
 
 540  0
         return field;
 541  
     }
 542  
 
 543  
         public static DataDictionaryService getDataDictionaryService() {
 544  0
             if (dataDictionaryService == null) {
 545  0
                     dataDictionaryService = KRADServiceLocatorWeb.getDataDictionaryService();
 546  
             }
 547  0
                 return dataDictionaryService;
 548  
         }
 549  
 
 550  
         public static PersistenceStructureService getPersistenceStructureService() {
 551  0
             if (persistenceStructureService == null) {
 552  0
                     persistenceStructureService = KRADServiceLocator.getPersistenceStructureService();
 553  
             }
 554  0
                 return persistenceStructureService;
 555  
         }
 556  
 
 557  
         public static BusinessObjectDictionaryService getBusinessObjectDictionaryService() {
 558  0
             if (businessObjectDictionaryService == null) {
 559  0
                     businessObjectDictionaryService = KRADServiceLocatorWeb.getBusinessObjectDictionaryService();
 560  
             }
 561  0
                 return businessObjectDictionaryService; 
 562  
         }
 563  
         
 564  
         public static MaintenanceDocumentDictionaryService getMaintenanceDocumentDictionaryService() {
 565  0
             if (maintenanceDocumentDictionaryService == null) {
 566  0
                     maintenanceDocumentDictionaryService = KRADServiceLocatorWeb.getMaintenanceDocumentDictionaryService();
 567  
             }
 568  0
                 return maintenanceDocumentDictionaryService; 
 569  
         }
 570  
 
 571  
 }
 572