Search in sources :

Example 1 with PropertyConstraint

use of eu.esdihumboldt.hale.common.schema.model.PropertyConstraint in project hale by halestudio.

the class InstanceValidator method validateProperty.

/**
 * Validates the given property values against their
 * {@link PropertyDefinition}.<br>
 * Then calls
 * {@link #validateChildren(Object[], ChildDefinition, InstanceValidationReporter, QName, List, boolean, InstanceReference, InstanceValidationContext, EntityDefinition)}
 * .
 *
 * @param properties the array of existing properties, may be null
 * @param propertyDef their definition
 * @param reporter the reporter to report to
 * @param type the top level type
 * @param path the current property path
 * @param reference the instance reference
 * @param context the instance validation context
 * @param entity the property's entity definition or <code>null</code>
 */
@SuppressWarnings("unchecked")
private void validateProperty(Object[] properties, PropertyDefinition propertyDef, InstanceValidationReporter reporter, QName type, List<QName> path, InstanceReference reference, InstanceValidationContext context, @Nullable EntityDefinition entity) {
    ValidationLocation loc = new ValidationLocation(reference, type, new ArrayList<QName>(path));
    // property constraint validators
    for (Entry<Class<PropertyConstraint>, PropertyConstraintValidator> entry : ConstraintValidatorExtension.getInstance().getPropertyConstraintValidators().entrySet()) {
        try {
            entry.getValue().validatePropertyConstraint(properties, propertyDef.getConstraint((Class<? extends PropertyConstraint>) ConstraintUtil.getConstraintType(entry.getKey())), propertyDef, context, loc);
        } catch (ValidationException vE) {
            reporter.warn(new DefaultInstanceValidationMessage(loc, entry.getKey().getSimpleName(), vE.getMessage()));
        }
    }
    if (properties != null) {
        // generic validators
        for (InstanceModelValidator validator : additionalValidators) {
            for (Object value : properties) {
                // visit each value
                if (value instanceof Instance) {
                    try {
                        validator.validateInstance((Instance) value, entity, context);
                    } catch (ValidationException vE) {
                        reporter.warn(new DefaultInstanceValidationMessage(reference, type, new ArrayList<QName>(path), validator.getCategory(), vE.getMessage()));
                    }
                } else {
                    try {
                        validator.validateProperty(value, propertyDef, entity, context);
                    } catch (ValidationException vE) {
                        reporter.warn(new DefaultInstanceValidationMessage(reference, type, new ArrayList<QName>(path), validator.getCategory(), vE.getMessage()));
                    }
                }
            }
        }
    }
    validateChildren(properties, propertyDef, reporter, type, path, false, reference, context, entity);
}
Also used : GroupPropertyConstraint(eu.esdihumboldt.hale.common.schema.model.GroupPropertyConstraint) PropertyConstraint(eu.esdihumboldt.hale.common.schema.model.PropertyConstraint) ValidationException(eu.esdihumboldt.hale.common.instance.extension.validation.ValidationException) MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) QName(javax.xml.namespace.QName) DefaultInstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationMessage) ValidationLocation(eu.esdihumboldt.hale.common.instance.extension.validation.ValidationLocation) GroupPropertyConstraintValidator(eu.esdihumboldt.hale.common.instance.extension.validation.GroupPropertyConstraintValidator) PropertyConstraintValidator(eu.esdihumboldt.hale.common.instance.extension.validation.PropertyConstraintValidator)

Aggregations

GroupPropertyConstraintValidator (eu.esdihumboldt.hale.common.instance.extension.validation.GroupPropertyConstraintValidator)1 PropertyConstraintValidator (eu.esdihumboldt.hale.common.instance.extension.validation.PropertyConstraintValidator)1 ValidationException (eu.esdihumboldt.hale.common.instance.extension.validation.ValidationException)1 ValidationLocation (eu.esdihumboldt.hale.common.instance.extension.validation.ValidationLocation)1 DefaultInstanceValidationMessage (eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationMessage)1 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)1 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)1 DefaultInstance (eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance)1 GroupPropertyConstraint (eu.esdihumboldt.hale.common.schema.model.GroupPropertyConstraint)1 PropertyConstraint (eu.esdihumboldt.hale.common.schema.model.PropertyConstraint)1 QName (javax.xml.namespace.QName)1