Search in sources :

Example 1 with Validator

use of org.openforis.idm.metamodel.validation.Validator in project collect by openforis.

the class RecordUpdater method validateCardinality.

private Set<NodePointer> validateCardinality(Record record, Collection<NodePointer> pointers, NodeChangeMap changeMap) {
    Set<NodePointer> updatedPointers = new HashSet<NodePointer>();
    Validator validator = record.getSurveyContext().getValidator();
    for (NodePointer nodePointer : pointers) {
        Entity entity = nodePointer.getEntity();
        NodeDefinition childDef = nodePointer.getChildDefinition();
        ValidationResultFlag minCountResult, maxCountResult;
        if (entity.isRelevant(childDef)) {
            minCountResult = validator.validateMinCount(entity, childDef);
            maxCountResult = validator.validateMaxCount(entity, childDef);
        } else {
            minCountResult = maxCountResult = ValidationResultFlag.OK;
        }
        if (entity.getMinCountValidationResult(childDef) != minCountResult) {
            entity.setMinCountValidationResult(childDef, minCountResult);
            changeMap.addMinCountValidationResultChange(nodePointer, minCountResult);
            updatedPointers.add(nodePointer);
        }
        if (entity.getMaxCountValidationResult(childDef) != maxCountResult) {
            entity.setMaxCountValidationResult(childDef, maxCountResult);
            changeMap.addMaxCountValidationResultChange(nodePointer, maxCountResult);
            updatedPointers.add(nodePointer);
        }
    }
    return updatedPointers;
}
Also used : Entity(org.openforis.idm.model.Entity) ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NodePointer(org.openforis.idm.model.NodePointer) Validator(org.openforis.idm.metamodel.validation.Validator) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with Validator

use of org.openforis.idm.metamodel.validation.Validator in project collect by openforis.

the class RecordUpdater method validateAttributes.

private void validateAttributes(Record record, Set<Attribute<?, ?>> attributes, NodeChangeMap changeMap) {
    Validator validator = record.getSurveyContext().getValidator();
    for (Attribute<?, ?> a : attributes) {
        ValidationResults validationResults;
        if (a.isRelevant()) {
            validationResults = validator.validate(a);
        } else {
            validationResults = new ValidationResults();
        }
        a.setValidationResults(validationResults);
        changeMap.addValidationResultChange(a, validationResults);
    }
}
Also used : ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) Validator(org.openforis.idm.metamodel.validation.Validator)

Aggregations

Validator (org.openforis.idm.metamodel.validation.Validator)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)1 ValidationResultFlag (org.openforis.idm.metamodel.validation.ValidationResultFlag)1 ValidationResults (org.openforis.idm.metamodel.validation.ValidationResults)1 Entity (org.openforis.idm.model.Entity)1 NodePointer (org.openforis.idm.model.NodePointer)1