Search in sources :

Example 66 with Validation

use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.

the class PositiveIntegerValidator method validate.

@Override
public void validate(Object target, List<Validation> validations, String id, ValidationStatus status) {
    Integer value = (Integer) target;
    if (value == null || value < 0) {
        Validation validation = new Validation();
        validation.setScope(scope);
        validation.setId(id);
        validation.setMessage(String.format(violationMessage, target != null ? target.toString() : null));
        validation.setStatus(status);
        validations.add(validation);
    }
}
Also used : Validation(io.atlasmap.v2.Validation)

Example 67 with Validation

use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.

the class DefaultAtlasValidationService method validateLookupFieldMapping.

// mapping field validations
private void validateLookupFieldMapping(List<Mapping> fieldMappings, LookupTables lookupTables, List<Validation> validations, Set<String> usedIds) {
    Set<String> lookupFieldMappingTableNameRefs = fieldMappings.stream().map(Mapping::getLookupTableName).collect(Collectors.toSet());
    Set<String> tableNames = lookupTables.getLookupTable().stream().map(LookupTable::getName).collect(Collectors.toSet());
    if (!lookupFieldMappingTableNameRefs.isEmpty() && !tableNames.isEmpty()) {
        Set<String> disjoint = Stream.concat(lookupFieldMappingTableNameRefs.stream(), tableNames.stream()).collect(Collectors.toMap(Function.identity(), t -> true, (a, b) -> null)).keySet();
        if (!disjoint.isEmpty()) {
            boolean isInFieldList = !lookupFieldMappingTableNameRefs.stream().filter(disjoint::contains).collect(Collectors.toList()).isEmpty();
            boolean isInTableNameList = !tableNames.stream().filter(disjoint::contains).collect(Collectors.toList()).isEmpty();
            // which list has the disjoin.... if its the lookup fields then ERROR
            if (isInFieldList) {
                Validation validation = new Validation();
                validation.setScope(ValidationScope.LOOKUP_TABLE);
                validation.setMessage("One ore more LookupFieldMapping references a non existent LookupTable name in the mapping: " + disjoint.toString());
                validation.setStatus(ValidationStatus.ERROR);
                validations.add(validation);
            }
            // uses it, else WARN
            if (isInTableNameList) {
                Validation validation = new Validation();
                validation.setScope(ValidationScope.LOOKUP_TABLE);
                validation.setMessage("A LookupTable is defined but not used by any LookupField: " + disjoint.toString());
                validation.setStatus(ValidationStatus.WARN);
                validations.add(validation);
            }
        }
    }
    for (Mapping fieldMapping : fieldMappings) {
        String mappingId = fieldMapping.getId();
        validateMappingId(mappingId, usedIds, validations);
        if (fieldMapping.getInputField() != null) {
            Validators.MAP_INPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getInputField(), validations, mappingId);
        }
        Validators.MAP_OUTPUT_NOT_NULL.get().validate(fieldMapping.getOutputField(), validations, mappingId, ValidationStatus.WARN);
        if (fieldMapping.getOutputField() != null) {
            Validators.MAP_OUTPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getOutputField(), validations, mappingId, ValidationStatus.WARN);
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Aggregations

Validation (io.atlasmap.v2.Validation)55 AtlasMapping (io.atlasmap.v2.AtlasMapping)18 Field (io.atlasmap.v2.Field)16 Test (org.junit.jupiter.api.Test)16 Mapping (io.atlasmap.v2.Mapping)14 Validations (io.atlasmap.v2.Validations)10 JavaField (io.atlasmap.java.v2.JavaField)6 BaseMapping (io.atlasmap.v2.BaseMapping)6 FieldType (io.atlasmap.v2.FieldType)6 AtlasException (io.atlasmap.api.AtlasException)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 AtlasConversionConcern (io.atlasmap.spi.AtlasConversionConcern)4 AtlasConversionInfo (io.atlasmap.spi.AtlasConversionInfo)4 FieldGroup (io.atlasmap.v2.FieldGroup)4 ValidationScope (io.atlasmap.v2.ValidationScope)4 ValidationStatus (io.atlasmap.v2.ValidationStatus)4 Method (java.lang.reflect.Method)4 Arrays (java.util.Arrays)4 Optional (java.util.Optional)4