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