Search in sources :

Example 36 with DataSource

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

the class BaseMarshallerTest method generateMultiSourceMapping.

protected AtlasMapping generateMultiSourceMapping() {
    AtlasMapping mapping = generateSeparateAtlasMapping();
    DataSource sourceA = generateDataSource("srcId", "srcUri", DataSourceType.SOURCE);
    mapping.getDataSource().add(sourceA);
    DataSource targetA = generateDataSource("tgtId", "tgtUri", DataSourceType.TARGET);
    mapping.getDataSource().add(targetA);
    DataSource targetB = generateDataSource("tgtId", "tgtUri", DataSourceType.TARGET);
    mapping.getDataSource().add(targetB);
    Mapping fm = (Mapping) mapping.getMappings().getMapping().get(0);
    fm.getInputField().get(0).setDocId("docid");
    fm.getOutputField().get(0).setDocId("docid");
    fm.getOutputField().get(1).setDocId("docid");
    populateMapping(fm, MappingType.MAP, "MapPropertyFieldAlias", ",", ",");
    populateMappingString(fm, "description", "id", "lookupTableName", "strategy", "strategyClassName");
    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 37 with DataSource

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

the class BaseMarshallerTest method generateDataSource.

private void generateDataSource(AtlasMapping atlasMapping) {
    DataSource src = generateDataSource("srcId", "srcUri", DataSourceType.SOURCE);
    DataSource tgt = generateDataSource("tgtId", "tgtUri", DataSourceType.TARGET);
    atlasMapping.getDataSource().add(src);
    atlasMapping.getDataSource().add(tgt);
}
Also used : DataSource(io.atlasmap.v2.DataSource)

Example 38 with DataSource

use of com.google.cloud.bigquery.datatransfer.v1.DataSource 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)

Example 39 with DataSource

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

the class XmlValidationServiceTest 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)

Example 40 with DataSource

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

the class AtlasEndpoint method populateTargetDocuments.

private void populateTargetDocuments(AtlasSession session, Exchange exchange) {
    Message outMessage = exchange.getOut();
    outMessage.setHeaders(exchange.getIn().getHeaders());
    outMessage.setAttachments(exchange.getIn().getAttachments());
    if (session.getMapping().getDataSource() == null) {
        return;
    }
    DataSource[] targetDataSources = session.getMapping().getDataSource().stream().filter(ds -> ds.getDataSourceType() == DataSourceType.TARGET).toArray(DataSource[]::new);
    if (targetDataSources.length == 0) {
        Object newBody = session.getDefaultTargetDocument();
        outMessage.setBody(newBody);
        return;
    }
    if (targetDataSources.length == 1) {
        String docId = targetDataSources[0].getId();
        if (docId == null || docId.isEmpty()) {
            Object newBody = session.getDefaultTargetDocument();
            outMessage.setBody(newBody);
        } else {
            Object newBody = session.getTargetDocument(docId);
            outMessage.setBody(newBody);
        }
        setContentType(targetDataSources[0], outMessage);
        return;
    }
    Map<String, Object> targetDocuments = new HashMap<>();
    for (DataSource ds : targetDataSources) {
        String docId = ds.getId();
        if (docId == null || docId.isEmpty()) {
            targetDocuments.put(io.atlasmap.api.AtlasConstants.DEFAULT_TARGET_DOCUMENT_ID, session.getDefaultTargetDocument());
            Object newBody = session.getDefaultTargetDocument();
            outMessage.setBody(newBody);
            setContentType(ds, outMessage);
        } else {
            targetDocuments.put(docId, session.getTargetDocument(docId));
        }
    }
    switch(targetMapMode) {
        case MAP:
            if (targetMapName != null) {
                exchange.setProperty(targetMapName, targetDocuments);
            } else {
                outMessage.setBody(targetDocuments);
            }
            break;
        case MESSAGE_HEADER:
            targetDocuments.remove(io.atlasmap.api.AtlasConstants.DEFAULT_TARGET_DOCUMENT_ID);
            outMessage.getHeaders().putAll(targetDocuments);
            break;
        case EXCHANGE_PROPERTY:
            targetDocuments.remove(io.atlasmap.api.AtlasConstants.DEFAULT_TARGET_DOCUMENT_ID);
            exchange.getProperties().putAll(targetDocuments);
            break;
    }
}
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) 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