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