Search in sources :

Example 11 with Mapping

use of io.atlasmap.v2.Mapping 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 12 with Mapping

use of io.atlasmap.v2.Mapping 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 13 with Mapping

use of io.atlasmap.v2.Mapping 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 14 with Mapping

use of io.atlasmap.v2.Mapping 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 15 with Mapping

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

the class AtlasService method listMappings.

@GET
@Path("/mappings")
@Produces(MediaType.APPLICATION_JSON)
public Response listMappings(@Context UriInfo uriInfo, @QueryParam("filter") final String filter) {
    StringMap sMap = new StringMap();
    java.nio.file.Path mappingFolder = Paths.get(baseFolder);
    File[] mappings = mappingFolder.toFile().listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            if (filter != null && name != null && !name.toLowerCase().contains(filter.toLowerCase())) {
                return false;
            }
            return (name != null ? name.matches("atlasmapping-[a-zA-Z0-9\\.\\-]+.xml") : false);
        }
    });
    if (mappings == null) {
        return Response.ok().entity(toJson(sMap)).build();
    }
    try {
        for (File mapping : mappings) {
            AtlasMapping map = getMappingFromFile(mapping.getAbsolutePath());
            StringMapEntry mapEntry = new StringMapEntry();
            mapEntry.setName(map.getName());
            UriBuilder builder = uriInfo.getBaseUriBuilder().path("v2").path("atlas").path("mapping").path(map.getName());
            mapEntry.setValue(builder.build().toString());
            sMap.getStringMapEntry().add(mapEntry);
        }
    } catch (JAXBException e) {
        throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
    }
    return Response.ok().entity(toJson(sMap)).build();
}
Also used : StringMap(io.atlasmap.v2.StringMap) WebApplicationException(javax.ws.rs.WebApplicationException) JAXBException(javax.xml.bind.JAXBException) FilenameFilter(java.io.FilenameFilter) AtlasMapping(io.atlasmap.v2.AtlasMapping) StringMapEntry(io.atlasmap.v2.StringMapEntry) UriBuilder(javax.ws.rs.core.UriBuilder) File(java.io.File) Path(javax.ws.rs.Path) ApplicationPath(javax.ws.rs.ApplicationPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

AtlasMapping (io.atlasmap.v2.AtlasMapping)120 Mapping (io.atlasmap.v2.Mapping)83 Test (org.junit.Test)65 BaseMapping (io.atlasmap.v2.BaseMapping)29 Field (io.atlasmap.v2.Field)28 Validation (io.atlasmap.v2.Validation)26 DataSource (io.atlasmap.v2.DataSource)21 JavaField (io.atlasmap.java.v2.JavaField)19 MockField (io.atlasmap.v2.MockField)17 Mappings (io.atlasmap.v2.Mappings)11 SimpleField (io.atlasmap.v2.SimpleField)11 MappingType (io.atlasmap.v2.MappingType)10 PropertyField (io.atlasmap.v2.PropertyField)9 File (java.io.File)9 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 AtlasContext (io.atlasmap.api.AtlasContext)8 AtlasSession (io.atlasmap.api.AtlasSession)8 Actions (io.atlasmap.v2.Actions)8 BaseValidatorTest (io.atlasmap.validators.BaseValidatorTest)8