Search in sources :

Example 26 with Field

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;
}
Also used : Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField) ArrayList(java.util.ArrayList) DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) StepDefinition(io.syndesis.qe.bdd.entities.StepDefinition) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasmapEndpoint(io.syndesis.qe.endpoints.AtlasmapEndpoint)

Example 27 with Field

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);
                    }
                }
            }
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField) JavaField(io.atlasmap.java.v2.JavaField) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) BaseMapping(io.atlasmap.v2.BaseMapping)

Example 28 with Field

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());
    }
}
Also used : Field(io.atlasmap.v2.Field) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField) DocumentJavaFieldReader(io.atlasmap.java.core.DocumentJavaFieldReader)

Example 29 with Field

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());
    }
}
Also used : Field(io.atlasmap.v2.Field) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField) DocumentJavaFieldWriter(io.atlasmap.java.core.DocumentJavaFieldWriter)

Example 30 with Field

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);
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AtlasPath(io.atlasmap.core.AtlasPath) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AtlasException(io.atlasmap.api.AtlasException)

Aggregations

Field (io.atlasmap.v2.Field)60 JavaField (io.atlasmap.java.v2.JavaField)15 Mapping (io.atlasmap.v2.Mapping)15 AtlasMapping (io.atlasmap.v2.AtlasMapping)14 SimpleField (io.atlasmap.v2.SimpleField)14 BaseMapping (io.atlasmap.v2.BaseMapping)12 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)11 Test (org.junit.Test)11 JsonField (io.atlasmap.json.v2.JsonField)8 LookupTable (io.atlasmap.v2.LookupTable)8 XmlField (io.atlasmap.xml.v2.XmlField)7 AtlasException (io.atlasmap.api.AtlasException)6 ConstantField (io.atlasmap.v2.ConstantField)6 AtlasConversionException (io.atlasmap.api.AtlasConversionException)5 JsonDocument (io.atlasmap.json.v2.JsonDocument)5 PropertyField (io.atlasmap.v2.PropertyField)5 ArrayList (java.util.ArrayList)5 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)4 AtlasModule (io.atlasmap.spi.AtlasModule)3 FieldType (io.atlasmap.v2.FieldType)3