use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.
the class DefaultAtlasContext method doCreateSession.
private AtlasSession doCreateSession() {
AtlasSession session = new DefaultAtlasSession(mappingDefinition);
session.setAtlasContext(this);
session.setAudits(new Audits());
session.setValidations(new Validations());
setDefaultSessionProperties(session);
return session;
}
use of io.atlasmap.api.AtlasSession 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.api.AtlasSession 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.api.AtlasSession 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.api.AtlasSession in project atlasmap by atlasmap.
the class OverloadedFieldActionsTest method testMappingDayOfWeekInteger.
@Test
public void testMappingDayOfWeekInteger() throws Exception {
AtlasContext context = atlasContextFactory.createContext(generateMappingDayOfWeek(Integer.class));
AtlasSession session = context.createSession();
SourceFlatPrimitiveClass src = new SourceFlatPrimitiveClass();
src.setIntField(1);
session.setInput(src);
context.process(session);
Object tgt = session.getOutput();
assertNotNull(tgt);
assertTrue(tgt.getClass().isAssignableFrom(TargetFlatPrimitiveClass.class));
System.out.println(((TargetFlatPrimitiveClass) tgt).getBoxedStringField());
}
Aggregations