Search in sources :

Example 56 with Mappings

use of io.atlasmap.v2.Mappings 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)

Example 57 with Mappings

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

the class DefaultAtlasContextCollectionExpansionTest method shouldNotExponentialyGrowExpandedCollectionMappings.

@Test
public void shouldNotExponentialyGrowExpandedCollectionMappings() throws Exception {
    final AtlasMapping mapping = new AtlasMapping();
    final DefaultAtlasContext context = new DefaultAtlasContext(DefaultAtlasContextFactory.getInstance(), mapping) {

        protected void init() {
        // hijack initialization
        }
    };
    context.setSourceModules(Collections.singletonMap("source", new JsonModule()));
    final DefaultAtlasSession session = (DefaultAtlasSession) context.createSession();
    session.setSourceDocument("source", "{ \"array\": [ { \"property\": 1 }, { \"property\": 2 }, { \"property\": 3 } ] }");
    final Collection baseMapping = new Collection();
    baseMapping.setMappingType(MappingType.COLLECTION);
    final Mappings mappings = new Mappings();
    final Mapping singleMapping = new Mapping();
    singleMapping.setMappingType(MappingType.MAP);
    final JsonField nestedArrayField = new JsonField();
    nestedArrayField.setDocId("source");
    nestedArrayField.setPath("/array<>/property");
    singleMapping.getInputField().add(nestedArrayField);
    mappings.getMapping().add(singleMapping);
    baseMapping.setMappings(mappings);
    Method m = DefaultAtlasContext.class.getDeclaredMethod("unwrapCollectionMappings", new Class[] { DefaultAtlasSession.class, BaseMapping.class });
    m.setAccessible(true);
    assertEquals(1, List.class.cast(m.invoke(context, new Object[] { session, baseMapping })).size());
    assertEquals(1, List.class.cast(m.invoke(context, new Object[] { session, baseMapping })).size());
    assertEquals(1, List.class.cast(m.invoke(context, new Object[] { session, baseMapping })).size());
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) AtlasMapping(io.atlasmap.v2.AtlasMapping) DefaultAtlasContext(io.atlasmap.core.DefaultAtlasContext) Mappings(io.atlasmap.v2.Mappings) Collection(io.atlasmap.v2.Collection) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) BaseMapping(io.atlasmap.v2.BaseMapping) Method(java.lang.reflect.Method) JsonModule(io.atlasmap.json.module.JsonModule) DefaultAtlasSession(io.atlasmap.core.DefaultAtlasSession) Test(org.junit.jupiter.api.Test)

Example 58 with Mappings

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

the class NestedCollectionJsonTest method testAsymmetricSingleTarget.

@Test
public void testAsymmetricSingleTarget() throws Exception {
    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("mappings/atlasmapping-nested-collection-asymmetric.json");
    ADMArchiveHandler admHandler = new ADMArchiveHandler(Thread.currentThread().getContextClassLoader());
    admHandler.load(AtlasContextFactory.Format.JSON, in);
    AtlasMapping mapping = admHandler.getMappingDefinition();
    mapping.getMappings().getMapping().removeIf(m -> !"3-1".equals(((Mapping) m).getId()));
    AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(mapping);
    AtlasSession session = context.createSession();
    String source = new String(Files.readAllBytes(Paths.get(Thread.currentThread().getContextClassLoader().getResource("mappings/document-nested-collection.json").toURI())));
    session.setSourceDocument("JSONInstanceNestedCollection", source);
    context.process(session);
    assertFalse(session.hasErrors(), TestHelper.printAudit(session));
    assertTrue(session.hasWarns(), TestHelper.printAudit(session));
    Object output = session.getTargetDocument("JSONInstanceNestedCollection");
    assertEquals(String.class, output.getClass());
    JsonNode outputJson = mapper.readTree((String) output);
    String prettyPrinted = mapper.writeValueAsString(outputJson);
    ArrayNode firstArray = (ArrayNode) outputJson.get("firstArray");
    assertEquals(10, firstArray.size(), prettyPrinted);
    assertEquals("thirdArrayValue0-0-0", firstArray.get(0).get("value").asText(), prettyPrinted);
    assertNull(firstArray.get(0).get("secondArray"), prettyPrinted);
    assertEquals("thirdArrayValue0-0-1", firstArray.get(1).get("value").asText(), prettyPrinted);
    assertNull(firstArray.get(1).get("secondArray"), prettyPrinted);
    assertEquals("thirdArrayValue0-1-0", firstArray.get(2).get("value").asText(), prettyPrinted);
    assertNull(firstArray.get(2).get("secondArray"), prettyPrinted);
    assertEquals("thirdArrayValue0-1-1", firstArray.get(3).get("value").asText(), prettyPrinted);
    assertNull(firstArray.get(3).get("secondArray"), prettyPrinted);
    assertEquals("thirdArrayValue0-1-2", firstArray.get(4).get("value").asText(), prettyPrinted);
    assertNull(firstArray.get(4).get("secondArray"), prettyPrinted);
    assertEquals("thirdArrayValue1-0-0", firstArray.get(5).get("value").asText(), prettyPrinted);
    assertNull(firstArray.get(5).get("secondArray"), prettyPrinted);
    assertEquals("thirdArrayValue1-0-1", firstArray.get(6).get("value").asText(), prettyPrinted);
    assertNull(firstArray.get(6).get("secondArray"), prettyPrinted);
    assertEquals("thirdArrayValue1-0-2", firstArray.get(7).get("value").asText(), prettyPrinted);
    assertNull(firstArray.get(7).get("secondArray"), prettyPrinted);
    assertEquals("thirdArrayValue1-1-0", firstArray.get(8).get("value").asText(), prettyPrinted);
    assertNull(firstArray.get(8).get("secondArray"), prettyPrinted);
    assertEquals("thirdArrayValue1-1-1", firstArray.get(9).get("value").asText(), prettyPrinted);
    assertNull(firstArray.get(9).get("secondArray"), prettyPrinted);
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) InputStream(java.io.InputStream) AtlasContext(io.atlasmap.api.AtlasContext) JsonNode(com.fasterxml.jackson.databind.JsonNode) ADMArchiveHandler(io.atlasmap.core.ADMArchiveHandler) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.jupiter.api.Test)

