use of io.atlasmap.v2.AtlasMapping in project atlasmap by atlasmap.
the class AtlasService method getMappingFromFile.
public AtlasMapping getMappingFromFile(String fileName) throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance("io.atlasmap.v2:io.atlasmap.java.v2:io.atlasmap.xml.v2:io.atlasmap.json.v2");
Marshaller marshaller = null;
Unmarshaller unmarshaller = null;
marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
unmarshaller = jaxbContext.createUnmarshaller();
StreamSource fileSource = new StreamSource(new File(fileName));
JAXBElement<AtlasMapping> mappingElem = unmarshaller.unmarshal(fileSource, AtlasMapping.class);
if (mappingElem != null) {
return mappingElem.getValue();
}
return null;
}
use of io.atlasmap.v2.AtlasMapping 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();
}
use of io.atlasmap.v2.AtlasMapping 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;
}
use of io.atlasmap.v2.AtlasMapping 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());
}
use of io.atlasmap.v2.AtlasMapping 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());
}
Aggregations