use of io.atlasmap.v2.Mappings in project syndesis-qe by syndesisio.
the class AtlasMapperGenerator method getAtlasMappingStep.
public Step getAtlasMappingStep(StepDefinition mapping, List<StepDefinition> precedingSteps, StepDefinition followingStep) {
processPrecedingSteps(precedingSteps);
processFolowingStep(followingStep);
List<DataMapperStepDefinition> mappings = mapping.getDataMapperDefinition().get().getDataMapperStepDefinition();
AtlasMapping atlasMapping = new AtlasMapping();
atlasMapping.setMappings(new Mappings());
for (DataSource s : processSources(precedingSteps)) {
atlasMapping.getDataSource().add(s);
}
atlasMapping.setName("REST." + UUID.randomUUID().toString());
atlasMapping.setLookupTables(new LookupTables());
atlasMapping.setProperties(new Properties());
atlasMapping.getDataSource().add(processTarget(followingStep));
atlasMapping.getMappings().getMapping().addAll(generateBaseMappings(mappings, precedingSteps, followingStep));
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("error: {}" + e);
}
final Step mapperStep = new Step.Builder().stepKind(StepKind.mapper).configuredProperties(TestUtils.map("atlasmapping", mapperString)).action(getMapperStepAction(followingStep.getConnectorDescriptor().get())).id(UUID.randomUUID().toString()).build();
return mapperStep;
}
use of io.atlasmap.v2.Mappings in project atlasmap by atlasmap.
the class AtlasService method listMappings.
@GET
@Path("/mappings")
@Produces(MediaType.APPLICATION_JSON)
public Response listMappings(@Context UriInfo uriInfo, @QueryParam("filter") final String filter) {
StringMap sMap = new StringMap();
java.nio.file.Path mappingFolder = Paths.get(baseFolder);
File[] mappings = mappingFolder.toFile().listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (filter != null && name != null && !name.toLowerCase().contains(filter.toLowerCase())) {
return false;
}
return (name != null ? name.matches("atlasmapping-[a-zA-Z0-9\\.\\-]+.xml") : false);
}
});
if (mappings == null) {
return Response.ok().entity(toJson(sMap)).build();
}
try {
for (File mapping : mappings) {
AtlasMapping map = getMappingFromFile(mapping.getAbsolutePath());
StringMapEntry mapEntry = new StringMapEntry();
mapEntry.setName(map.getName());
UriBuilder builder = uriInfo.getBaseUriBuilder().path("v2").path("atlas").path("mapping").path(map.getName());
mapEntry.setValue(builder.build().toString());
sMap.getStringMapEntry().add(mapEntry);
}
} catch (JAXBException e) {
throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
}
return Response.ok().entity(toJson(sMap)).build();
}
use of io.atlasmap.v2.Mappings in project atlasmap by atlasmap.
the class Atlasmap233Test method test.
@Test
public void test() throws Exception {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/issue/atlasmap-233-mapping.xml");
AtlasMapping mapping = mappingService.loadMapping(url, AtlasMappingFormat.XML);
AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(mapping);
AtlasSession session = context.createSession();
session.setSourceDocument("io.atlasmap.core.issue.SourceClass", new SourceClass().setSourceInteger(-1));
context.process(session);
assertFalse(TestHelper.printAudit(session), session.hasErrors());
Object output = session.getTargetDocument("io.atlasmap.core.issue.TargetClass");
assertEquals(TargetClass.class, output.getClass());
assertEquals(1, ((TargetClass) output).getTargetInteger());
}
use of io.atlasmap.v2.Mappings in project atlasmap by atlasmap.
the class CombineSeparateChangeDelimiterTest method test.
@Test
public void test() throws Exception {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/issue/combine-separate-change-delimiter-mapping.xml");
AtlasMapping mapping = mappingService.loadMapping(url, AtlasMappingFormat.XML);
AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(mapping);
AtlasSession session = context.createSession();
SourceClass source = new SourceClass().setSourceFirstName("Manjiro").setSourceLastName("Nakahama").setSourceName("Manjiro,Nakahama");
session.setSourceDocument("io.atlasmap.core.issue.SourceClass", source);
context.process(session);
assertFalse(TestHelper.printAudit(session), session.hasErrors());
assertFalse(TestHelper.printAudit(session), session.hasWarns());
Object output = session.getTargetDocument("io.atlasmap.core.issue.TargetClass");
assertEquals(TargetClass.class, output.getClass());
TargetClass target = TargetClass.class.cast(output);
assertEquals("Manjiro", target.getTargetFirstName());
assertEquals("Nakahama", target.getTargetLastName());
assertEquals("Manjiro,Nakahama", target.getTargetName());
}
use of io.atlasmap.v2.Mappings in project atlasmap by atlasmap.
the class AtlasModuleSupportTest method testListTargetPathsListOfBaseMapping.
@Test
public void testListTargetPathsListOfBaseMapping() {
List<BaseMapping> mappings = null;
assertEquals(0, AtlasModuleSupport.listTargetPaths(mappings).size());
mappings = new ArrayList<>();
assertEquals(0, AtlasModuleSupport.listTargetPaths(mappings).size());
Mapping mapping = new Mapping();
Field field = new MockField();
field.setPath("MockPath");
mapping.getOutputField().add(field);
mappings.add(mapping);
assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
Collection collection = null;
mappings.add(collection);
assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
collection = new Collection();
mappings.add(collection);
assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
Mappings mapings = new Mappings();
collection.setMappings(mapings);
assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
}
Aggregations