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.ApcRuleDefinition; 22 import org.kuali.rice.kns.datadictionary.ReferenceDefinition; 23 import org.kuali.rice.kns.document.Document; 24 import org.kuali.rice.kns.document.TransactionalDocument; 25 26 27 /** 28 * Defines the API for the validating against the data dictionary. 29 * 30 * 31 */ 32 public interface DictionaryValidationService { 33 34 /** 35 * Validates the contents of a document (i.e. attributes within a document) against the data dictionary. 36 * 37 * @param document - document to validate 38 */ 39 public void validateDocument(Document document); 40 41 /** 42 * Validates the contents of a document (i.e. attributes within a document) against the data dictionary. Recursively checks 43 * business objects of the document. 44 * 45 * @param document - document to validate 46 * @param depth - Specify how deep the recrusion should go (0 based). If a negative number is supplied, it's infinite. 47 * 48 * @deprecated Use {@link #validateDocumentAndUpdatableReferencesRecursively(Document, int, boolean)} 49 */ 50 @Deprecated 51 public void validateDocumentRecursively(Document document, int depth); 52 53 /** 54 * Validates the contents of a document and recursively validates any of its updatable references 55 * 56 * @param document the document 57 * @param maxDepth the maximum numbers of levels to recurse 58 * @param validateRequired whether to validate whether a field is required and is currently blank 59 */ 60 public void validateDocumentAndUpdatableReferencesRecursively(Document document, int maxDepth, boolean validateRequired); 61 62 /** 63 * Validates the contents of a document and recursively validates any of its updatable references 64 * 65 * @param document the document 66 * @param maxDepth the maximum numbers of levels to recurse 67 * @param validateRequired whether to validate whether a field is required and is currently blank 68 * @param chompLastLetterSFromCollectionName if true, the error path for any collections encountered will have the last "s" removed from the collection name if it ends 69 * with the letter "s". If false, this method acts like {@link #validateDocumentAndUpdatableReferencesRecursively(Document, int, boolean)} 70 */ 71 public void validateDocumentAndUpdatableReferencesRecursively(Document document, int maxDepth, boolean validateRequired, boolean chompLastLetterSFromCollectionName); 72 73 /** 74 * Validates the specified attribute of the given document against the data dictionary. 75 * 76 * @param document 77 * @param attributeName 78 * @param errorPrefix 79 */ 80 public void validateDocumentAttribute(Document document, String attributeName, String errorPrefix); 81 82 83 /** 84 * Validates the business object primitive attributes against the data dictionary. Adds errors to the map as they are 85 * encountered. 86 * 87 * @param businessObject - business object to validate 88 */ 89 public void validateBusinessObject(BusinessObject businessObject); 90 91 /** 92 * Validates the business object primitive attributes against the data dictionary. Adds errors to the map as they are 93 * encountered. 94 * 95 * @param businessObject - business object to validate 96 * @param validateRequired - whether to execute required field checks 97 */ 98 public void validateBusinessObject(BusinessObject businessObject, boolean validateRequired); 99 100 public void validateBusinessObjectOnMaintenanceDocument(BusinessObject businessObject, String docTypeName); 101 102 /** 103 * Encapsulates <code>{@link #validateBusinessObject(BusinessObject) and returns boolean so one doesn't need to check the 104 * ErrorMap.Validates the business object primitive attributes against the data dictionary. Adds errors to the map as they are 105 * encountered.<br/> 106 * <br/> 107 * Makes no error path adjustments 108 * 109 * @param businessObject - business object to validate 110 * @return boolean validOrNot 111 */ 112 public boolean isBusinessObjectValid(BusinessObject businessObject); 113 114 /** 115 * Encapsulates <code>{@link #validateBusinessObject(BusinessObject) and returns boolean so one doesn't need to check the 116 * ErrorMap.Validates the business object primitive attributes against the data dictionary. Adds errors to the map as they are 117 * encountered.<br/> 118 * <br/> 119 * Makes no error path adjustments 120 * 121 * @param businessObject - business object to validate 122 * @param prefix - error prefix 123 * @return boolean valid or not 124 */ 125 public boolean isBusinessObjectValid(BusinessObject businessObject, String prefix); 126 127 /** 128 * Validates the business object against the dictionary, uses reflection to get any child business objects, and recursively 129 * calls back. Adds errors to the map as they are encountered. 130 * 131 * @param businessObject - business object to validate 132 * @param depth - Specify how deep the recrusion should go (0 based). If a negative number is supplied, it's infinite. 133 */ 134 public void validateBusinessObjectsRecursively(BusinessObject businessObject, int depth); 135 136 /** 137 * Validates an attribute of a given class for proper min, max length, syntax, and required. 138 * 139 * @param entryName - name of the dd entry 140 * @param attributeName - name of attribute in the bo class 141 * @param attributeValue - current value to validate 142 * @param errorKey - key to place the errors under 143 */ 144 public void validateAttributeFormat(String entryName, String attributeName, String attributeValue, String errorKey); 145 146 /** 147 * Validates an attribute of a given class for proper min, max length, syntax, and required. The attribute will be validated 148 * according to the specified data type. 149 * 150 * @param entryName - name of the dd entry 151 * @param attributeName - name of attribute in the bo class 152 * @param attributeValue - current value to validate 153 * @param attributeDataType - data type that this attribute should be treated as for validation purposes 154 * @param errorKey - key to place the errors under 155 */ 156 public void validateAttributeFormat(String entryName, String attributeName, String attributeValue, String attributeDataType, String errorKey); 157 158 /** 159 * Validates an attribute of a given class for required check. 160 * 161 * @param entryName - name of the dd entry 162 * @param attributeName - name of attribute in the bo class 163 * @param attributeValue - current value to validate 164 * @param errorKey - key to place to errors under 165 */ 166 public void validateAttributeRequired(String entryName, String attributeName, Object attributeValue, Boolean forMaintenance, String errorKey); 167 168 /** 169 * 170 * This method examines the populated BusinessObject bo instance passed in for a member named by the referenceName. If this 171 * member exists, and if this member is a descendent of BusinessObject, then an existence check proceeds. 172 * 173 * First the foreign keys for this reference are gathered, and then examined to see if they have values. If they do not have 174 * values, the method ends with a true return value. If they all have values, then an object with those primary keys is retrieve 175 * from the database. If one is retrieve, then the reference exists, and True is returned. Otherwise, false is returned. 176 * 177 * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no 178 * prefix, other than what has already been pushed onto the errorMap. 179 * 180 * @param bo - The bo whose reference is being tested. 181 * @param reference - The ReferenceDefinition to be existence tested. 182 * @return True if no exceptions occur and the object exists in the db, false otherwise. 183 * 184 */ 185 public boolean validateReferenceExists(BusinessObject bo, ReferenceDefinition reference); 186 187 /** 188 * 189 * This method examines the populated BusinessObject bo instance passed in for a member named by the referenceName. If this 190 * member exists, and if this member is a descendent of BusinessObject, then an existence check proceeds. 191 * 192 * First the foreign keys for this reference are gathered, and then examined to see if they have values. If they do not have 193 * values, the method ends with a true return value. If they all have values, then an object with those primary keys is retrieve 194 * from the database. If one is retrieve, then the reference exists, and True is returned. Otherwise, false is returned. 195 * 196 * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no 197 * prefix, other than what has already been pushed onto the errorMap. 198 * 199 * @param bo - The bo whose reference is being tested. 200 * @param referenceName - The name of the member to be existence tested. 201 * @return True if no exceptions occur and the object exists in the db, false otherwise. 202 * 203 */ 204 public boolean validateReferenceExists(BusinessObject bo, String referenceName); 205 206 /** 207 * 208 * This method retrieves the reference from the DB, and then tests whether the object is active. 209 * 210 * It will return false if there is no activeIndicator field on this object, if the object doesnt exist in the DB, if the field 211 * doesnt exist or cannot be cast as a boolean, if the field value is null, or if the field value is false. 212 * 213 * 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 214 * true. 215 * 216 * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no 217 * prefix, other than what has already been pushed onto the errorMap. 218 * 219 * @param bo 220 * @param reference 221 * @return 222 * 223 */ 224 public boolean validateReferenceIsActive(BusinessObject bo, ReferenceDefinition reference); 225 226 /** 227 * 228 * This method retrieves the reference from the DB, and then tests whether the object is active. 229 * 230 * It will return false if there is no activeIndicator field on this object, if the object doesnt exist in the DB, if the field 231 * doesnt exist or cannot be cast as a boolean, if the field value is null, or if the field value is false. 232 * 233 * 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 234 * true. 235 * 236 * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no 237 * prefix, other than what has already been pushed onto the errorMap. 238 * 239 * @param bo 240 * @param referenceName 241 * @return 242 * 243 */ 244 public boolean validateReferenceIsActive(BusinessObject bo, String referenceName); 245 246 /** 247 * 248 * This method intelligently tests the designated reference on the bo for both existence and active status, where appropriate. 249 * 250 * It will not test anything if the foreign-key fields for the given reference arent filled out with values, and it will not 251 * test active status if the reference doesnt exist. 252 * 253 * Further, it will only test active status where the correct flag is set. 254 * 255 * On failures of either sort, it will put the relevant errors into the GlobalVariables errorMap, and return a false. If there 256 * are no failures, or nothing can be tested because the foreign-key fields arent fully filled out, it will return true and add 257 * no errors. 258 * 259 * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no 260 * prefix, other than what has already been pushed onto the errorMap. 261 * 262 * @param bo - the BusinessObject instance to be tested. 263 * @param reference - the ReferenceDefinition to control the nature of the testing. 264 * @return true or false as per the criteria above 265 * 266 */ 267 public boolean validateReferenceExistsAndIsActive(BusinessObject bo, ReferenceDefinition reference); 268 269 /** 270 * 271 * This method intelligently tests the designated reference on the bo for both existence and active status, where appropriate. 272 * 273 * It will not test anything if the foreign-key fields for the given reference arent filled out with values, and it will not 274 * test active status if the reference doesnt exist. 275 * 276 * 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 277 * (ie, the 'if any field is filled, then all must be filled' rule), you'll have to do that separately. 278 * 279 * Further, it will only test active status where the correct flag is set. 280 * 281 * On failures of either sort, it will put the relevant errors into the GlobalVariables errorMap, and return a false. If there 282 * are no failures, or nothing can be tested because the foreign-key fields arent fully filled out, it will return true and add 283 * no errors. 284 * 285 * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no 286 * prefix, other than what has already been pushed onto the errorMap. 287 * 288 * @param bo - the BusinessObject instance to be tested. 289 * @param referenceName - the member name on the bo to be tested for existence and active-state 290 * @param activeIndicatorAttributeName - the name on the class of the referenceName member to indicate active status 291 * @param activeIndicatorReversed - a flag to indicate if the flag means closed or inactive, rather than active 292 * @param activeIndicatorSet - a flag to control whether active state testing happens at all 293 * @param attributeToHighlightOnFail - the fieldName to highlight with the error message on a failure 294 * @param displayFieldName - the human-readable display name of the failed field, to go in the error message 295 * @return true or false as per the criteria above 296 */ 297 public boolean validateReferenceExistsAndIsActive(BusinessObject bo, String referenceName, String attributeToHighlightOnFail, String displayFieldName); 298 299 /** 300 * 301 * This method does an existence check against all references of a BusinessObject as defined in the MaintenanceDocument.xml file 302 * for that business object. 303 * 304 * Appropriate errors will also be placed in the GlobalVariables.ErrorMap. 305 * 306 * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no 307 * prefix, other than what has already been pushed onto the errorMap. 308 * 309 * @param bo - BusinessObject instance that should be tested 310 * @return true if all passed existence tests, false if any failed 311 * 312 */ 313 public boolean validateDefaultExistenceChecks(BusinessObject bo); 314 315 /** 316 * 317 * Does an existence check against all references configured as a default existence check in the maintenance 318 * document data dictionary file for the given business object 319 * 320 * Appropriate errors will also be placed in the GlobalVariables.ErrorMap. 321 * 322 * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no 323 * prefix, other than what has already been pushed onto the errorMap. 324 * 325 * @param bo parent business object instance to retrieve default checks for 326 * @param newCollectionItem new collection line to validate 327 * @param collectionName name of the collection in the parent 328 * @return true if all passed existence tests, false if any failed 329 * 330 */ 331 public boolean validateDefaultExistenceChecksForNewCollectionItem(BusinessObject bo, BusinessObject newCollectionItem, String collectionName); 332 333 /** 334 * 335 * This method does an existence check against all references of a transactionalDocument 336 * 337 * Appropriate errors will also be placed in the GlobalVariables.ErrorMap. 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 doc document instance that should be tested 343 * @return true if all passed existence tests, false if any failed 344 * 345 */ 346 public boolean validateDefaultExistenceChecksForTransDoc(TransactionalDocument document); 347 348 /** 349 * 350 * This method does an existence check against all references of a transactionalDocument 351 * 352 * Appropriate errors will also be placed in the GlobalVariables.ErrorMap. 353 * 354 * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no 355 * prefix, other than what has already been pushed onto the errorMap. 356 * 357 * @param doc document instance that should be tested 358 * @param accountingLine that should be tested 359 * @param collectionName that should be tested 360 * @return true if all passed existence tests, false if any failed 361 * 362 */ 363 public boolean validateDefaultExistenceChecksForNewCollectionItem(TransactionalDocument document, BusinessObject accountingLine, String collectionName); 364 365 /** 366 * 367 * This method applies a specific rule against the given BusinessObject as defined in the MaintenanceDocument.xml file. 368 * 369 * Appropriate errors will also be placed in the GlobalVariables.ErrorMap. 370 * 371 * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no 372 * prefix, other than what has already been pushed onto the errorMap. 373 * 374 * @param bo 375 * @param apcRule 376 * @return true if rule passes 377 */ 378 public boolean validateApcRule(BusinessObject bo, ApcRuleDefinition apcRule); 379 380 /** 381 * This method applies all rules against the given BusinessObject as defined in the MaintenanceDocument.xml file. 382 * 383 * Appropriate errors will also be placed in the GlobalVariables.ErrorMap. 384 * 385 * This method assumes that you already have the errorPath set exactly as desired, and adds new errors to the errorMap with no 386 * prefix, other than what has already been pushed onto the errorMap. 387 * 388 * @param bo 389 * @return true if rule passes 390 */ 391 public boolean validateApcRules(BusinessObject bo); 392 393 public void validatePrimitiveFromDescriptor(String entryName, Object object, PropertyDescriptor propertyDescriptor, String errorPrefix, boolean validateRequired); 394 }