Search in sources :

Example 61 with Field

use of org.talend.hl7.Field in project atlasmap by atlasmap.

the class DocumentJavaFieldReader method extractFromCollection.

private Object extractFromCollection(AtlasInternalSession session, Object source, AtlasPath atlasPath) {
    if (source == null) {
        return null;
    }
    String lastSegment = atlasPath.getLastSegment();
    if (!AtlasPath.isCollectionSegment(lastSegment) || !atlasPath.isIndexedCollection()) {
        return source;
    }
    Integer index = atlasPath.getCollectionIndex(atlasPath.getLastSegment());
    if (AtlasPath.isArraySegment(lastSegment)) {
        return Array.get(source, index);
    } else if (AtlasPath.isListSegment(lastSegment)) {
        return Collection.class.cast(source).toArray()[index];
    } else if (AtlasPath.isMapSegment(lastSegment)) {
        // TODO support map key
        String key = index.toString();
        return Map.class.cast(source).get(key);
    } else {
        Field sourceField = session.head().getSourceField();
        AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Ignoring unknown collection type in path '%s'", sourceField.getPath()), sourceField.getPath(), AuditStatus.WARN, null);
        return source;
    }
}
Also used : JavaEnumField(io.atlasmap.java.v2.JavaEnumField) Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField) Collection(java.util.Collection) Map(java.util.Map)

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