Search in sources :

Example 41 with DataSource

use of com.google.cloud.bigquery.datatransfer.v1.DataSource in project atlasmap by atlasmap.

the class AtlasEndpoint method populateSourceDocuments.

private void populateSourceDocuments(Exchange exchange, AtlasSession session) {
    if (session.getMapping().getDataSource() == null) {
        return;
    }
    Message inMessage = exchange.getIn();
    CamelAtlasPropertyStrategy propertyStrategy = new CamelAtlasPropertyStrategy();
    propertyStrategy.setCurrentSourceMessage(inMessage);
    propertyStrategy.setTargetMessage(exchange.getMessage());
    propertyStrategy.setExchange(exchange);
    session.setAtlasPropertyStrategy(propertyStrategy);
    DataSource[] sourceDataSources = session.getMapping().getDataSource().stream().filter(ds -> ds.getDataSourceType() == DataSourceType.SOURCE).toArray(DataSource[]::new);
    if (sourceDataSources.length == 0) {
        session.setDefaultSourceDocument(exchange.getIn().getBody());
        return;
    }
    if (sourceDataSources.length == 1) {
        String docId = sourceDataSources[0].getId();
        Object payload = extractPayload(sourceDataSources[0], inMessage);
        if (docId == null || docId.isEmpty()) {
            session.setDefaultSourceDocument(payload);
        } else {
            session.setSourceDocument(docId, payload);
            propertyStrategy.setSourceMessage(docId, inMessage);
        }
        return;
    }
    Map<String, Message> sourceMessages = null;
    Map<String, Object> sourceDocuments = null;
    if (sourceMapName != null) {
        sourceMessages = exchange.getProperty(sourceMapName, Map.class);
    }
    if (sourceMessages == null) {
        Object body = exchange.getIn().getBody();
        if (body instanceof Map) {
            sourceDocuments = (Map<String, Object>) body;
        } else {
            session.setDefaultSourceDocument(body);
        }
    }
    for (DataSource ds : sourceDataSources) {
        String docId = ds.getId();
        if (docId == null || docId.isEmpty()) {
            Object payload = extractPayload(ds, inMessage);
            session.setDefaultSourceDocument(payload);
        } else if (sourceMessages != null) {
            Object payload = extractPayload(ds, sourceMessages.get(docId));
            session.setSourceDocument(docId, payload);
            propertyStrategy.setSourceMessage(docId, sourceMessages.get(docId));
        } else if (sourceDocuments != null) {
            Object payload = sourceDocuments.get(docId);
            session.setSourceDocument(docId, payload);
        } else if (inMessage.getHeaders().containsKey(docId)) {
            Object payload = inMessage.getHeader(docId);
            session.setSourceDocument(docId, payload);
        } else if (exchange.getProperties().containsKey(docId)) {
            Object payload = exchange.getProperty(docId);
            session.setSourceDocument(docId, payload);
        } else {
            LOG.warn("Ignoring missing source document: '{}(ID:{})'", ds.getName(), ds.getId());
        }
    }
}
Also used : Message(org.apache.camel.Message) LoggerFactory(org.slf4j.LoggerFactory) DataSource(io.atlasmap.v2.DataSource) HashMap(java.util.HashMap) Exchange(org.apache.camel.Exchange) ArrayList(java.util.ArrayList) UriEndpoint(org.apache.camel.spi.UriEndpoint) UriParam(org.apache.camel.spi.UriParam) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) ResourceEndpoint(org.apache.camel.component.ResourceEndpoint) AtlasContextFactory(io.atlasmap.api.AtlasContextFactory) ExchangePattern(org.apache.camel.ExchangePattern) Logger(org.slf4j.Logger) AtlasException(io.atlasmap.api.AtlasException) ADM(io.atlasmap.api.AtlasContextFactory.Format.ADM) MessageHelper(org.apache.camel.util.MessageHelper) DataSourceType(io.atlasmap.v2.DataSourceType) List(java.util.List) Audit(io.atlasmap.v2.Audit) JSON(io.atlasmap.api.AtlasContextFactory.Format.JSON) AtlasSession(io.atlasmap.api.AtlasSession) ObjectHelper(org.apache.camel.util.ObjectHelper) AtlasContext(io.atlasmap.api.AtlasContext) InputStream(java.io.InputStream) Message(org.apache.camel.Message) HashMap(java.util.HashMap) Map(java.util.Map) DataSource(io.atlasmap.v2.DataSource)

