Search in sources :

Example 1 with XmlDataSource

use of io.atlasmap.xml.v2.XmlDataSource in project atlasmap by atlasmap.

the class XmlFieldReaderTest method mockDataSources.

private void mockDataSources(String docId, AtlasInternalSession session) {
    AtlasMapping atlasMapping = mock(AtlasMapping.class);
    List<DataSource> dataSources = new ArrayList<>();
    XmlDataSource xmlDataSource = new XmlDataSource();
    xmlDataSource.setId(docId);
    xmlDataSource.setDataSourceType(DataSourceType.SOURCE);
    XmlNamespaces atlasNamespaces = new XmlNamespaces();
    XmlNamespace xmlNamespaceQ = new XmlNamespace();
    xmlNamespaceQ.setAlias("q");
    xmlNamespaceQ.setUri("http://www.example.com/q/");
    XmlNamespace xmlNamespaceX = new XmlNamespace();
    xmlNamespaceX.setAlias("");
    xmlNamespaceX.setUri("http://www.example.com/x/");
    XmlNamespace xmlNamespaceY = new XmlNamespace();
    xmlNamespaceY.setAlias("y");
    xmlNamespaceY.setUri("http://www.example.com/y/");
    atlasNamespaces.getXmlNamespace().add(xmlNamespaceQ);
    atlasNamespaces.getXmlNamespace().add(xmlNamespaceX);
    atlasNamespaces.getXmlNamespace().add(xmlNamespaceY);
    xmlDataSource.setXmlNamespaces(atlasNamespaces);
    dataSources.add(xmlDataSource);
    when(atlasMapping.getDataSource()).thenReturn(dataSources);
    when(session.getMapping()).thenReturn(atlasMapping);
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) ArrayList(java.util.ArrayList) XmlNamespaces(io.atlasmap.xml.v2.XmlNamespaces) DataSource(io.atlasmap.v2.DataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Example 2 with XmlDataSource

use of io.atlasmap.xml.v2.XmlDataSource 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 3 with XmlDataSource

use of io.atlasmap.xml.v2.XmlDataSource 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.
 *
 * @param dataShape datashape of the processed step
 * @param step step definition
 * @param dataSourceType datasource type
 * @return datasource
 */
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();
        source.setUri("atlas:xml:" + step.getStep().getId().get());
        XmlNamespaces xmlNamespaces = new XmlNamespaces();
        // Init the array, so that we don't have the null value
        xmlNamespaces.getXmlNamespace();
        ((XmlDataSource) source).setXmlNamespaces(xmlNamespaces);
    } else {
        fail("Unknown datashape kind " + dataShapeKind.toString());
    }
    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) XmlNamespaces(io.atlasmap.xml.v2.XmlNamespaces) DataSource(io.atlasmap.v2.DataSource) JsonDataSource(io.atlasmap.json.v2.JsonDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Example 4 with XmlDataSource

use of io.atlasmap.xml.v2.XmlDataSource in project atlasmap by atlasmap.

the class XmlFieldReader method getSourceNamespaces.

private Optional<XmlNamespaces> getSourceNamespaces(AtlasInternalSession session, Field field) {
    DataSource dataSource = null;
    AtlasMapping mapping = session.getMapping();
    // this is to simplify tests which uses mocks
    if (mapping == null || mapping.getDataSource() == null || field.getDocId() == null) {
        return Optional.empty();
    }
    List<DataSource> dataSources = mapping.getDataSource();
    for (DataSource source : dataSources) {
        if (!source.getDataSourceType().equals(DataSourceType.SOURCE)) {
            continue;
        }
        if (field.getDocId().equals(source.getId())) {
            dataSource = source;
            break;
        }
    }
    if (dataSource == null || !XmlDataSource.class.isInstance(dataSource)) {
        return Optional.empty();
    }
    XmlDataSource xmlDataSource = XmlDataSource.class.cast(dataSource);
    return xmlDataSource.getXmlNamespaces() != null ? Optional.of(xmlDataSource.getXmlNamespaces()) : Optional.empty();
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) DataSource(io.atlasmap.v2.DataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Example 5 with XmlDataSource

use of io.atlasmap.xml.v2.XmlDataSource in project atlasmap by atlasmap.

the class XmlModule method processPreTargetExecution.

@Override
public void processPreTargetExecution(AtlasInternalSession session) throws AtlasException {
    XmlNamespaces xmlNs = null;
    String template = null;
    DataSource ds = getDataSource();
    if (ds instanceof XmlDataSource) {
        xmlNs = ((XmlDataSource) ds).getXmlNamespaces();
        template = ((XmlDataSource) ds).getTemplate();
    }
    Map<String, String> nsMap = new HashMap<String, String>();
    if (xmlNs != null && xmlNs.getXmlNamespace() != null && !xmlNs.getXmlNamespace().isEmpty()) {
        for (XmlNamespace ns : xmlNs.getXmlNamespace()) {
            nsMap.put(ns.getAlias(), ns.getUri());
        }
    }
    XmlFieldWriter writer = new XmlFieldWriter(getClassLoader(), nsMap, template);
    session.setFieldWriter(getDocId(), writer);
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: processPreTargetExcution completed", getDocId());
    }
}
Also used : HashMap(java.util.HashMap) XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) XmlFieldWriter(io.atlasmap.xml.core.XmlFieldWriter) XmlNamespaces(io.atlasmap.xml.v2.XmlNamespaces) DataSource(io.atlasmap.v2.DataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Aggregations

DataSource (io.atlasmap.v2.DataSource)5 XmlDataSource (io.atlasmap.xml.v2.XmlDataSource)5 XmlNamespaces (io.atlasmap.xml.v2.XmlNamespaces)3 JsonDataSource (io.atlasmap.json.v2.JsonDataSource)2 AtlasMapping (io.atlasmap.v2.AtlasMapping)2 XmlNamespace (io.atlasmap.xml.v2.XmlNamespace)2 DataShapeKinds (io.syndesis.common.model.DataShapeKinds)2 XmlFieldWriter (io.atlasmap.xml.core.XmlFieldWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1