| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kns.service.impl; |
| 17 | |
|
| 18 | |
import org.apache.commons.beanutils.PropertyUtils; |
| 19 | |
import org.apache.commons.lang.ArrayUtils; |
| 20 | |
import org.apache.commons.lang.StringUtils; |
| 21 | |
import org.kuali.rice.core.LogicalOperator; |
| 22 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
| 23 | |
import org.kuali.rice.core.framework.persistence.jdbc.sql.SQLUtils; |
| 24 | |
import org.kuali.rice.core.util.type.TypeUtils; |
| 25 | |
import org.kuali.rice.core.web.format.DateFormatter; |
| 26 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 27 | |
import org.kuali.rice.kns.bo.BusinessObject; |
| 28 | |
import org.kuali.rice.kns.bo.Inactivateable; |
| 29 | |
import org.kuali.rice.kns.bo.PersistableBusinessObject; |
| 30 | |
import org.kuali.rice.kns.datadictionary.*; |
| 31 | |
import org.kuali.rice.kns.datadictionary.control.ControlDefinition; |
| 32 | |
import org.kuali.rice.kns.document.Document; |
| 33 | |
import org.kuali.rice.kns.document.TransactionalDocument; |
| 34 | |
import org.kuali.rice.kns.exception.InfrastructureException; |
| 35 | |
import org.kuali.rice.kns.exception.ObjectNotABusinessObjectRuntimeException; |
| 36 | |
import org.kuali.rice.kns.service.*; |
| 37 | |
import org.kuali.rice.kns.util.GlobalVariables; |
| 38 | |
import org.kuali.rice.kns.util.KNSConstants; |
| 39 | |
import org.kuali.rice.kns.util.MessageMap; |
| 40 | |
import org.kuali.rice.kns.util.ObjectUtils; |
| 41 | |
import org.kuali.rice.kns.workflow.service.WorkflowAttributePropertyResolutionService; |
| 42 | |
|
| 43 | |
import java.beans.PropertyDescriptor; |
| 44 | |
import java.lang.reflect.InvocationTargetException; |
| 45 | |
import java.lang.reflect.Method; |
| 46 | |
import java.math.BigDecimal; |
| 47 | |
import java.util.*; |
| 48 | |
import java.util.regex.Pattern; |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | 0 | public class DictionaryValidationServiceImpl implements DictionaryValidationService { |
| 57 | 0 | private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DictionaryValidationServiceImpl.class); |
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
public static final String VALIDATE_METHOD="validate"; |
| 64 | |
|
| 65 | |
private DataDictionaryService dataDictionaryService; |
| 66 | |
private BusinessObjectService businessObjectService; |
| 67 | |
private MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService; |
| 68 | |
private TransactionalDocumentDictionaryService transactionalDocumentDictionaryService; |
| 69 | |
private PersistenceService persistenceService; |
| 70 | |
private WorkflowAttributePropertyResolutionService workflowAttributePropertyResolutionService; |
| 71 | |
|
| 72 | |
private PersistenceStructureService persistenceStructureService; |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
private static Set<BusinessObject> newIdentitySet() { |
| 79 | 0 | return java.util.Collections.newSetFromMap(new IdentityHashMap<BusinessObject, Boolean>()); |
| 80 | |
} |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
@Override |
| 86 | |
public void validateDocument(Document document) { |
| 87 | 0 | String documentEntryName = document.getDocumentHeader().getWorkflowDocument().getDocumentType(); |
| 88 | |
|
| 89 | |
|
| 90 | 0 | validatePrimitivesFromDescriptors(documentEntryName, document, PropertyUtils.getPropertyDescriptors(document.getClass()), "", true); |
| 91 | 0 | } |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
@Override |
| 99 | |
public void validateDocumentAttribute(Document document, String attributeName, String errorPrefix) { |
| 100 | 0 | String documentEntryName = document.getDocumentHeader().getWorkflowDocument().getDocumentType(); |
| 101 | |
|
| 102 | |
try { |
| 103 | 0 | PropertyDescriptor attributeDescriptor = PropertyUtils.getPropertyDescriptor(document, attributeName); |
| 104 | 0 | validatePrimitiveFromDescriptor(documentEntryName, document, attributeDescriptor, errorPrefix, true); |
| 105 | |
} |
| 106 | 0 | catch (NoSuchMethodException e) { |
| 107 | 0 | throw new InfrastructureException("unable to find propertyDescriptor for property '" + attributeName + "'", e); |
| 108 | |
} |
| 109 | 0 | catch (IllegalAccessException e) { |
| 110 | 0 | throw new InfrastructureException("unable to access propertyDescriptor for property '" + attributeName + "'", e); |
| 111 | |
} |
| 112 | 0 | catch (InvocationTargetException e) { |
| 113 | 0 | throw new InfrastructureException("unable to invoke methods for property '" + attributeName + "'", e); |
| 114 | 0 | } |
| 115 | 0 | } |
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
@Override |
| 121 | |
public void validateDocumentRecursively(Document document, int depth) { |
| 122 | |
|
| 123 | 0 | validateDocument(document); |
| 124 | |
|
| 125 | |
|
| 126 | 0 | validateBusinessObjectsFromDescriptors(document, PropertyUtils.getPropertyDescriptors(document.getClass()), depth); |
| 127 | 0 | } |
| 128 | |
|
| 129 | |
@Override |
| 130 | |
public void validateDocumentAndUpdatableReferencesRecursively(Document document, int maxDepth, boolean validateRequired) { |
| 131 | 0 | validateDocumentAndUpdatableReferencesRecursively(document, maxDepth, validateRequired, false); |
| 132 | 0 | } |
| 133 | |
|
| 134 | |
@Override |
| 135 | |
public void validateDocumentAndUpdatableReferencesRecursively(Document document, int maxDepth, boolean validateRequired, boolean chompLastLetterSFromCollectionName) { |
| 136 | 0 | String documentEntryName = document.getDocumentHeader().getWorkflowDocument().getDocumentType(); |
| 137 | |
|
| 138 | 0 | validatePrimitivesFromDescriptors(documentEntryName, document, PropertyUtils.getPropertyDescriptors(document.getClass()), "", validateRequired); |
| 139 | |
|
| 140 | 0 | if (maxDepth > 0) { |
| 141 | 0 | validateUpdatabableReferencesRecursively(document, maxDepth - 1, validateRequired, chompLastLetterSFromCollectionName, newIdentitySet()); |
| 142 | |
} |
| 143 | 0 | } |
| 144 | |
|
| 145 | |
private void validateUpdatabableReferencesRecursively(BusinessObject businessObject, int maxDepth, boolean validateRequired, boolean chompLastLetterSFromCollectionName, Set<BusinessObject> processedBOs) { |
| 146 | |
|
| 147 | 0 | if (ObjectUtils.isNull(businessObject) || processedBOs.contains(businessObject)) { |
| 148 | 0 | return; |
| 149 | |
} |
| 150 | 0 | processedBOs.add(businessObject); |
| 151 | 0 | Map<String, Class> references = persistenceStructureService.listReferenceObjectFields(businessObject.getClass()); |
| 152 | 0 | for (String referenceName : references.keySet()) { |
| 153 | 0 | if (persistenceStructureService.isReferenceUpdatable(businessObject.getClass(), referenceName)) { |
| 154 | 0 | Object referenceObj = ObjectUtils.getPropertyValue(businessObject, referenceName); |
| 155 | |
|
| 156 | 0 | if (ObjectUtils.isNull(referenceObj) || !(referenceObj instanceof PersistableBusinessObject)) { |
| 157 | 0 | continue; |
| 158 | |
} |
| 159 | |
|
| 160 | 0 | BusinessObject referenceBusinessObject = (BusinessObject) referenceObj; |
| 161 | 0 | GlobalVariables.getMessageMap().addToErrorPath(referenceName); |
| 162 | 0 | validateBusinessObject(referenceBusinessObject, validateRequired); |
| 163 | 0 | if (maxDepth > 0) { |
| 164 | 0 | validateUpdatabableReferencesRecursively(referenceBusinessObject, maxDepth - 1, validateRequired, chompLastLetterSFromCollectionName, processedBOs); |
| 165 | |
} |
| 166 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath(referenceName); |
| 167 | |
|
| 168 | 0 | } |
| 169 | |
} |
| 170 | 0 | Map<String, Class> collections = persistenceStructureService.listCollectionObjectTypes(businessObject.getClass()); |
| 171 | 0 | for (String collectionName : collections.keySet()) { |
| 172 | 0 | if (persistenceStructureService.isCollectionUpdatable(businessObject.getClass(), collectionName)) { |
| 173 | 0 | Object listObj = ObjectUtils.getPropertyValue(businessObject, collectionName); |
| 174 | |
|
| 175 | 0 | if (ObjectUtils.isNull(listObj)) { |
| 176 | 0 | continue; |
| 177 | |
} |
| 178 | |
|
| 179 | 0 | if (!(listObj instanceof List)) { |
| 180 | 0 | if ( LOG.isInfoEnabled() ) { |
| 181 | 0 | LOG.info("The reference named " + collectionName + " of BO class " + businessObject.getClass().getName() + " should be of type java.util.List to be validated properly."); |
| 182 | |
} |
| 183 | |
continue; |
| 184 | |
} |
| 185 | |
|
| 186 | 0 | List list = (List) listObj; |
| 187 | |
|
| 188 | |
|
| 189 | 0 | ObjectUtils.materializeObjects(list); |
| 190 | |
|
| 191 | 0 | for (int i = 0; i < list.size(); i++) { |
| 192 | 0 | final Object o = list.get(i); |
| 193 | 0 | if (ObjectUtils.isNotNull(o) && o instanceof PersistableBusinessObject) { |
| 194 | 0 | final BusinessObject element = (BusinessObject) o; |
| 195 | |
|
| 196 | |
final String errorPathAddition; |
| 197 | 0 | if (chompLastLetterSFromCollectionName) { |
| 198 | 0 | errorPathAddition = StringUtils.chomp(collectionName, "s") + "[" + Integer.toString(i) + "]"; |
| 199 | |
} else { |
| 200 | 0 | errorPathAddition = collectionName + "[" + Integer.toString(i) + "]"; |
| 201 | |
} |
| 202 | |
|
| 203 | 0 | GlobalVariables.getMessageMap().addToErrorPath(errorPathAddition); |
| 204 | 0 | validateBusinessObject(element, validateRequired); |
| 205 | 0 | if (maxDepth > 0) { |
| 206 | 0 | validateUpdatabableReferencesRecursively(element, maxDepth - 1, validateRequired, chompLastLetterSFromCollectionName, processedBOs); |
| 207 | |
} |
| 208 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath(errorPathAddition); |
| 209 | |
} |
| 210 | |
} |
| 211 | 0 | } |
| 212 | |
} |
| 213 | 0 | } |
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
@Override |
| 219 | |
public void validateBusinessObject(BusinessObject businessObject) { |
| 220 | 0 | validateBusinessObject(businessObject, true); |
| 221 | 0 | } |
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
@Override |
| 227 | |
public void validateBusinessObject(BusinessObject businessObject, boolean validateRequired) { |
| 228 | 0 | if (ObjectUtils.isNull(businessObject)) { |
| 229 | 0 | return; |
| 230 | |
} |
| 231 | |
try { |
| 232 | |
|
| 233 | 0 | validatePrimitivesFromDescriptors(businessObject.getClass().getName(), businessObject, PropertyUtils.getPropertyDescriptors(businessObject.getClass()), "", validateRequired); |
| 234 | 0 | } catch(RuntimeException e) { |
| 235 | 0 | LOG.error(String.format("Exception while validating %s", businessObject.getClass().getName()), e); |
| 236 | 0 | throw e; |
| 237 | 0 | } |
| 238 | 0 | } |
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
@Override |
| 244 | |
public void validateBusinessObjectOnMaintenanceDocument(BusinessObject businessObject, String docTypeName) { |
| 245 | 0 | MaintenanceDocumentEntry entry = KNSServiceLocatorWeb.getMaintenanceDocumentDictionaryService().getMaintenanceDocumentEntry(docTypeName); |
| 246 | 0 | for (MaintainableSectionDefinition sectionDefinition : entry.getMaintainableSections()) { |
| 247 | 0 | validateBusinessObjectOnMaintenanceDocumentHelper(businessObject, sectionDefinition.getMaintainableItems(), ""); |
| 248 | |
} |
| 249 | 0 | } |
| 250 | |
|
| 251 | |
protected void validateBusinessObjectOnMaintenanceDocumentHelper(BusinessObject businessObject, List<? extends MaintainableItemDefinition> itemDefinitions, String errorPrefix) { |
| 252 | 0 | for (MaintainableItemDefinition itemDefinition : itemDefinitions) { |
| 253 | 0 | if (itemDefinition instanceof MaintainableFieldDefinition) { |
| 254 | 0 | if (getDataDictionaryService().isAttributeDefined(businessObject.getClass(), itemDefinition.getName())) { |
| 255 | 0 | Object value = ObjectUtils.getPropertyValue(businessObject, itemDefinition.getName()); |
| 256 | 0 | if (value != null && StringUtils.isNotBlank(value.toString())) { |
| 257 | 0 | Class propertyType = ObjectUtils.getPropertyType(businessObject, itemDefinition.getName(), persistenceStructureService); |
| 258 | 0 | if (TypeUtils.isStringClass(propertyType) || TypeUtils.isIntegralClass(propertyType) || TypeUtils.isDecimalClass(propertyType) || TypeUtils.isTemporalClass(propertyType)) { |
| 259 | |
|
| 260 | 0 | if (!TypeUtils.isTemporalClass(propertyType)) { |
| 261 | 0 | validateAttributeFormat(businessObject.getClass().getName(), itemDefinition.getName(), value.toString(), errorPrefix + itemDefinition.getName()); |
| 262 | |
} |
| 263 | |
} |
| 264 | |
} |
| 265 | 0 | } |
| 266 | |
} |
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
|
| 281 | |
|
| 282 | |
} |
| 283 | 0 | } |
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
@Override |
| 290 | |
public boolean isBusinessObjectValid(BusinessObject businessObject) { |
| 291 | 0 | return isBusinessObjectValid(businessObject, null); |
| 292 | |
} |
| 293 | |
|
| 294 | |
|
| 295 | |
|
| 296 | |
|
| 297 | |
@Override |
| 298 | |
public boolean isBusinessObjectValid(BusinessObject businessObject, String prefix) { |
| 299 | 0 | final MessageMap errorMap = GlobalVariables.getMessageMap(); |
| 300 | 0 | int originalErrorCount = errorMap.getErrorCount(); |
| 301 | |
|
| 302 | 0 | errorMap.addToErrorPath(prefix); |
| 303 | 0 | validateBusinessObject(businessObject); |
| 304 | 0 | errorMap.removeFromErrorPath(prefix); |
| 305 | |
|
| 306 | 0 | return errorMap.getErrorCount() == originalErrorCount; |
| 307 | |
} |
| 308 | |
|
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
@Override |
| 314 | |
public void validateBusinessObjectsRecursively(BusinessObject businessObject, int depth) { |
| 315 | 0 | if (ObjectUtils.isNull(businessObject)) { |
| 316 | 0 | return; |
| 317 | |
} |
| 318 | |
|
| 319 | |
|
| 320 | 0 | validateBusinessObject(businessObject); |
| 321 | |
|
| 322 | |
|
| 323 | 0 | validateBusinessObjectsFromDescriptors(businessObject, PropertyUtils.getPropertyDescriptors(businessObject.getClass()), depth); |
| 324 | 0 | } |
| 325 | |
|
| 326 | |
|
| 327 | |
|
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
@Override |
| 332 | |
public void validateAttributeFormat(String objectClassName, String attributeName, String attributeInValue, String errorKey) { |
| 333 | |
|
| 334 | 0 | String attributeDataType = null; |
| 335 | |
try { |
| 336 | 0 | attributeDataType = getWorkflowAttributePropertyResolutionService().determineFieldDataType((Class<? extends BusinessObject>)Class.forName( |
| 337 | |
getDataDictionaryService().getDataDictionary().getDictionaryObjectEntry(objectClassName).getFullClassName()), attributeName); |
| 338 | 0 | } catch(ClassNotFoundException e) { |
| 339 | 0 | attributeDataType = KEWConstants.SearchableAttributeConstants.DATA_TYPE_STRING; |
| 340 | 0 | } catch (NullPointerException e) { |
| 341 | 0 | attributeDataType = KEWConstants.SearchableAttributeConstants.DATA_TYPE_STRING; |
| 342 | 0 | } |
| 343 | |
|
| 344 | 0 | validateAttributeFormat(objectClassName, attributeName, attributeInValue, attributeDataType, errorKey); |
| 345 | 0 | } |
| 346 | |
|
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
|
| 352 | |
|
| 353 | |
|
| 354 | |
@Override |
| 355 | |
public void validateAttributeFormat(String objectClassName, String attributeName, String attributeInValue, String attributeDataType, String errorKey) { |
| 356 | 0 | boolean checkDateBounds = false; |
| 357 | 0 | Class<?> formatterClass = null; |
| 358 | |
|
| 359 | 0 | if ( LOG.isDebugEnabled() ) { |
| 360 | 0 | LOG.debug("(bo, attributeName, attributeValue) = (" + objectClassName + "," + attributeName + "," + attributeInValue + ")"); |
| 361 | |
} |
| 362 | |
|
| 363 | |
|
| 364 | |
|
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | 0 | List<String> attributeValues = getCleanedSearchableValues(attributeInValue, attributeDataType); |
| 369 | |
|
| 370 | 0 | if(attributeValues == null || attributeValues.isEmpty()) { |
| 371 | 0 | return; |
| 372 | |
} |
| 373 | |
|
| 374 | 0 | for(String attributeValue : attributeValues){ |
| 375 | 0 | if (StringUtils.isNotBlank(attributeValue)) { |
| 376 | 0 | Integer maxLength = getDataDictionaryService().getAttributeMaxLength(objectClassName, attributeName); |
| 377 | 0 | if ((maxLength != null) && (maxLength.intValue() < attributeValue.length())) { |
| 378 | 0 | String errorLabel = getDataDictionaryService().getAttributeErrorLabel(objectClassName, attributeName); |
| 379 | 0 | GlobalVariables.getMessageMap().putError(errorKey, RiceKeyConstants.ERROR_MAX_LENGTH, new String[] { errorLabel, maxLength.toString() }); |
| 380 | 0 | return; |
| 381 | |
} |
| 382 | 0 | Pattern validationExpression = getDataDictionaryService().getAttributeValidatingExpression(objectClassName, attributeName); |
| 383 | 0 | if (validationExpression != null && !validationExpression.pattern().equals(".*")) { |
| 384 | 0 | if ( LOG.isDebugEnabled() ) { |
| 385 | 0 | LOG.debug("(bo, attributeName, validationExpression) = (" + objectClassName + "," + attributeName + "," + validationExpression + ")"); |
| 386 | |
} |
| 387 | |
|
| 388 | 0 | if (!validationExpression.matcher(attributeValue).matches()) { |
| 389 | |
|
| 390 | 0 | if(formatterClass == null){ |
| 391 | |
|
| 392 | 0 | formatterClass=getDataDictionaryService().getAttributeFormatter( |
| 393 | |
objectClassName, attributeName); |
| 394 | |
} |
| 395 | |
|
| 396 | 0 | if (formatterClass != null) { |
| 397 | 0 | boolean valuesAreValid = true; |
| 398 | 0 | boolean isError=true; |
| 399 | 0 | String errorKeyPrefix = ""; |
| 400 | |
try { |
| 401 | |
|
| 402 | |
|
| 403 | 0 | if (DateFormatter.class.isAssignableFrom(formatterClass)) { |
| 404 | 0 | String[] values = attributeInValue.split("\\.\\."); |
| 405 | 0 | if(values.length == 2 && attributeValues.size() == 2){ |
| 406 | 0 | checkDateBounds = true; |
| 407 | 0 | if(attributeValues.indexOf(attributeValue) == 0){ |
| 408 | 0 | errorKeyPrefix = KNSConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX; |
| 409 | |
} |
| 410 | |
} |
| 411 | |
} |
| 412 | |
|
| 413 | 0 | Method validatorMethod=formatterClass.getDeclaredMethod( |
| 414 | |
VALIDATE_METHOD, new Class<?>[] {String.class}); |
| 415 | 0 | Object o=validatorMethod.invoke( |
| 416 | |
formatterClass.newInstance(), attributeValue); |
| 417 | 0 | if (o instanceof Boolean) { |
| 418 | 0 | isError = !((Boolean)o).booleanValue(); |
| 419 | |
} |
| 420 | 0 | valuesAreValid &= !isError; |
| 421 | 0 | } catch (Exception e) { |
| 422 | 0 | if ( LOG.isDebugEnabled() ) { |
| 423 | 0 | LOG.debug(e.getMessage(), e); |
| 424 | |
} |
| 425 | 0 | isError =true; |
| 426 | 0 | valuesAreValid = false; |
| 427 | 0 | } |
| 428 | 0 | if (isError) { |
| 429 | 0 | checkDateBounds = false; |
| 430 | 0 | String errorMessageKey = getDataDictionaryService().getAttributeValidatingErrorMessageKey(objectClassName, attributeName); |
| 431 | 0 | String[] errorMessageParameters = getDataDictionaryService().getAttributeValidatingErrorMessageParameters(objectClassName, attributeName); |
| 432 | 0 | GlobalVariables.getMessageMap().putError(errorKeyPrefix + errorKey, errorMessageKey, errorMessageParameters); |
| 433 | |
} |
| 434 | 0 | } else { |
| 435 | |
|
| 436 | 0 | String errorMessageKey = getDataDictionaryService().getAttributeValidatingErrorMessageKey(objectClassName, attributeName); |
| 437 | 0 | String[] errorMessageParameters = getDataDictionaryService().getAttributeValidatingErrorMessageParameters(objectClassName, attributeName); |
| 438 | 0 | GlobalVariables.getMessageMap().putError(errorKey, errorMessageKey, errorMessageParameters); |
| 439 | |
} |
| 440 | |
} |
| 441 | |
|
| 442 | |
} |
| 443 | 0 | BigDecimal exclusiveMin = getDataDictionaryService().getAttributeExclusiveMin(objectClassName, attributeName); |
| 444 | 0 | if (exclusiveMin != null) { |
| 445 | |
try { |
| 446 | 0 | if (exclusiveMin.compareTo(new BigDecimal(attributeValue)) >= 0) { |
| 447 | 0 | String errorLabel = getDataDictionaryService().getAttributeErrorLabel(objectClassName, attributeName); |
| 448 | 0 | GlobalVariables.getMessageMap().putError(errorKey, RiceKeyConstants.ERROR_EXCLUSIVE_MIN, |
| 449 | |
|
| 450 | |
new String[] { errorLabel, exclusiveMin.toString() }); |
| 451 | 0 | return; |
| 452 | |
} |
| 453 | |
} |
| 454 | 0 | catch (NumberFormatException e) { |
| 455 | |
|
| 456 | 0 | } |
| 457 | |
} |
| 458 | 0 | BigDecimal inclusiveMax = getDataDictionaryService().getAttributeInclusiveMax(objectClassName, attributeName); |
| 459 | 0 | if (inclusiveMax != null) { |
| 460 | |
try { |
| 461 | 0 | if (inclusiveMax.compareTo(new BigDecimal(attributeValue)) < 0) { |
| 462 | 0 | String errorLabel = getDataDictionaryService().getAttributeErrorLabel(objectClassName, attributeName); |
| 463 | 0 | GlobalVariables.getMessageMap().putError(errorKey, RiceKeyConstants.ERROR_INCLUSIVE_MAX, |
| 464 | |
|
| 465 | |
new String[] { errorLabel, inclusiveMax.toString() }); |
| 466 | 0 | return; |
| 467 | |
} |
| 468 | |
} |
| 469 | 0 | catch (NumberFormatException e) { |
| 470 | |
|
| 471 | 0 | } |
| 472 | |
} |
| 473 | 0 | } |
| 474 | |
} |
| 475 | |
|
| 476 | 0 | if(checkDateBounds){ |
| 477 | |
|
| 478 | 0 | java.sql.Timestamp lVal = null; |
| 479 | 0 | java.sql.Timestamp uVal = null; |
| 480 | |
try{ |
| 481 | 0 | lVal = KNSServiceLocator.getDateTimeService().convertToSqlTimestamp(attributeValues.get(0)); |
| 482 | 0 | uVal = KNSServiceLocator.getDateTimeService().convertToSqlTimestamp(attributeValues.get(1)); |
| 483 | 0 | }catch(Exception ex){ |
| 484 | |
|
| 485 | 0 | String errorMessageKey = getDataDictionaryService().getAttributeValidatingErrorMessageKey(objectClassName, attributeName); |
| 486 | 0 | String[] errorMessageParameters = getDataDictionaryService().getAttributeValidatingErrorMessageParameters(objectClassName, attributeName); |
| 487 | 0 | GlobalVariables.getMessageMap().putError(KNSConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX + errorKey, errorMessageKey, errorMessageParameters); |
| 488 | 0 | } |
| 489 | |
|
| 490 | 0 | if(lVal != null && lVal.compareTo(uVal) > 0){ |
| 491 | 0 | String errorMessageKey = getDataDictionaryService().getAttributeValidatingErrorMessageKey(objectClassName, attributeName); |
| 492 | 0 | String[] errorMessageParameters = getDataDictionaryService().getAttributeValidatingErrorMessageParameters(objectClassName, attributeName); |
| 493 | 0 | GlobalVariables.getMessageMap().putError(KNSConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX + errorKey, errorMessageKey + ".range", errorMessageParameters); |
| 494 | |
} |
| 495 | |
} |
| 496 | 0 | } |
| 497 | |
|
| 498 | |
|
| 499 | |
|
| 500 | |
|
| 501 | |
|
| 502 | |
|
| 503 | |
|
| 504 | |
|
| 505 | |
|
| 506 | |
private static List<String> getCleanedSearchableValues(String valueEntered, String propertyDataType) { |
| 507 | 0 | List<String> lRet = null; |
| 508 | 0 | List<String> lTemp = getSearchableValues(valueEntered); |
| 509 | 0 | if(lTemp != null && !lTemp.isEmpty()){ |
| 510 | 0 | lRet = new ArrayList<String>(); |
| 511 | 0 | for(String val: lTemp){ |
| 512 | |
|
| 513 | 0 | if (KNSConstants.DATA_TYPE_STRING.equals(propertyDataType)) { |
| 514 | 0 | lRet.add(ObjectUtils.clean(val)); |
| 515 | 0 | } else if (KNSConstants.DATA_TYPE_FLOAT.equals(propertyDataType) || KNSConstants.DATA_TYPE_LONG.equals(propertyDataType)) { |
| 516 | 0 | lRet.add(SQLUtils.cleanNumericOfValidOperators(val)); |
| 517 | 0 | } else if (KNSConstants.DATA_TYPE_DATE.equals(propertyDataType)) { |
| 518 | 0 | lRet.add(SQLUtils.cleanDate(val)); |
| 519 | |
} else { |
| 520 | 0 | lRet.add(ObjectUtils.clean(val)); |
| 521 | |
} |
| 522 | |
} |
| 523 | |
} |
| 524 | 0 | return lRet; |
| 525 | |
} |
| 526 | |
|
| 527 | |
|
| 528 | |
|
| 529 | |
|
| 530 | |
|
| 531 | |
|
| 532 | |
|
| 533 | |
|
| 534 | |
private static List<String> getSearchableValues(String valueEntered) { |
| 535 | 0 | List<String> lRet = new ArrayList<String>(); |
| 536 | 0 | getSearchableValueRecursive(valueEntered, lRet); |
| 537 | 0 | return lRet; |
| 538 | |
} |
| 539 | |
|
| 540 | |
private static void getSearchableValueRecursive(String valueEntered, List lRet) { |
| 541 | 0 | if(valueEntered == null) { |
| 542 | 0 | return; |
| 543 | |
} |
| 544 | |
|
| 545 | 0 | valueEntered = valueEntered.trim(); |
| 546 | |
|
| 547 | 0 | if(lRet == null){ |
| 548 | 0 | throw new NullPointerException("The list passed in is by reference and should never be null."); |
| 549 | |
} |
| 550 | |
|
| 551 | 0 | if (StringUtils.contains(valueEntered, LogicalOperator.BETWEEN.op())) { |
| 552 | 0 | List<String> l = Arrays.asList(valueEntered.split("\\.\\.")); |
| 553 | 0 | for(String value : l){ |
| 554 | 0 | getSearchableValueRecursive(value,lRet); |
| 555 | |
} |
| 556 | 0 | return; |
| 557 | |
} |
| 558 | 0 | if (StringUtils.contains(valueEntered, LogicalOperator.OR.op())) { |
| 559 | 0 | List<String> l = Arrays.asList(StringUtils.split(valueEntered, LogicalOperator.OR.op())); |
| 560 | 0 | for(String value : l){ |
| 561 | 0 | getSearchableValueRecursive(value,lRet); |
| 562 | |
} |
| 563 | 0 | return; |
| 564 | |
} |
| 565 | 0 | if (StringUtils.contains(valueEntered, LogicalOperator.AND.op())) { |
| 566 | |
|
| 567 | 0 | List<String> l = Arrays.asList(StringUtils.split(valueEntered, LogicalOperator.AND.op())); |
| 568 | 0 | for(String value : l){ |
| 569 | 0 | getSearchableValueRecursive(value,lRet); |
| 570 | |
} |
| 571 | 0 | return; |
| 572 | |
} |
| 573 | |
|
| 574 | |
|
| 575 | 0 | lRet.add(valueEntered); |
| 576 | 0 | } |
| 577 | |
|
| 578 | |
|
| 579 | |
|
| 580 | |
|
| 581 | |
@Override |
| 582 | |
public void validateAttributeRequired(String objectClassName, String attributeName, Object attributeValue, Boolean forMaintenance, String errorKey) { |
| 583 | |
|
| 584 | 0 | if (attributeValue == null || (attributeValue instanceof String && StringUtils.isBlank((String) attributeValue))) { |
| 585 | 0 | Boolean required = getDataDictionaryService().isAttributeRequired(objectClassName, attributeName); |
| 586 | 0 | ControlDefinition controlDef = getDataDictionaryService().getAttributeControlDefinition(objectClassName, attributeName); |
| 587 | |
|
| 588 | 0 | if (required != null && required.booleanValue() && !(controlDef != null && controlDef.isHidden())) { |
| 589 | |
|
| 590 | |
|
| 591 | 0 | String errorLabel = getDataDictionaryService().getAttributeErrorLabel(objectClassName, attributeName); |
| 592 | 0 | GlobalVariables.getMessageMap().putError(errorKey, RiceKeyConstants.ERROR_REQUIRED, errorLabel); |
| 593 | |
} |
| 594 | |
} |
| 595 | 0 | } |
| 596 | |
|
| 597 | |
|
| 598 | |
|
| 599 | |
|
| 600 | |
|
| 601 | |
|
| 602 | |
|
| 603 | |
|
| 604 | |
private void validateBusinessObjectsFromDescriptors(Object object, PropertyDescriptor[] propertyDescriptors, int depth) { |
| 605 | 0 | for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { |
| 606 | |
|
| 607 | 0 | if (propertyDescriptor.getPropertyType() != null && PersistableBusinessObject.class.isAssignableFrom(propertyDescriptor.getPropertyType()) && ObjectUtils.getPropertyValue(object, propertyDescriptor.getName()) != null) { |
| 608 | 0 | BusinessObject bo = (BusinessObject) ObjectUtils.getPropertyValue(object, propertyDescriptor.getName()); |
| 609 | 0 | if (depth == 0) { |
| 610 | 0 | GlobalVariables.getMessageMap().addToErrorPath(propertyDescriptor.getName()); |
| 611 | 0 | validateBusinessObject(bo); |
| 612 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath(propertyDescriptor.getName()); |
| 613 | |
} |
| 614 | |
else { |
| 615 | 0 | validateBusinessObjectsRecursively(bo, depth - 1); |
| 616 | |
} |
| 617 | 0 | } |
| 618 | |
|
| 619 | |
|
| 620 | |
|
| 621 | |
|
| 622 | |
|
| 623 | 0 | else if (propertyDescriptor.getPropertyType() != null && (List.class).isAssignableFrom(propertyDescriptor.getPropertyType()) && ObjectUtils.getPropertyValue(object, propertyDescriptor.getName()) != null) { |
| 624 | 0 | List propertyList = (List) ObjectUtils.getPropertyValue(object, propertyDescriptor.getName()); |
| 625 | 0 | for (int j = 0; j < propertyList.size(); j++) { |
| 626 | 0 | if (propertyList.get(j) != null && propertyList.get(j) instanceof PersistableBusinessObject) { |
| 627 | 0 | if (depth == 0) { |
| 628 | 0 | GlobalVariables.getMessageMap().addToErrorPath(StringUtils.chomp(propertyDescriptor.getName(), "s") + "[" + (new Integer(j)).toString() + "]"); |
| 629 | 0 | validateBusinessObject((BusinessObject) propertyList.get(j)); |
| 630 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath(StringUtils.chomp(propertyDescriptor.getName(), "s") + "[" + (new Integer(j)).toString() + "]"); |
| 631 | |
} |
| 632 | |
else { |
| 633 | 0 | validateBusinessObjectsRecursively((BusinessObject) propertyList.get(j), depth - 1); |
| 634 | |
} |
| 635 | |
} |
| 636 | |
} |
| 637 | |
|
| 638 | |
} |
| 639 | |
} |
| 640 | 0 | } |
| 641 | |
|
| 642 | |
|
| 643 | |
|
| 644 | |
|
| 645 | |
|
| 646 | |
|
| 647 | |
|
| 648 | |
|
| 649 | |
|
| 650 | |
private void validatePrimitivesFromDescriptors(String entryName, Object object, PropertyDescriptor[] propertyDescriptors, String errorPrefix, boolean validateRequired) { |
| 651 | 0 | for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { |
| 652 | 0 | validatePrimitiveFromDescriptor(entryName, object, propertyDescriptor, errorPrefix, validateRequired); |
| 653 | |
} |
| 654 | 0 | } |
| 655 | |
|
| 656 | |
|
| 657 | |
|
| 658 | |
|
| 659 | |
|
| 660 | |
|
| 661 | |
|
| 662 | |
|
| 663 | |
|
| 664 | |
@Override |
| 665 | |
public void validatePrimitiveFromDescriptor(String entryName, Object object, PropertyDescriptor propertyDescriptor, String errorPrefix, boolean validateRequired) { |
| 666 | |
|
| 667 | 0 | if (null != propertyDescriptor && getDataDictionaryService().isAttributeDefined(entryName, propertyDescriptor.getName())) { |
| 668 | 0 | Object value = ObjectUtils.getPropertyValue(object, propertyDescriptor.getName()); |
| 669 | 0 | Class propertyType = propertyDescriptor.getPropertyType(); |
| 670 | |
|
| 671 | 0 | if (TypeUtils.isStringClass(propertyType) || TypeUtils.isIntegralClass(propertyType) || TypeUtils.isDecimalClass(propertyType) || TypeUtils.isTemporalClass(propertyType)) { |
| 672 | |
|
| 673 | |
|
| 674 | 0 | if (value != null && StringUtils.isNotBlank(value.toString())) { |
| 675 | 0 | if (!TypeUtils.isTemporalClass(propertyType)) { |
| 676 | 0 | validateAttributeFormat(entryName, propertyDescriptor.getName(), value.toString(), errorPrefix + propertyDescriptor.getName()); |
| 677 | |
} |
| 678 | |
} |
| 679 | 0 | else if (validateRequired) { |
| 680 | 0 | validateAttributeRequired(entryName, propertyDescriptor.getName(), value, Boolean.FALSE, errorPrefix + propertyDescriptor.getName()); |
| 681 | |
} |
| 682 | |
} |
| 683 | |
} |
| 684 | 0 | } |
| 685 | |
|
| 686 | |
|
| 687 | |
|
| 688 | |
|
| 689 | |
|
| 690 | |
@Override |
| 691 | |
public boolean validateReferenceExists(BusinessObject bo, ReferenceDefinition reference) { |
| 692 | 0 | return validateReferenceExists(bo, reference.getAttributeName()); |
| 693 | |
} |
| 694 | |
|
| 695 | |
|
| 696 | |
|
| 697 | |
|
| 698 | |
|
| 699 | |
@Override |
| 700 | |
public boolean validateReferenceExists(BusinessObject bo, String referenceName) { |
| 701 | |
|
| 702 | |
|
| 703 | 0 | BusinessObject referenceBo = businessObjectService.getReferenceIfExists(bo, referenceName); |
| 704 | |
|
| 705 | |
|
| 706 | 0 | if (ObjectUtils.isNotNull(referenceBo)) { |
| 707 | 0 | return true; |
| 708 | |
} |
| 709 | |
|
| 710 | |
|
| 711 | |
else { |
| 712 | 0 | return false; |
| 713 | |
} |
| 714 | |
|
| 715 | |
} |
| 716 | |
|
| 717 | |
|
| 718 | |
|
| 719 | |
|
| 720 | |
|
| 721 | |
@Override |
| 722 | |
public boolean validateReferenceIsActive(BusinessObject bo, ReferenceDefinition reference) { |
| 723 | 0 | return validateReferenceIsActive(bo, reference.getAttributeName()); |
| 724 | |
} |
| 725 | |
|
| 726 | |
|
| 727 | |
|
| 728 | |
|
| 729 | |
|
| 730 | |
@Override |
| 731 | |
public boolean validateReferenceIsActive(BusinessObject bo, String referenceName) { |
| 732 | |
|
| 733 | |
|
| 734 | 0 | BusinessObject referenceBo = businessObjectService.getReferenceIfExists(bo, referenceName); |
| 735 | 0 | if (referenceBo == null) { |
| 736 | 0 | return false; |
| 737 | |
} |
| 738 | 0 | if (!(referenceBo instanceof Inactivateable) || ((Inactivateable) referenceBo).isActive()) { |
| 739 | 0 | return true; |
| 740 | |
}else{ |
| 741 | 0 | return false; |
| 742 | |
} |
| 743 | |
} |
| 744 | |
|
| 745 | |
|
| 746 | |
|
| 747 | |
|
| 748 | |
|
| 749 | |
@Override |
| 750 | |
public boolean validateReferenceExistsAndIsActive(BusinessObject bo, ReferenceDefinition reference) { |
| 751 | 0 | boolean success = true; |
| 752 | |
|
| 753 | |
|
| 754 | |
String displayFieldName; |
| 755 | 0 | if (reference.isDisplayFieldNameSet()) { |
| 756 | 0 | displayFieldName = reference.getDisplayFieldName(); |
| 757 | |
} |
| 758 | |
else { |
| 759 | 0 | Class boClass = reference.isCollectionReference() ? reference.getCollectionBusinessObjectClass() : bo.getClass(); |
| 760 | 0 | displayFieldName = dataDictionaryService.getAttributeLabel(boClass, reference.getAttributeToHighlightOnFail()); |
| 761 | |
} |
| 762 | |
|
| 763 | 0 | if (reference.isCollectionReference()) { |
| 764 | 0 | success = validateCollectionReferenceExistsAndIsActive(bo, reference, displayFieldName, StringUtils.split(reference.getCollection(), "."), null); |
| 765 | |
} |
| 766 | |
else { |
| 767 | 0 | success = validateReferenceExistsAndIsActive(bo, reference.getAttributeName(),reference.getAttributeToHighlightOnFail(), displayFieldName); |
| 768 | |
} |
| 769 | 0 | return success; |
| 770 | |
} |
| 771 | |
|
| 772 | |
|
| 773 | |
|
| 774 | |
|
| 775 | |
|
| 776 | |
|
| 777 | |
|
| 778 | |
|
| 779 | |
|
| 780 | |
|
| 781 | |
private boolean validateCollectionReferenceExistsAndIsActive(BusinessObject bo, ReferenceDefinition reference, String displayFieldName, String[] intermediateCollections, String pathToAttributeI) { |
| 782 | 0 | boolean success = true; |
| 783 | |
Collection<PersistableBusinessObject> referenceCollection; |
| 784 | 0 | String collectionName = intermediateCollections[0]; |
| 785 | |
|
| 786 | 0 | intermediateCollections = (String[]) ArrayUtils.removeElement(intermediateCollections, collectionName); |
| 787 | |
try { |
| 788 | 0 | referenceCollection = (Collection) PropertyUtils.getProperty(bo, collectionName); |
| 789 | |
} |
| 790 | 0 | catch (Exception e) { |
| 791 | 0 | throw new RuntimeException(e); |
| 792 | 0 | } |
| 793 | 0 | int pos = 0; |
| 794 | 0 | Iterator<PersistableBusinessObject> iterator = referenceCollection.iterator(); |
| 795 | 0 | while (iterator.hasNext()) { |
| 796 | 0 | String pathToAttribute = StringUtils.defaultString(pathToAttributeI) + collectionName + "[" + (pos++) + "]."; |
| 797 | |
|
| 798 | 0 | if (intermediateCollections.length > 0) { |
| 799 | 0 | success &= validateCollectionReferenceExistsAndIsActive(iterator.next(), reference, displayFieldName, intermediateCollections, pathToAttribute); |
| 800 | |
} |
| 801 | |
else { |
| 802 | 0 | String attributeToHighlightOnFail = pathToAttribute + reference.getAttributeToHighlightOnFail(); |
| 803 | 0 | success &= validateReferenceExistsAndIsActive(iterator.next(), reference.getAttributeName(), attributeToHighlightOnFail, displayFieldName); |
| 804 | |
} |
| 805 | 0 | } |
| 806 | |
|
| 807 | 0 | return success; |
| 808 | |
|
| 809 | |
} |
| 810 | |
|
| 811 | |
|
| 812 | |
|
| 813 | |
|
| 814 | |
|
| 815 | |
|
| 816 | |
@Override |
| 817 | |
public boolean validateReferenceExistsAndIsActive(BusinessObject bo, String referenceName, String attributeToHighlightOnFail, String displayFieldName) { |
| 818 | |
|
| 819 | |
|
| 820 | |
|
| 821 | |
|
| 822 | 0 | if (ObjectUtils.isNestedAttribute(referenceName)) { |
| 823 | 0 | String nestedAttributePrefix = ObjectUtils.getNestedAttributePrefix(referenceName); |
| 824 | 0 | String nestedAttributePrimitive = ObjectUtils.getNestedAttributePrimitive(referenceName); |
| 825 | 0 | Object nestedObject = ObjectUtils.getPropertyValue(bo, nestedAttributePrefix); |
| 826 | 0 | if (!(nestedObject instanceof BusinessObject)) { |
| 827 | 0 | throw new ObjectNotABusinessObjectRuntimeException("Attribute requested (" + nestedAttributePrefix + ") is of class: " + "'" + nestedObject.getClass().getName() + "' and is not a " + "descendent of BusinessObject."); |
| 828 | |
} |
| 829 | 0 | return validateReferenceExistsAndIsActive((BusinessObject)nestedObject, nestedAttributePrimitive, attributeToHighlightOnFail, displayFieldName); |
| 830 | |
} |
| 831 | |
|
| 832 | 0 | boolean success = true; |
| 833 | |
boolean exists; |
| 834 | |
boolean active; |
| 835 | |
|
| 836 | 0 | boolean fkFieldsPopulated = true; |
| 837 | |
|
| 838 | 0 | List<String> fkFields = getDataDictionaryService().getRelationshipSourceAttributes(bo.getClass().getName(), referenceName); |
| 839 | 0 | if (fkFields != null) { |
| 840 | 0 | for (String fkFieldName : fkFields) { |
| 841 | 0 | Object fkFieldValue = null; |
| 842 | |
try { |
| 843 | 0 | fkFieldValue = PropertyUtils.getProperty(bo, fkFieldName); |
| 844 | |
} |
| 845 | |
|
| 846 | |
|
| 847 | 0 | catch (IllegalAccessException e) { |
| 848 | 0 | fkFieldsPopulated = false; |
| 849 | |
} |
| 850 | 0 | catch (InvocationTargetException e) { |
| 851 | 0 | fkFieldsPopulated = false; |
| 852 | |
} |
| 853 | 0 | catch (NoSuchMethodException e) { |
| 854 | 0 | fkFieldsPopulated = false; |
| 855 | 0 | } |
| 856 | |
|
| 857 | |
|
| 858 | 0 | if (fkFieldValue == null) { |
| 859 | 0 | fkFieldsPopulated = false; |
| 860 | |
} |
| 861 | 0 | else if (String.class.isAssignableFrom(fkFieldValue.getClass())) { |
| 862 | 0 | if (StringUtils.isBlank((String) fkFieldValue)) { |
| 863 | 0 | fkFieldsPopulated = false; |
| 864 | |
} |
| 865 | |
} |
| 866 | 0 | } |
| 867 | |
} |
| 868 | 0 | else if ( bo instanceof PersistableBusinessObject ) { |
| 869 | 0 | fkFieldsPopulated = persistenceService.allForeignKeyValuesPopulatedForReference((PersistableBusinessObject)bo, referenceName); |
| 870 | |
} |
| 871 | |
|
| 872 | |
|
| 873 | 0 | if (fkFieldsPopulated) { |
| 874 | |
|
| 875 | |
|
| 876 | 0 | exists = validateReferenceExists(bo, referenceName); |
| 877 | 0 | if (exists) { |
| 878 | |
|
| 879 | |
|
| 880 | 0 | if (!(bo instanceof Inactivateable) || ((Inactivateable) bo).isActive()) { |
| 881 | 0 | active = validateReferenceIsActive(bo, referenceName); |
| 882 | 0 | if (!active) { |
| 883 | 0 | GlobalVariables.getMessageMap().putError(attributeToHighlightOnFail, RiceKeyConstants.ERROR_INACTIVE, displayFieldName); |
| 884 | 0 | success &= false; |
| 885 | |
} |
| 886 | |
} |
| 887 | |
} |
| 888 | |
else { |
| 889 | 0 | GlobalVariables.getMessageMap().putError(attributeToHighlightOnFail, RiceKeyConstants.ERROR_EXISTENCE, displayFieldName); |
| 890 | 0 | success &= false; |
| 891 | |
} |
| 892 | |
} |
| 893 | 0 | return success; |
| 894 | |
} |
| 895 | |
|
| 896 | |
|
| 897 | |
|
| 898 | |
|
| 899 | |
@Override |
| 900 | |
public boolean validateDefaultExistenceChecks(BusinessObject bo) { |
| 901 | |
|
| 902 | 0 | boolean success = true; |
| 903 | |
|
| 904 | |
|
| 905 | 0 | Collection references = maintenanceDocumentDictionaryService.getDefaultExistenceChecks(bo.getClass()); |
| 906 | |
|
| 907 | |
|
| 908 | 0 | for (Iterator iter = references.iterator(); iter.hasNext();) { |
| 909 | 0 | ReferenceDefinition reference = (ReferenceDefinition) iter.next(); |
| 910 | |
|
| 911 | |
|
| 912 | 0 | success &= validateReferenceExistsAndIsActive(bo, reference); |
| 913 | 0 | } |
| 914 | 0 | return success; |
| 915 | |
} |
| 916 | |
|
| 917 | |
|
| 918 | |
|
| 919 | |
|
| 920 | |
@Override |
| 921 | |
public boolean validateDefaultExistenceChecksForNewCollectionItem(BusinessObject bo, BusinessObject newCollectionItem, |
| 922 | |
String collectionName) { |
| 923 | 0 | boolean success = true; |
| 924 | |
|
| 925 | 0 | if (StringUtils.isNotBlank(collectionName)) { |
| 926 | |
|
| 927 | 0 | Collection references = maintenanceDocumentDictionaryService.getDefaultExistenceChecks(bo.getClass()); |
| 928 | |
|
| 929 | |
|
| 930 | 0 | for (Iterator iter = references.iterator(); iter.hasNext();) { |
| 931 | 0 | ReferenceDefinition reference = (ReferenceDefinition) iter.next(); |
| 932 | 0 | if(collectionName != null && collectionName.equals(reference.getCollection())){ |
| 933 | |
String displayFieldName; |
| 934 | 0 | if (reference.isDisplayFieldNameSet()) { |
| 935 | 0 | displayFieldName = reference.getDisplayFieldName(); |
| 936 | |
} |
| 937 | |
else { |
| 938 | 0 | Class boClass = reference.isCollectionReference() ? reference.getCollectionBusinessObjectClass() : bo.getClass(); |
| 939 | 0 | displayFieldName = dataDictionaryService.getAttributeLabel(boClass, reference.getAttributeToHighlightOnFail()); |
| 940 | |
} |
| 941 | |
|
| 942 | 0 | success &= validateReferenceExistsAndIsActive(newCollectionItem, reference.getAttributeName(), reference.getAttributeToHighlightOnFail(), displayFieldName); |
| 943 | |
} |
| 944 | 0 | } |
| 945 | |
} |
| 946 | |
|
| 947 | 0 | return success; |
| 948 | |
} |
| 949 | |
|
| 950 | |
|
| 951 | |
|
| 952 | |
|
| 953 | |
|
| 954 | |
|
| 955 | |
@Override |
| 956 | |
public boolean validateDefaultExistenceChecksForTransDoc(TransactionalDocument document) { |
| 957 | 0 | boolean success = true; |
| 958 | |
|
| 959 | |
|
| 960 | 0 | Collection references = transactionalDocumentDictionaryService.getDefaultExistenceChecks(document); |
| 961 | |
|
| 962 | |
|
| 963 | 0 | for (Iterator iter = references.iterator(); iter.hasNext();) { |
| 964 | 0 | ReferenceDefinition reference = (ReferenceDefinition) iter.next(); |
| 965 | |
|
| 966 | |
|
| 967 | 0 | success &= validateReferenceExistsAndIsActive(document, reference); |
| 968 | 0 | } |
| 969 | 0 | return success; |
| 970 | |
} |
| 971 | |
|
| 972 | |
|
| 973 | |
|
| 974 | |
|
| 975 | |
|
| 976 | |
|
| 977 | |
|
| 978 | |
@Override |
| 979 | |
public boolean validateDefaultExistenceChecksForNewCollectionItem( |
| 980 | |
TransactionalDocument document, |
| 981 | |
BusinessObject newCollectionItem, String collectionName) { |
| 982 | 0 | boolean success = true; |
| 983 | 0 | if (StringUtils.isNotBlank(collectionName)) { |
| 984 | |
|
| 985 | 0 | Collection references = transactionalDocumentDictionaryService.getDefaultExistenceChecks(document); |
| 986 | |
|
| 987 | |
|
| 988 | 0 | for (Iterator iter = references.iterator(); iter.hasNext();) { |
| 989 | 0 | ReferenceDefinition reference = (ReferenceDefinition) iter.next(); |
| 990 | 0 | if(collectionName != null && collectionName.equals(reference.getCollection())){ |
| 991 | |
String displayFieldName; |
| 992 | 0 | if (reference.isDisplayFieldNameSet()) { |
| 993 | 0 | displayFieldName = reference.getDisplayFieldName(); |
| 994 | |
} |
| 995 | |
else { |
| 996 | 0 | Class boClass = reference.isCollectionReference() ? reference.getCollectionBusinessObjectClass() : document.getClass(); |
| 997 | 0 | displayFieldName = dataDictionaryService.getAttributeLabel(boClass, reference.getAttributeToHighlightOnFail()); |
| 998 | |
} |
| 999 | |
|
| 1000 | 0 | success &= validateReferenceExistsAndIsActive(newCollectionItem, reference.getAttributeName(), reference.getAttributeToHighlightOnFail(), displayFieldName); |
| 1001 | |
} |
| 1002 | 0 | } |
| 1003 | |
} |
| 1004 | 0 | return success; |
| 1005 | |
} |
| 1006 | |
|
| 1007 | |
|
| 1008 | |
|
| 1009 | |
|
| 1010 | |
|
| 1011 | |
|
| 1012 | |
|
| 1013 | |
public DataDictionaryService getDataDictionaryService() { |
| 1014 | 0 | return dataDictionaryService; |
| 1015 | |
} |
| 1016 | |
|
| 1017 | |
|
| 1018 | |
|
| 1019 | |
|
| 1020 | |
public void setDataDictionaryService(DataDictionaryService dataDictionaryService) { |
| 1021 | 0 | this.dataDictionaryService = dataDictionaryService; |
| 1022 | 0 | } |
| 1023 | |
|
| 1024 | |
|
| 1025 | |
|
| 1026 | |
|
| 1027 | |
|
| 1028 | |
|
| 1029 | |
public void setBusinessObjectService(BusinessObjectService businessObjectService) { |
| 1030 | 0 | this.businessObjectService = businessObjectService; |
| 1031 | 0 | } |
| 1032 | |
|
| 1033 | |
|
| 1034 | |
|
| 1035 | |
|
| 1036 | |
|
| 1037 | |
|
| 1038 | |
public void setMaintenanceDocumentDictionaryService(MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService) { |
| 1039 | 0 | this.maintenanceDocumentDictionaryService = maintenanceDocumentDictionaryService; |
| 1040 | 0 | } |
| 1041 | |
|
| 1042 | |
|
| 1043 | |
|
| 1044 | |
|
| 1045 | |
|
| 1046 | |
public void setTransactionalDocumentDictionaryService( |
| 1047 | |
TransactionalDocumentDictionaryService transactionalDocumentDictionaryService) { |
| 1048 | 0 | this.transactionalDocumentDictionaryService = transactionalDocumentDictionaryService; |
| 1049 | 0 | } |
| 1050 | |
|
| 1051 | |
|
| 1052 | |
|
| 1053 | |
|
| 1054 | |
|
| 1055 | |
|
| 1056 | |
|
| 1057 | |
public void setPersistenceService(PersistenceService persistenceService) { |
| 1058 | 0 | this.persistenceService = persistenceService; |
| 1059 | 0 | } |
| 1060 | |
|
| 1061 | |
public void setPersistenceStructureService(PersistenceStructureService persistenceStructureService) { |
| 1062 | 0 | this.persistenceStructureService = persistenceStructureService; |
| 1063 | 0 | } |
| 1064 | |
|
| 1065 | |
private WorkflowAttributePropertyResolutionService getWorkflowAttributePropertyResolutionService() { |
| 1066 | 0 | if (workflowAttributePropertyResolutionService == null) { |
| 1067 | 0 | workflowAttributePropertyResolutionService = KNSServiceLocatorInternal.getWorkflowAttributePropertyResolutionService(); |
| 1068 | |
} |
| 1069 | 0 | return workflowAttributePropertyResolutionService; |
| 1070 | |
} |
| 1071 | |
} |