Example 42 with DataSource

use of com.google.cloud.bigquery.datatransfer.v1.DataSource in project atlasmap by atlasmap.

the class AtlasEndpointTest method noConversionIfJsonTargetDataSource.

@Test(expected = ComparisonFailure.class)
public void noConversionIfJsonTargetDataSource() throws Exception {
    final List<DataSource> dataSources = new ArrayList<>();
    final DataSource dataSource = new DataSource();
    dataSource.setDataSourceType(DataSourceType.TARGET);
    dataSource.setUri("atlas:json:SomeType");
    dataSources.add(dataSource);
    perform(dataSources, null, null, true);
}
Also used : ArrayList(java.util.ArrayList) DataSource(io.atlasmap.v2.DataSource) Test(org.junit.Test)

Example 43 with DataSource

use of com.google.cloud.bigquery.datatransfer.v1.DataSource in project atlasmap by atlasmap.

the class AtlasEndpointTest method noConversionIfXmlTargetDataSource.

@Test(expected = ComparisonFailure.class)
public void noConversionIfXmlTargetDataSource() throws Exception {
    final List<DataSource> dataSources = new ArrayList<>();
    final DataSource dataSource = new DataSource();
    dataSource.setDataSourceType(DataSourceType.TARGET);
    dataSource.setUri("atlas:xml:SomeType");
    dataSources.add(dataSource);
    perform(dataSources, null, null, true);
}
Also used : ArrayList(java.util.ArrayList) DataSource(io.atlasmap.v2.DataSource) Test(org.junit.Test)

Example 44 with DataSource

use of com.google.cloud.bigquery.datatransfer.v1.DataSource in project atlasmap by atlasmap.

the class AtlasEndpointTest method doConversionIfXmlDataSource.

@Test
public void doConversionIfXmlDataSource() throws Exception {
    final List<DataSource> dataSources = new ArrayList<>();
    final DataSource dataSource = new DataSource();
    dataSource.setDataSourceType(DataSourceType.SOURCE);
    dataSource.setUri("atlas:xml:SomeType");
    dataSources.add(dataSource);
    perform(dataSources, null, null, true);
}
Also used : ArrayList(java.util.ArrayList) DataSource(io.atlasmap.v2.DataSource) Test(org.junit.Test)

Example 45 with DataSource

use of com.google.cloud.bigquery.datatransfer.v1.DataSource in project atlasmap by atlasmap.

the class XmlJsonFlatMappingTest method generateDataSource.

protected DataSource generateDataSource(String uri, DataSourceType type) {
    DataSource ds = new DataSource();
    ds.setUri(uri);
    ds.setDataSourceType(type);
    return ds;
}
Also used : DataSource(io.atlasmap.v2.DataSource)

Aggregations

DataSource (io.atlasmap.v2.DataSource)54 AtlasMapping (io.atlasmap.v2.AtlasMapping)15 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 JavaField (io.atlasmap.java.v2.JavaField)5 AtlasContext (io.atlasmap.api.AtlasContext)4 AtlasSession (io.atlasmap.api.AtlasSession)4 XmlNamespaces (io.atlasmap.xml.v2.XmlNamespaces)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 AtlasException (io.atlasmap.api.AtlasException)3 DataSourceType (io.atlasmap.v2.DataSourceType)3 HashMap (java.util.HashMap)3 AtlasContextFactory (io.atlasmap.api.AtlasContextFactory)2 ADM (io.atlasmap.api.AtlasContextFactory.Format.ADM)2