use of eu.esdihumboldt.hale.common.instance.extension.validation.InstanceValidationContext 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;
}
use of eu.esdihumboldt.hale.common.instance.extension.validation.InstanceValidationContext 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;
}
use of eu.esdihumboldt.hale.common.instance.extension.validation.InstanceValidationContext 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;
}
Aggregations