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