use of io.atlasmap.json.core.JsonFieldWriter in project atlasmap by atlasmap.
the class JsonModule 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 targetValue = null;
// Do auto-conversion
if (sourceField.getFieldType() != null && sourceField.getFieldType().equals(targetField.getFieldType())) {
targetValue = sourceField.getValue();
} else if (sourceField.getValue() != null) {
try {
targetValue = 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(targetValue);
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);
}
JsonFieldWriter writer = session.getFieldWriter(getDocId(), JsonFieldWriter.class);
writer.write(session);
}
use of io.atlasmap.json.core.JsonFieldWriter in project atlasmap by atlasmap.
the class JsonModule method processPreTargetExecution.
@Override
public void processPreTargetExecution(AtlasInternalSession session) throws AtlasException {
JsonFieldWriter writer = new JsonFieldWriter();
session.setFieldWriter(getDocId(), writer);
if (LOG.isDebugEnabled()) {
LOG.debug("{} processPreTargetExcution completed", getDocId());
}
}
use of io.atlasmap.json.core.JsonFieldWriter in project atlasmap by atlasmap.
the class JsonModule method processPostTargetExecution.
@Override
public void processPostTargetExecution(AtlasInternalSession session) throws AtlasException {
JsonFieldWriter writer = session.getFieldWriter(getDocId(), JsonFieldWriter.class);
if (writer != null && writer.getRootNode() != null) {
String outputBody = writer.getRootNode().toString();
session.setTargetDocument(getDocId(), outputBody);
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("processPostTargetExecution converting JsonNode to string size=%s", outputBody.length()));
}
} 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());
}
}
Aggregations