Search in sources :

Example 76 with AtlasEdge

use of org.apache.atlas.repository.graphdb.AtlasEdge in project atlas by apache.

the class GraphHelper method getAssociatedEntityVertex.

public static AtlasVertex getAssociatedEntityVertex(AtlasVertex classificationVertex) {
    AtlasVertex ret = null;
    Iterable edges = classificationVertex.query().direction(AtlasEdgeDirection.IN).label(CLASSIFICATION_LABEL).has(CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY, false).has(CLASSIFICATION_EDGE_NAME_PROPERTY_KEY, getTypeName(classificationVertex)).edges();
    if (edges != null) {
        Iterator<AtlasEdge> iterator = edges.iterator();
        if (iterator != null && iterator.hasNext()) {
            AtlasEdge edge = iterator.next();
            ret = edge.getOutVertex();
        }
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 77 with AtlasEdge

use of org.apache.atlas.repository.graphdb.AtlasEdge in project atlas by apache.

the class GraphHelper method getClassificationEdge.

public static AtlasEdge getClassificationEdge(AtlasVertex entityVertex, AtlasVertex classificationVertex) {
    AtlasEdge ret = null;
    Iterable edges = entityVertex.query().direction(AtlasEdgeDirection.OUT).label(CLASSIFICATION_LABEL).has(CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY, false).has(CLASSIFICATION_EDGE_NAME_PROPERTY_KEY, getTypeName(classificationVertex)).edges();
    if (edges != null) {
        Iterator<AtlasEdge> iterator = edges.iterator();
        if (iterator.hasNext()) {
            AtlasEdge edge = iterator.next();
            ret = (edge != null && edge.getInVertex().equals(classificationVertex)) ? edge : null;
        }
    }
    return ret;
}
Also used : AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 78 with AtlasEdge

use of org.apache.atlas.repository.graphdb.AtlasEdge in project atlas by apache.

the class GraphHelper method addClassificationEdge.

public AtlasEdge addClassificationEdge(AtlasVertex entityVertex, AtlasVertex classificationVertex, boolean isPropagated) {
    AtlasEdge ret = addEdge(entityVertex, classificationVertex, CLASSIFICATION_LABEL);
    if (ret != null) {
        AtlasGraphUtilsV1.setProperty(ret, CLASSIFICATION_EDGE_NAME_PROPERTY_KEY, getTypeName(classificationVertex));
        AtlasGraphUtilsV1.setProperty(ret, CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY, isPropagated);
        AtlasGraphUtilsV1.setProperty(ret, CLASSIFICATION_EDGE_STATE_PROPERTY_KEY, AtlasClassification.PropagationState.ACTIVE);
    }
    return ret;
}
Also used : AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 79 with AtlasEdge

use of org.apache.atlas.repository.graphdb.AtlasEdge in project atlas by apache.

the class GraphHelper method getEdgeForLabel.

public AtlasEdge getEdgeForLabel(AtlasVertex vertex, String edgeLabel, AtlasEdgeDirection edgeDirection) {
    Iterator<AtlasEdge> iterator = getAdjacentEdgesByLabel(vertex, edgeDirection, edgeLabel);
    AtlasEdge latestDeletedEdge = null;
    long latestDeletedEdgeTime = Long.MIN_VALUE;
    while (iterator != null && iterator.hasNext()) {
        AtlasEdge edge = iterator.next();
        Id.EntityState edgeState = getState(edge);
        if (edgeState == null || edgeState == Id.EntityState.ACTIVE) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Found {}", string(edge));
            }
            return edge;
        } else {
            Long modificationTime = edge.getProperty(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
            if (modificationTime != null && modificationTime >= latestDeletedEdgeTime) {
                latestDeletedEdgeTime = modificationTime;
                latestDeletedEdge = edge;
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Found {}", latestDeletedEdge == null ? "null" : string(latestDeletedEdge));
    }
    // If the vertex is deleted, return latest deleted edge
    return latestDeletedEdge;
}
Also used : AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Id(org.apache.atlas.v1.model.instance.Id) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 80 with AtlasEdge

use of org.apache.atlas.repository.graphdb.AtlasEdge in project atlas by apache.

the class GraphHelper method getRelationshipDef.

public AtlasRelationshipDef getRelationshipDef(AtlasVertex entityVertex, AtlasEntityType entityType, String attributeName) {
    List<AtlasRelationshipType> relationshipTypes = entityType.getRelationshipAttributeType(attributeName);
    AtlasRelationshipDef ret = null;
    if (relationshipTypes.size() > 1) {
        Iterator<AtlasEdge> iter = entityVertex.getEdges(AtlasEdgeDirection.IN).iterator();
        while (iter.hasNext() && ret == null) {
            String edgeTypeName = AtlasGraphUtilsV1.getTypeName(iter.next());
            for (AtlasRelationshipType relationType : relationshipTypes) {
                AtlasRelationshipDef relationshipDef = relationType.getRelationshipDef();
                if (StringUtils.equals(edgeTypeName, relationshipDef.getName())) {
                    ret = relationshipDef;
                    break;
                }
            }
        }
        if (ret == null) {
            ret = relationshipTypes.get(0).getRelationshipDef();
        }
    } else {
        // relationshipTypes will have at least one relationshipDef
        ret = relationshipTypes.get(0).getRelationshipDef();
    }
    return ret;
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Aggregations

AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)138 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)60 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)28 AtlasType (org.apache.atlas.type.AtlasType)15 ArrayList (java.util.ArrayList)13 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)13 AtlasStructType (org.apache.atlas.type.AtlasStructType)12 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)12 RepositoryException (org.apache.atlas.repository.RepositoryException)11 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)11 Edge (org.apache.tinkerpop.gremlin.structure.Edge)10 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)8 AtlasRelationship (org.apache.atlas.model.instance.AtlasRelationship)8 AtlasMapType (org.apache.atlas.type.AtlasMapType)8 AtlasArrayType (org.apache.atlas.type.AtlasArrayType)7 HashSet (java.util.HashSet)6 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)6 Id (org.apache.atlas.typesystem.persistence.Id)6 AtlasException (org.apache.atlas.AtlasException)5 Iterator (java.util.Iterator)4