use of org.talend.hl7.Field in project atlasmap by atlasmap.
the class JsonModule method processSourceFieldMapping.
@Override
public void processSourceFieldMapping(AtlasInternalSession session) throws AtlasException {
Field sourceField = session.head().getSourceField();
JsonFieldReader reader = session.getFieldReader(getDocId(), JsonFieldReader.class);
if (reader == null) {
AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Source document '%s' doesn't exist", getDocId()), sourceField.getPath(), AuditStatus.ERROR, null);
return;
}
reader.read(session);
if (sourceField.getActions() != null && sourceField.getActions().getActions() != null) {
getFieldActionService().processActions(sourceField.getActions(), sourceField);
}
if (LOG.isDebugEnabled()) {
LOG.debug("{}: processSourceFieldMapping completed: SourceField:[docId={}, path={}, type={}, value={}]", getDocId(), sourceField.getDocId(), sourceField.getPath(), sourceField.getFieldType(), sourceField.getValue());
}
}
use of org.talend.hl7.Field 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 org.talend.hl7.Field in project atlasmap by atlasmap.
the class XmlFieldWriter method write.
@Override
public void write(AtlasInternalSession session) throws AtlasException {
Field targetField = session.head().getTargetField();
if (targetField == null) {
throw new AtlasException(new IllegalArgumentException("Argument 'field' cannot be null"));
}
if (LOG.isDebugEnabled()) {
LOG.debug("Now processing field p={} t={} v={}", targetField.getPath(), targetField.getFieldType(), targetField.getValue());
}
XmlPath path = new XmlPath(targetField.getPath());
String lastSegment = path.getLastSegment();
Element parentNode = null;
String parentSegment = null;
for (String segment : path.getSegments()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Now processing segment: {}", segment);
LOG.debug("Parent element is currently: {}", XmlIOHelper.writeDocumentToString(true, parentNode));
}
if (parentNode == null) {
// processing root node
parentNode = document.getDocumentElement();
String cleanedSegment = XmlPath.cleanPathSegment(segment);
if (parentNode == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Creating root element with name: {}", cleanedSegment);
}
// no root node exists yet, create root node with this segment name;
Element rootNode = createElement(segment);
addNamespacesToElement(rootNode, namespaces);
document.appendChild(rootNode);
parentNode = rootNode;
} else if (!(parentNode.getNodeName().equals(segment))) {
// make sure root element's name matches.
throw new AtlasException(String.format("Root element name '%s' does not match expected name '%s' from path: %s", parentNode.getNodeName(), segment, targetField.getPath()));
}
parentSegment = segment;
} else {
if (LOG.isDebugEnabled()) {
if (segment.equals(lastSegment)) {
LOG.debug("Now processing field value segment: {}", segment);
} else {
LOG.debug("Now processing parent segment: {}", segment);
}
}
if (segment.equals(lastSegment) && targetField.getValue() == null) {
break;
}
if (!XmlPath.isAttributeSegment(segment)) {
// if current segment of path isn't attribute, it refers to a child element,
// find it or create it..
Element childNode = getChildNode(parentNode, parentSegment, segment);
if (childNode == null) {
childNode = createParentNode(parentNode, parentSegment, segment);
}
parentNode = childNode;
parentSegment = segment;
}
if (segment.equals(lastSegment)) {
writeValue(parentNode, segment, targetField);
}
}
}
}
use of org.talend.hl7.Field in project atlasmap by atlasmap.
the class SchemaInspectorTest method inspectFlatPrimitiveNoRoot.
@Test
public void inspectFlatPrimitiveNoRoot() throws Exception {
final String instance = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/flatprimitive-base-unrooted.json")));
JsonDocument document = inspectionService.inspectJsonSchema(instance);
assertNotNull(document);
assertEquals(5, document.getFields().getField().size());
List<Field> fields = document.getFields().getField();
JsonField field = (JsonField) fields.get(0);
assertEquals("booleanField", field.getName());
assertEquals("/booleanField", field.getPath());
assertEquals(FieldType.BOOLEAN, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
field = (JsonField) fields.get(1);
assertEquals("stringField", field.getName());
assertEquals("/stringField", field.getPath());
assertEquals(FieldType.STRING, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
field = (JsonField) fields.get(2);
assertEquals("numberField", field.getName());
assertEquals("/numberField", field.getPath());
assertEquals(FieldType.NUMBER, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
field = (JsonField) fields.get(3);
assertEquals("intField", field.getName());
assertEquals("/intField", field.getPath());
assertEquals(FieldType.INTEGER, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
field = (JsonField) fields.get(4);
assertEquals("nullField", field.getName());
assertEquals("/nullField", field.getPath());
assertEquals(FieldType.NONE, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
}
use of org.talend.hl7.Field in project atlasmap by atlasmap.
the class JsonFieldWriterTest method write.
private void write(Field field) throws Exception {
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(mock(Head.class));
when(session.head().getSourceField()).thenReturn(mock(Field.class));
when(session.head().getTargetField()).thenReturn(field);
writer.write(session);
}
Aggregations