Search in sources :

Example 16 with Json

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

the class AtlasMappingService method loadMapping.

public AtlasMapping loadMapping(File file, AtlasMappingFormat format) throws AtlasValidationException {
    try {
        AtlasMapping atlasMapping;
        switch(format) {
            case XML:
                StreamSource streamSource = new StreamSource(file);
                atlasMapping = createUnmarshaller().unmarshal(streamSource, AtlasMapping.class).getValue();
                break;
            case JSON:
                atlasMapping = jsonMapper.readValue(file, AtlasMapping.class);
                break;
            default:
                throw new AtlasValidationException("Unsupported mapping format: " + format.value);
        }
        validate(atlasMapping);
        return atlasMapping;
    } catch (Exception e) {
        throw new AtlasValidationException(e.getMessage(), e);
    }
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) StreamSource(javax.xml.transform.stream.StreamSource) AtlasValidationException(io.atlasmap.api.AtlasValidationException) AtlasValidationException(io.atlasmap.api.AtlasValidationException) AtlasException(io.atlasmap.api.AtlasException) URISyntaxException(java.net.URISyntaxException) JAXBException(javax.xml.bind.JAXBException)

Example 17 with Json

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

the class AtlasMappingService method loadMapping.

public AtlasMapping loadMapping(Reader reader, AtlasMappingFormat format) throws AtlasValidationException {
    try {
        AtlasMapping atlasMapping;
        switch(format) {
            case XML:
                StreamSource streamSource = new StreamSource(reader);
                atlasMapping = createUnmarshaller().unmarshal(streamSource, AtlasMapping.class).getValue();
                break;
            case JSON:
                atlasMapping = jsonMapper.readValue(reader, AtlasMapping.class);
                break;
            default:
                throw new AtlasValidationException("Unsupported mapping format: " + format.value);
        }
        validate(atlasMapping);
        return atlasMapping;
    } catch (Exception e) {
        throw new AtlasValidationException(e.getMessage(), e);
    }
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) StreamSource(javax.xml.transform.stream.StreamSource) AtlasValidationException(io.atlasmap.api.AtlasValidationException) AtlasValidationException(io.atlasmap.api.AtlasValidationException) AtlasException(io.atlasmap.api.AtlasException) URISyntaxException(java.net.URISyntaxException) JAXBException(javax.xml.bind.JAXBException)

Example 18 with Json

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

the class SchemaInspectorTest method inspectJsonSchemaGeo.

// examples from json-schema.org
@Test
public void inspectJsonSchemaGeo() throws Exception {
    final String schema = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/geo.json")));
    JsonDocument document = inspectionService.inspectJsonSchema(schema);
    List<Field> fields = document.getFields().getField();
    JsonField f = (JsonField) fields.get(0);
    assertEquals("latitude", f.getName());
    assertEquals("/latitude", f.getPath());
    assertEquals(FieldType.NUMBER, f.getFieldType());
    f = (JsonField) fields.get(1);
    assertEquals("longitude", f.getName());
    assertEquals("/longitude", f.getPath());
    assertEquals(FieldType.NUMBER, f.getFieldType());
}
Also used : Field(io.atlasmap.v2.Field) JsonField(io.atlasmap.json.v2.JsonField) JsonField(io.atlasmap.json.v2.JsonField) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.Test)

Example 19 with Json

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

the class JavaToXMLJSONMarshallingTest method testCombineMappingDemarshaller.

@Test
public void testCombineMappingDemarshaller() throws Exception {
    // this test is for AT-466: issue saving mappings in combine mode (parser
    // complaining about strategy property)
    // the json has been changed from what the UI was sending, now the "actions"
    // property on the output field is "null" rather than "[]"
    String filename = "src/test/resources/javaToXml/javaToXmlMapping-combine.json";
    AtlasMapping uMapping = mapper.readValue(new File(filename), AtlasMapping.class);
    assertNotNull(uMapping);
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) File(java.io.File) Test(org.junit.Test)

Example 20 with Json

use of io.atlasmap.v2.Json in project syndesis-qe by syndesisio.

the class AtlasMapperGenerator method getAtlasMappingStep.

/**
 * This method is used to generate the "AtlasMapping" - the atlasMapping contains list of specifications of
 * dataSources and a list of specifications of dataMappings. Both these a must have for a complete and working
 * AtlasMapping.
 *
 * @return step with the mapping defined
 */
public Step getAtlasMappingStep() {
    processPrecedingSteps();
    processFollowingStep();
    AtlasMapping atlasMapping = new AtlasMapping();
    atlasMapping.setMappings(new Mappings());
    for (DataSource s : processSources()) {
        atlasMapping.getDataSource().add(s);
    }
    atlasMapping.setName("REST." + UUID.randomUUID().toString().replaceAll("-", ""));
    atlasMapping.setLookupTables(new LookupTables());
    atlasMapping.setProperties(new Properties());
    atlasMapping.getDataSource().add(processTarget());
    atlasMapping.getMappings().getMapping().addAll(generateBaseMappings());
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
    String mapperString = null;
    try {
        mapperString = mapper.writeValueAsString(atlasMapping);
        log.debug(mapperString);
    } catch (JsonProcessingException e) {
        log.error("Unable to write mapper json as string", e);
    }
    return new Step.Builder().stepKind(StepKind.mapper).name(mapping.getStep().getName()).configuredProperties(TestUtils.map("atlasmapping", mapperString)).action(getMapperStepAction(followingStep.getStep().getAction().get().getInputDataShape().get())).id(UUID.randomUUID().toString()).build();
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) LookupTables(io.atlasmap.v2.LookupTables) Properties(io.atlasmap.v2.Properties) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataSource(io.atlasmap.v2.DataSource) JsonDataSource(io.atlasmap.json.v2.JsonDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Aggregations

Test (org.junit.jupiter.api.Test)15 Field (io.atlasmap.v2.Field)12 AtlasMapping (io.atlasmap.v2.AtlasMapping)11 JsonField (io.atlasmap.json.v2.JsonField)7 File (java.io.File)7 FieldGroup (io.atlasmap.v2.FieldGroup)6 AtlasException (io.atlasmap.api.AtlasException)5 AtlasValidationException (io.atlasmap.api.AtlasValidationException)4 ProcessMappingResponse (io.atlasmap.v2.ProcessMappingResponse)4 Response (javax.ws.rs.core.Response)4 AtlasPath (io.atlasmap.core.AtlasPath)3 JavaField (io.atlasmap.java.v2.JavaField)3 JsonDataSource (io.atlasmap.json.v2.JsonDataSource)3 DataSource (io.atlasmap.v2.DataSource)3 XmlDataSource (io.atlasmap.xml.v2.XmlDataSource)3 Test (org.junit.Test)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 AtlasConversionException (io.atlasmap.api.AtlasConversionException)2 JsonDocument (io.atlasmap.json.v2.JsonDocument)2