Search in sources :

Example 41 with AtlasType

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

the class AtlasArrayFormatConverter method fromV2ToV1.

@Override
public Collection fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException {
    Collection ret = null;
    if (v2Obj != null) {
        if (v2Obj instanceof List) {
            ret = new ArrayList();
        } else if (v2Obj instanceof Set) {
            ret = new LinkedHashSet();
        } else {
            throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "List or Set", v2Obj.getClass().getCanonicalName());
        }
        AtlasArrayType arrType = (AtlasArrayType) type;
        AtlasType elemType = arrType.getElementType();
        AtlasFormatConverter elemConverter = converterRegistry.getConverter(elemType.getTypeCategory());
        Collection v2List = (Collection) v2Obj;
        for (Object v2Elem : v2List) {
            Object convertedVal = elemConverter.fromV2ToV1(v2Elem, 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) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ArrayList(java.util.ArrayList) Collection(java.util.Collection) AtlasType(org.apache.atlas.type.AtlasType) List(java.util.List) ArrayList(java.util.ArrayList)

Example 42 with AtlasType

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

the class DeleteHandlerV1 method deleteEdge.

protected void deleteEdge(AtlasEdge edge, boolean updateInverseAttribute, boolean force) throws AtlasBaseException {
    // update inverse attribute
    if (updateInverseAttribute) {
        AtlasEdgeLabel atlasEdgeLabel = new AtlasEdgeLabel(edge.getLabel());
        AtlasType parentType = typeRegistry.getType(atlasEdgeLabel.getTypeName());
        if (parentType instanceof AtlasEntityType) {
            AtlasEntityType parentEntityType = (AtlasEntityType) parentType;
            AtlasStructType.AtlasAttribute attribute = parentEntityType.getAttribute(atlasEdgeLabel.getAttributeName());
            if (attribute.getInverseRefAttribute() != null) {
                deleteEdgeBetweenVertices(edge.getInVertex(), edge.getOutVertex(), attribute.getInverseRefAttribute());
            }
        }
    }
    deleteEdge(edge, force);
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasEdgeLabel(org.apache.atlas.repository.graph.AtlasEdgeLabel) AtlasType(org.apache.atlas.type.AtlasType) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 43 with AtlasType

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

the class DeleteHandlerV1 method getAttributeForEdge.

protected AtlasAttribute getAttributeForEdge(String edgeLabel) throws AtlasBaseException {
    AtlasEdgeLabel atlasEdgeLabel = new AtlasEdgeLabel(edgeLabel);
    AtlasType parentType = typeRegistry.getType(atlasEdgeLabel.getTypeName());
    AtlasStructType parentStructType = (AtlasStructType) parentType;
    return parentStructType.getAttribute(atlasEdgeLabel.getAttributeName());
}
Also used : AtlasEdgeLabel(org.apache.atlas.repository.graph.AtlasEdgeLabel) AtlasType(org.apache.atlas.type.AtlasType) AtlasStructType(org.apache.atlas.type.AtlasStructType)

Example 44 with AtlasType

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

the class DeleteHandlerV1 method getOwnedVertices.

/**
 * Get the GUIDs and vertices for all composite entities owned/contained by the specified root entity AtlasVertex.
 * The graph is traversed from the root entity through to the leaf nodes of the containment graph.
 *
 * @param entityVertex the root entity vertex
 * @return set of VertexInfo for all composite entities
 * @throws AtlasException
 */
public Set<GraphHelper.VertexInfo> getOwnedVertices(AtlasVertex entityVertex) throws AtlasBaseException {
    Set<GraphHelper.VertexInfo> result = new LinkedHashSet<>();
    Stack<AtlasVertex> vertices = new Stack<>();
    vertices.push(entityVertex);
    while (vertices.size() > 0) {
        AtlasVertex vertex = vertices.pop();
        AtlasEntity.Status state = AtlasGraphUtilsV1.getState(vertex);
        if (state == AtlasEntity.Status.DELETED) {
            // If the reference vertex is marked for deletion, skip it
            continue;
        }
        String typeName = GraphHelper.getTypeName(vertex);
        String guid = GraphHelper.getGuid(vertex);
        result.add(new GraphHelper.VertexInfo(guid, vertex, typeName));
        AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
        if (entityType == null) {
            throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), typeName);
        }
        for (AtlasStructType.AtlasAttribute attributeInfo : entityType.getAllAttributes().values()) {
            if (!attributeInfo.isOwnedRef()) {
                continue;
            }
            String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(entityType, attributeInfo.getName());
            AtlasType attrType = attributeInfo.getAttributeType();
            switch(attrType.getTypeCategory()) {
                case OBJECT_ID_TYPE:
                    AtlasEdge edge = graphHelper.getEdgeForLabel(vertex, edgeLabel);
                    if (edge != null && AtlasGraphUtilsV1.getState(edge) == AtlasEntity.Status.ACTIVE) {
                        AtlasVertex compositeVertex = edge.getInVertex();
                        vertices.push(compositeVertex);
                    }
                    break;
                case ARRAY:
                    AtlasArrayType arrType = (AtlasArrayType) attrType;
                    if (arrType.getElementType().getTypeCategory() != TypeCategory.OBJECT_ID_TYPE) {
                        continue;
                    }
                    Iterator<AtlasEdge> edges = graphHelper.getOutGoingEdgesByLabel(vertex, edgeLabel);
                    if (edges != null) {
                        while (edges.hasNext()) {
                            edge = edges.next();
                            if (edge != null && AtlasGraphUtilsV1.getState(edge) == AtlasEntity.Status.ACTIVE) {
                                AtlasVertex compositeVertex = edge.getInVertex();
                                vertices.push(compositeVertex);
                            }
                        }
                    }
                    break;
                case MAP:
                    AtlasMapType mapType = (AtlasMapType) attrType;
                    TypeCategory valueTypeCategory = mapType.getValueType().getTypeCategory();
                    if (valueTypeCategory != TypeCategory.OBJECT_ID_TYPE) {
                        continue;
                    }
                    String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(entityType, attributeInfo.getName());
                    List<String> keys = vertex.getProperty(propertyName, List.class);
                    if (keys != null) {
                        for (String key : keys) {
                            String mapEdgeLabel = GraphHelper.getQualifiedNameForMapKey(edgeLabel, key);
                            edge = graphHelper.getEdgeForLabel(vertex, mapEdgeLabel);
                            if (edge != null && AtlasGraphUtilsV1.getState(edge) == AtlasEntity.Status.ACTIVE) {
                                AtlasVertex compositeVertex = edge.getInVertex();
                                vertices.push(compositeVertex);
                            }
                        }
                    }
                    break;
                default:
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasArrayType(org.apache.atlas.type.AtlasArrayType) GraphHelper(org.apache.atlas.repository.graph.GraphHelper) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasType(org.apache.atlas.type.AtlasType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasMapType(org.apache.atlas.type.AtlasMapType) Stack(java.util.Stack) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) TypeCategory(org.apache.atlas.model.TypeCategory) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 45 with AtlasType

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

the class AtlasStructFormatConverter method fromV1ToV2.

protected Map<String, Object> fromV1ToV2(AtlasStructType structType, Map attributes, ConverterContext context) throws AtlasBaseException {
    Map<String, Object> ret = null;
    if (MapUtils.isNotEmpty(attributes)) {
        ret = new HashMap<>();
        // Only process the requested/set attributes
        for (Object attribKey : attributes.keySet()) {
            String attrName = attribKey.toString();
            AtlasAttribute attr = structType.getAttribute(attrName);
            if (attr == null) {
                LOG.warn("ignored unknown attribute {}.{}", structType.getTypeName(), attrName);
                continue;
            }
            AtlasType attrType = attr.getAttributeType();
            AtlasFormatConverter attrConverter = converterRegistry.getConverter(attrType.getTypeCategory());
            Object v1Value = attributes.get(attr.getName());
            Object v2Value = attrConverter.fromV1ToV2(v1Value, attrType, context);
            ret.put(attr.getAttributeDef().getName(), v2Value);
        }
    }
    return ret;
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasType(org.apache.atlas.type.AtlasType)

Aggregations

AtlasType (org.apache.atlas.type.AtlasType)95 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)51 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)33 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)23 AtlasArrayType (org.apache.atlas.type.AtlasArrayType)17 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)17 AtlasStructType (org.apache.atlas.type.AtlasStructType)16 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)15 AtlasMapType (org.apache.atlas.type.AtlasMapType)13 ArrayList (java.util.ArrayList)11 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)9 HashMap (java.util.HashMap)8 AtlasTypeAccessRequest (org.apache.atlas.authorize.AtlasTypeAccessRequest)8 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)8 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)8 Map (java.util.Map)7 List (java.util.List)6 Collection (java.util.Collection)5 LinkedHashSet (java.util.LinkedHashSet)5 Set (java.util.Set)4