Search in sources :

Example 1 with DefaultInstanceValidationReporter

use of eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationReporter in project hale by halestudio.

the class InstanceValidator method validateInstances.

/**
 * Validates the given instances using all constraints that are validatable.
 *
 * @param instances the instances to validate
 * @param monitor the progress monitor
 * @return a report of the validation
 */
public InstanceValidationReport validateInstances(InstanceCollection instances, IProgressMonitor monitor) {
    monitor.beginTask("Instance validation", instances.hasSize() ? instances.size() : IProgressMonitor.UNKNOWN);
    InstanceValidationReporter reporter = new DefaultInstanceValidationReporter(false);
    reporter.setSuccess(false);
    ATransaction trans = log.begin("Instance validation");
    InstanceValidationContext context = new InstanceValidationContext();
    ResourceIterator<Instance> iterator = instances.iterator();
    try {
        while (iterator.hasNext()) {
            if (monitor.isCanceled())
                return reporter;
            Instance instance = iterator.next();
            validateInstance(instance, reporter, instance.getDefinition().getName(), new ArrayList<QName>(), false, instances.getReference(instance), context, null, null);
            monitor.worked(1);
        }
    } finally {
        iterator.close();
        trans.end();
    }
    validateContext(context, reporter);
    reporter.setSuccess(true);
    return reporter;
}
Also used : InstanceValidationReporter(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReporter) DefaultInstanceValidationReporter(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationReporter) 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) ATransaction(de.fhg.igd.slf4jplus.ATransaction) DefaultInstanceValidationReporter(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationReporter) InstanceValidationContext(eu.esdihumboldt.hale.common.instance.extension.validation.InstanceValidationContext)

Example 2 with DefaultInstanceValidationReporter

use of eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationReporter in project hale by halestudio.

the class InstanceValidator method validate.

/**
 * Validates the given object. The created reports messages do not have an
 * {@link InstanceReference} set.
 *
 * @param object the object to validate (i. e. an instance, group or basic
 *            value)
 * @param childDef the child definition of the given object
 * @return a report of the validation
 */
public InstanceValidationReporter validate(Object object, ChildDefinition<?> childDef) {
    InstanceValidationReporter reporter = new DefaultInstanceValidationReporter(false);
    reporter.setSuccess(false);
    InstanceValidationContext context = new InstanceValidationContext();
    // first a special case for Choice-Flag
    // XXX a better way to do this than coding this special case?
    boolean onlyCheckExistingChildren = false;
    if (childDef.asGroup() != null) {
        GroupPropertyConstraintValidator validator = ConstraintValidatorExtension.getInstance().getGroupPropertyConstraintValidators().get(ChoiceFlag.class);
        if (validator != null)
            try {
                validator.validateGroupPropertyConstraint(new Object[] { object }, childDef.asGroup().getConstraint(ChoiceFlag.class), childDef.asGroup(), context);
            } catch (ValidationException vE) {
                reporter.warn(new DefaultInstanceValidationMessage(null, null, Collections.<QName>emptyList(), ChoiceFlag.class.getSimpleName(), vE.getMessage()));
            }
        onlyCheckExistingChildren = childDef.asGroup().getConstraint(ChoiceFlag.class).isEnabled();
    }
    // then validate the object as if it were a lone property value
    validateChildren(new Object[] { object }, childDef, reporter, null, new ArrayList<QName>(), onlyCheckExistingChildren, null, context, null);
    reporter.setSuccess(true);
    return reporter;
}
Also used : ValidationException(eu.esdihumboldt.hale.common.instance.extension.validation.ValidationException) InstanceValidationReporter(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReporter) DefaultInstanceValidationReporter(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationReporter) QName(javax.xml.namespace.QName) DefaultInstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationMessage) DefaultInstanceValidationReporter(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationReporter) InstanceValidationContext(eu.esdihumboldt.hale.common.instance.extension.validation.InstanceValidationContext) GroupPropertyConstraintValidator(eu.esdihumboldt.hale.common.instance.extension.validation.GroupPropertyConstraintValidator)

Example 3 with DefaultInstanceValidationReporter

use of eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationReporter in project hale by halestudio.

the class InstanceValidator method validate.

/**
 * Validates the given {@link Instance}. The created reports messages do not
 * have an {@link InstanceReference} set.
 *
 * @param instance the instance to validate
 * @return a report of the validation
 */
public InstanceValidationReporter validate(Instance instance) {
    InstanceValidationReporter reporter = new DefaultInstanceValidationReporter(false);
    reporter.setSuccess(false);
    InstanceValidationContext context = new InstanceValidationContext();
    validateInstance(instance, reporter, instance.getDefinition().getName(), new ArrayList<QName>(), false, null, context, null, null);
    reporter.setSuccess(true);
    return reporter;
}
Also used : InstanceValidationReporter(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReporter) DefaultInstanceValidationReporter(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationReporter) QName(javax.xml.namespace.QName) DefaultInstanceValidationReporter(eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationReporter) InstanceValidationContext(eu.esdihumboldt.hale.common.instance.extension.validation.InstanceValidationContext)

Aggregations

InstanceValidationContext (eu.esdihumboldt.hale.common.instance.extension.validation.InstanceValidationContext)3 InstanceValidationReporter (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReporter)3 DefaultInstanceValidationReporter (eu.esdihumboldt.hale.common.instance.extension.validation.report.impl.DefaultInstanceValidationReporter)3 QName (javax.xml.namespace.QName)3 ATransaction (de.fhg.igd.slf4jplus.ATransaction)1 GroupPropertyConstraintValidator (eu.esdihumboldt.hale.common.instance.extension.validation.GroupPropertyConstraintValidator)1 ValidationException (eu.esdihumboldt.hale.common.instance.extension.validation.ValidationException)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