Coverage Report - org.kuali.rice.kns.datadictionary.FieldDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
FieldDefinition
0%
0/128
0%
0/42
1.74
 
 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  
 
 17  
 package org.kuali.rice.kns.datadictionary;
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException;
 21  
 import org.kuali.rice.kns.datadictionary.exception.ClassValidationException;
 22  
 import org.kuali.rice.kns.datadictionary.mask.Mask;
 23  
 import org.kuali.rice.kns.lookup.valuefinder.ValueFinder;
 24  
 import org.kuali.rice.kns.service.BusinessObjectMetaDataService;
 25  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 26  
 import org.kuali.rice.kns.service.KNSServiceLocatorWeb;
 27  
 
 28  
 /**
 29  
  * Contains field-related information for DataDictionary entries.  Used by lookups and inquiries.
 30  
  *
 31  
  * Note: the setters do copious amounts of validation, to facilitate generating errors during the parsing process.
 32  
  */
 33  
 public class FieldDefinition extends DataDictionaryDefinitionBase implements FieldDefinitionI {
 34  
     private static final long serialVersionUID = -3426603523049661524L;
 35  
     
 36  
         protected String attributeName;
 37  0
     protected boolean required = false;
 38  0
     protected boolean forceInquiry = false;
 39  0
     protected boolean noInquiry = false;
 40  0
     protected boolean noDirectInquiry = false;
 41  0
     protected boolean forceLookup = false;
 42  0
     protected boolean noLookup = false;
 43  0
     protected boolean useShortLabel = false;
 44  
     protected String defaultValue;
 45  
     protected Class<? extends ValueFinder> defaultValueFinderClass;
 46  
     protected String quickfinderParameterString;
 47  
     protected Class<? extends ValueFinder> quickfinderParameterStringBuilderClass;
 48  
 
 49  0
     protected Integer maxLength = null;
 50  
 
 51  
     protected String displayEditMode;
 52  
     protected Mask displayMask;
 53  
 
 54  0
         protected boolean hidden         = false;
 55  0
         protected boolean readOnly         = false;
 56  
 
 57  0
         protected boolean treatWildcardsAndOperatorsAsLiteral = false;
 58  
         
 59  
     protected String alternateDisplayAttributeName;
 60  
     protected String additionalDisplayAttributeName;
 61  
         
 62  
         protected boolean triggerOnChange;
 63  0
         protected boolean total = false;
 64  
         
 65  0
     public FieldDefinition() {
 66  0
     }
 67  
 
 68  
 
 69  
     /**
 70  
      * @return attributeName
 71  
      */
 72  
     public String getAttributeName() {
 73  0
         return attributeName;
 74  
     }
 75  
 
 76  
     /**
 77  
      * Sets attributeName to the given value.
 78  
      *
 79  
      * @param attributeName
 80  
      * @throws IllegalArgumentException if the given attributeName is blank
 81  
      */
 82  
     public void setAttributeName(String attributeName) {
 83  0
         if (StringUtils.isBlank(attributeName)) {
 84  0
             throw new IllegalArgumentException("invalid (blank) attributeName");
 85  
         }
 86  0
         this.attributeName = attributeName;
 87  0
     }
 88  
 
 89  
 
 90  
     /**
 91  
      * @return true if this attribute is required
 92  
      */
 93  
     public boolean isRequired() {
 94  0
         return required;
 95  
     }
 96  
 
 97  
 
 98  
     /**
 99  
                     required = true means that the user must enter something
 100  
                         into the search criterion lookup field
 101  
      */
 102  
     public void setRequired(boolean required) {
 103  0
         this.required = required;
 104  0
     }
 105  
 
 106  
 
 107  
     /**
 108  
      * @return Returns the forceInquiry.
 109  
      */
 110  
     public boolean isForceInquiry() {
 111  0
         return forceInquiry;
 112  
     }
 113  
 
 114  
 
 115  
     /**
 116  
      * forceInquiry = true means that the displayed field value will
 117  
                     always be made inquirable (this attribute is not used within the code).
 118  
      */
 119  
     public void setForceInquiry(boolean forceInquiry) {
 120  0
         this.forceInquiry = forceInquiry;
 121  0
     }
 122  
 
 123  
     /**
 124  
      * @return Returns the forceLookup.
 125  
      */
 126  
     public boolean isForceLookup() {
 127  0
         return forceLookup;
 128  
     }
 129  
 
 130  
     /**
 131  
      * forceLookup = this attribute is not used
 132  
      */
 133  
     public void setForceLookup(boolean forceLookup) {
 134  0
         this.forceLookup = forceLookup;
 135  0
     }
 136  
 
 137  
     /**
 138  
      * @return Returns the noInquiry.
 139  
      */
 140  
     public boolean isNoInquiry() {
 141  0
         return noInquiry;
 142  
     }
 143  
 
 144  
     /**
 145  
      * @return Returns a boolean value indicating whether or not to provide
 146  
      *          a direct inquiry for the lookup field
 147  
      */
 148  
     public boolean isNoDirectInquiry()
 149  
     {
 150  0
         return noDirectInquiry;
 151  
     }
 152  
 
 153  
     /**
 154  
      * noInquiry = true means that the displayed field will never be made inquirable.
 155  
      */
 156  
     public void setNoInquiry(boolean noInquiry) {
 157  0
         this.noInquiry = noInquiry;
 158  0
     }
 159  
 
 160  
     /**
 161  
      * @param noInquiry If true, the displayed field will not have a direct
 162  
          *     inquiry facility
 163  
      */
 164  
     public void setNoDirectInquiry(boolean noDirectInquiry) {
 165  0
         this.noDirectInquiry = noDirectInquiry;
 166  0
     }
 167  
 
 168  
     /**
 169  
      * @return Returns the noLookup.
 170  
      */
 171  
     public boolean isNoLookup() {
 172  0
         return noLookup;
 173  
     }
 174  
 
 175  
     /**
 176  
      * noLookup = true means that field should not include magnifying glass (i.e. quickfinder)
 177  
      */
 178  
     public void setNoLookup(boolean noLookup) {
 179  0
         this.noLookup = noLookup;
 180  0
     }
 181  
 
 182  
 
 183  
     /**
 184  
          * @return the useShortLabel
 185  
          */
 186  
         public boolean isUseShortLabel() {
 187  0
                 return this.useShortLabel;
 188  
         }
 189  
 
 190  
 
 191  
         /**
 192  
          * @param useShortLabel the useShortLabel to set
 193  
          */
 194  
         public void setUseShortLabel(boolean useShortLabel) {
 195  0
                 this.useShortLabel = useShortLabel;
 196  0
         }
 197  
 
 198  
 
 199  
         /**
 200  
      * @return Returns the defaultValue.
 201  
      */
 202  
     public String getDefaultValue() {
 203  0
         return defaultValue;
 204  
     }
 205  
 
 206  
 
 207  
     /**
 208  
            The defaultValue element will pre-load the specified value
 209  
            into the field.
 210  
      */
 211  
     public void setDefaultValue(String defaultValue) {
 212  0
         this.defaultValue = defaultValue;
 213  0
     }
 214  
 
 215  
     /**
 216  
          * the quickfinderParameterString is a comma separated list of parameter/value pairs, of the format
 217  
          * "param1=value1,param2=value2", where the parameters correspond to attributes of the target class
 218  
          * for the quickfinder, and the values to literals that those attributes will default to when the
 219  
          * quickfinder is used.
 220  
          * @return the quickfinderParameterString
 221  
          */
 222  
         public String getQuickfinderParameterString() {
 223  0
                 return this.quickfinderParameterString;
 224  
         }
 225  
 
 226  
         /**
 227  
          * @param quickfinderParameterString the quickfinderParameterString to set.  See {@link #getQuickfinderParameterString()}
 228  
          */
 229  
         public void setQuickfinderParameterString(String quickfinderParameterString) {
 230  0
                 this.quickfinderParameterString = quickfinderParameterString;
 231  0
         }
 232  
 
 233  
 
 234  
     /**
 235  
      * the quickfinderParameterStringBuilderClass specifies the java class that will be used
 236  
      * to determine the default value(s) for field(s) on the target lookup when the quickfinder
 237  
      * is used. The classname specified in this field must implement
 238  
      * {@link org.kuali.rice.kns.lookup.valuefinder.ValueFinder}.  See {@link #getQuickfinderParameterString()}
 239  
      * for the result string format.
 240  
          * @return the quickfinderParameterStringBuilderClass
 241  
          */
 242  
         public Class<? extends ValueFinder> getQuickfinderParameterStringBuilderClass() {
 243  0
                 return this.quickfinderParameterStringBuilderClass;
 244  
         }
 245  
 
 246  
     /**
 247  
      * See {@link #getQuickfinderParameterStringBuilderClass()}
 248  
          * @param quickfinderParameterStringBuilderClass the quickfinderParameterStringBuilderClass to set
 249  
      */
 250  
         public void setQuickfinderParameterStringBuilderClass(
 251  
                         Class<? extends ValueFinder> quickfinderParameterStringBuilderClass) {
 252  0
         if (quickfinderParameterStringBuilderClass == null) {
 253  0
             throw new IllegalArgumentException("invalid (null) quickfinderParameterStringBuilderClass");
 254  
         }
 255  0
                 this.quickfinderParameterStringBuilderClass = quickfinderParameterStringBuilderClass;
 256  0
     }
 257  
 
 258  
     /**
 259  
      * Directly validate simple fields.
 260  
      *
 261  
      * @see org.kuali.rice.kns.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
 262  
      */
 263  
     public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
 264  0
             BusinessObjectMetaDataService boMetadataService = KNSServiceLocatorWeb.getBusinessObjectMetaDataService();
 265  
 
 266  0
         if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getAttributeName())) {
 267  0
             throw new AttributeValidationException("unable to find attribute '" + attributeName + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
 268  
         }
 269  
 
 270  0
         if (StringUtils.isNotBlank(getAlternateDisplayAttributeName())) {
 271  0
             if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getAlternateDisplayAttributeName())) {
 272  0
                 throw new AttributeValidationException("unable to find attribute named '" + getName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
 273  
             }
 274  
         }
 275  
         
 276  0
         if (StringUtils.isNotBlank(getAdditionalDisplayAttributeName())) {
 277  0
             if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getAdditionalDisplayAttributeName())) {
 278  0
                 throw new AttributeValidationException("unable to find attribute named '" + getName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
 279  
             }
 280  
         }
 281  
 
 282  0
         if (defaultValueFinderClass != null && defaultValue != null) {
 283  0
             throw new AttributeValidationException("Both defaultValue and defaultValueFinderClass can not be specified on attribute " + getAttributeName() + " in rootBusinessObjectClass " + rootBusinessObjectClass.getName());
 284  
         }
 285  
 
 286  0
         validateQuickfinderParameters(rootBusinessObjectClass, boMetadataService);
 287  
 
 288  0
         if (forceInquiry == true && noInquiry == true) {
 289  0
             throw new AttributeValidationException("Both forceInquiry and noInquiry can not be set to true on attribute " + getAttributeName() + " in rootBusinessObjectClass " + rootBusinessObjectClass.getName());
 290  
         }
 291  0
         if (forceLookup == true && noLookup == true) {
 292  0
             throw new AttributeValidationException("Both forceLookup and noLookup can not be set to true on attribute " + getAttributeName() + " in rootBusinessObjectClass " + rootBusinessObjectClass.getName());
 293  
         }
 294  0
     }
 295  
 
 296  
 
 297  
     /**
 298  
          * This method does validation on the quickfinderParameterString and quickfinderParameterStringBuilderClass members
 299  
          *
 300  
          * @param rootBusinessObjectClass
 301  
          * @param boMetadataService
 302  
          */
 303  
         private void validateQuickfinderParameters(Class rootBusinessObjectClass,
 304  
                         BusinessObjectMetaDataService boMetadataService) {
 305  0
                 if (quickfinderParameterStringBuilderClass != null && quickfinderParameterString != null) {
 306  0
             throw new AttributeValidationException("Both quickfinderParameterString and quickfinderParameterStringBuilderClass can not be specified on attribute " + getAttributeName() + " in rootBusinessObjectClass " + rootBusinessObjectClass.getName());
 307  
         }
 308  
 
 309  
         // String used for building exception messages
 310  0
         String quickfinderParameterStringSource = "quickfinderParameterString";
 311  
 
 312  0
         if (quickfinderParameterStringBuilderClass != null) {
 313  
                 try {
 314  0
                         quickfinderParameterStringSource = "quickfinderParameterStringBuilderClass " + quickfinderParameterStringBuilderClass.getCanonicalName();
 315  0
                                 quickfinderParameterString = quickfinderParameterStringBuilderClass.newInstance().getValue();
 316  0
                         } catch (InstantiationException e) {
 317  0
                                 throw new ClassValidationException("unable to create new instance of "+  quickfinderParameterStringSource +" while validating rootBusinessObjectClass '"+ rootBusinessObjectClass.getName() +"'", e);
 318  0
                         } catch (IllegalAccessException e) {
 319  0
                                 throw new ClassValidationException("unable to create new instance of "+  quickfinderParameterStringSource +" while validating rootBusinessObjectClass '"+ rootBusinessObjectClass.getName() +"'", e);
 320  0
                         }
 321  
         }
 322  
 
 323  0
         if (!StringUtils.isEmpty(quickfinderParameterString)) {
 324  
                 // quickfinderParameterString will look something like "campusTypeCode=P,active=Y"
 325  0
                 for (String quickfinderParam : quickfinderParameterString.split(",")) { // this is guaranteed to return at least one
 326  0
                         if (quickfinderParam.contains("=")) {
 327  0
                                 String propertyName = quickfinderParam.split("=")[0];
 328  0
                                 RelationshipDefinition relationship = boMetadataService.getBusinessObjectRelationshipDefinition(rootBusinessObjectClass, attributeName);
 329  0
                                 Class targetClass = relationship.getTargetClass();
 330  
 
 331  
                                 // This is insufficient to ensure the property is valid for a lookup default, but it's better than nothing.
 332  0
                             if (!DataDictionary.isPropertyOf(targetClass, propertyName)) {
 333  0
                                     throw new ClassValidationException("malformed parameter string  '"+ quickfinderParameterString +"' from "+ quickfinderParameterStringSource +
 334  
                                                     ", '"+ propertyName +"' is not a property of "+ targetClass +"' for rootBusinessObjectClass '"+ rootBusinessObjectClass.getName() +"'");
 335  
                             }
 336  
 
 337  0
                         } else {
 338  0
                                 throw new ClassValidationException("malformed parameter string '"+ quickfinderParameterString +"' from "+ quickfinderParameterStringSource +
 339  
                                                 " for rootBusinessObjectClass '"+ rootBusinessObjectClass.getName() +"'");
 340  
                         }
 341  
                 }
 342  
         }
 343  0
         }
 344  
 
 345  
 
 346  
     /**
 347  
      * @see java.lang.Object#toString()
 348  
      */
 349  
     public String toString() {
 350  0
         return "FieldDefinition for attribute " + getAttributeName();
 351  
     }
 352  
 
 353  
 
 354  
     public String getName() {
 355  0
         return attributeName;
 356  
     }
 357  
 
 358  
 
 359  
     public String getDisplayEditMode() {
 360  0
         return displayEditMode;
 361  
     }
 362  
 
 363  
 
 364  
     /*
 365  
                         The document authorizer classes have a method getEditMode, which is a map of edit mode to
 366  
                         value mappings.  Depending on the context, the value of the mapping may be relevant, and the logic determining
 367  
                         whether the value is relevant is often implemented in the JSP/tag layer.
 368  
 
 369  
                         Fields on a document (particularily maintenance documents) may be associated with
 370  
                         an edit mode.  If the edit mode is mapped to a relevant value, then the all fields associated with the edit mode
 371  
                         will be rendered unhidden.
 372  
 
 373  
                         The displayEditMode element is used to specify the edit mode that will be associated with the field.
 374  
                         If the document authorizer returns a map with this edit mode mapped to a proper value, then the field will be unhidden to the user.
 375  
      */
 376  
     public void setDisplayEditMode(String displayEditMode) {
 377  0
         this.displayEditMode = displayEditMode;
 378  0
     }
 379  
 
 380  
 
 381  
     public Mask getDisplayMask() {
 382  0
         return displayMask;
 383  
     }
 384  
 
 385  
     /**
 386  
      * The displayMask element specifies the type of masking to
 387  
                     be used to hide the value from un-authorized users.
 388  
                     There are three types of masking.
 389  
      */
 390  
     public void setDisplayMask(Mask displayMask) {
 391  0
         this.displayMask = displayMask;
 392  0
     }
 393  
 
 394  
 
 395  
 
 396  
     public boolean isReadOnlyAfterAdd() {
 397  0
         return false;
 398  
     }
 399  
 
 400  
 
 401  
     /**
 402  
      * Gets the maxLength attribute.
 403  
      * @return Returns the maxLength.
 404  
      */
 405  
     public Integer getMaxLength() {
 406  0
         return maxLength;
 407  
     }
 408  
 
 409  
 
 410  
     /**
 411  
      * maxLength = the maximum allowable length of the field in the lookup result fields.  In other contexts,
 412  
                     like inquiries, this field has no effect.
 413  
      */
 414  
     public void setMaxLength(Integer maxLength) {
 415  0
         this.maxLength = maxLength;
 416  0
     }
 417  
 
 418  
     /**
 419  
      * @return custom defaultValue class
 420  
      */
 421  
     public Class<? extends ValueFinder> getDefaultValueFinderClass() {
 422  0
         return this.defaultValueFinderClass;
 423  
     }
 424  
 
 425  
     /**
 426  
                       The defaultValueFinderClass specifies the java class that will be
 427  
                       used to determine the default value of a field.  The classname
 428  
                       specified in this field must implement org.kuali.rice.kns.lookup.valuefinder.ValueFinder
 429  
      */
 430  
     public void setDefaultValueFinderClass(Class<? extends ValueFinder> defaultValueFinderClass) {
 431  0
         if (defaultValueFinderClass == null) {
 432  0
             throw new IllegalArgumentException("invalid (null) defaultValueFinderClass");
 433  
         }
 434  0
         this.defaultValueFinderClass = defaultValueFinderClass;
 435  0
     }
 436  
     
 437  
         /**
 438  
          * @return the hidden
 439  
          */
 440  
         public boolean isHidden() {
 441  0
                 return this.hidden;
 442  
         }
 443  
 
 444  
         /**
 445  
          * @param hidden
 446  
      *  If the ControlDefinition.isHidden == true then a corresponding LookupDefinition would
 447  
      *  automatically be removed from the search criteria.  In some cases you might want the
 448  
      *  hidden field to be used as a search criteria.  For example, in PersonImpl.xml a client
 449  
      *  might want to have the campus code hidden and preset to Bloomington.  So when the search
 450  
      *  is run, only people from the bloomington campus are returned.
 451  
      *
 452  
      *   So, if you want to have a hidden search criteria, set this variable to true. Defaults to
 453  
      *   false.
 454  
      */
 455  
         public void setHidden(boolean hidden) {
 456  0
                 this.hidden = hidden;
 457  0
         }
 458  
         
 459  
         /**
 460  
          * @return the readOnly
 461  
          */
 462  
         public boolean isReadOnly() {
 463  0
                 return this.readOnly;
 464  
         }
 465  
         
 466  
         /**
 467  
          * @param readOnly the readOnly to set
 468  
          */
 469  
         public void setReadOnly(boolean readOnly) {
 470  0
                 this.readOnly = readOnly;
 471  0
         }
 472  
         
 473  
         public boolean isTriggerOnChange() {
 474  0
                 return this.triggerOnChange;
 475  
         }
 476  
 
 477  
         public void setTriggerOnChange(boolean triggerOnChange) {
 478  0
                 this.triggerOnChange = triggerOnChange;
 479  0
         }
 480  
 
 481  
         /**
 482  
          * @return the treatWildcardsAndOperatorsAsLiteralOnLookups
 483  
          */
 484  
         public boolean isTreatWildcardsAndOperatorsAsLiteral() {
 485  0
                 return this.treatWildcardsAndOperatorsAsLiteral;
 486  
         }
 487  
 
 488  
 
 489  
         /**
 490  
          * @param treatWildcardsAndOperatorsAsLiteralOnLookups the treatWildcardsAndOperatorsAsLiteralOnLookups to set
 491  
          */
 492  
         public void setTreatWildcardsAndOperatorsAsLiteral(
 493  
                         boolean treatWildcardsAndOperatorsAsLiteralOnLookups) {
 494  0
                 this.treatWildcardsAndOperatorsAsLiteral = treatWildcardsAndOperatorsAsLiteralOnLookups;
 495  0
         }
 496  
 
 497  
 
 498  
         public String getAlternateDisplayAttributeName() {
 499  0
                 return this.alternateDisplayAttributeName;
 500  
         }
 501  
 
 502  
 
 503  
         public void setAlternateDisplayAttributeName(String alternateDisplayAttributeName) {
 504  0
                 this.alternateDisplayAttributeName = alternateDisplayAttributeName;
 505  0
         }
 506  
 
 507  
 
 508  
         public String getAdditionalDisplayAttributeName() {
 509  0
                 return this.additionalDisplayAttributeName;
 510  
         }
 511  
 
 512  
 
 513  
         public void setAdditionalDisplayAttributeName(String additionalDisplayAttributeName) {
 514  0
                 this.additionalDisplayAttributeName = additionalDisplayAttributeName;
 515  0
         }
 516  
 
 517  
 
 518  
         public boolean isTotal() {
 519  0
                 return this.total;
 520  
         }
 521  
 
 522  
 
 523  
         public void setTotal(boolean total) {
 524  0
                 this.total = total;
 525  0
         }
 526  
         
 527  
 }