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