Search in sources :

Example 1 with CustomCheck

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

the class SurveyValidator method validateCheck.

private List<SurveyValidationResult> validateCheck(AttributeDefinition node, Check<?> check) {
    List<SurveyValidationResult> results = new ArrayList<SurveyValidationResult>();
    // validate condition expression
    addBooleanExpressionValidationResult(results, node, check.getCondition(), "survey.validation.check.error.invalid_condition_expression");
    if (check instanceof ComparisonCheck) {
        addBooleanExpressionValidationResult(results, node, ((ComparisonCheck) check).getExpression(), "survey.validation.check.comparison.error.invalid_comparison_expression");
    } else if (check instanceof CustomCheck) {
        addBooleanExpressionValidationResult(results, node, ((CustomCheck) check).getExpression(), "survey.validation.check.custom.error.error.invalid_custom_expression");
    } else if (check instanceof DistanceCheck) {
        // validate source point
        addValueExpressionValidationResult(results, node, ((DistanceCheck) check).getSourcePointExpression(), "survey.validation.check.distance.error.invalid_source_point_expression");
        // validate destination point
        addValueExpressionValidationResult(results, node, ((DistanceCheck) check).getDestinationPointExpression(), "survey.validation.check.distance.error.invalid_destination_point_expression");
        // validate min distance
        addValueExpressionValidationResult(results, node, ((DistanceCheck) check).getMinDistanceExpression(), "survey.validation.check.distance.error.invalid_min_distance_expression");
        // validate max distance
        addValueExpressionValidationResult(results, node, ((DistanceCheck) check).getMaxDistanceExpression(), "survey.validation.check.distance.error.invalid_max_distance_expression");
    } else if (check instanceof PatternCheck) {
        String regEx = ((PatternCheck) check).getRegularExpression();
        if (StringUtils.isNotBlank(regEx)) {
            ExpressionValidationResult result = expressionValidator.validateRegularExpression(regEx);
            if (result.isError()) {
                results.add(new SurveyValidationResult(node.getPath(), "survey.validation.check.pattern.error.invalid_pattern_expression", result.getMessage()));
            }
        }
    } else if (check instanceof UniquenessCheck) {
        String expression = ((UniquenessCheck) check).getExpression();
        if (StringUtils.isNotBlank(expression)) {
            ExpressionValidationResult result = expressionValidator.validateUniquenessExpression(node.getParentEntityDefinition(), node, expression);
            if (result.isError()) {
                results.add(new SurveyValidationResult(node.getPath(), "survey.validation.check.uniqueness.error.invalid_uniqueness_expression", result.getMessage()));
            }
        }
    }
    return results;
}
Also used : PatternCheck(org.openforis.idm.metamodel.validation.PatternCheck) CustomCheck(org.openforis.idm.metamodel.validation.CustomCheck) DistanceCheck(org.openforis.idm.metamodel.validation.DistanceCheck) UniquenessCheck(org.openforis.idm.metamodel.validation.UniquenessCheck) ArrayList(java.util.ArrayList) ComparisonCheck(org.openforis.idm.metamodel.validation.ComparisonCheck) ExpressionValidationResult(org.openforis.idm.metamodel.expression.ExpressionValidator.ExpressionValidationResult)

Example 2 with CustomCheck

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

the class StateDependencyMap method registerDependencies.

