Search in sources :

Example 21 with DataSource

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

the class BaseDefaultAtlasContextTest method init.

@BeforeEach
public void init() throws AtlasException {
    mapping = AtlasTestData.generateAtlasMapping();
    context = new DefaultAtlasContext(DefaultAtlasContextFactory.getInstance(), mapping) {

        protected void init() {
        // hijack initialization
        }
    };
    previewContext = new DefaultAtlasPreviewContext(DefaultAtlasContextFactory.getInstance());
    sourceModule = mockAtlasModule();
    DataSource sds = new DataSource();
    sds.setDataSourceType(DataSourceType.SOURCE);
    sourceModule.setDataSource(sds);
    targetModule = mockAtlasModule();
    DataSource tds = new DataSource();
    tds.setDataSourceType(DataSourceType.TARGET);
    targetModule.setDataSource(tds);
    context.getSourceModules().put(AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, sourceModule);
    context.getTargetModules().put(AtlasConstants.DEFAULT_TARGET_DOCUMENT_ID, targetModule);
    ConstantModule constantModule = new ConstantModule();
    constantModule.setConversionService(DefaultAtlasConversionService.getInstance());
    context.getSourceModules().put(AtlasConstants.CONSTANTS_DOCUMENT_ID, constantModule);
    PropertyModule sourcePropertyModule = new PropertyModule(new DefaultAtlasPropertyStrategy());
    sourcePropertyModule.setConversionService(DefaultAtlasConversionService.getInstance());
    context.getSourceModules().put(AtlasConstants.PROPERTIES_SOURCE_DOCUMENT_ID, sourcePropertyModule);
    PropertyModule targetPropertyModule = new PropertyModule(new DefaultAtlasPropertyStrategy());
    targetPropertyModule.setConversionService(DefaultAtlasConversionService.getInstance());
    context.getTargetModules().put(AtlasConstants.PROPERTIES_TARGET_DOCUMENT_ID, targetPropertyModule);
    recreateSession();
}
Also used : DataSource(io.atlasmap.v2.DataSource) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 22 with DataSource

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

the class BaseMarshallerTest method generateMultiSourceMapping.

protected AtlasMapping generateMultiSourceMapping() {
    AtlasMapping mapping = generateSeparateAtlasMapping();
    DataSource source1 = new DataSource();
    source1.setUri("xml:foo1");
    source1.setDataSourceType(DataSourceType.SOURCE);
    source1.setId("xml1");
    DataSource source2 = new DataSource();
    source2.setUri("xml:foo2");
    source2.setDataSourceType(DataSourceType.SOURCE);
    source2.setId("xml2");
    DataSource target = new DataSource();
    target.setUri("xml:bar");
    target.setDataSourceType(DataSourceType.TARGET);
    target.setId("target1");
    mapping.getDataSource().add(source1);
    mapping.getDataSource().add(source2);
    mapping.getDataSource().add(target);
    Mapping fm = (Mapping) mapping.getMappings().getMapping().get(0);
    fm.getInputField().get(0).setDocId("xml1");
    fm.getOutputField().get(0).setDocId("target1");
    fm.getOutputField().get(1).setDocId("target1");
    return mapping;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) DataSource(io.atlasmap.v2.DataSource)

Example 23 with DataSource

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

the class AtlasMapperGenerator method processSources.

/**
 * Gets list of output data shapes for preceding steps.
 *
 * @param precedingSteps
 * @return
 */
