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;
}
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);
}
}
}
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;
}
Aggregations