private void registerDependencies(AttributeDefinition attributeDefinition) {
    List<AttributeDefault> attributeDefaults = attributeDefinition.getAttributeDefaults();
    for (AttributeDefault attributeDefault : attributeDefaults) {
        registerDependencies(attributeDefinition, attributeDefault.getCondition(), defaultValueDependencies);
        registerDependencies(attributeDefinition, attributeDefault.getExpression(), defaultValueDependencies);
    }
    List<Check> checks = attributeDefinition.getChecks();
    for (Check check : checks) {
        registerDependencies(attributeDefinition, check.getCondition(), checkDependencies);
        if (check instanceof ComparisonCheck) {
            registerDependencies(attributeDefinition, ((ComparisonCheck) check).getEqualsExpression(), checkDependencies);
            registerDependencies(attributeDefinition, ((ComparisonCheck) check).getLessThanExpression(), checkDependencies);
            registerDependencies(attributeDefinition, ((ComparisonCheck) check).getLessThanOrEqualsExpression(), checkDependencies);
            registerDependencies(attributeDefinition, ((ComparisonCheck) check).getGreaterThanExpression(), checkDependencies);
            registerDependencies(attributeDefinition, ((ComparisonCheck) check).getGreaterThanOrEqualsExpression(), checkDependencies);
        } else if (check instanceof CustomCheck) {
            registerDependencies(attributeDefinition, ((CustomCheck) check).getExpression(), checkDependencies);
        } else if (check instanceof DistanceCheck) {
            registerDependencies(attributeDefinition, ((DistanceCheck) check).getDestinationPointExpression(), checkDependencies);
            registerDependencies(attributeDefinition, ((DistanceCheck) check).getMaxDistanceExpression(), checkDependencies);
            registerDependencies(attributeDefinition, ((DistanceCheck) check).getMinDistanceExpression(), checkDependencies);
            registerDependencies(attributeDefinition, ((DistanceCheck) check).getSourcePointExpression(), checkDependencies);
        } else if (check instanceof UniquenessCheck) {
            registerDependencies(attributeDefinition, ((UniquenessCheck) check).getExpression(), checkDependencies);
        }
    }
}
Also used : CustomCheck(org.openforis.idm.metamodel.validation.CustomCheck) DistanceCheck(org.openforis.idm.metamodel.validation.DistanceCheck) UniquenessCheck(org.openforis.idm.metamodel.validation.UniquenessCheck) AttributeDefault(org.openforis.idm.metamodel.AttributeDefault) CustomCheck(org.openforis.idm.metamodel.validation.CustomCheck) UniquenessCheck(org.openforis.idm.metamodel.validation.UniquenessCheck) Check(org.openforis.idm.metamodel.validation.Check) DistanceCheck(org.openforis.idm.metamodel.validation.DistanceCheck) ComparisonCheck(org.openforis.idm.metamodel.validation.ComparisonCheck) ComparisonCheck(org.openforis.idm.metamodel.validation.ComparisonCheck)

Example 3 with CustomCheck

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

the class DependencyGraphTest method attributeDefinition.

protected AttributeDefinition attributeDefinition(EntityDefinition parent, String name, String calculatedValueExpression, String relevantExpression, String validationExpression) {
    Schema schema = survey.getSchema();
    AttributeDefinition defn = schema.createTextAttributeDefinition();
    defn.setName(name);
    if (calculatedValueExpression != null) {
        defn.setCalculated(true);
        defn.addAttributeDefault(new AttributeDefault(calculatedValueExpression));
    }
    defn.setRelevantExpression(relevantExpression);
    if (validationExpression != null) {
        defn.addCheck(new CustomCheck(validationExpression));
    }
    parent.addChildDefinition(defn);
    survey.refreshSurveyDependencies();
    return defn;
}
Also used : CustomCheck(org.openforis.idm.metamodel.validation.CustomCheck) Schema(org.openforis.idm.metamodel.Schema) AttributeDefault(org.openforis.idm.metamodel.AttributeDefault) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Aggregations

CustomCheck (org.openforis.idm.metamodel.validation.CustomCheck)3 AttributeDefault (org.openforis.idm.metamodel.AttributeDefault)2 ComparisonCheck (org.openforis.idm.metamodel.validation.ComparisonCheck)2 DistanceCheck (org.openforis.idm.metamodel.validation.DistanceCheck)2 UniquenessCheck (org.openforis.idm.metamodel.validation.UniquenessCheck)2 ArrayList (java.util.ArrayList)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 Schema (org.openforis.idm.metamodel.Schema)1 ExpressionValidationResult (org.openforis.idm.metamodel.expression.ExpressionValidator.ExpressionValidationResult)1 Check (org.openforis.idm.metamodel.validation.Check)1 PatternCheck (org.openforis.idm.metamodel.validation.PatternCheck)1