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);
}
}
}
}
}
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;
}
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);
}
}
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);
}
}
}
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();
}
Aggregations