use of io.atlasmap.xml.core.XmlFieldWriter in project atlasmap by atlasmap.
the class XmlModule method processPostTargetExecution.
@Override
public void processPostTargetExecution(AtlasInternalSession session) throws AtlasException {
XmlFieldWriter writer = session.getFieldWriter(getDocId(), XmlFieldWriter.class);
if (writer != null && writer.getDocument() != null) {
session.setTargetDocument(getDocId(), convertDocumentToString(writer.getDocument()));
} else {
AtlasUtil.addAudit(session, getDocId(), String.format("No target document created for DataSource:[id=%s, uri=%s]", getDocId(), this.getUri()), null, AuditStatus.WARN, null);
}
session.removeFieldWriter(getDocId());
if (LOG.isDebugEnabled()) {
LOG.debug("{}: processPostTargetExecution completed", getDocId());
}
}
use of io.atlasmap.xml.core.XmlFieldWriter in project atlasmap by atlasmap.
the class XmlModule method processPreTargetExecution.
@Override
public void processPreTargetExecution(AtlasInternalSession session) throws AtlasException {
XmlNamespaces xmlNs = null;
String template = null;
for (DataSource ds : session.getMapping().getDataSource()) {
if (DataSourceType.TARGET.equals(ds.getDataSourceType()) && ds instanceof XmlDataSource && (ds.getId() == null || ds.getId().equals(getDocId()))) {
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(nsMap, template);
session.setFieldWriter(getDocId(), writer);
if (LOG.isDebugEnabled()) {
LOG.debug("{}: processPreTargetExcution completed", getDocId());
}
}
use of io.atlasmap.xml.core.XmlFieldWriter in project atlasmap by atlasmap.
the class XmlModule method processTargetFieldMapping.
@Override
public void processTargetFieldMapping(AtlasInternalSession session) throws AtlasException {
Field sourceField = session.head().getSourceField();
Field targetField = session.head().getTargetField();
// Attempt to Auto-detect field type based on input value
if (targetField.getFieldType() == null && sourceField.getValue() != null) {
targetField.setFieldType(getConversionService().fieldTypeFromClass(sourceField.getValue().getClass()));
}
Object outputValue = null;
// Do auto-conversion
if (sourceField.getFieldType() != null && sourceField.getFieldType().equals(targetField.getFieldType())) {
outputValue = sourceField.getValue();
} else if (sourceField.getValue() != null) {
try {
outputValue = getConversionService().convertType(sourceField.getValue(), sourceField.getFormat(), targetField.getFieldType(), targetField.getFormat());
} catch (AtlasConversionException e) {
AtlasUtil.addAudit(session, targetField.getDocId(), String.format("Unable to auto-convert for sT=%s tT=%s tF=%s msg=%s", sourceField.getFieldType(), targetField.getFieldType(), targetField.getPath(), e.getMessage()), targetField.getPath(), AuditStatus.ERROR, null);
return;
}
}
targetField.setValue(outputValue);
LookupTable lookupTable = session.head().getLookupTable();
if (lookupTable != null) {
processLookupField(session, lookupTable, targetField.getValue(), targetField);
}
if (isAutomaticallyProcessOutputFieldActions() && targetField.getActions() != null && targetField.getActions().getActions() != null) {
getFieldActionService().processActions(targetField.getActions(), targetField);
}
XmlFieldWriter writer = session.getFieldWriter(getDocId(), XmlFieldWriter.class);
writer.write(session);
if (LOG.isDebugEnabled()) {
LOG.debug("{}: processTargetFieldMapping completed: SourceField:[docId={}, path={}, type={}, value={}], TargetField:[docId={}, path={}, type={}, value={}]", getDocId(), sourceField.getDocId(), sourceField.getPath(), sourceField.getFieldType(), sourceField.getValue(), targetField.getDocId(), targetField.getPath(), targetField.getFieldType(), targetField.getValue());
}
}
Aggregations