Search in sources :

Example 6 with Validations

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

the class DefaultAtlasValidationService method validateSeparateMapping.

private void validateSeparateMapping(List<Mapping> fieldMappings, List<Validation> validations, Set<String> usedIds) {
    for (Mapping fieldMapping : fieldMappings) {
        String mappingId = fieldMapping.getId();
        validateMappingId(mappingId, usedIds, validations);
        Validators.SEPARATE_INPUT_NOT_NULL.get().validate(fieldMapping.getInputField(), validations, mappingId);
        if (fieldMapping.getInputField() != null) {
            Validators.SEPARATE_INPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getInputField(), validations, mappingId);
        // source must be a String type
        }
        Validators.SEPARATE_OUTPUT_NOT_NULL.get().validate(fieldMapping.getOutputField(), validations, mappingId, ValidationStatus.WARN);
        Validators.SEPARATE_OUTPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getOutputField(), validations, mappingId, ValidationStatus.WARN);
        if (fieldMapping.getOutputField() != null) {
            for (Field field : fieldMapping.getOutputField()) {
                Validators.SEPARATE_OUTPUT_FIELD_NOT_NULL.get().validate(field, validations, mappingId);
                if (field.getIndex() == null || field.getIndex() < 0) {
                    Validators.SEPARATE_OUTPUT_FIELD_FIELD_ACTION_INDEX_POSITIVE.get().validate(field.getIndex(), validations, mappingId);
                }
            }
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Example 7 with Validations

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

the class DefaultAtlasValidationService method validateMapping.

@Override
public List<Validation> validateMapping(AtlasMapping mapping) {
    List<Validation> validations = new ArrayList<Validation>();
    Validators.MAPPING_NAME.get().validate(mapping.getName(), validations, null);
    List<DataSource> dataSources = mapping.getDataSource();
    for (DataSource ds : dataSources) {
        switch(ds.getDataSourceType()) {
            case SOURCE:
                Validators.DATASOURCE_SOURCE_URI.get().validate(ds.getUri(), validations, ds.getId());
                break;
            case TARGET:
                Validators.DATASOURCE_TARGET_URI.get().validate(ds.getUri(), validations, ds.getId());
                break;
            default:
                throw new IllegalArgumentException(String.format("Unknown DataSource type '%s'", ds.getDataSourceType()));
        }
    }
    validateFieldMappings(mapping.getMappings(), mapping.getLookupTables(), validations);
    return validations;
}
Also used : Validation(io.atlasmap.v2.Validation) ArrayList(java.util.ArrayList) DataSource(io.atlasmap.v2.DataSource)

Example 8 with Validations

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

the class DefaultAtlasValidationService method validateMappingId.

private void validateMappingId(String id, Set<String> usedIds, List<Validation> validations) {
    if (id == null) {
        return;
    }
    if (usedIds.contains(id)) {
        Validation validation = new Validation();
        validation.setScope(ValidationScope.MAPPING);
        validation.setMessage(String.format("Duplicated mapping ID '%s' is found", id));
        validation.setStatus(ValidationStatus.WARN);
        validations.add(validation);
    } else {
        usedIds.add(id);
    }
}
Also used : Validation(io.atlasmap.v2.Validation)

Example 9 with Validations

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

the class DefaultAtlasValidationService method validateLookupTables.

private void validateLookupTables(List<Mapping> lookupFieldMappings, LookupTables lookupTables, List<Validation> validations, Set<String> usedIds) {
    if (lookupTables != null && lookupTables.getLookupTable() != null && !lookupTables.getLookupTable().isEmpty()) {
        // check for duplicate names
        Validators.LOOKUPTABLE_NAME_CHECK_FOR_DUPLICATE.get().validate(lookupTables, validations, null);
        if (lookupFieldMappings.isEmpty()) {
            Validation validation = new Validation();
            validation.setScope(ValidationScope.LOOKUP_TABLE);
            validation.setMessage("LookupTables are defined but no LookupFields are utilized.");
            validation.setStatus(ValidationStatus.WARN);
            validations.add(validation);
        } else {
            validateLookupFieldMapping(lookupFieldMappings, lookupTables, validations, usedIds);
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation)

Example 10 with Validations

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

the class BaseModuleValidationService method populateConversionConcerns.

protected void populateConversionConcerns(String mappingId, AtlasConversionInfo converterAnno, String inputFieldName, String outFieldName, List<Validation> validations) {
    if (converterAnno == null || converterAnno.concerns() == null) {
        return;
    }
    for (AtlasConversionConcern atlasConversionConcern : converterAnno.concerns()) {
        String message = atlasConversionConcern.getMessage(converterAnno);
        if (AtlasConversionConcern.NONE.equals(atlasConversionConcern)) {
            Validation validation = new Validation();
            validation.setScope(ValidationScope.MAPPING);
            validation.setId(mappingId);
            validation.setMessage(message);
            validation.setStatus(ValidationStatus.INFO);
            validations.add(validation);
        } else if (atlasConversionConcern.equals(AtlasConversionConcern.RANGE) || atlasConversionConcern.equals(AtlasConversionConcern.FORMAT) || atlasConversionConcern.equals(AtlasConversionConcern.FRACTIONAL_PART) || atlasConversionConcern.equals(AtlasConversionConcern.TIMEZONE)) {
            Validation validation = new Validation();
            validation.setScope(ValidationScope.MAPPING);
            validation.setId(mappingId);
            validation.setMessage(message);
            validation.setStatus(ValidationStatus.WARN);
            validations.add(validation);
        } else if (atlasConversionConcern.equals(AtlasConversionConcern.UNSUPPORTED)) {
            Validation validation = new Validation();
            validation.setScope(ValidationScope.MAPPING);
            validation.setId(mappingId);
            validation.setMessage(message);
            validation.setStatus(ValidationStatus.ERROR);
            validations.add(validation);
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation) AtlasConversionConcern(io.atlasmap.spi.AtlasConversionConcern)

Aggregations

Validation (io.atlasmap.v2.Validation)36 Test (org.junit.Test)26 AtlasMapping (io.atlasmap.v2.AtlasMapping)17 Mapping (io.atlasmap.v2.Mapping)17 Validations (io.atlasmap.v2.Validations)15 DataSource (io.atlasmap.v2.DataSource)10 AtlasModuleDetail (io.atlasmap.spi.AtlasModuleDetail)9 FieldType (io.atlasmap.v2.FieldType)9 ValidationScope (io.atlasmap.v2.ValidationScope)9 ValidationStatus (io.atlasmap.v2.ValidationStatus)9 List (java.util.List)9 Before (org.junit.Before)9 AtlasModuleMode (io.atlasmap.spi.AtlasModuleMode)8 Field (io.atlasmap.v2.Field)8 MappingType (io.atlasmap.v2.MappingType)8 AtlasMappingBaseTest (io.atlasmap.validation.AtlasMappingBaseTest)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 AtlasMappingUtil (io.atlasmap.core.AtlasMappingUtil)7 DefaultAtlasConversionService (io.atlasmap.core.DefaultAtlasConversionService)7