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());
}
}
}
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);
}
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);
}
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);
}
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;
}
Aggregations