use of org.openforis.idm.metamodel.expression.ExpressionValidator.ExpressionValidationResult in project collect by openforis.
the class PatternCheckFormValidator method validateExpression.
private boolean validateExpression(ValidationContext ctx) {
if (!validateRequired(ctx, REGULAR_EXPRESSION_FIELD)) {
return false;
}
ExpressionValidator expressionValidator = getExpressionValidator(ctx);
String expression = getValue(ctx, REGULAR_EXPRESSION_FIELD);
ExpressionValidationResult result = expressionValidator.validateRegularExpression(expression);
if (result.isError()) {
String message = Strings.firstNotBlank(result.getDetailedMessage(), result.getMessage());
addInvalidMessage(ctx, REGULAR_EXPRESSION_FIELD, getMessage(INVALID_EXPRESSION_MESSAGE_KEY, message));
return false;
}
return true;
}
use of org.openforis.idm.metamodel.expression.ExpressionValidator.ExpressionValidationResult in project collect by openforis.
the class UniquenessCheckFormValidator method validateExpression.
private boolean validateExpression(ValidationContext ctx) {
if (validateRequired(ctx, EXPRESSION_FIELD)) {
ExpressionValidator expressionValidator = getExpressionValidator(ctx);
NodeDefinition contextNode = getContextNode(ctx);
String expression = getValue(ctx, EXPRESSION_FIELD);
ExpressionValidationResult result = expressionValidator.validateUniquenessExpression(contextNode.getParentDefinition(), contextNode, expression);
if (result.isError()) {
String message = Strings.firstNotBlank(result.getDetailedMessage(), result.getMessage());
addInvalidMessage(ctx, EXPRESSION_FIELD, getMessage(INVALID_EXPRESSION_MESSAGE_KEY, message));
return false;
}
}
return true;
}
use of org.openforis.idm.metamodel.expression.ExpressionValidator.ExpressionValidationResult in project collect by openforis.
the class ExpressionValidatorTest method validate.
private ExpressionValidationResult validate(Survey survey, String contextNodeDefPath, String expression) {
ExpressionValidator validator = new ExpressionValidator(survey.getContext().getExpressionFactory());
ExpressionValidationResult result = validator.validateValueExpression(survey.getSchema().getDefinitionByPath(contextNodeDefPath), expression);
return result;
}
use of org.openforis.idm.metamodel.expression.ExpressionValidator.ExpressionValidationResult 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.expression.ExpressionValidator.ExpressionValidationResult in project collect by openforis.
the class SimpleValidator method validateExpression.
protected boolean validateExpression(Errors errors, NodeDefinition contextNodeDef, NodeDefinition thisNodeDef, String field, String expression, ExpressionType type) {
ExpressionValidationResult result = expressionValidator.validateExpression(type, contextNodeDef, thisNodeDef, expression);
if (result.isError()) {
String errorCode = "validation.invalid_expression";
String validationMessage = StringUtils.defaultString(result.getDetailedMessage(), result.getMessage());
String[] errorMessageArgs = new String[] { validationMessage };
String defaultMessage = messageSource.getMessage(errorCode, errorMessageArgs, Locale.ENGLISH);
errors.rejectValue(field, errorCode, defaultMessage);
}
return result.isOk();
}
Aggregations