Example 59 with Mappings

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

the class NestedCollectionXmlTest method processXmlNestedCollection.

private String processXmlNestedCollection(List<String> mappingsToProcess, boolean assertNoWarnings) throws AtlasException, IOException, URISyntaxException {
    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("mappings/atlasmapping-nested-collection-xml.json");
    ADMArchiveHandler admHandler = new ADMArchiveHandler(Thread.currentThread().getContextClassLoader());
    admHandler.load(AtlasContextFactory.Format.JSON, in);
    AtlasMapping mapping = admHandler.getMappingDefinition();
    mapping.getMappings().getMapping().removeIf(m -> !mappingsToProcess.contains(((Mapping) m).getId()));
    AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(mapping);
    AtlasSession session = context.createSession();
    String source = new String(Files.readAllBytes(Paths.get(Thread.currentThread().getContextClassLoader().getResource("mappings/document-nested-collection.xml").toURI())));
    session.setSourceDocument("XMLInstanceNestedCollection", source);
    context.process(session);
    assertFalse(session.hasErrors(), TestHelper.printAudit(session));
    if (assertNoWarnings) {
        assertFalse(session.hasWarns(), TestHelper.printAudit(session));
    }
    Object output = session.getTargetDocument("XMLInstanceNestedCollection");
    return (String) output;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) InputStream(java.io.InputStream) AtlasContext(io.atlasmap.api.AtlasContext) ADMArchiveHandler(io.atlasmap.core.ADMArchiveHandler) AtlasSession(io.atlasmap.api.AtlasSession)

Example 60 with Mappings

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

the class DefaultAtlasValidationServiceTest method testAtlasMappingUtil.

@Test
public void testAtlasMappingUtil() throws Exception {
    Files.createDirectories(Paths.get("target/mappings"));
    AtlasMapping mapping = getAtlasMappingFullValid();
    assertNotNull(mapping);
    AtlasMappingUtil atlasMappingUtil = new AtlasMappingUtil();
    final String fileName = "target/mappings/HappyPathMapping.json";
    atlasMappingUtil.marshallMapping(mapping, fileName);
    assertTrue(Files.exists(Paths.get(fileName)));
    AtlasMapping atlasMapping = atlasMappingUtil.loadMapping(fileName);
    assertNotNull(atlasMapping);
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.jupiter.api.Test) BaseValidatorTest(io.atlasmap.validators.BaseValidatorTest)

Aggregations

AtlasMapping (io.atlasmap.v2.AtlasMapping)86 Mapping (io.atlasmap.v2.Mapping)50 Test (org.junit.jupiter.api.Test)45 BaseMapping (io.atlasmap.v2.BaseMapping)26 File (java.io.File)20 Mappings (io.atlasmap.v2.Mappings)16 Test (org.junit.Test)15 JavaField (io.atlasmap.java.v2.JavaField)14 AtlasContext (io.atlasmap.api.AtlasContext)12 AtlasSession (io.atlasmap.api.AtlasSession)12 DataSource (io.atlasmap.v2.DataSource)12 Validation (io.atlasmap.v2.Validation)11 Field (io.atlasmap.v2.Field)10 JsonField (io.atlasmap.json.v2.JsonField)7 AtlasModelFactory (io.atlasmap.v2.AtlasModelFactory)7 DataSourceType (io.atlasmap.v2.DataSourceType)7 FieldType (io.atlasmap.v2.FieldType)7 MappingType (io.atlasmap.v2.MappingType)7 ProcessMappingResponse (io.atlasmap.v2.ProcessMappingResponse)7 ValidationScope (io.atlasmap.v2.ValidationScope)7