Coverage Report - org.kuali.rice.kns.service.DictionaryValidationService
 
Classes in this File Line Coverage Branch Coverage Complexity
DictionaryValidationService
N/A
N/A
1
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kns.service;
 17  
 
 18  
 import java.beans.PropertyDescriptor;
 19  
 
 20  
 import org.kuali.rice.kns.bo.BusinessObject;
 21  
 import org.kuali.rice.kns.datadictionary.DataDictionaryEntry;
 22  
 import org.kuali.rice.kns.datadictionary.ReferenceDefinition;
 23  
 import org.kuali.rice.kns.datadictionary.validation.result.DictionaryValidationResult;
 24  
 import org.kuali.rice.kns.document.Document;
 25  
 import org.kuali.rice.kns.document.TransactionalDocument;
 26  
 
 27  
 
 28  
 /**
 29  
  * Defines the API for the validating against the data dictionary.
 30  
  * 
 31  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 32  
  */
 33  
 public interface DictionaryValidationService {
 34  
 
 35  
     /**
 36  
      * Validates the contents of a document (i.e. attributes within a document) against the data dictionary.
 37  
      * 
 38  
      * @param document - document to validate
 39  
      */
 40  
     public void validateDocument(Document document);
 41  
 
 42  
     /**
 43  
      * Validates the contents of a document (i.e. attributes within a document) against the data dictionary. Recursively checks
 44  
      * business objects of the document.
 45  
      * 
 46  
      * @param document - document to validate
 47  
      * @param depth - Specify how deep the recrusion should go (0 based). If a negative number is supplied, it's infinite.
 48  
      * 
 49  
      * @deprecated Use {@link #validateDocumentAndUpdatableReferencesRecursively(Document, int, boolean)}
 50  
      */
 51  
     @Deprecated
 52  
     public void validateDocumentRecursively(Document document, int depth);
 53  
 
 54  
     /**
 55  
      * Validates the contents of a document and recursively validates any of its updatable references
 56  
      * 
 57  
      * @param document the document
 58  
      * @param maxDepth the maximum numbers of levels to recurse
 59  
      * @param validateRequired whether to validate whether a field is required and is currently blank
 60  
      */
 61  
     public void validateDocumentAndUpdatableReferencesRecursively(Document document, int maxDepth, boolean validateRequired);
 62  
     
 63  
     /**
 64  
      * Validates the contents of a document and recursively validates any of its updatable references
 65  
      * 
 66  
      * @param document the document
 67  
      * @param maxDepth the maximum numbers of levels to recurse
 68  
      * @param validateRequired whether to validate whether a field is required and is currently blank
 69  
      * @param chompLastLetterSFromCollectionName if true, the error path for any collections encountered will have the last "s" removed from the collection name if it ends
 70  
      * with the letter "s".  If false, this method acts like {@link #validateDocumentAndUpdatableReferencesRecursively(Document, int, boolean)}
 71  
      */
 72  
     public void validateDocumentAndUpdatableReferencesRecursively(Document document, int maxDepth, boolean validateRequired, boolean chompLastLetterSFromCollectionName);
 73  
 
 74  
     /**
 75  
      * Validates the specified attribute of the given document against the data dictionary.
 76  
      * 
 77  
      * @param document
 78  
      * @param attributeName
 79  
      * @param errorPrefix
 80  
      */
 81  
     public void validateDocumentAttribute(Document document, String attributeName, String errorPrefix);
 82  
 
 83  
 
 84  
     /**
 85  
      * Validates the business object primitive attributes against the data dictionary. Adds errors to the map as they are
 86  
      * encountered.
 87  
      * 
 88  
      * @param businessObject - business object to validate
 89  
      * @deprecated since 1.1 - use validate(Object.class) instead
 90  
      */
 91  
     @Deprecated 
 92  
     public void validateBusinessObject(BusinessObject businessObject);
 93  
 
 94  
     /**
 95  
      * Validates the business object primitive attributes against the data dictionary. Adds errors to the map as they are
 96  
      * encountered.
 97  
      * 
 98  
      * @param businessObject - business object to validate
 99  
      * @param validateRequired - whether to execute required field checks
 100  
      * @deprecated since 1.1 - use validate(Object.class) instead
 101  
      */
 102  
     @Deprecated 
 103  
     public void validateBusinessObject(BusinessObject businessObject, boolean validateRequired);
 104  
     
 105  
     @Deprecated
 106  
     public void validateBusinessObjectOnMaintenanceDocument(BusinessObject businessObject, String docTypeName);
 107  
     
 108  
     /**
 109  
      * Validates an object using its class name as the entry name to look up its metadata in the dictionary.
 110  
      * 
 111  
      * @param object - an object to validate
 112  
      * @return the dictionary validation result object associated with this validation
 113  
      */
 114  
     public DictionaryValidationResult validate(Object object);
 115  
     
 116  
     /**
 117  
      * Validates an object using its class name as the entry name to look up its metadata in the dictionary.
 118  
      * 
 119  
      * @param object - an object to validate
 120  
      * @param doOptionalProcessing true if the validation should do optional validation (e.g. to check if empty values are required or not), false otherwise
 121  
      * @return the dictionary validation result object associated with this validation
 122  
      */
 123  
     public DictionaryValidationResult validate(Object object, boolean doOptionalProcessing);
 124  
     
 125  
     /**
 126  
      * Validates an object using the passed entry name to look up metadata in the dictionary
 127  
      * 
 128  
      * @param object - an object to validate
 129  
      * @param entryName - the dictionary entry name to look up the metadata associated with this object
 130  
      * @return the dictionary validation result object associated with this validation
 131  
      * 
 132  
      * @since 1.1
 133  
      */
 134  
     public DictionaryValidationResult validate(Object object, String entryName);
 135  
     
 136  
     
 137  
     /**
 138  
      * Same as {@link #validate(java.lang.Object, java.lang.String)} except that it provides a boolean parameter for the 
 139  
      * calling method to choose whether to do optional processing (generally to check if blank/empty values are required or not).  
 140  
      * 
 141  
      * @param object - an object to validate
 142  
      * @param entryName - the dictionary entry name to look up the metadata associated with this object
 143  
      * @param doOptionalProcessing true if the validation should do optional validation (e.g. to check if empty values are required or not), false otherwise
 144  
      * @return the dictionary validation result object associated with this validation
 145  
      * 
 146  
      * @since 1.1
 147  
      */
 148  
     public DictionaryValidationResult validate(Object object, String entryName, boolean doOptionalProcessing);
 149  
     
 150  
     
 151  
     /**
 152  
      * Validates a single attribute on the passed object using the passed entry name to look up 
 153  
      * metadata in the dictionary. 
 154  
      * 
 155  
      * @param object - an object to validate
 156  
      * @param entryName - the dictionary entry name to look up the metadata associated with this object
 157  
      * @param attributeName - the name of the attribute (field) on the object that should be validated
 158  
      * @return the dictionary validation result object associated with this validation
 159  
      * 
 160  
      * @since 1.1
 161  
      */
 162  
     public DictionaryValidationResult validate(Object object, String entryName, String attributeName);
 163  
     
 164  
    
 165  
     /**
 166  
      * Same as {@link #validate(Object, String, String)} except that it provides a boolean parameter for the 
 167  
      * calling method to choose whether to do optional processing (generally to check if blank/empty values are required or not). 
 168  
      * 
 169  
      * @param object - an object to validate
 170  
      * @param entryName - the dictionary entry name to look up the metadata associated with this object
 171  
      * @param attributeName - the name of the attribute (field) on the object that should be validated
 172  
      * @param doOptionalProcessing true if the validation should do optional validation (e.g. to check if empty values are required or not), false otherwise
 173  
      * @return the dictionary validation result object associated with this validation
 174  
      * 
 175  
      * @since 1.1
 176  
      */
 177  
     public DictionaryValidationResult validate(Object object, String entryName, String attributeName, boolean doOptionalProcessing);
 178  
    
 179  
     
 180  
     /**
 181  
      * Same as {@link DictionaryValidationService#validate(Object, String, boolean) except that it provides an explicit data dictionary
 182  
      * entry to use for the purpose of validation. 
 183  
      * 
 184  
      * @param object - an object to validate
 185  
      * @param entryName - the dictionary entry name to use in association with error look ups
 186  
      * @param entry - the dictionary entry to use for validation 
 187  
      * @param doOptionalProcessing true if the validation should do optional validation (e.g. to check if empty values are required or not), false otherwise
 188  
      * @return the dictionary validation result object associated with this validation
 189  
      * 
 190  
      * @since 1.1
 191  
      */
 192  
     public DictionaryValidationResult validate(Object object, String entryName, DataDictionaryEntry entry, boolean doOptionalProcessing);
 193  
     
 194  
     
 195  
     /**
 196  
      * Instead of validating an object with dictionary metadata, or validating a specific member of an object by name, validates a 
 197  
      * specific attribute of an object by passing in the attribute value itself. This limits the amount of validation that can be done
 198  
      * to constraints that directly affect this attribute. 
 199  
      * 
 200  
      * @param entryName - the dictionary entry name to use in association with error look ups
 201  
      * @param attributeName - the dictionary entry attribute name to use in association with error look ups
 202  
      * @param attributeValue - the value of the attribute being validated
 203  
      */
 204  
     public void validate(String entryName, String attributeName, Object attributeValue);
 205  
     
 206  
     /**
 207  
      * Same as {@link #validate(String, String, Object)} except that it provides a boolean parameter for the 
 208  
      * calling method to choose whether to do optional processing (generally to check if blank/empty values are required or not). 
 209  
      * 
 210  
      * @param entryName - the dictionary entry name to use in association with error look ups
 211  
      * @param attributeName - the dictionary entry attribute name to use in association with error look ups
 212  
      * @param attributeValue - the value of the attribute being validated
 213  
      * @param doOptionalProcessing - true if the validation should do optional validation (e.g. to check if empty values are required or not), false otherwise
 214  
      */
 215  
     public void validate(String entryName, String attributeName, Object attributeValue, boolean doOptionalProcessing);
 216  
     
 217  
     /**
 218  
      * Encapsulates <code>{@link #validateBusinessObject(BusinessObject) and returns boolean so one doesn't need to check the 
 219  
      * ErrorMap.Validates the business object primitive attributes against the data dictionary. Adds errors to the map as they are
 220  
      * encountered.<br/>
 221  
      * <br/>
 222  
      * Makes no error path adjustments
 223  
      * 
 224  
      * @param businessObject - business object to validate
 225  
      * @return boolean validOrNot
 226  
      */
 227  
     public boolean isBusinessObjectValid(BusinessObject businessObject);
 228  
 
 229  
     /**
 230  
      * Encapsulates <code>{@link #validateBusinessObject(BusinessObject) and returns boolean so one doesn't need to check the 
 231  
      * ErrorMap.Validates the business object primitive attributes against the data dictionary. Adds errors to the map as they are
 232  
      * encountered.<br/>
 233  
      * <br/>
 234  
      * Makes no error path adjustments
 235  
      * 
 236  
      * @param businessObject - business object to validate
 237  
      * @param prefix - error prefix
 238  
      * @return boolean valid or not
 239  
      */
 240  
     public boolean isBusinessObjectValid(BusinessObject businessObject, String prefix);
 241  
 
 242  
     /**
 243  
      * Validates the business object against the dictionary, uses reflection to get any child business objects, and recursively
 244  
      * calls back. Adds errors to the map as they are encountered.
 245  
      * 
 246  
      * @param businessObject - business object to validate
 247  
      * @param depth - Specify how deep the recrusion should go (0 based). If a negative number is supplied, it's infinite.
 248  
      * @deprecated since 1.1
 249  
      */
 250  
     @Deprecated
 251  
     public void validateBusinessObjectsRecursively(BusinessObject businessObject, int depth);
 252  
 
 253  
     /**
 254  
      * Validates an attribute of a given class for proper min, max length, syntax, and required.
 255  
      * 
 256  
      * @param entryName - name of the dd entry
 257  
      * @param attributeName - name of attribute in the bo class
 258  
      * @param attributeValue - current value to validate
 259  
      * @param errorKey - key to place the errors under
 260  
      * @deprecated since 1.1
 261  
      */
 262  
     @Deprecated
 263  
     public void validateAttributeFormat(String entryName, String attributeName, String attributeValue, String errorKey);
 264  
 
 265  
     /**
 266  
      * Validates an attribute of a given class for proper min, max length, syntax, and required. The attribute will be validated
 267  
      * according to the specified data type.
 268  
      * 
 269  
      * @param entryName - name of the dd entry
 270  
      * @param attributeName - name of attribute in the bo class
 271  
      * @param attributeValue - current value to validate 
 272  
      * @param attributeDataType - data type that this attribute should be treated as for validation purposes
 273  
      * @param errorKey - key to place the errors under
 274  
      * @deprecated since 1.1
 275  
      */
 276  
     @Deprecated
 277  
     public void validateAttributeFormat(String entryName, String attributeName, String attributeValue, String attributeDataType, String errorKey);
 278  
 
 279  
     /**
 280  
      * Validates an attribute of a given class for required check.
 281  
      * 
 282  
      * @param entryName - name of the dd entry
 283  
      * @param attributeName - name of attribute in the bo class
 284  
      * @param attributeValue - current value to validate
 285  
      * @param errorKey - key to place to errors under
 286  
      * @deprecated since 1.1
 287  
      */
 288  
     @Deprecated
 289  
     public void validateAttributeRequired(String entryName, String attributeName, Object attributeValue, Boolean forMaintenance, String errorKey);
 290  
 
 291  
     /**
 292  
      * 
 293  
      * This method examines the populated BusinessObject bo instance passed in for a member named by the referenceName. If this
 294  
      * member exists, and if this member is a descendent of BusinessObject, then an existence check proceeds.
 295  
      * 
 296  
      * First the foreign keys for this reference are gathered, and then examined to see if they have values. If they do not have
 297  
      * values, the method ends with a true return value. If they all have values, then an object with those primary keys is retrieve
 298  
      * from the database. If one is retrieve, then the reference exists, and True is returned. Otherwise, false is returned.
 299  
      * 
 300  
      * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no
 301  
      * prefix, other than what has already been pushed onto the errorMap.
 302  
      * 
 303  
      * @param bo - The bo whose reference is being tested.
 304  
      * @param reference - The ReferenceDefinition to be existence tested.
 305  
      * @return True if no exceptions occur and the object exists in the db, false otherwise.
 306  
      * 
 307  
      */
 308  
     public boolean validateReferenceExists(BusinessObject bo, ReferenceDefinition reference);
 309  
 
 310  
     /**
 311  
      * 
 312  
      * This method examines the populated BusinessObject bo instance passed in for a member named by the referenceName. If this
 313  
      * member exists, and if this member is a descendent of BusinessObject, then an existence check proceeds.
 314  
      * 
 315  
      * First the foreign keys for this reference are gathered, and then examined to see if they have values. If they do not have
 316  
      * values, the method ends with a true return value. If they all have values, then an object with those primary keys is retrieve
 317  
      * from the database. If one is retrieve, then the reference exists, and True is returned. Otherwise, false is returned.
 318  
      * 
 319  
      * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no
 320  
      * prefix, other than what has already been pushed onto the errorMap.
 321  
      * 
 322  
      * @param bo - The bo whose reference is being tested.
 323  
      * @param referenceName - The name of the member to be existence tested.
 324  
      * @return True if no exceptions occur and the object exists in the db, false otherwise.
 325  
      * 
 326  
      */
 327  
     public boolean validateReferenceExists(BusinessObject bo, String referenceName);
 328  
 
 329  
     /**
 330  
      * 
 331  
      * This method retrieves the reference from the DB, and then tests whether the object is active.
 332  
      * 
 333  
      * It will return false if there is no activeIndicator field on this object, if the object doesnt exist in the DB, if the field
 334  
      * doesnt exist or cannot be cast as a boolean, if the field value is null, or if the field value is false.
 335  
      * 
 336  
      * It will only return true if the reference bo is present, the field is present, it is a boolean and non-null, and the value is
 337  
      * true.
 338  
      * 
 339  
      * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no
 340  
      * prefix, other than what has already been pushed onto the errorMap.
 341  
      * 
 342  
      * @param bo
 343  
      * @param reference
 344  
      * @return
 345  
      * 
 346  
      */
 347  
     public boolean validateReferenceIsActive(BusinessObject bo, ReferenceDefinition reference);
 348  
 
 349  
     /**
 350  
      * 
 351  
      * This method retrieves the reference from the DB, and then tests whether the object is active.
 352  
      * 
 353  
      * It will return false if there is no activeIndicator field on this object, if the object doesnt exist in the DB, if the field
 354  
      * doesnt exist or cannot be cast as a boolean, if the field value is null, or if the field value is false.
 355  
      * 
 356  
      * It will only return true if the reference bo is present, the field is present, it is a boolean and non-null, and the value is
 357  
      * true.
 358  
      * 
 359  
      * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no
 360  
      * prefix, other than what has already been pushed onto the errorMap.
 361  
      * 
 362  
      * @param bo
 363  
      * @param referenceName
 364  
      * @return
 365  
      * 
 366  
      */
 367  
     public boolean validateReferenceIsActive(BusinessObject bo, String referenceName);
 368  
 
 369  
     /**
 370  
      * 
 371  
      * This method intelligently tests the designated reference on the bo for both existence and active status, where appropriate.
 372  
      * 
 373  
      * It will not test anything if the foreign-key fields for the given reference arent filled out with values, and it will not
 374  
      * test active status if the reference doesnt exist.
 375  
      * 
 376  
      * Further, it will only test active status where the correct flag is set.
 377  
      * 
 378  
      * On failures of either sort, it will put the relevant errors into the GlobalVariables errorMap, and return a false. If there
 379  
      * are no failures, or nothing can be tested because the foreign-key fields arent fully filled out, it will return true and add
 380  
      * no errors.
 381  
      * 
 382  
      * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no
 383  
      * prefix, other than what has already been pushed onto the errorMap.
 384  
      * 
 385  
      * @param bo - the BusinessObject instance to be tested.
 386  
      * @param reference - the ReferenceDefinition to control the nature of the testing.
 387  
      * @return true or false as per the criteria above
 388  
      * 
 389  
      */
 390  
     public boolean validateReferenceExistsAndIsActive(BusinessObject bo, ReferenceDefinition reference);
 391  
 
 392  
     /**
 393  
      * 
 394  
      * This method intelligently tests the designated reference on the bo for both existence and active status, where appropriate.
 395  
      * 
 396  
      * It will not test anything if the foreign-key fields for the given reference arent filled out with values, and it will not
 397  
      * test active status if the reference doesnt exist.
 398  
      * 
 399  
      * Note that it will not fail or raise any error if all of the foreign-keys are filled with a value. If this needs to be tested
 400  
      * (ie, the 'if any field is filled, then all must be filled' rule), you'll have to do that separately.
 401  
      * 
 402  
      * Further, it will only test active status where the correct flag is set.
 403  
      * 
 404  
      * On failures of either sort, it will put the relevant errors into the GlobalVariables errorMap, and return a false. If there
 405  
      * are no failures, or nothing can be tested because the foreign-key fields arent fully filled out, it will return true and add
 406  
      * no errors.
 407  
      * 
 408  
      * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no
 409  
      * prefix, other than what has already been pushed onto the errorMap.
 410  
      * 
 411  
      * @param bo - the BusinessObject instance to be tested.
 412  
      * @param referenceName - the member name on the bo to be tested for existence and active-state
 413  
      * @param attributeToHighlightOnFail - the fieldName to highlight with the error message on a failure
 414  
      * @param displayFieldName - the human-readable display name of the failed field, to go in the error message
 415  
      * @return true or false as per the criteria above
 416  
      */
 417  
     public boolean validateReferenceExistsAndIsActive(BusinessObject bo, String referenceName, String attributeToHighlightOnFail, String displayFieldName);
 418  
 
 419  
     /**
 420  
      * 
 421  
      * This method does an existence check against all references of a BusinessObject as defined in the MaintenanceDocument.xml file
 422  
      * for that business object.
 423  
      * 
 424  
      * Appropriate errors will also be placed in the GlobalVariables.ErrorMap.
 425  
      * 
 426  
      * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no
 427  
      * prefix, other than what has already been pushed onto the errorMap.
 428  
      * 
 429  
      * @param bo - BusinessObject instance that should be tested
 430  
      * @return true if all passed existence tests, false if any failed
 431  
      * 
 432  
      */
 433  
     public boolean validateDefaultExistenceChecks(BusinessObject bo);
 434  
     
 435  
         /**
 436  
          * 
 437  
          * Does an existence check against all references configured as a default existence check in the maintenance
 438  
          * document data dictionary file for the given business object
 439  
          * 
 440  
          * Appropriate errors will also be placed in the GlobalVariables.ErrorMap.
 441  
          * 
 442  
          * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no
 443  
          * prefix, other than what has already been pushed onto the errorMap.
 444  
          * 
 445  
          * @param bo parent business object instance to retrieve default checks for
 446  
          * @param newCollectionItem new collection line to validate
 447  
          * @param collectionName name of the collection in the parent
 448  
          * @return true if all passed existence tests, false if any failed
 449  
          * 
 450  
          */
 451  
         public boolean validateDefaultExistenceChecksForNewCollectionItem(BusinessObject bo, BusinessObject newCollectionItem, String collectionName);
 452  
 
 453  
         /**
 454  
          * 
 455  
          * This method does an existence check against all references of a transactionalDocument
 456  
          * 
 457  
          * Appropriate errors will also be placed in the GlobalVariables.ErrorMap.
 458  
          * 
 459  
          * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no
 460  
          * prefix, other than what has already been pushed onto the errorMap.
 461  
          * 
 462  
          * @param document document instance that should be tested
 463  
          * @return true if all passed existence tests, false if any failed
 464  
          * 
 465  
          */
 466  
         public boolean validateDefaultExistenceChecksForTransDoc(TransactionalDocument document);
 467  
         
 468  
         /**
 469  
          * 
 470  
          * This method does an existence check against all references of a transactionalDocument
 471  
          * 
 472  
          * Appropriate errors will also be placed in the GlobalVariables.ErrorMap.
 473  
          * 
 474  
          * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no
 475  
          * prefix, other than what has already been pushed onto the errorMap.
 476  
          * 
 477  
          * @param document document instance that should be tested
 478  
          * @param accountingLine that should be tested
 479  
          * @param collectionName that should be tested
 480  
          * @return true if all passed existence tests, false if any failed
 481  
          * 
 482  
          */
 483  
         public boolean validateDefaultExistenceChecksForNewCollectionItem(TransactionalDocument document, BusinessObject accountingLine, String collectionName);
 484  
     
 485  
     /**
 486  
      * @deprecated since 1.1
 487  
      */
 488  
         @Deprecated
 489  
     public void validatePrimitiveFromDescriptor(String entryName, Object object, PropertyDescriptor propertyDescriptor, String errorPrefix, boolean validateRequired);
 490  
 }