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