private List<DataSource> processSources(List<StepDefinition> precedingSteps) {
    List<DataSource> sources = new ArrayList<>();
    for (StepDefinition s : precedingSteps) {
        DataShape outDataShape = s.getConnectorDescriptor().get().getOutputDataShape().get();
        sources.add(createDataSource(outDataShape, s, DataSourceType.SOURCE));
    }
    return sources;
}
Also used : ArrayList(java.util.ArrayList) DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) StepDefinition(io.syndesis.qe.bdd.entities.StepDefinition) DataShape(io.syndesis.common.model.DataShape) DataSource(io.atlasmap.v2.DataSource) JsonDataSource(io.atlasmap.json.v2.JsonDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Example 24 with DataSource

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

the class AtlasMapperGenerator method createDataSource.

/**
 * Used to generate data source elements for atlasMapping. There are three types of them: Java, Json, XML.
 *
 * TODO(tplevko): update also for XML
 *
 * @param dataShape
 * @param step
 * @param dataSourceType
 * @return
 */
private DataSource createDataSource(DataShape dataShape, StepDefinition step, DataSourceType dataSourceType) {
    DataShapeKinds dataShapeKind = dataShape.getKind();
    DataSource source = null;
    if (dataShapeKind.toString().contains("json")) {
        source = new JsonDataSource();
        source.setUri("atlas:" + "json:" + step.getStep().getId().get());
    } else if (dataShapeKind.toString().contains("java")) {
        source = new DataSource();
        source.setUri("atlas:" + "java:" + step.getStep().getId().get() + "?className=" + dataShape.getType());
    } else if (dataShapeKind.toString().contains("xml")) {
        source = new XmlDataSource();
    // TODO(tplevko): find out how should look the XML datasource definition
    }
    source.setId(step.getStep().getId().get());
    source.setDataSourceType(dataSourceType);
    return source;
}
Also used : JsonDataSource(io.atlasmap.json.v2.JsonDataSource) DataShapeKinds(io.syndesis.common.model.DataShapeKinds) DataSource(io.atlasmap.v2.DataSource) JsonDataSource(io.atlasmap.json.v2.JsonDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Example 25 with DataSource

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

the class ConcurrencyChaosMonkeyTest method generateMappingURI.

protected URI generateMappingURI() throws Exception {
    AtlasMapping mapping = AtlasModelFactory.createAtlasMapping();
    mapping.setName("mockMapping");
    DataSource src = new DataSource();
    src.setDataSourceType(DataSourceType.SOURCE);
    src.setUri("atlas:java?className=twitter4j.Status");
    DataSource tgt = new DataSource();
    tgt.setDataSourceType(DataSourceType.TARGET);
    tgt.setUri("atlas:java?className=org.apache.camel.salesforce.dto.Contact");
    mapping.getDataSource().add(src);
    mapping.getDataSource().add(tgt);
    Mapping sepMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
    JavaField jNameField = new JavaField();
    jNameField.setName("Name");
    jNameField.setPath("User.name");
    jNameField.setGetMethod("getName");
    jNameField.setFieldType(FieldType.STRING);
    JavaField jFirstNameField = new JavaField();
    jFirstNameField.setName("FirstName");
    jFirstNameField.setPath("FirstName");
    jFirstNameField.setSetMethod("setFirstName");
    jFirstNameField.setFieldType(FieldType.STRING);
    jFirstNameField.setIndex(0);
    JavaField jLastNameField = new JavaField();
    jLastNameField.setName("LastName");
    jLastNameField.setPath("LastName");
    jLastNameField.setSetMethod("setLastName");
    jLastNameField.setFieldType(FieldType.STRING);
    jLastNameField.setIndex(1);
    sepMapping.getInputField().add(jNameField);
    sepMapping.getOutputField().add(jFirstNameField);
    sepMapping.getOutputField().add(jLastNameField);
    mapping.getMappings().getMapping().add(sepMapping);
    Mapping textDescMapping = AtlasModelFactory.createMapping(MappingType.MAP);
    JavaField jTextField = new JavaField();
    jTextField.setName("Text");
    jTextField.setPath("Text");
    jTextField.setGetMethod("getText");
    jTextField.setFieldType(FieldType.STRING);
    JavaField jDescField = new JavaField();
    jDescField.setName("Description");
    jDescField.setPath("description");
    jDescField.setSetMethod("setDescription");
    jDescField.setFieldType(FieldType.STRING);
    textDescMapping.getInputField().add(jTextField);
    textDescMapping.getOutputField().add(jDescField);
    mapping.getMappings().getMapping().add(textDescMapping);
    Mapping screenTitleMapping = AtlasModelFactory.createMapping(MappingType.MAP);
    JavaField jScreenField = new JavaField();
    jScreenField.setName("ScreenName");
    jScreenField.setPath("User.screenName");
    jScreenField.setGetMethod("getScreenName");
    jScreenField.setFieldType(FieldType.STRING);
    JavaField jTitleField = new JavaField();
    jTitleField.setName("Title");
    jTitleField.setPath("Title");
    jTitleField.setSetMethod("setTitle");
    jTitleField.setFieldType(FieldType.STRING);
    screenTitleMapping.getInputField().add(jScreenField);
    screenTitleMapping.getOutputField().add(jTitleField);
    mapping.getMappings().getMapping().add(screenTitleMapping);
    File mappingFile = new File("target/junit-atlasmapping.xml");
    atlasContextFactory.getMappingService().saveMappingAsFile(mapping, mappingFile);
    return mappingFile.toURI();
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) File(java.io.File) DataSource(io.atlasmap.v2.DataSource)

Aggregations

DataSource (io.atlasmap.v2.DataSource)54 AtlasMapping (io.atlasmap.v2.AtlasMapping)16 ArrayList (java.util.ArrayList)14 Mapping (io.atlasmap.v2.Mapping)11 XmlDataSource (io.atlasmap.xml.v2.XmlDataSource)10 Mappings (io.atlasmap.v2.Mappings)8 JsonDataSource (io.atlasmap.json.v2.JsonDataSource)7 Test (org.junit.Test)7 File (java.io.File)6 AtlasContext (io.atlasmap.api.AtlasContext)5 AtlasSession (io.atlasmap.api.AtlasSession)5 JavaField (io.atlasmap.java.v2.JavaField)5 AtlasException (io.atlasmap.api.AtlasException)4 XmlNamespaces (io.atlasmap.xml.v2.XmlNamespaces)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 AtlasModule (io.atlasmap.spi.AtlasModule)3 HashMap (java.util.HashMap)3 Exchange (org.apache.camel.Exchange)3