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