Coverage Report - org.kuali.rice.kns.util.FieldUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
FieldUtils
0%
0/631
0%
0/400
6.842
 
 1  
 /*
 2  
  * Copyright 2005-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.kns.util;
 17  
 
 18  
 import org.apache.commons.beanutils.PropertyUtils;
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.kuali.rice.core.api.CoreApiServiceLocator;
 21  
 import org.kuali.rice.core.api.encryption.EncryptionService;
 22  
 import org.kuali.rice.core.util.ClassLoaderUtils;
 23  
 import org.kuali.rice.core.web.format.FormatException;
 24  
 import org.kuali.rice.kew.util.KEWConstants;
 25  
 import org.kuali.rice.kim.bo.Person;
 26  
 import org.kuali.rice.kns.datadictionary.FieldDefinition;
 27  
 import org.kuali.rice.kns.datadictionary.MaintainableCollectionDefinition;
 28  
 import org.kuali.rice.kns.datadictionary.control.ButtonControlDefinition;
 29  
 import org.kuali.rice.kns.web.ui.Field;
 30  
 import org.kuali.rice.kns.web.ui.PropertyRenderingConfigElement;
 31  
 import org.kuali.rice.kns.web.ui.Row;
 32  
 import org.kuali.rice.kns.web.ui.Section;
 33  
 import org.kuali.rice.krad.bo.MutableInactivatable;
 34  
 import org.kuali.rice.krad.datadictionary.control.ControlDefinition;
 35  
 import org.kuali.rice.kns.datadictionary.control.CurrencyControlDefinition;
 36  
 import org.kuali.rice.kns.datadictionary.control.KualiUserControlDefinition;
 37  
 import org.kuali.rice.kns.datadictionary.control.LinkControlDefinition;
 38  
 import org.kuali.rice.kns.document.authorization.FieldRestriction;
 39  
 import org.kuali.rice.kns.document.authorization.MaintenanceDocumentRestrictions;
 40  
 import org.kuali.rice.kns.inquiry.Inquirable;
 41  
 import org.kuali.rice.kns.lookup.HtmlData;
 42  
 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
 43  
 import org.kuali.rice.kns.lookup.LookupUtils;
 44  
 import org.kuali.rice.kns.service.BusinessObjectMetaDataService;
 45  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 46  
 import org.kuali.rice.krad.bo.BusinessObject;
 47  
 import org.kuali.rice.krad.bo.BusinessObjectRelationship;
 48  
 import org.kuali.rice.krad.bo.KualiCode;
 49  
 import org.kuali.rice.krad.bo.PersistableBusinessObject;
 50  
 import org.kuali.rice.kns.datadictionary.BusinessObjectEntry;
 51  
 import org.kuali.rice.krad.datadictionary.exception.UnknownBusinessClassAttributeException;
 52  
 import org.kuali.rice.krad.datadictionary.mask.MaskFormatter;
 53  
 import org.kuali.rice.krad.keyvalues.IndicatorValuesFinder;
 54  
 import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
 55  
 import org.kuali.rice.krad.keyvalues.PersistableBusinessObjectValuesFinder;
 56  
 import org.kuali.rice.krad.valuefinder.ValueFinder;
 57  
 import org.kuali.rice.krad.service.BusinessObjectDictionaryService;
 58  
 import org.kuali.rice.krad.service.DataDictionaryService;
 59  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 60  
 import org.kuali.rice.krad.service.KualiModuleService;
 61  
 import org.kuali.rice.krad.service.ModuleService;
 62  
 import org.kuali.rice.krad.util.ExternalizableBusinessObjectUtils;
 63  
 import org.kuali.rice.krad.util.GlobalVariables;
 64  
 import org.kuali.rice.krad.util.KRADConstants;
 65  
 import org.kuali.rice.krad.util.KRADPropertyConstants;
 66  
 import org.kuali.rice.krad.util.MessageMap;
 67  
 import org.kuali.rice.krad.util.ObjectUtils;
 68  
 
 69  
 import java.lang.reflect.InvocationTargetException;
 70  
 import java.security.GeneralSecurityException;
 71  
 import java.util.ArrayList;
 72  
 import java.util.HashMap;
 73  
 import java.util.Iterator;
 74  
 import java.util.List;
 75  
 import java.util.Map;
 76  
 
 77  
 
 78  
 /**
 79  
  * This class is used to build Field objects from underlying data dictionary and general utility methods for handling fields.
 80  
  */
 81  
 public final class FieldUtils {
 82  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(FieldUtils.class);
 83  0
     private static DataDictionaryService dataDictionaryService = null;
 84  0
     private static BusinessObjectMetaDataService businessObjectMetaDataService = null;
 85  0
     private static BusinessObjectDictionaryService businessObjectDictionaryService = null;
 86  0
     private static KualiModuleService kualiModuleService = null;
 87  
     
 88  0
         private FieldUtils() {
 89  0
                 throw new UnsupportedOperationException("do not call");
 90  
         }
 91  
 
 92  
     public static void setInquiryURL(Field field, BusinessObject bo, String propertyName) {
 93  0
         HtmlData inquiryHref = new AnchorHtmlData(KRADConstants.EMPTY_STRING, KRADConstants.EMPTY_STRING);
 94  
 
 95  0
         Boolean b = getBusinessObjectDictionaryService().noInquiryFieldInquiry(bo.getClass(), propertyName);
 96  0
         if (b == null || !b.booleanValue()) {
 97  0
             Class<Inquirable> inquirableClass = getBusinessObjectDictionaryService().getInquirableClass(bo.getClass());
 98  0
             Boolean b2 = getBusinessObjectDictionaryService().forceLookupResultFieldInquiry(bo.getClass(), propertyName);
 99  0
             Inquirable inq = null;
 100  
             try {
 101  0
                 if ( inquirableClass != null ) {
 102  0
                     inq = inquirableClass.newInstance();
 103  
                 } else {
 104  0
                     inq = KNSServiceLocator.getKualiInquirable();
 105  0
                     if ( LOG.isDebugEnabled() ) {
 106  0
                         LOG.debug( "Default Inquirable Class: " + inq.getClass() );
 107  
         }
 108  
                 }
 109  
 
 110  0
                 inquiryHref = inq.getInquiryUrl(bo, propertyName, null == b2 ? false : b2.booleanValue() );
 111  
 
 112  0
             } catch ( Exception ex ) {
 113  0
                 LOG.error("unable to create inquirable to get inquiry URL", ex );
 114  0
             }
 115  
         }
 116  
 
 117  0
         field.setInquiryURL(inquiryHref);
 118  0
     }
 119  
 
 120  
         /**
 121  
          * Sets the control on the field based on the data dictionary definition
 122  
          *
 123  
          * @param businessObjectClass
 124  
          *            - business object class for the field attribute
 125  
          * @param attributeName
 126  
          *            - name of the attribute whose {@link Field} is being set
 127  
          * @param convertForLookup
 128  
          *            - whether the field is being build for lookup search which impacts the control chosen
 129  
          * @param field
 130  
          *            - {@link Field} to set control on
 131  
          */
 132  
         public static void setFieldControl(Class businessObjectClass, String attributeName, boolean convertForLookup,
 133  
                         Field field) {
 134  0
                 ControlDefinition control = getDataDictionaryService().getAttributeControlDefinition(businessObjectClass,
 135  
                                 attributeName);
 136  0
                 String fieldType = Field.TEXT;
 137  
 
 138  0
                 if (control != null) {
 139  0
                         if (control.isSelect()) {
 140  0
                                 if (control.getScript() != null && control.getScript().length() > 0) {
 141  0
                                         fieldType = Field.DROPDOWN_SCRIPT;
 142  0
                                         field.setScript(control.getScript());
 143  
                                 } else {
 144  0
                                         fieldType = Field.DROPDOWN;
 145  
                                 }
 146  
                         }
 147  
 
 148  0
                         if (control.isMultiselect()) {
 149  0
                                 fieldType = Field.MULTISELECT;
 150  
                         }
 151  
 
 152  0
                         if (control.isCheckbox()) {
 153  0
                                 fieldType = Field.CHECKBOX;
 154  
                         }
 155  
 
 156  0
                         if (control.isRadio()) {
 157  0
                                 fieldType = Field.RADIO;
 158  
                         }
 159  
 
 160  0
                         if (control.isHidden()) {
 161  0
                                 fieldType = Field.HIDDEN;
 162  
                         }
 163  
 
 164  0
                         if (control.isKualiUser()) {
 165  0
                                 fieldType = Field.KUALIUSER;
 166  0
                                 KualiUserControlDefinition kualiUserControl = (KualiUserControlDefinition) control;
 167  0
                                 field.setUniversalIdAttributeName(kualiUserControl.getUniversalIdAttributeName());
 168  0
                                 field.setUserIdAttributeName(kualiUserControl.getUserIdAttributeName());
 169  0
                                 field.setPersonNameAttributeName(kualiUserControl.getPersonNameAttributeName());
 170  
                         }
 171  
 
 172  0
                         if (control.isWorkflowWorkgroup()) {
 173  0
                                 fieldType = Field.WORKFLOW_WORKGROUP;
 174  
                         }
 175  
 
 176  0
                         if (control.isFile()) {
 177  0
                                 fieldType = Field.FILE;
 178  
                         }
 179  
 
 180  0
                         if (control.isTextarea() && !convertForLookup) {
 181  0
                                 fieldType = Field.TEXT_AREA;
 182  
                         }
 183  
 
 184  0
                         if (control.isLookupHidden()) {
 185  0
                                 fieldType = Field.LOOKUP_HIDDEN;
 186  
                         }
 187  
 
 188  0
                         if (control.isLookupReadonly()) {
 189  0
                                 fieldType = Field.LOOKUP_READONLY;
 190  
                         }
 191  
 
 192  0
                         if (control.isCurrency()) {
 193  0
                                 fieldType = Field.CURRENCY;
 194  
                         }
 195  
 
 196  0
                         if (control.isButton()) {
 197  0
                                 fieldType = Field.BUTTON;
 198  
                         }
 199  
 
 200  0
                         if (control.isLink()) {
 201  0
                                 fieldType = Field.LINK;
 202  
                         }
 203  
 
 204  0
                         if (Field.CURRENCY.equals(fieldType) && control instanceof CurrencyControlDefinition) {
 205  0
                                 CurrencyControlDefinition currencyControl = (CurrencyControlDefinition) control;
 206  0
                                 field.setStyleClass("amount");
 207  0
                                 field.setSize(currencyControl.getSize());
 208  0
                                 field.setFormattedMaxLength(currencyControl.getFormattedMaxLength());
 209  
                         }
 210  
 
 211  
                         // for text controls, set size attribute
 212  0
                         if (Field.TEXT.equals(fieldType)) {
 213  0
                                 Integer size = control.getSize();
 214  0
                                 if (size != null) {
 215  0
                                         field.setSize(size.intValue());
 216  
                                 } else {
 217  0
                                         field.setSize(30);
 218  
                                 }
 219  0
                                 field.setDatePicker(control.isDatePicker());
 220  0
                                 field.setRanged(control.isRanged());
 221  
                         }
 222  
 
 223  0
                         if (Field.WORKFLOW_WORKGROUP.equals(fieldType)) {
 224  0
                                 Integer size = control.getSize();
 225  0
                                 if (size != null) {
 226  0
                                         field.setSize(size.intValue());
 227  
                                 } else {
 228  0
                                         field.setSize(30);
 229  
                                 }
 230  
                         }
 231  
 
 232  
                         // for text area controls, set rows and cols attributes
 233  0
                         if (Field.TEXT_AREA.equals(fieldType)) {
 234  0
                                 Integer rows = control.getRows();
 235  0
                                 if (rows != null) {
 236  0
                                         field.setRows(rows.intValue());
 237  
                                 } else {
 238  0
                                         field.setRows(3);
 239  
                                 }
 240  
 
 241  0
                                 Integer cols = control.getCols();
 242  0
                                 if (cols != null) {
 243  0
                                         field.setCols(cols.intValue());
 244  
                                 } else {
 245  0
                                         field.setCols(40);
 246  
                                 }
 247  0
                                 field.setExpandedTextArea(control.isExpandedTextArea());
 248  
                         }
 249  
 
 250  
                         // for dropdown and radio, get instance of specified KeyValuesFinder and set field values
 251  0
                         if (Field.DROPDOWN.equals(fieldType) || Field.RADIO.equals(fieldType)
 252  
                                         || Field.DROPDOWN_SCRIPT.equals(fieldType)
 253  
                                         || Field.MULTISELECT.equals(fieldType)) {
 254  0
                                 String keyFinderClassName = control.getValuesFinderClass();
 255  
 
 256  0
                                 if (StringUtils.isNotBlank(keyFinderClassName)) {
 257  
                                         try {
 258  0
                                                 Class keyFinderClass = ClassLoaderUtils.getClass(keyFinderClassName);
 259  0
                                                 KeyValuesFinder finder = (KeyValuesFinder) keyFinderClass.newInstance();
 260  
 
 261  0
                                                 if (finder != null) {
 262  0
                                                         if (finder instanceof PersistableBusinessObjectValuesFinder) {
 263  0
                                                                 ((PersistableBusinessObjectValuesFinder) finder)
 264  
                                                                                 .setBusinessObjectClass(ClassLoaderUtils.getClass(control
 265  
                                                 .getBusinessObjectClass()));
 266  0
                                                                 ((PersistableBusinessObjectValuesFinder) finder).setKeyAttributeName(control
 267  
                                         .getKeyAttribute());
 268  0
                                                                 ((PersistableBusinessObjectValuesFinder) finder).setLabelAttributeName(control
 269  
                                                                                 .getLabelAttribute());
 270  0
                                                                 if (control.getIncludeBlankRow() != null) {
 271  0
                                                                         ((PersistableBusinessObjectValuesFinder) finder).setIncludeBlankRow(control
 272  
                                                                                         .getIncludeBlankRow());
 273  
                                                                 }
 274  0
                                                                 ((PersistableBusinessObjectValuesFinder) finder).setIncludeKeyInDescription(control
 275  
                                         .getIncludeKeyInLabel());
 276  
                                                         }
 277  0
                                                         field.setFieldValidValues(finder.getKeyValues());
 278  0
                                                         field.setFieldInactiveValidValues(finder.getKeyValues(false));
 279  
                                                 }
 280  0
                                         } catch (InstantiationException e) {
 281  0
                                                 LOG.error("Unable to get new instance of finder class: " + keyFinderClassName);
 282  0
                                                 throw new RuntimeException("Unable to get new instance of finder class: " + keyFinderClassName);
 283  0
                                         } catch (IllegalAccessException e) {
 284  0
                                                 LOG.error("Unable to get new instance of finder class: " + keyFinderClassName);
 285  0
                                                 throw new RuntimeException("Unable to get new instance of finder class: " + keyFinderClassName);
 286  0
                                         }
 287  
                                 }
 288  
                         }
 289  
 
 290  0
                         if (Field.CHECKBOX.equals(fieldType) && convertForLookup) {
 291  0
                                 fieldType = Field.RADIO;
 292  0
                                 field.setFieldValidValues(IndicatorValuesFinder.INSTANCE.getKeyValues());
 293  
                         }
 294  
 
 295  
                         // for button control
 296  0
                         if (Field.BUTTON.equals(fieldType)) {
 297  0
                                 ButtonControlDefinition buttonControl = (ButtonControlDefinition) control;
 298  0
                                 field.setImageSrc(buttonControl.getImageSrc());
 299  0
                                 field.setStyleClass(buttonControl.getStyleClass());
 300  
                         }
 301  
 
 302  
                         // for link control
 303  0
                         if (Field.LINK.equals(fieldType)) {
 304  0
                                 LinkControlDefinition linkControl = (LinkControlDefinition) control;
 305  0
                                 field.setStyleClass(linkControl.getStyleClass());
 306  0
                                 field.setTarget(linkControl.getTarget());
 307  0
                                 field.setHrefText(linkControl.getHrefText());
 308  
                         }
 309  
 
 310  
                 }
 311  
 
 312  0
                 field.setFieldType(fieldType);
 313  0
         }
 314  
 
 315  
 
 316  
     /**
 317  
      * Builds up a Field object based on the propertyName and business object class.
 318  
      *
 319  
      * See KULRICE-2480 for info on convertForLookup flag
 320  
      *
 321  
      * @param propertyName
 322  
      * @return Field
 323  
      */
 324  
     public static Field getPropertyField(Class businessObjectClass, String attributeName, boolean convertForLookup) {
 325  0
         Field field = new Field();
 326  0
         field.setPropertyName(attributeName);
 327  0
         field.setFieldLabel(getDataDictionaryService().getAttributeLabel(businessObjectClass, attributeName));
 328  
 
 329  0
         setFieldControl(businessObjectClass, attributeName, convertForLookup, field);
 330  
 
 331  0
         Boolean fieldRequired = getBusinessObjectDictionaryService().getLookupAttributeRequired(businessObjectClass, attributeName);
 332  0
         if (fieldRequired != null) {
 333  0
             field.setFieldRequired(fieldRequired.booleanValue());
 334  
         }
 335  
 
 336  0
         Integer maxLength = getDataDictionaryService().getAttributeMaxLength(businessObjectClass, attributeName);
 337  0
         if (maxLength != null) {
 338  0
             field.setMaxLength(maxLength.intValue());
 339  
         }
 340  
 
 341  0
         Boolean upperCase = null;
 342  
         try {
 343  0
             upperCase = getDataDictionaryService().getAttributeForceUppercase(businessObjectClass, attributeName);
 344  
         }
 345  0
         catch (UnknownBusinessClassAttributeException t) {
 346  
                 // do nothing
 347  0
                 LOG.warn( "UnknownBusinessClassAttributeException in fieldUtils.getPropertyField() : " + t.getMessage() );
 348  0
         }
 349  0
         if (upperCase != null) {
 350  0
             field.setUpperCase(upperCase.booleanValue());
 351  
         }
 352  
         
 353  0
                 if (!businessObjectClass.isInterface()) {
 354  
                         try {
 355  0
                                 field.setFormatter(
 356  
                         ObjectUtils.getFormatterWithDataDictionary(businessObjectClass.newInstance(), attributeName));
 357  0
                         } catch (InstantiationException e) {
 358  0
                                 LOG.info("Unable to get new instance of business object class: " + businessObjectClass.getName(), e);
 359  
                                 // just swallow exception and leave formatter blank
 360  0
                         } catch (IllegalAccessException e) {
 361  0
                                 LOG.info("Unable to get new instance of business object class: " + businessObjectClass.getName(), e);
 362  
                                 // just swallow exception and leave formatter blank
 363  0
                         }
 364  
                 }
 365  
 
 366  
         // set Field help properties
 367  0
         field.setBusinessObjectClassName(businessObjectClass.getName());
 368  0
         field.setFieldHelpName(attributeName);
 369  0
         field.setFieldHelpSummary(getDataDictionaryService().getAttributeSummary(businessObjectClass, attributeName));
 370  
 
 371  0
         return field;
 372  
     }
 373  
 
 374  
         /**
 375  
          * For attributes that are codes (determined by whether they have a
 376  
          * reference to a KualiCode bo and similar naming) sets the name as an
 377  
          * additional display property
 378  
          * 
 379  
          * @param businessObjectClass -
 380  
          *            class containing attribute
 381  
          * @param attributeName - 
 382  
          *            name of attribute in the business object
 383  
          * @param field - 
 384  
          *            property display element
 385  
          */
 386  
         public static void setAdditionalDisplayPropertyForCodes(Class businessObjectClass, String attributeName, PropertyRenderingConfigElement field) {
 387  
                 try {
 388  0
                         BusinessObjectRelationship relationship = getBusinessObjectMetaDataService().getBusinessObjectRelationship(
 389  
                                         (BusinessObject) businessObjectClass.newInstance(), attributeName);
 390  
 
 391  0
                         if (relationship != null && attributeName.startsWith(relationship.getParentAttributeName())
 392  
                                         && KualiCode.class.isAssignableFrom(relationship.getRelatedClass())) {
 393  0
                                 field.setAdditionalDisplayPropertyName(relationship.getParentAttributeName() + "."
 394  
                                                 + KRADPropertyConstants.NAME);
 395  
                         }
 396  0
                 } catch (Exception e) {
 397  0
                         throw new RuntimeException("Cannot get new instance of class to check for KualiCode references: "
 398  
                                         + e.getMessage());
 399  0
                 }
 400  0
         }
 401  
 
 402  
 
 403  
     /**
 404  
      * Wraps each Field in the list into a Row.
 405  
      *
 406  
      * @param fields
 407  
      * @return List of Row objects
 408  
      */
 409  
     public static List wrapFields(List fields) {
 410  0
         return wrapFields(fields, KRADConstants.DEFAULT_NUM_OF_COLUMNS);
 411  
     }
 412  
 
 413  
     /**
 414  
      * This method is to implement multiple columns where the numberOfColumns is obtained from data dictionary.
 415  
      *
 416  
      * @param fields
 417  
      * @param numberOfColumns
 418  
      * @return
 419  
      */
 420  
     public static List<Row> wrapFields(List<Field> fields, int numberOfColumns) {
 421  
 
 422  0
         List<Row> rows = new ArrayList();
 423  0
         List<Field> fieldOnlyList = new ArrayList();
 424  
 
 425  0
         List<Field> visableFields = getVisibleFields(fields);
 426  0
             List<Field> nonVisableFields = getNonVisibleFields(fields);
 427  
 
 428  0
         int fieldsPosition = 0;
 429  0
         for (Field element : visableFields) {
 430  0
             if (Field.SUB_SECTION_SEPARATOR.equals(element.getFieldType()) || Field.CONTAINER.equals(element.getFieldType())) {
 431  0
                 fieldsPosition = createBlankSpace(fieldOnlyList, rows, numberOfColumns, fieldsPosition);
 432  0
                 List fieldList = new ArrayList();
 433  0
                 fieldList.add(element);
 434  0
                 rows.add(new Row(fieldList));
 435  0
             }
 436  
             else {
 437  0
                 if (fieldsPosition < numberOfColumns) {
 438  0
                     fieldOnlyList.add(element);
 439  0
                     fieldsPosition++;
 440  
                 }
 441  
                 else {
 442  0
                     rows.add(new Row(new ArrayList(fieldOnlyList)));
 443  0
                     fieldOnlyList.clear();
 444  0
                     fieldOnlyList.add(element);
 445  0
                     fieldsPosition = 1;
 446  
                 }
 447  
             }
 448  
         }
 449  0
         createBlankSpace(fieldOnlyList, rows, numberOfColumns, fieldsPosition);
 450  
 
 451  
      // Add back the non Visible Rows
 452  0
             if(nonVisableFields != null && !nonVisableFields.isEmpty()){
 453  0
                     Row nonVisRow = new Row();
 454  0
                     nonVisRow.setFields(nonVisableFields);
 455  0
                     rows.add(nonVisRow);
 456  
             }
 457  
 
 458  
 
 459  0
         return rows;
 460  
     }
 461  
 
 462  
     private static List<Field> getVisibleFields(List<Field> fields){
 463  0
             List<Field> rList = new ArrayList<Field>();
 464  
 
 465  0
                    for(Field f: fields){
 466  0
                            if(!Field.HIDDEN.equals(f.getFieldType()) &&  !Field.BLANK_SPACE.equals(f.getFieldType())){
 467  0
                                    rList.add(f);
 468  
                            }
 469  
                    }
 470  
 
 471  0
             return rList;
 472  
     }
 473  
 
 474  
     private static List<Field> getNonVisibleFields(List<Field> fields){
 475  0
             List<Field> rList = new ArrayList<Field>();
 476  
 
 477  0
                    for(Field f: fields){
 478  0
                            if(Field.HIDDEN.equals(f.getFieldType()) || Field.BLANK_SPACE.equals(f.getFieldType())){
 479  0
                                    rList.add(f);
 480  
                            }
 481  
                    }
 482  
 
 483  0
             return rList;
 484  
     }
 485  
 
 486  
     /**
 487  
      * This is a helper method to create and add a blank space to the fieldOnly List.
 488  
      *
 489  
      * @param fieldOnlyList
 490  
      * @param rows
 491  
      * @param numberOfColumns
 492  
      * @return fieldsPosition
 493  
      */
 494  
     private static int createBlankSpace(List<Field> fieldOnlyList, List<Row> rows, int numberOfColumns, int fieldsPosition) {
 495  0
         int fieldOnlySize = fieldOnlyList.size();
 496  0
         if (fieldOnlySize > 0) {
 497  0
             for (int i = 0; i < (numberOfColumns - fieldOnlySize); i++) {
 498  0
                 Field empty = new Field();
 499  0
                 empty.setFieldType(Field.BLANK_SPACE);
 500  
                 // Must be set or AbstractLookupableHelperServiceImpl::preprocessDateFields dies
 501  0
                 empty.setPropertyName(Field.BLANK_SPACE);
 502  0
                 fieldOnlyList.add(empty);
 503  
             }
 504  0
             rows.add(new Row(new ArrayList(fieldOnlyList)));
 505  0
             fieldOnlyList.clear();
 506  0
             fieldsPosition = 0;
 507  
         }
 508  0
         return fieldsPosition;
 509  
     }
 510  
 
 511  
     /**
 512  
      * Wraps list of fields into a Field of type CONTAINER
 513  
      *
 514  
      * @param name name for the field
 515  
      * @param label label for the field
 516  
      * @param fields list of fields that should be contained in the container
 517  
      * @return Field of type CONTAINER
 518  
      */
 519  
     public static Field constructContainerField(String name, String label, List fields) {
 520  0
         return constructContainerField(name, label, fields, KRADConstants.DEFAULT_NUM_OF_COLUMNS);
 521  
     }
 522  
 
 523  
     /**
 524  
      * Wraps list of fields into a Field of type CONTAINER and arrange them into multiple columns.
 525  
      *
 526  
      * @param name name for the field
 527  
      * @param label label for the field
 528  
      * @param fields list of fields that should be contained in the container
 529  
      * @param numberOfColumns the number of columns for each row that the fields should be arranged into
 530  
      * @return Field of type CONTAINER
 531  
      */
 532  
     public static Field constructContainerField(String name, String label, List fields, int numberOfColumns) {
 533  0
         Field containerField = new Field();
 534  0
         containerField.setPropertyName(name);
 535  0
         containerField.setFieldLabel(label);
 536  0
         containerField.setFieldType(Field.CONTAINER);
 537  0
         containerField.setNumberOfColumnsForCollection(numberOfColumns);
 538  
 
 539  0
         List rows = wrapFields(fields, numberOfColumns);
 540  0
         containerField.setContainerRows(rows);
 541  
 
 542  0
         return containerField;
 543  
     }
 544  
 
 545  
     /**
 546  
      * Uses reflection to get the property names of the business object, then checks for a matching field property name. If found,
 547  
      * takes the value of the business object property and populates the field value. Iterates through for all fields in the list.
 548  
      *
 549  
      * @param fields list of Field object to populate
 550  
      * @param bo business object to get field values from
 551  
      * @return List of fields with values populated from business object.
 552  
      */
 553  
     public static List<Field> populateFieldsFromBusinessObject(List<Field> fields, BusinessObject bo) {
 554  0
         List<Field> populatedFields = new ArrayList<Field>();
 555  
 
 556  0
         if (bo instanceof PersistableBusinessObject) {
 557  0
                 ((PersistableBusinessObject) bo).refreshNonUpdateableReferences();
 558  
         }
 559  
         
 560  0
         for (Iterator<Field> iter = fields.iterator(); iter.hasNext();) {
 561  0
             Field element = iter.next();
 562  0
             if (element.containsBOData()) {
 563  0
                 String propertyName = element.getPropertyName();
 564  
 
 565  
                 // See: https://test.kuali.org/jira/browse/KULCOA-1185
 566  
                 // Properties that could not possibly be set by the BusinessObject should be ignored.
 567  
                 // (https://test.kuali.org/jira/browse/KULRNE-4354; this code was killing the src attribute of IMAGE_SUBMITs).
 568  0
                 if (isPropertyNested(propertyName) && !isObjectTreeNonNullAllTheWayDown(bo, propertyName) && ((!element.getFieldType().equals(Field.IMAGE_SUBMIT)) && !(element.getFieldType().equals(Field.CONTAINER)) && (!element.getFieldType().equals(Field.QUICKFINDER)))) {
 569  0
                     element.setPropertyValue(null);
 570  
                 }
 571  0
                 else if (PropertyUtils.isReadable(bo, propertyName)) {
 572  0
                         populateReadableField(element, bo);
 573  
                 }
 574  
                 
 575  0
                             if (StringUtils.isNotBlank(element.getAlternateDisplayPropertyName())) {
 576  0
                                     String alternatePropertyValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(bo, element
 577  
                                                     .getAlternateDisplayPropertyName());
 578  0
                                     element.setAlternateDisplayPropertyValue(alternatePropertyValue);
 579  
                             }
 580  
 
 581  0
                             if (StringUtils.isNotBlank(element.getAdditionalDisplayPropertyName())) {
 582  0
                                     String additionalPropertyValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(bo, element
 583  
                                                     .getAdditionalDisplayPropertyName());
 584  0
                                     element.setAdditionalDisplayPropertyValue(additionalPropertyValue);
 585  
                             }
 586  
             }
 587  0
             populatedFields.add(element);
 588  0
         }
 589  
 
 590  0
         return populatedFields;
 591  
     }
 592  
 
 593  
     public static void populateReadableField(Field field, BusinessObject businessObject){
 594  0
                 Object obj = ObjectUtils.getNestedValue(businessObject, field.getPropertyName());
 595  0
                 if (obj != null) {
 596  0
                         String formattedValue = ObjectUtils.getFormattedPropertyValueUsingDataDictionary(businessObject, field.getPropertyName());
 597  0
                         field.setPropertyValue(formattedValue);
 598  
                 
 599  
             // for user fields, attempt to pull the principal ID and person's name from the source object
 600  0
             if ( field.getFieldType().equals(Field.KUALIUSER) ) {
 601  
                     // this is supplemental, so catch and log any errors
 602  
                     try {
 603  0
                             if ( StringUtils.isNotBlank(field.getUniversalIdAttributeName()) ) {
 604  0
                                     Object principalId = ObjectUtils.getNestedValue(businessObject, field.getUniversalIdAttributeName());
 605  0
                                     if ( principalId != null ) {
 606  0
                                             field.setUniversalIdValue(principalId.toString());
 607  
                                     }
 608  
                             }
 609  0
                             if ( StringUtils.isNotBlank(field.getPersonNameAttributeName()) ) {
 610  0
                                     Object personName = ObjectUtils.getNestedValue(businessObject, field.getPersonNameAttributeName());
 611  0
                                     if ( personName != null ) {
 612  0
                                             field.setPersonNameValue( personName.toString() );
 613  
                                     }
 614  
                             }
 615  0
                     } catch ( Exception ex ) {
 616  0
                             LOG.warn( "Unable to get principal ID or person name property in FieldBridge.", ex );
 617  0
                     }
 618  
             }
 619  
         }
 620  
         
 621  0
         populateSecureField(field, obj);
 622  0
     }
 623  
 
 624  
     public static void populateSecureField(Field field, Object fieldValue){
 625  
         // set encrypted & masked value if user does not have permission to see real value in UI
 626  
         // element.isSecure() => a non-null AttributeSecurity object is set in the field
 627  0
         if (field.isSecure()) {
 628  
             try {
 629  0
                 if (fieldValue != null && fieldValue.toString().endsWith(EncryptionService.HASH_POST_PREFIX)) {
 630  0
                         field.setEncryptedValue(fieldValue.toString());
 631  
                 }
 632  
                 else {
 633  0
                         field.setEncryptedValue(CoreApiServiceLocator.getEncryptionService().encrypt(fieldValue) + EncryptionService.ENCRYPTION_POST_PREFIX);
 634  
                 }
 635  
             }
 636  0
             catch (GeneralSecurityException e) {
 637  0
                 throw new RuntimeException("Unable to encrypt secure field " + e.getMessage());
 638  0
             }
 639  
             //field.setDisplayMaskValue(field.getAttributeSecurity().getDisplayMaskValue(fieldValue));
 640  
         }
 641  0
     }
 642  
 
 643  
     /**
 644  
      * This method indicates whether or not propertyName refers to a nested attribute.
 645  
      *
 646  
      * @param propertyName
 647  
      * @return true if propertyName refers to a nested property (e.g. "x.y")
 648  
      */
 649  
     static private boolean isPropertyNested(String propertyName) {
 650  0
         return -1 != propertyName.indexOf('.');
 651  
     }
 652  
 
 653  
     /**
 654  
      * This method verifies that all of the parent objects of propertyName are non-null.
 655  
      *
 656  
      * @param bo
 657  
      * @param propertyName
 658  
      * @return true if all parents are non-null, otherwise false
 659  
      */
 660  
 
 661  
     static private boolean isObjectTreeNonNullAllTheWayDown(BusinessObject bo, String propertyName) {
 662  0
         String[] propertyParts = propertyName.split("\\.");
 663  
 
 664  0
         StringBuffer property = new StringBuffer();
 665  0
         for (int i = 0; i < propertyParts.length - 1; i++) {
 666  
 
 667  0
             property.append((0 == property.length()) ? "" : ".").append(propertyParts[i]);
 668  
             try {
 669  0
                 if (null == PropertyUtils.getNestedProperty(bo, property.toString())) {
 670  0
                     return false;
 671  
                 }
 672  
             }
 673  0
             catch (Throwable t) {
 674  0
                 LOG.debug("Either getter or setter not specified for property \"" + property.toString() + "\"", t);
 675  0
                 return false;
 676  0
             }
 677  
         }
 678  
 
 679  0
         return true;
 680  
 
 681  
     }
 682  
 
 683  
     /**
 684  
      * @param bo
 685  
      * @param propertyName
 686  
      * @return true if one (or more) of the intermediate objects in the given propertyName is null
 687  
      */
 688  
     private static boolean containsIntermediateNull(Object bo, String propertyName) {
 689  0
         boolean containsNull = false;
 690  
 
 691  0
         if (StringUtils.contains(propertyName, ".")) {
 692  0
             String prefix = StringUtils.substringBefore(propertyName, ".");
 693  0
             Object propertyValue = ObjectUtils.getPropertyValue(bo, prefix);
 694  
 
 695  0
             if (propertyValue == null) {
 696  0
                 containsNull = true;
 697  
             }
 698  
             else {
 699  0
                 String suffix = StringUtils.substringAfter(propertyName, ".");
 700  0
                 containsNull = containsIntermediateNull(propertyValue, suffix);
 701  
             }
 702  
         }
 703  
 
 704  0
         return containsNull;
 705  
     }
 706  
 
 707  
     /**
 708  
      * Uses reflection to get the property names of the business object, then checks for the property name as a key in the passed
 709  
      * map. If found, takes the value from the map and sets the business object property.
 710  
      *
 711  
      * @param bo
 712  
      * @param fieldValues
 713  
      * @return Cached Values from any formatting failures
 714  
      */
 715  
     public static Map populateBusinessObjectFromMap(BusinessObject bo, Map fieldValues) {
 716  0
         return populateBusinessObjectFromMap(bo, fieldValues, "");
 717  
     }
 718  
 
 719  
     /**
 720  
      * Uses reflection to get the property names of the business object, then checks for the property name as a key in the passed
 721  
      * map. If found, takes the value from the map and sets the business object property.
 722  
      *
 723  
      * @param bo
 724  
      * @param fieldValues
 725  
      * @param propertyNamePrefix this value will be prepended to all property names in the returned unformattable values map
 726  
      * @return Cached Values from any formatting failures
 727  
      */
 728  
     public static Map populateBusinessObjectFromMap(BusinessObject bo, Map<String, ?> fieldValues, String propertyNamePrefix) {
 729  0
         Map cachedValues = new HashMap();
 730  0
         MessageMap errorMap = GlobalVariables.getMessageMap();
 731  
 
 732  
         try {
 733  0
             for (Iterator<String> iter = fieldValues.keySet().iterator(); iter.hasNext();) {
 734  0
                 String propertyName = iter.next();
 735  
 
 736  0
                 if (propertyName.endsWith(KRADConstants.CHECKBOX_PRESENT_ON_FORM_ANNOTATION)) {
 737  
                     // since checkboxes do not post values when unchecked, this code detects whether a checkbox was unchecked, and
 738  
                     // sets the value to false.
 739  0
                     if (StringUtils.isNotBlank((String) fieldValues.get(propertyName))) {
 740  0
                         String checkboxName = StringUtils.removeEnd(propertyName, KRADConstants.CHECKBOX_PRESENT_ON_FORM_ANNOTATION);
 741  0
                         String checkboxValue = (String) fieldValues.get(checkboxName);
 742  0
                         if (checkboxValue == null) {
 743  
                             // didn't find a checkbox value, assume that it is unchecked
 744  0
                             if (PropertyUtils.isWriteable(bo, checkboxName)) {
 745  0
                                 Class type = ObjectUtils.easyGetPropertyType(bo, checkboxName);
 746  0
                                 if (type == Boolean.TYPE || type == Boolean.class) {
 747  
                                     // ASSUMPTION: unchecked means false
 748  0
                                     ObjectUtils.setObjectProperty(bo, checkboxName, type, "false");
 749  
                                 }
 750  
                             }
 751  
                         }
 752  0
                     }
 753  
                     // else, if not null, then it has a value, and we'll let the rest of the code handle it when the param is processed on
 754  
                     // another iteration (may be before or after this iteration).
 755  
                 }
 756  0
                 else if (PropertyUtils.isWriteable(bo, propertyName) && fieldValues.get(propertyName) != null ) {
 757  
                     // if the field propertyName is a valid property on the bo class
 758  0
                     Class type = ObjectUtils.easyGetPropertyType(bo, propertyName);
 759  
                     try {
 760  0
                             Object fieldValue = fieldValues.get(propertyName);
 761  0
                         ObjectUtils.setObjectProperty(bo, propertyName, type, fieldValue);
 762  
                     }
 763  0
                     catch (FormatException e) {
 764  0
                         cachedValues.put(propertyNamePrefix + propertyName, fieldValues.get(propertyName));
 765  0
                         errorMap.putError(propertyNamePrefix + propertyName, e.getErrorKey(), e.getErrorArgs());
 766  0
                     }
 767  
                 }
 768  0
             }
 769  
         }
 770  0
         catch (IllegalAccessException e) {
 771  0
             LOG.error("unable to populate business object" + e.getMessage());
 772  0
             throw new RuntimeException(e.getMessage(), e);
 773  
         }
 774  0
         catch (InvocationTargetException e) {
 775  0
             LOG.error("unable to populate business object" + e.getMessage());
 776  0
             throw new RuntimeException(e.getMessage(), e);
 777  
         }
 778  0
         catch (NoSuchMethodException e) {
 779  0
             LOG.error("unable to populate business object" + e.getMessage());
 780  0
             throw new RuntimeException(e.getMessage(), e);
 781  0
         }
 782  
 
 783  0
         return cachedValues;
 784  
     }
 785  
 
 786  
     /**
 787  
      * Does prefixing and read only settings of a Field UI for display in a maintenance document.
 788  
      *
 789  
      * @param field - the Field object to be displayed
 790  
      * @param keyFieldNames - Primary key property names for the business object being maintained.
 791  
      * @param namePrefix - String to prefix Field names with.
 792  
      * @param maintenanceAction - The maintenance action requested.
 793  
      * @param readOnly - Indicates whether all fields should be read only.
 794  
      * @return Field
 795  
      */
 796  
     public static Field fixFieldForForm(Field field, List keyFieldNames, String namePrefix, String maintenanceAction, boolean readOnly, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) {
 797  0
         String propertyName = field.getPropertyName();
 798  
         // We only need to do the following processing if the field is not a sub section header
 799  0
         if (field.containsBOData()) {
 800  
 
 801  
             // don't prefix submit fields, must start with dispatch parameter name
 802  0
             if (!propertyName.startsWith(KRADConstants.DISPATCH_REQUEST_PARAMETER)) {
 803  
                 // if the developer hasn't set a specific prefix use the one supplied
 804  0
                 if (field.getPropertyPrefix() == null || field.getPropertyPrefix().equals("")) {
 805  0
                     field.setPropertyName(namePrefix + propertyName);
 806  
                 }
 807  
                 else {
 808  0
                     field.setPropertyName(field.getPropertyPrefix() + "." + propertyName);
 809  
                 }
 810  
             }
 811  
 
 812  0
             if (readOnly) {
 813  0
                 field.setReadOnly(true);
 814  
             }
 815  
 
 816  
             // set keys read only for edit
 817  0
             if ( KRADConstants.MAINTENANCE_EDIT_ACTION.equals(maintenanceAction) ) {
 818  0
                     if (keyFieldNames.contains(propertyName) ) {
 819  0
                         field.setReadOnly(true);
 820  0
                         field.setKeyField(true);
 821  0
                     } else if ( StringUtils.isNotBlank( field.getUniversalIdAttributeName() )
 822  
                                     && keyFieldNames.contains(field.getUniversalIdAttributeName() ) ) {
 823  
                             // special handling for when the principal ID is the PK field for a record
 824  
                             // this causes locking down of the user ID field
 825  0
                         field.setReadOnly(true);
 826  0
                         field.setKeyField(true);
 827  
                     }
 828  
             }
 829  
 
 830  
             // apply any authorization restrictions to field availability on the UI
 831  0
             applyAuthorization(field, maintenanceAction, auths, documentStatus, documentInitiatorPrincipalId);
 832  
 
 833  
             // if fieldConversions specified, prefix with new constant
 834  0
             if (StringUtils.isNotBlank(field.getFieldConversions())) {
 835  0
                 String fieldConversions = field.getFieldConversions();
 836  0
                 String newFieldConversions = KRADConstants.EMPTY_STRING;
 837  0
                 String[] conversions = StringUtils.split(fieldConversions, KRADConstants.FIELD_CONVERSIONS_SEPARATOR);
 838  
 
 839  0
                 for (int l = 0; l < conversions.length; l++) {
 840  0
                     String conversion = conversions[l];
 841  
                     //String[] conversionPair = StringUtils.split(conversion, KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR);
 842  0
                     String[] conversionPair = StringUtils.split(conversion, KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR, 2);
 843  0
                     String conversionFrom = conversionPair[0];
 844  0
                     String conversionTo = conversionPair[1];
 845  0
                     conversionTo = KRADConstants.MAINTENANCE_NEW_MAINTAINABLE + conversionTo;
 846  0
                     newFieldConversions += (conversionFrom + KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR + conversionTo);
 847  
 
 848  0
                     if (l < conversions.length) {
 849  0
                         newFieldConversions += KRADConstants.FIELD_CONVERSIONS_SEPARATOR;
 850  
                     }
 851  
                 }
 852  
 
 853  0
                 field.setFieldConversions(newFieldConversions);
 854  
             }
 855  
 
 856  
             // if inquiryParameters specified, prefix with new constant
 857  0
             if (StringUtils.isNotBlank(field.getInquiryParameters())) {
 858  0
                 String inquiryParameters = field.getInquiryParameters();
 859  0
                 StringBuilder newInquiryParameters = new StringBuilder();
 860  0
                 String[] parameters = StringUtils.split(inquiryParameters, KRADConstants.FIELD_CONVERSIONS_SEPARATOR);
 861  
 
 862  0
                 for (int l = 0; l < parameters.length; l++) {
 863  0
                     String parameter = parameters[l];
 864  
                     //String[] parameterPair = StringUtils.split(parameter, KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR);
 865  0
                     String[] parameterPair = StringUtils.split(parameter, KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR, 2);
 866  0
                     String conversionFrom = parameterPair[0];
 867  0
                     String conversionTo = parameterPair[1];
 868  
 
 869  
                     // append the conversionFrom string, prefixed by document.newMaintainable
 870  0
                     newInquiryParameters.append(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE).append(conversionFrom);
 871  
 
 872  0
                     newInquiryParameters.append(KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR).append(conversionTo);
 873  
 
 874  0
                     if (l < parameters.length - 1) {
 875  0
                         newInquiryParameters.append(KRADConstants.FIELD_CONVERSIONS_SEPARATOR);
 876  
                     }
 877  
                 }
 878  
 
 879  0
                 field.setInquiryParameters(newInquiryParameters.toString());
 880  
             }
 881  
 
 882  0
             if (Field.KUALIUSER.equals(field.getFieldType())) {
 883  
                 // prefix the personNameAttributeName
 884  0
                     int suffixIndex = field.getPropertyName().indexOf( field.getUserIdAttributeName() );
 885  0
                     if ( suffixIndex != -1 ) {
 886  0
                             field.setPersonNameAttributeName( field.getPropertyName().substring( 0, suffixIndex ) + field.getPersonNameAttributeName() );
 887  0
                             field.setUniversalIdAttributeName( field.getPropertyName().substring( 0, suffixIndex ) + field.getUniversalIdAttributeName() );
 888  
                     } else {
 889  0
                             field.setPersonNameAttributeName(namePrefix + field.getPersonNameAttributeName());
 890  0
                             field.setUniversalIdAttributeName(namePrefix + field.getUniversalIdAttributeName());
 891  
                     }
 892  
 
 893  
                 // TODO: do we need to prefix the universalIdAttributeName in Field as well?
 894  
             }
 895  
 
 896  
             // if lookupParameters specified, prefix with new constant
 897  0
             if (StringUtils.isNotBlank(field.getLookupParameters())) {
 898  0
                 String lookupParameters = field.getLookupParameters();
 899  0
                 String newLookupParameters = KRADConstants.EMPTY_STRING;
 900  0
                 String[] conversions = StringUtils.split(lookupParameters, KRADConstants.FIELD_CONVERSIONS_SEPARATOR);
 901  
 
 902  0
                 for (int m = 0; m < conversions.length; m++) {
 903  0
                     String conversion = conversions[m];
 904  
                     //String[] conversionPair = StringUtils.split(conversion, KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR);
 905  0
                     String[] conversionPair = StringUtils.split(conversion, KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR, 2);
 906  0
                     String conversionFrom = conversionPair[0];
 907  0
                     String conversionTo = conversionPair[1];
 908  0
                     conversionFrom = KRADConstants.MAINTENANCE_NEW_MAINTAINABLE + conversionFrom;
 909  0
                     newLookupParameters += (conversionFrom + KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR + conversionTo);
 910  
 
 911  0
                     if (m < conversions.length) {
 912  0
                         newLookupParameters += KRADConstants.FIELD_CONVERSIONS_SEPARATOR;
 913  
                     }
 914  
                 }
 915  
 
 916  0
                 field.setLookupParameters(newLookupParameters);
 917  
             }
 918  
 
 919  
             // CONTAINER field types have nested rows and fields that need setup for the form
 920  0
             if (Field.CONTAINER.equals(field.getFieldType())) {
 921  0
                 List containerRows = field.getContainerRows();
 922  0
                 List fixedRows = new ArrayList();
 923  
 
 924  0
                 for (Iterator iter = containerRows.iterator(); iter.hasNext();) {
 925  0
                     Row containerRow = (Row) iter.next();
 926  0
                     List containerFields = containerRow.getFields();
 927  0
                     List fixedFields = new ArrayList();
 928  
 
 929  0
                     for (Iterator iterator = containerFields.iterator(); iterator.hasNext();) {
 930  0
                         Field containerField = (Field) iterator.next();
 931  0
                         containerField = fixFieldForForm(containerField, keyFieldNames, namePrefix, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId);
 932  0
                         fixedFields.add(containerField);
 933  0
                     }
 934  
 
 935  0
                     fixedRows.add(new Row(fixedFields));
 936  0
                 }
 937  
 
 938  0
                 field.setContainerRows(fixedRows);
 939  
             }
 940  
         }
 941  0
         return field;
 942  
     }
 943  
 
 944  
     public static void applyAuthorization(Field field, String maintenanceAction, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) {
 945  0
             String fieldName = "";
 946  0
             FieldRestriction fieldAuth = null;
 947  0
             Person user = GlobalVariables.getUserSession().getPerson();
 948  
         // only apply this on the newMaintainable
 949  0
         if (field.getPropertyName().startsWith(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE)) {
 950  
             // get just the actual fieldName, with the document.newMaintainableObject, etc etc removed
 951  0
             fieldName = field.getPropertyName().substring(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE.length());
 952  
 
 953  
             // if the field is restricted somehow
 954  0
             if (auths.hasRestriction(fieldName)) {
 955  0
                 fieldAuth = auths.getFieldRestriction(fieldName);
 956  0
                 if(KRADConstants.MAINTENANCE_NEW_ACTION.equals(maintenanceAction) || KRADConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceAction)){
 957  0
                         if((KEWConstants.ROUTE_HEADER_SAVED_CD.equals(documentStatus) || KEWConstants.ROUTE_HEADER_INITIATED_CD.equals(documentStatus))
 958  
                                 && user.getPrincipalId().equals(documentInitiatorPrincipalId)){
 959  
 
 960  
                                 //user should be able to see the unmark value
 961  
                         }else{
 962  0
                                 if(fieldAuth.isPartiallyMasked()){
 963  0
                                     field.setSecure(true);
 964  0
                                     fieldAuth.setShouldBeEncrypted(true);
 965  0
                                     MaskFormatter maskFormatter = fieldAuth.getMaskFormatter();
 966  0
                                     String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue());
 967  0
                                     field.setDisplayMaskValue(displayMaskValue);
 968  0
                                     populateSecureField(field, field.getPropertyValue());
 969  0
                             }
 970  0
                             else if(fieldAuth.isMasked()){
 971  0
                                     field.setSecure(true);
 972  0
                                     fieldAuth.setShouldBeEncrypted(true);
 973  0
                                     MaskFormatter maskFormatter = fieldAuth.getMaskFormatter();
 974  0
                                     String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue());
 975  0
                                     field.setDisplayMaskValue(displayMaskValue);
 976  0
                                     populateSecureField(field, field.getPropertyValue());
 977  
                             }
 978  
                         }
 979  
                 }
 980  
 
 981  0
                 if (KRADConstants.MAINTENANCE_EDIT_ACTION.equals(maintenanceAction) || KRADConstants.MAINTENANCE_NEWWITHEXISTING_ACTION.equals(maintenanceAction)) {
 982  
                         // if there's existing data on the page that we're not going to clear out, then we will mask it out
 983  0
                         if(fieldAuth.isPartiallyMasked()){
 984  0
                                 field.setSecure(true);
 985  0
                                 fieldAuth.setShouldBeEncrypted(true);
 986  0
                                 MaskFormatter maskFormatter = fieldAuth.getMaskFormatter();
 987  0
                                 String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue());
 988  0
                                 field.setDisplayMaskValue(displayMaskValue);
 989  0
                                 populateSecureField(field, field.getPropertyValue());
 990  0
                         }
 991  0
                         else if(fieldAuth.isMasked()){
 992  0
                                 field.setSecure(true);
 993  0
                                 fieldAuth.setShouldBeEncrypted(true);
 994  0
                                 MaskFormatter maskFormatter = fieldAuth.getMaskFormatter();
 995  0
                                 String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue());
 996  0
                                 field.setDisplayMaskValue(displayMaskValue);
 997  0
                                 populateSecureField(field, field.getPropertyValue());
 998  
                         }
 999  
                 }
 1000  
 
 1001  0
                 if (Field.isInputField(field.getFieldType()) || field.getFieldType().equalsIgnoreCase(Field.CHECKBOX)) {
 1002  
                         // if its an editable field, allow decreasing availability to readonly or hidden
 1003  
                     // only touch the field if the restricted type is hidden or readonly
 1004  0
                     if (fieldAuth.isReadOnly()) {
 1005  0
                         if (!field.isReadOnly() && !fieldAuth.isMasked() && !fieldAuth.isPartiallyMasked()) {
 1006  0
                             field.setReadOnly(true);
 1007  
                         }
 1008  
                     }
 1009  0
                     else if (fieldAuth.isHidden()) {
 1010  0
                         if (field.getFieldType() != Field.HIDDEN) {
 1011  0
                             field.setFieldType(Field.HIDDEN);
 1012  
                         }
 1013  
                     }
 1014  
                 }
 1015  
 
 1016  0
                 if(Field.BUTTON.equalsIgnoreCase(field.getFieldType()) && fieldAuth.isHidden()){
 1017  0
                         field.setFieldType(Field.HIDDEN);
 1018  
                 }
 1019  
 
 1020  
                 // if the field is readOnly, and the authorization says it should be hidden,
 1021  
                 // then restrict it
 1022  0
                 if (field.isReadOnly() && fieldAuth.isHidden()) {
 1023  0
                     field.setFieldType(Field.HIDDEN);
 1024  
                 }
 1025  
 
 1026  
             }
 1027  
             // special check for old maintainable - need to ensure that fields hidden on the
 1028  
             // "new" side are also hidden on the old side
 1029  
         }
 1030  0
         else if (field.getPropertyName().startsWith(KRADConstants.MAINTENANCE_OLD_MAINTAINABLE)) {
 1031  
             // get just the actual fieldName, with the document.oldMaintainableObject, etc etc removed
 1032  0
             fieldName = field.getPropertyName().substring(KRADConstants.MAINTENANCE_OLD_MAINTAINABLE.length());
 1033  
             // if the field is restricted somehow
 1034  0
             if (auths.hasRestriction(fieldName)) {
 1035  0
                 fieldAuth = auths.getFieldRestriction(fieldName);
 1036  0
                 if(fieldAuth.isPartiallyMasked()){
 1037  0
                     field.setSecure(true);
 1038  0
                     MaskFormatter maskFormatter = fieldAuth.getMaskFormatter();
 1039  0
                     String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue());
 1040  0
                     field.setDisplayMaskValue(displayMaskValue);
 1041  0
                     field.setPropertyValue(displayMaskValue);
 1042  0
                     populateSecureField(field, field.getPropertyValue());
 1043  
 
 1044  
                }
 1045  
 
 1046  0
                if(fieldAuth.isMasked()){
 1047  0
                     field.setSecure(true);
 1048  0
                     MaskFormatter maskFormatter = fieldAuth.getMaskFormatter();
 1049  0
                     String displayMaskValue = maskFormatter.maskValue(field.getPropertyValue());
 1050  0
                     field.setDisplayMaskValue(displayMaskValue);
 1051  0
                     field.setPropertyValue(displayMaskValue);
 1052  0
                     populateSecureField(field, field.getPropertyValue());
 1053  
                 }
 1054  
 
 1055  0
                 if (fieldAuth.isHidden()) {
 1056  0
                     field.setFieldType(Field.HIDDEN);
 1057  
                 }
 1058  
             }
 1059  
         }
 1060  0
     }
 1061  
 
 1062  
     /**
 1063  
      * Merges together sections of the old maintainable and new maintainable.
 1064  
      *
 1065  
      * @param oldSections
 1066  
      * @param newSections
 1067  
      * @param keyFieldNames
 1068  
      * @param maintenanceAction
 1069  
      * @param readOnly
 1070  
      * @return List of Section objects
 1071  
      */
 1072  
     public static List meshSections(List oldSections, List newSections, List keyFieldNames, String maintenanceAction, boolean readOnly, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) {
 1073  0
         List meshedSections = new ArrayList();
 1074  
 
 1075  0
         for (int i = 0; i < newSections.size(); i++) {
 1076  0
             Section maintSection = (Section) newSections.get(i);
 1077  0
             List sectionRows = maintSection.getRows();
 1078  0
             Section oldMaintSection = (Section) oldSections.get(i);
 1079  0
             List oldSectionRows = oldMaintSection.getRows();
 1080  0
             List<Row> meshedRows = new ArrayList();
 1081  0
             meshedRows = meshRows(oldSectionRows, sectionRows, keyFieldNames, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId);
 1082  0
             maintSection.setRows(meshedRows);
 1083  0
             if (StringUtils.isBlank(maintSection.getErrorKey())) {
 1084  0
                 maintSection.setErrorKey(MaintenanceUtils.generateErrorKeyForSection(maintSection));
 1085  
             }
 1086  0
             meshedSections.add(maintSection);
 1087  
         }
 1088  
 
 1089  0
         return meshedSections;
 1090  
     }
 1091  
 
 1092  
     /**
 1093  
      * Merges together rows of an old maintainable section and new maintainable section.
 1094  
      *
 1095  
      * @param oldRows
 1096  
      * @param newRows
 1097  
      * @param keyFieldNames
 1098  
      * @param maintenanceAction
 1099  
      * @param readOnly
 1100  
      * @return List of Row objects
 1101  
      */
 1102  
     public static List meshRows(List oldRows, List newRows, List keyFieldNames, String maintenanceAction, boolean readOnly, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) {
 1103  0
         List<Row> meshedRows = new ArrayList<Row>();
 1104  
 
 1105  0
         for (int j = 0; j < newRows.size(); j++) {
 1106  0
             Row sectionRow = (Row) newRows.get(j);
 1107  0
             List rowFields = sectionRow.getFields();
 1108  0
             Row oldSectionRow = null;
 1109  0
             List oldRowFields = new ArrayList();
 1110  
 
 1111  0
             if (null != oldRows && oldRows.size() > j) {
 1112  0
                 oldSectionRow = (Row) oldRows.get(j);
 1113  0
                 oldRowFields = oldSectionRow.getFields();
 1114  
             }
 1115  
 
 1116  0
             List meshedFields = meshFields(oldRowFields, rowFields, keyFieldNames, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId);
 1117  0
             if (meshedFields.size() > 0) {
 1118  0
                 Row meshedRow = new Row(meshedFields);
 1119  0
                 if (sectionRow.isHidden()) {
 1120  0
                     meshedRow.setHidden(true);
 1121  
                 }
 1122  
 
 1123  0
                 meshedRows.add(meshedRow);
 1124  
             }
 1125  
         }
 1126  
 
 1127  0
         return meshedRows;
 1128  
     }
 1129  
 
 1130  
 
 1131  
     /**
 1132  
      * Merges together fields and an old maintainble row and new maintainable row, for each field call fixFieldForForm.
 1133  
      *
 1134  
      * @param oldFields
 1135  
      * @param newFields
 1136  
      * @param keyFieldNames
 1137  
      * @param maintenanceAction
 1138  
      * @param readOnly
 1139  
      * @return List of Field objects
 1140  
      */
 1141  
     public static List meshFields(List oldFields, List newFields, List keyFieldNames, String maintenanceAction, boolean readOnly, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) {
 1142  0
         List meshedFields = new ArrayList();
 1143  
 
 1144  0
         List newFieldsToMerge = new ArrayList();
 1145  0
         List oldFieldsToMerge = new ArrayList();
 1146  
 
 1147  0
         for (int k = 0; k < newFields.size(); k++) {
 1148  0
             Field newMaintField = (Field) newFields.get(k);
 1149  0
             String propertyName = newMaintField.getPropertyName();
 1150  
             // If this is an add button, then we have to have only this field for the entire row.
 1151  0
             if (Field.IMAGE_SUBMIT.equals(newMaintField.getFieldType())) {
 1152  0
                 meshedFields.add(newMaintField);
 1153  
             }
 1154  0
             else if (Field.CONTAINER.equals(newMaintField.getFieldType())) {
 1155  0
                 if (oldFields.size() > k) {
 1156  0
                     Field oldMaintField = (Field) oldFields.get(k);
 1157  0
                     newMaintField = meshContainerFields(oldMaintField, newMaintField, keyFieldNames, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId);
 1158  0
                 }
 1159  
                 else {
 1160  0
                     newMaintField = meshContainerFields(newMaintField, newMaintField, keyFieldNames, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId);
 1161  
                 }
 1162  0
                 meshedFields.add(newMaintField);
 1163  
             }
 1164  
             else {
 1165  0
                 newMaintField = FieldUtils.fixFieldForForm(newMaintField, keyFieldNames, KRADConstants.MAINTENANCE_NEW_MAINTAINABLE, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId);
 1166  
                 // add old fields for edit
 1167  0
                 if (KRADConstants.MAINTENANCE_EDIT_ACTION.equals(maintenanceAction) || KRADConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceAction)) {
 1168  0
                     Field oldMaintField = (Field) oldFields.get(k);
 1169  
 
 1170  
                     // compare values for change, and set new maintainable fields for highlighting
 1171  
                     // no point in highlighting the hidden fields, since they won't be rendered anyways
 1172  0
                     if (!StringUtils.equalsIgnoreCase(newMaintField.getPropertyValue(), oldMaintField.getPropertyValue())
 1173  
                             && !Field.HIDDEN.equals(newMaintField.getFieldType())) {
 1174  0
                         newMaintField.setHighlightField(true);
 1175  
                     }
 1176  
 
 1177  0
                     oldMaintField = FieldUtils.fixFieldForForm(oldMaintField, keyFieldNames, KRADConstants.MAINTENANCE_OLD_MAINTAINABLE, maintenanceAction, true, auths, documentStatus, documentInitiatorPrincipalId);
 1178  0
                     oldFieldsToMerge.add(oldMaintField);
 1179  
                 }
 1180  
 
 1181  0
                 newFieldsToMerge.add(newMaintField);
 1182  
 
 1183  0
                 for (Iterator iter = oldFieldsToMerge.iterator(); iter.hasNext();) {
 1184  0
                     Field element = (Field) iter.next();
 1185  0
                     meshedFields.add(element);
 1186  0
                 }
 1187  
 
 1188  0
                 for (Iterator iter = newFieldsToMerge.iterator(); iter.hasNext();) {
 1189  0
                     Field element = (Field) iter.next();
 1190  0
                     meshedFields.add(element);
 1191  0
                 }
 1192  
             }
 1193  
         }
 1194  0
         return meshedFields;
 1195  
     }
 1196  
 
 1197  
     /**
 1198  
      * Determines whether field level help is enabled for the field corresponding to the dataObjectClass and attribute name
 1199  
      *
 1200  
      * If this value is true, then the field level help will be enabled.
 1201  
      * If false, then whether a field is enabled is determined by the value returned by {@link #isLookupFieldLevelHelpDisabled(Class, String)} and the system-wide
 1202  
      * parameter setting.  Note that if a field is read-only, that may cause field-level help to not be rendered.
 1203  
      *
 1204  
      * @param businessObjectClass the looked up class
 1205  
      * @param attributeName the attribute for the field
 1206  
      * @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
 1207  
      * affects the enablement of field level help
 1208  
      */
 1209  
     protected static boolean isLookupFieldLevelHelpEnabled(Class businessObjectClass, String attributeName) {
 1210  0
         return false;
 1211  
     }
 1212  
 
 1213  
     /**
 1214  
      * Determines whether field level help is disabled for the field corresponding to the dataObjectClass and attribute name
 1215  
      *
 1216  
      * If this value is true and {@link #isLookupFieldLevelHelpEnabled(Class, String)} returns false,
 1217  
      * then the field level help will not be rendered.  If both this and {@link #isLookupFieldLevelHelpEnabled(Class, String)} return false, then the system-wide
 1218  
      * setting will determine whether field level help is enabled.  Note that if a field is read-only, that may cause field-level help to not be rendered.
 1219  
      *
 1220  
      * @param businessObjectClass the looked up class
 1221  
      * @param attributeName the attribute for the field
 1222  
      * @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
 1223  
      * affects the enablement of field level help
 1224  
      */
 1225  
     protected static boolean isLookupFieldLevelHelpDisabled(Class businessObjectClass, String attributeName) {
 1226  0
         return false;
 1227  
     }
 1228  
 
 1229  
     public static List createAndPopulateFieldsForLookup(List<String> lookupFieldAttributeList, List<String> readOnlyFieldsList, Class businessObjectClass) throws InstantiationException, IllegalAccessException {
 1230  0
         List<Field> fields = new ArrayList<Field>();
 1231  0
         BusinessObjectEntry boe = (BusinessObjectEntry) getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(businessObjectClass.getName());
 1232  
 
 1233  0
         Map<String, Boolean> isHiddenMap = new HashMap<String, Boolean>();
 1234  0
         Map<String, Boolean> isReadOnlyMap = new HashMap<String, Boolean>();
 1235  
 
 1236  
         /*
 1237  
              * Check if any field is hidden or read only.  This allows us to
 1238  
              * set lookup criteria as hidden/readonly outside the controlDefinition.
 1239  
              */
 1240  0
             if(boe.hasLookupDefinition()){
 1241  0
                     List<FieldDefinition> fieldDefs = boe.getLookupDefinition().getLookupFields();
 1242  0
                     for(FieldDefinition field : fieldDefs){
 1243  0
                                 isReadOnlyMap.put(field.getAttributeName(), Boolean.valueOf(field.isReadOnly()));
 1244  0
                                 isHiddenMap.put(field.getAttributeName(), Boolean.valueOf(field.isHidden()));
 1245  
                     }
 1246  
             }
 1247  
 
 1248  0
         for( String attributeName : lookupFieldAttributeList )
 1249  
         {
 1250  0
             Field field = FieldUtils.getPropertyField(businessObjectClass, attributeName, true);
 1251  
 
 1252  0
             if(field.isDatePicker() && field.isRanged()) {
 1253  
 
 1254  0
                     Field newDate = createRangeDateField(field);
 1255  0
                     fields.add(newDate);
 1256  
             }
 1257  
 
 1258  
             BusinessObject newBusinessObjectInstance;
 1259  0
             if (ExternalizableBusinessObjectUtils.isExternalizableBusinessObjectInterface(businessObjectClass)) {
 1260  0
                     ModuleService moduleService = getKualiModuleService().getResponsibleModuleService(businessObjectClass);
 1261  0
                     newBusinessObjectInstance = (BusinessObject) moduleService.createNewObjectFromExternalizableClass(businessObjectClass);
 1262  0
             }
 1263  
             else {
 1264  0
                     newBusinessObjectInstance = (BusinessObject) businessObjectClass.newInstance();
 1265  
             }
 1266  
             //quickFinder is synonymous with a field-based Lookup
 1267  0
             field = LookupUtils.setFieldQuickfinder(newBusinessObjectInstance, attributeName, field, lookupFieldAttributeList);
 1268  0
             field = LookupUtils.setFieldDirectInquiry(newBusinessObjectInstance, attributeName, field);
 1269  
 
 1270  
             // overwrite maxLength to allow for wildcards and ranges in the select, but only if it's not a mulitselect box, because maxLength determines the # of entries
 1271  0
             if (!Field.MULTISELECT.equals(field.getFieldType())) {
 1272  0
                     field.setMaxLength(100);
 1273  
             }
 1274  
 
 1275  
             // if the attrib name is "active", and BO is Inactivatable, then set the default value to Y
 1276  0
             if (attributeName.equals(KRADPropertyConstants.ACTIVE) && MutableInactivatable.class.isAssignableFrom(businessObjectClass)) {
 1277  0
                     field.setPropertyValue(KRADConstants.YES_INDICATOR_VALUE);
 1278  0
                     field.setDefaultValue(KRADConstants.YES_INDICATOR_VALUE);
 1279  
             }
 1280  
             // set default value
 1281  0
             String defaultValue = getBusinessObjectMetaDataService().getLookupFieldDefaultValue(businessObjectClass, attributeName);
 1282  0
             if (defaultValue != null) {
 1283  0
                 field.setPropertyValue(defaultValue);
 1284  0
                 field.setDefaultValue(defaultValue);
 1285  
             }
 1286  
 
 1287  0
             Class defaultValueFinderClass = getBusinessObjectMetaDataService().getLookupFieldDefaultValueFinderClass(businessObjectClass, attributeName);
 1288  
             //getBusinessObjectMetaDataService().getLookupFieldDefaultValue(dataObjectClass, attributeName)
 1289  0
             if (defaultValueFinderClass != null) {
 1290  0
                 field.setPropertyValue(((ValueFinder) defaultValueFinderClass.newInstance()).getValue());
 1291  0
                 field.setDefaultValue(((ValueFinder) defaultValueFinderClass.newInstance()).getValue());
 1292  
             }
 1293  0
             if ( (readOnlyFieldsList != null && readOnlyFieldsList.contains(field.getPropertyName()))
 1294  
                             || ( isReadOnlyMap.containsKey(field.getPropertyName()) && isReadOnlyMap.get(field.getPropertyName()).booleanValue())
 1295  
                     ) {
 1296  0
                 field.setReadOnly(true);
 1297  
             }
 1298  
 
 1299  0
             populateQuickfinderDefaultsForLookup(businessObjectClass, attributeName, field);
 1300  
 
 1301  0
                         if ((isHiddenMap.containsKey(field.getPropertyName()) && isHiddenMap.get(field.getPropertyName()).booleanValue())) {
 1302  0
                                 field.setFieldType(Field.HIDDEN);
 1303  
                         }
 1304  
             
 1305  0
             boolean triggerOnChange = getBusinessObjectDictionaryService().isLookupFieldTriggerOnChange(businessObjectClass, attributeName);
 1306  0
             field.setTriggerOnChange(triggerOnChange);
 1307  
 
 1308  0
             field.setFieldLevelHelpEnabled(isLookupFieldLevelHelpEnabled(businessObjectClass, attributeName));
 1309  0
             field.setFieldLevelHelpDisabled(isLookupFieldLevelHelpDisabled(businessObjectClass, attributeName));
 1310  
             
 1311  0
             fields.add(field);
 1312  0
         }
 1313  0
         return fields;
 1314  
     }
 1315  
 
 1316  
 
 1317  
         /**
 1318  
          * This method ...
 1319  
          *
 1320  
          * @param businessObjectClass
 1321  
          * @param attributeName
 1322  
          * @param field
 1323  
          * @throws InstantiationException
 1324  
          * @throws IllegalAccessException
 1325  
          */
 1326  
         private static void populateQuickfinderDefaultsForLookup(
 1327  
                         Class businessObjectClass, String attributeName, Field field)
 1328  
                         throws InstantiationException, IllegalAccessException {
 1329  
                 // handle quickfinderParameterString / quickfinderParameterFinderClass
 1330  0
                 String quickfinderParamString = getBusinessObjectMetaDataService().getLookupFieldQuickfinderParameterString(businessObjectClass, attributeName);
 1331  0
                 Class<? extends ValueFinder> quickfinderParameterFinderClass =
 1332  
                         getBusinessObjectMetaDataService().getLookupFieldQuickfinderParameterStringBuilderClass(businessObjectClass, attributeName);
 1333  0
                 if (quickfinderParameterFinderClass != null) {
 1334  0
                         quickfinderParamString = quickfinderParameterFinderClass.newInstance().getValue();
 1335  
                 }
 1336  
 
 1337  0
                 if (!StringUtils.isEmpty(quickfinderParamString)) {
 1338  0
                         String [] params = quickfinderParamString.split(",");
 1339  0
                         if (params != null) for (String param : params) {
 1340  0
                                 if (param.contains(KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER)) {
 1341  0
                                         String[] paramChunks = param.split(KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER, 2);
 1342  0
                                         field.appendLookupParameters(
 1343  
                                                         KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX+KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER+
 1344  
                                                         paramChunks[1]+":"+paramChunks[0]);
 1345  
                                 }
 1346  
                         }
 1347  
                 }
 1348  0
         }
 1349  
 
 1350  
 
 1351  
         /**
 1352  
          * creates an extra field for date from/to ranges
 1353  
          * @param field
 1354  
          * @return a new date field
 1355  
          */
 1356  
         public static Field createRangeDateField(Field field) {
 1357  0
                 Field newDate = (Field)ObjectUtils.deepCopy(field);
 1358  0
                 newDate.setFieldLabel(newDate.getFieldLabel()+" "+KRADConstants.LOOKUP_DEFAULT_RANGE_SEARCH_LOWER_BOUND_LABEL);
 1359  0
                 field.setFieldLabel(field.getFieldLabel()+" "+KRADConstants.LOOKUP_DEFAULT_RANGE_SEARCH_UPPER_BOUND_LABEL);
 1360  0
                 newDate.setPropertyName(KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX+newDate.getPropertyName());
 1361  0
                 return newDate;
 1362  
         }
 1363  
 
 1364  
     private static Field meshContainerFields(Field oldMaintField, Field newMaintField, List keyFieldNames, String maintenanceAction, boolean readOnly, MaintenanceDocumentRestrictions auths, String documentStatus, String documentInitiatorPrincipalId) {
 1365  0
         List resultingRows = new ArrayList();
 1366  0
         resultingRows.addAll(meshRows(oldMaintField.getContainerRows(), newMaintField.getContainerRows(), keyFieldNames, maintenanceAction, readOnly, auths, documentStatus, documentInitiatorPrincipalId));
 1367  0
         Field resultingField = newMaintField;
 1368  0
         resultingField.setFieldType(Field.CONTAINER);
 1369  
 
 1370  
         // save the summary info
 1371  0
         resultingField.setContainerElementName(newMaintField.getContainerElementName());
 1372  0
         resultingField.setContainerDisplayFields(newMaintField.getContainerDisplayFields());
 1373  0
         resultingField.setNumberOfColumnsForCollection(newMaintField.getNumberOfColumnsForCollection());
 1374  
 
 1375  0
         resultingField.setContainerRows(resultingRows);
 1376  0
         List resultingRowsList = newMaintField.getContainerRows();
 1377  0
         if (resultingRowsList.size() > 0) {
 1378  0
             List resultingFieldsList = ((Row) resultingRowsList.get(0)).getFields();
 1379  0
             if (resultingFieldsList.size() > 0) {
 1380  
                 // todo: assign the correct propertyName to the container in the first place. For now, I'm wary of the weird usages
 1381  
                 // of constructContainerField().
 1382  0
                 String containedFieldName = ((Field) (resultingFieldsList.get(0))).getPropertyName();
 1383  0
                 resultingField.setPropertyName(containedFieldName.substring(0, containedFieldName.lastIndexOf('.')));
 1384  
             }
 1385  0
         }
 1386  
         else {
 1387  0
             resultingField.setPropertyName(oldMaintField.getPropertyName());
 1388  
         }
 1389  0
         return resultingField;
 1390  
     }
 1391  
 
 1392  
     /**
 1393  
      * This method modifies the passed in field so that it may be used to render a multiple values lookup button
 1394  
      *
 1395  
      * @param field this object will be modified by this method
 1396  
      * @param parents
 1397  
      * @param definition
 1398  
      */
 1399  
     static final public void modifyFieldToSupportMultipleValueLookups(Field field, String parents, MaintainableCollectionDefinition definition) {
 1400  0
         field.setMultipleValueLookedUpCollectionName(parents + definition.getName());
 1401  0
         field.setMultipleValueLookupClassName(definition.getSourceClassName().getName());
 1402  0
         field.setMultipleValueLookupClassLabel(getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(definition.getSourceClassName().getName()).getObjectLabel());
 1403  0
     }
 1404  
 
 1405  
     /**
 1406  
      * Returns whether the passed in collection has been properly configured in the maint doc dictionary to support multiple value
 1407  
      * lookups.
 1408  
      *
 1409  
      * @param definition
 1410  
      * @return
 1411  
      */
 1412  
     static final public boolean isCollectionMultipleLookupEnabled(MaintainableCollectionDefinition definition) {
 1413  0
         return definition.getSourceClassName() != null && definition.isIncludeMultipleLookupLine();
 1414  
     }
 1415  
 
 1416  
     /**
 1417  
      * This method removes any duplicating spacing (internal or on the ends) from a String, meant to be exposed as a tag library
 1418  
      * function.
 1419  
      *
 1420  
      * @param s String to remove duplicate spacing from.
 1421  
      * @return String without duplicate spacing.
 1422  
      */
 1423  
     public static String scrubWhitespace(String s) {
 1424  0
         return s.replaceAll("(\\s)(\\s+)", " ");
 1425  
     }
 1426  
 
 1427  
     private static DataDictionaryService getDataDictionaryService() {
 1428  0
             if (dataDictionaryService == null) {
 1429  0
                     dataDictionaryService = KRADServiceLocatorWeb.getDataDictionaryService();
 1430  
             }
 1431  0
             return dataDictionaryService;
 1432  
     }
 1433  
 
 1434  
     private static BusinessObjectMetaDataService getBusinessObjectMetaDataService() {
 1435  0
             if (businessObjectMetaDataService == null) {
 1436  0
                     businessObjectMetaDataService = KNSServiceLocator.getBusinessObjectMetaDataService();
 1437  
             }
 1438  0
             return businessObjectMetaDataService;
 1439  
     }
 1440  
 
 1441  
     private static BusinessObjectDictionaryService getBusinessObjectDictionaryService() {
 1442  0
             if (businessObjectDictionaryService == null) {
 1443  0
                     businessObjectDictionaryService = KRADServiceLocatorWeb.getBusinessObjectDictionaryService();
 1444  
             }
 1445  0
             return businessObjectDictionaryService;
 1446  
     }
 1447  
 
 1448  
     private static KualiModuleService getKualiModuleService() {
 1449  0
             if (kualiModuleService == null) {
 1450  0
                     kualiModuleService = KRADServiceLocatorWeb.getKualiModuleService();
 1451  
             }
 1452  0
             return kualiModuleService;
 1453  
     }
 1454  
 }