Search in sources :

Example 36 with ConstraintViolation

use of org.molgenis.validation.ConstraintViolation in project molgenis by molgenis.

the class EntityAttributesValidator method checkValidationExpressions.

private Set<ConstraintViolation> checkValidationExpressions(Entity entity, EntityType meta) {
    List<String> validationExpressions = new ArrayList<>();
    List<Attribute> expressionAttributes = new ArrayList<>();
    for (Attribute attribute : meta.getAtomicAttributes()) {
        if (StringUtils.isNotBlank(attribute.getValidationExpression())) {
            expressionAttributes.add(attribute);
            validationExpressions.add(attribute.getValidationExpression());
        }
    }
    Set<ConstraintViolation> violations = new LinkedHashSet<>();
    if (!validationExpressions.isEmpty()) {
        List<Boolean> results = expressionValidator.resolveBooleanExpressions(validationExpressions, entity);
        for (int i = 0; i < results.size(); i++) {
            if (!TRUE.equals(results.get(i))) {
                violations.add(createConstraintViolation(entity, expressionAttributes.get(i), meta, format("Offended validation expression: %s", validationExpressions.get(i))));
            }
        }
    }
    return violations;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Attribute(org.molgenis.data.meta.model.Attribute) ConstraintViolation(org.molgenis.validation.ConstraintViolation) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList)

Aggregations

ConstraintViolation (org.molgenis.validation.ConstraintViolation)36 Entity (org.molgenis.data.Entity)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 Attribute (org.molgenis.data.meta.model.Attribute)14 DynamicEntity (org.molgenis.data.support.DynamicEntity)13 Test (org.junit.jupiter.api.Test)12 EntityType (org.molgenis.data.meta.model.EntityType)11 MolgenisValidationException (org.molgenis.data.validation.MolgenisValidationException)10 MethodSource (org.junit.jupiter.params.provider.MethodSource)6 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)6 AttributeType (org.molgenis.data.meta.AttributeType)4 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)4 Collectors.toList (java.util.stream.Collectors.toList)3 MolgenisDataException (org.molgenis.data.MolgenisDataException)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 Streams.stream (com.google.common.collect.Streams.stream)2 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2