use of org.talend.hl7.Field in project syndesis-qe by syndesisio.
the class AtlasMapperGenerator method generateCombineMapping.
private Mapping generateCombineMapping(DataMapperStepDefinition mappingDef, List<StepDefinition> precedingSteps, StepDefinition followingStep) {
StepDefinition fromStep = precedingSteps.get(mappingDef.getFromStep() - 1);
Mapping generatedMapping = new Mapping();
generatedMapping.setId(UUID.randomUUID().toString());
generatedMapping.setMappingType(MappingType.COMBINE);
generatedMapping.setDelimiter(mappingDef.getStrategy().name());
List<Field> in = new ArrayList<>();
for (int i = 0; i < mappingDef.getInputFields().size(); i++) {
String def = mappingDef.getInputFields().get(i);
Field inField = fromStep.getInspectionResponseFields().get().stream().filter(f -> f.getPath().matches(def)).findFirst().get();
inField.setIndex(i);
in.add(inField);
}
Field out = followingStep.getInspectionResponseFields().get().stream().filter(f -> f.getPath().matches(mappingDef.getOutputFields().get(0))).findFirst().get();
in.forEach(f -> f.setDocId(fromStep.getStep().getId().get()));
out.setDocId(followingStep.getStep().getId().get());
generatedMapping.getInputField().addAll(in);
generatedMapping.getOutputField().add(out);
return generatedMapping;
}
use of org.talend.hl7.Field in project atlasmap by atlasmap.
the class JavaModule method merge.
private void merge(JavaClass inspectionClass, List<BaseMapping> mappings) {
if (inspectionClass == null || inspectionClass.getJavaFields() == null || inspectionClass.getJavaFields().getJavaField() == null) {
return;
}
if (mappings == null || mappings.size() == 0) {
return;
}
for (BaseMapping fm : mappings) {
if (fm instanceof Mapping && (((Mapping) fm).getOutputField() != null)) {
Field f = ((Mapping) fm).getOutputField().get(0);
if (f.getPath() != null) {
Field inspectField = findFieldByPath(inspectionClass, f.getPath());
if (inspectField != null && f instanceof JavaField && inspectField instanceof JavaField) {
String overrideClassName = ((JavaField) f).getClassName();
JavaField javaInspectField = (JavaField) inspectField;
// Support mapping overrides className
if (overrideClassName != null && !overrideClassName.equals(javaInspectField.getClassName())) {
javaInspectField.setClassName(overrideClassName);
}
}
}
}
}
}
use of org.talend.hl7.Field in project atlasmap by atlasmap.
the class JavaModule method processSourceFieldMapping.
@Override
public void processSourceFieldMapping(AtlasInternalSession session) throws AtlasException {
Field sourceField = session.head().getSourceField();
DocumentJavaFieldReader reader = session.getFieldReader(getDocId(), DocumentJavaFieldReader.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 JavaModule method processTargetFieldMapping.
@Override
public void processTargetFieldMapping(AtlasInternalSession session) throws AtlasException {
DocumentJavaFieldWriter writer = session.getFieldWriter(getDocId(), DocumentJavaFieldWriter.class);
writer.write(session);
if (LOG.isDebugEnabled()) {
Field sourceField = session.head().getSourceField();
Field targetField = session.head().getTargetField();
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());
}
}
use of org.talend.hl7.Field in project atlasmap by atlasmap.
the class JsonFieldWriter method write.
@Override
public void write(AtlasInternalSession session) throws AtlasException {
Field targetField = session.head().getTargetField();
if (targetField == null) {
throw new AtlasException(new IllegalArgumentException("Argument 'jsonField' cannot be null"));
}
if (LOG.isDebugEnabled()) {
LOG.debug("Field: " + AtlasModelFactory.toString(targetField));
LOG.debug("Field type=" + targetField.getFieldType() + " path=" + targetField.getPath() + " v=" + targetField.getValue());
}
AtlasPath path = new AtlasPath(targetField.getPath());
String lastSegment = path.getLastSegment();
ObjectNode parentNode = this.rootNode;
String parentSegment = null;
for (String segment : path.getSegments()) {
if (!segment.equals(lastSegment)) {
// this is a parent node.
if (LOG.isDebugEnabled()) {
LOG.debug("Now processing parent segment: " + segment);
}
JsonNode childNode = getChildNode(parentNode, parentSegment, segment);
if (childNode == null) {
childNode = createParentNode(parentNode, parentSegment, segment);
} else if (childNode instanceof ArrayNode) {
int index = AtlasPath.indexOfSegment(segment);
ArrayNode arrayChild = (ArrayNode) childNode;
if (arrayChild.size() < (index + 1)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Object Array is too small, resizing to accomodate index: " + index + ", current array: " + arrayChild);
}
// index available
while (arrayChild.size() < (index + 1)) {
arrayChild.addObject();
}
if (LOG.isDebugEnabled()) {
LOG.debug("Object Array after resizing: " + arrayChild);
}
}
childNode = arrayChild.get(index);
}
parentNode = (ObjectNode) childNode;
parentSegment = segment;
} else {
// this is the last segment of the path, write the value
if (targetField.getFieldType() == FieldType.COMPLEX) {
createParentNode(parentNode, parentSegment, segment);
return;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Now processing field value segment: " + segment);
}
writeValue(parentNode, parentSegment, segment, targetField);
}
}
}
Aggregations