Search in sources :

Example 16 with Mapping

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

the class AtlasService method validateMapping.

protected Response validateMapping(AtlasMapping mapping, UriInfo uriInfo) throws IOException, AtlasException {
    File temporaryMappingFile = File.createTempFile("atlas-mapping", "xml");
    temporaryMappingFile.deleteOnExit();
    atlasContextFactory.getMappingService().saveMappingAsFile(mapping, temporaryMappingFile);
    AtlasContext context = atlasContextFactory.createContext(temporaryMappingFile.toURI());
    AtlasSession session = context.createSession();
    context.processValidation(session);
    Validations validations = session.getValidations();
    if (session.getValidations() == null) {
        validations = new Validations();
    }
    if (temporaryMappingFile.exists() && !temporaryMappingFile.delete()) {
        LOG.warn("Failed to deleting temporary file: " + (temporaryMappingFile != null ? temporaryMappingFile.toString() : null));
    }
    return Response.ok().entity(toJson(validations)).build();
}
Also used : Validations(io.atlasmap.v2.Validations) AtlasContext(io.atlasmap.api.AtlasContext) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession)

Example 17 with Mapping

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

the class XmlValidationServiceTest method getAtlasMappingFullValid.

protected AtlasMapping getAtlasMappingFullValid() {
    AtlasMapping mapping = AtlasModelFactory.createAtlasMapping();
    mapping.setName("thisis_a_valid.name");
    mapping.getDataSource().add(generateDataSource("atlas:xml:MockXml", DataSourceType.SOURCE));
    mapping.getDataSource().add(generateDataSource("atlas:xml:MockXml", DataSourceType.TARGET));
    Mapping mapMapping = AtlasModelFactory.createMapping(MappingType.MAP);
    Mapping sepMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
    Mapping combineMapping = AtlasModelFactory.createMapping(MappingType.COMBINE);
    // MappedField
    XmlField inputField = AtlasXmlModelFactory.createXmlField();
    inputField.setFieldType(FieldType.STRING);
    inputField.setPath("firstName");
    XmlField outputField = AtlasXmlModelFactory.createXmlField();
    outputField.setFieldType(FieldType.STRING);
    outputField.setPath("firstName");
    mapMapping.getInputField().add(inputField);
    mapMapping.getOutputField().add(outputField);
    XmlField sIJavaField = AtlasXmlModelFactory.createXmlField();
    sIJavaField.setFieldType(FieldType.STRING);
    sIJavaField.setPath("displayName");
    sepMapping.getInputField().add(sIJavaField);
    XmlField sOJavaField = AtlasXmlModelFactory.createXmlField();
    sOJavaField.setFieldType(FieldType.STRING);
    sOJavaField.setPath("lastName");
    sOJavaField.setIndex(1);
    sepMapping.getOutputField().add(sOJavaField);
    XmlField cIJavaField = AtlasXmlModelFactory.createXmlField();
    cIJavaField.setFieldType(FieldType.STRING);
    cIJavaField.setPath("displayName");
    combineMapping.getInputField().add(cIJavaField);
    XmlField cOJavaField = AtlasXmlModelFactory.createXmlField();
    cOJavaField.setFieldType(FieldType.STRING);
    cOJavaField.setPath("lastName");
    cOJavaField.setIndex(1);
    combineMapping.getOutputField().add(cOJavaField);
    mapping.getMappings().getMapping().add(mapMapping);
    mapping.getMappings().getMapping().add(sepMapping);
    mapping.getMappings().getMapping().add(combineMapping);
    return mapping;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) XmlField(io.atlasmap.xml.v2.XmlField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Example 18 with Mapping

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

the class XmlValidationServiceTest method testValidateMappingInvalidSeparateInputFieldType.

@Test
public void testValidateMappingInvalidSeparateInputFieldType() {
    AtlasMapping atlasMapping = getAtlasMappingFullValid();
    Mapping separateFieldMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
    separateFieldMapping.setId("separate.firstName.lastName");
    XmlField bIJavaField = xmlModelFactory.createXmlField();
    bIJavaField.setFieldType(FieldType.BOOLEAN);
    bIJavaField.setValue(Boolean.TRUE);
    bIJavaField.setPath("firstName");
    separateFieldMapping.getInputField().add(bIJavaField);
    XmlField sOJavaField = xmlModelFactory.createXmlField();
    sOJavaField.setFieldType(FieldType.STRING);
    sOJavaField.setPath("lastName");
    sOJavaField.setIndex(0);
    separateFieldMapping.getOutputField().add(sOJavaField);
    atlasMapping.getMappings().getMapping().add(separateFieldMapping);
    validations.addAll(sourceValidationService.validateMapping(atlasMapping));
    validations.addAll(targetValidationService.validateMapping(atlasMapping));
    assertTrue(validationHelper.hasErrors());
    assertFalse(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
    assertEquals(new Integer(1), new Integer(validationHelper.getCount()));
    Validation validation = validations.get(0);
    assertNotNull(validation);
    assertEquals(ValidationScope.MAPPING, validation.getScope());
    assertEquals("separate.firstName.lastName", validation.getId());
    assertEquals("Input field 'firstName' must be of type 'STRING' for a Separate Mapping", validation.getMessage());
    assertEquals(ValidationStatus.ERROR, validation.getStatus());
}
Also used : Validation(io.atlasmap.v2.Validation) AtlasMapping(io.atlasmap.v2.AtlasMapping) XmlField(io.atlasmap.xml.v2.XmlField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 19 with Mapping

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

the class XmlValidationServiceTest method testValidateMappingSupportedSourceToTargetConversion.

@Test
public void testValidateMappingSupportedSourceToTargetConversion() throws Exception {
    AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.xml");
    assertNotNull(mapping);
    Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
    XmlField in = (XmlField) fieldMapping.getInputField().get(0);
    in.setFieldType(FieldType.CHAR);
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    if (LOG.isDebugEnabled()) {
        debugErrors(validations);
    }
    assertFalse(validationHelper.hasErrors());
    assertFalse(validationHelper.hasWarnings());
    assertTrue(validationHelper.hasInfos());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) XmlField(io.atlasmap.xml.v2.XmlField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 20 with Mapping

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

the class XmlValidationServiceTest method testValidateMappingPathNull.

@Test
public void testValidateMappingPathNull() throws Exception {
    AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.xml");
    assertNotNull(mapping);
    Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
    XmlField in = (XmlField) fieldMapping.getInputField().get(0);
    in.setPath(null);
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    assertTrue(validationHelper.hasErrors());
    assertFalse(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) XmlField(io.atlasmap.xml.v2.XmlField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

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