Search in sources :

Example 6 with AtlasArrayType

use of org.apache.atlas.type.AtlasArrayType in project incubator-atlas by apache.

the class EntityGraphMapper method mapArrayValue.

public List mapArrayValue(AttributeMutationContext ctx, EntityMutationContext context) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> mapArrayValue({})", ctx);
    }
    AtlasAttribute attribute = ctx.getAttribute();
    List newElements = (List) ctx.getValue();
    AtlasArrayType arrType = (AtlasArrayType) attribute.getAttributeType();
    AtlasType elementType = arrType.getElementType();
    List<Object> currentElements = getArrayElementsProperty(elementType, ctx.getReferringVertex(), ctx.getVertexProperty());
    boolean isReference = AtlasGraphUtilsV1.isReference(elementType);
    AtlasAttribute inverseRefAttribute = attribute.getInverseRefAttribute();
    List<Object> newElementsCreated = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(newElements)) {
        for (int index = 0; index < newElements.size(); index++) {
            AtlasEdge existingEdge = getEdgeAt(currentElements, index, elementType);
            AttributeMutationContext arrCtx = new AttributeMutationContext(ctx.getOp(), ctx.getReferringVertex(), ctx.getAttribute(), newElements.get(index), ctx.getVertexProperty(), elementType, existingEdge);
            Object newEntry = mapCollectionElementsToVertex(arrCtx, context);
            if (isReference && newEntry instanceof AtlasEdge && inverseRefAttribute != null) {
                // Update the inverse reference value.
                AtlasEdge newEdge = (AtlasEdge) newEntry;
                addInverseReference(arrCtx, inverseRefAttribute, newEdge);
            }
            newElementsCreated.add(newEntry);
        }
    }
    if (isReference) {
        List<AtlasEdge> additionalEdges = removeUnusedArrayEntries(attribute, (List) currentElements, (List) newElementsCreated);
        newElementsCreated.addAll(additionalEdges);
    }
    // for dereference on way out
    setArrayElementsProperty(elementType, ctx.getReferringVertex(), ctx.getVertexProperty(), newElementsCreated);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== mapArrayValue({})", ctx);
    }
    return newElementsCreated;
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasArrayType(org.apache.atlas.type.AtlasArrayType) AtlasType(org.apache.atlas.type.AtlasType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 7 with AtlasArrayType

use of org.apache.atlas.type.AtlasArrayType in project incubator-atlas by apache.

the class ExportService method addType.

private void addType(AtlasType type, ExportContext context) {
    if (type.getTypeCategory() == TypeCategory.PRIMITIVE) {
        return;
    }
    if (type instanceof AtlasArrayType) {
        AtlasArrayType arrayType = (AtlasArrayType) type;
        addType(arrayType.getElementType(), context);
    } else if (type instanceof AtlasMapType) {
        AtlasMapType mapType = (AtlasMapType) type;
        addType(mapType.getKeyType(), context);
        addType(mapType.getValueType(), context);
    } else if (type instanceof AtlasEntityType) {
        addEntityType((AtlasEntityType) type, context);
    } else if (type instanceof AtlasClassificationType) {
        addClassificationType((AtlasClassificationType) type, context);
    } else if (type instanceof AtlasStructType) {
        addStructType((AtlasStructType) type, context);
    } else if (type instanceof AtlasEnumType) {
        addEnumType((AtlasEnumType) type, context);
    }
}
Also used : AtlasArrayType(org.apache.atlas.type.AtlasArrayType) AtlasEnumType(org.apache.atlas.type.AtlasEnumType) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) AtlasMapType(org.apache.atlas.type.AtlasMapType)

Example 8 with AtlasArrayType

use of org.apache.atlas.type.AtlasArrayType in project incubator-atlas by apache.

the class AtlasArrayFormatConverter method fromV1ToV2.

@Override
public Collection fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException {
    Collection ret = null;
    if (v1Obj != null) {
        if (v1Obj instanceof Set) {
            ret = new LinkedHashSet();
        } else {
            ret = new ArrayList();
        }
        AtlasArrayType arrType = (AtlasArrayType) type;
        AtlasType elemType = arrType.getElementType();
        AtlasFormatConverter elemConverter = converterRegistry.getConverter(elemType.getTypeCategory());
        if (v1Obj instanceof Collection) {
            Collection v1List = (Collection) v1Obj;
            for (Object v1Elem : v1List) {
                Object convertedVal = elemConverter.fromV1ToV2(v1Elem, elemType, ctx);
                ret.add(convertedVal);
            }
        } else {
            Object convertedVal = elemConverter.fromV1ToV2(v1Obj, elemType, ctx);
            ret.add(convertedVal);
        }
    }
    return ret;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AtlasArrayType(org.apache.atlas.type.AtlasArrayType) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) Collection(java.util.Collection) AtlasType(org.apache.atlas.type.AtlasType)

Aggregations

AtlasArrayType (org.apache.atlas.type.AtlasArrayType)8 AtlasType (org.apache.atlas.type.AtlasType)7 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)4 AtlasMapType (org.apache.atlas.type.AtlasMapType)4 AtlasStructType (org.apache.atlas.type.AtlasStructType)4 ArrayList (java.util.ArrayList)3 LinkedHashSet (java.util.LinkedHashSet)3 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)3 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)3 Collection (java.util.Collection)2 List (java.util.List)2 Set (java.util.Set)2 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 TypeCategory (org.apache.atlas.model.TypeCategory)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Stack (java.util.Stack)1 TestUtils.randomString (org.apache.atlas.TestUtils.randomString)1 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)1 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)1