Search in sources :

Example 96 with AtlasEdge

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

the class AtlasTypeDefGraphStoreV1 method hasIncomingEdgesWithLabel.

/**
 * Look to see if there are any IN edges with the supplied label
 * @param vertex
 * @param label
 * @return
 * @throws AtlasBaseException
 */
boolean hasIncomingEdgesWithLabel(AtlasVertex vertex, String label) throws AtlasBaseException {
    boolean foundEdges = false;
    Iterator<AtlasEdge> inEdges = vertex.getEdges(AtlasEdgeDirection.IN).iterator();
    while (inEdges.hasNext()) {
        AtlasEdge edge = inEdges.next();
        if (label.equals(edge.getLabel())) {
            foundEdges = true;
            break;
        }
    }
    return foundEdges;
}
Also used : AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 97 with AtlasEdge

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

the class EntityGraphMapper method createInverseReferenceUsingRelationship.

private AtlasEdge createInverseReferenceUsingRelationship(AtlasAttribute inverseAttribute, AtlasEdge edge, Map<String, Object> relationshipAttributes) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> createInverseReferenceUsingRelationship()");
    }
    String inverseAttributeName = inverseAttribute.getName();
    AtlasType inverseAttributeType = inverseAttribute.getDefinedInType();
    AtlasVertex inverseVertex = edge.getInVertex();
    AtlasVertex vertex = edge.getOutVertex();
    AtlasEdge ret;
    if (inverseAttributeType instanceof AtlasEntityType) {
        AtlasEntityType entityType = (AtlasEntityType) inverseAttributeType;
        if (entityType.hasRelationshipAttribute(inverseAttributeName)) {
            String relationshipName = graphHelper.getRelationshipDefName(inverseVertex, entityType, inverseAttributeName);
            ret = getOrCreateRelationship(inverseVertex, vertex, relationshipName, relationshipAttributes);
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("No RelationshipDef defined between {} and {} on attribute: {}", inverseAttributeType, AtlasGraphUtilsV1.getTypeName(vertex), inverseAttributeName);
            }
            // if no RelationshipDef found, use legacy way to create edges
            ret = createInverseReference(inverseAttribute, (AtlasStructType) inverseAttributeType, inverseVertex, vertex);
        }
    } else {
        // inverseAttribute not of type AtlasEntityType, use legacy way to create edges
        ret = createInverseReference(inverseAttribute, (AtlasStructType) inverseAttributeType, inverseVertex, vertex);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== createInverseReferenceUsingRelationship()");
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasType(org.apache.atlas.type.AtlasType) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 98 with AtlasEdge

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

the class EntityGraphMapper method isRelationshipExists.

private boolean isRelationshipExists(AtlasVertex fromVertex, AtlasVertex toVertex, String edgeLabel) {
    boolean ret = false;
    Iterator<AtlasEdge> edges = graphHelper.getOutGoingEdgesByLabel(fromVertex, edgeLabel);
    while (edges != null && edges.hasNext()) {
        AtlasEdge edge = edges.next();
        AtlasVertex inVertex = edge.getInVertex();
        if (inVertex != null && StringUtils.equals(getIdFromVertex(inVertex), getIdFromVertex(toVertex))) {
            ret = true;
        }
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 99 with AtlasEdge

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

the class EntityGraphMapper method updateRelationship.

private AtlasEdge updateRelationship(AtlasEdge currentEdge, final AtlasVertex parentEntityVertex, final AtlasVertex newEntityVertex, AtlasRelationshipEdgeDirection edgeDirection, Map<String, Object> relationshipAttributes) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Updating entity reference using relationship {} for reference attribute {}", getTypeName(newEntityVertex));
    }
    // Max's manager updated from Jane to Julius (Max.manager --> Jane.subordinates)
    // manager attribute (OUT direction), current manager vertex (Jane) (IN vertex)
    // Max's mentor updated from John to Jane (John.mentee --> Max.mentor)
    // mentor attribute (IN direction), current mentee vertex (John) (OUT vertex)
    String currentEntityId;
    if (edgeDirection == IN) {
        currentEntityId = getIdFromOutVertex(currentEdge);
    } else if (edgeDirection == OUT) {
        currentEntityId = getIdFromInVertex(currentEdge);
    } else {
        currentEntityId = getIdFromBothVertex(currentEdge, parentEntityVertex);
    }
    String newEntityId = getIdFromVertex(newEntityVertex);
    AtlasEdge ret = currentEdge;
    if (!currentEntityId.equals(newEntityId)) {
        // create a new relationship edge to the new attribute vertex from the instance
        String relationshipName = AtlasGraphUtilsV1.getTypeName(currentEdge);
        if (relationshipName == null) {
            relationshipName = currentEdge.getLabel();
        }
        if (edgeDirection == IN) {
            ret = getOrCreateRelationship(newEntityVertex, currentEdge.getInVertex(), relationshipName, relationshipAttributes);
        } else if (edgeDirection == OUT) {
            ret = getOrCreateRelationship(currentEdge.getOutVertex(), newEntityVertex, relationshipName, relationshipAttributes);
        } else {
            ret = getOrCreateRelationship(newEntityVertex, parentEntityVertex, relationshipName, relationshipAttributes);
        }
        // record entity update on new relationship vertex
        recordEntityUpdate(newEntityVertex);
    }
    return ret;
}
Also used : AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 100 with AtlasEdge

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

the class EntityGraphMapper method mapObjectIdValue.

private AtlasEdge mapObjectIdValue(AttributeMutationContext ctx, EntityMutationContext context) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> mapObjectIdValue({})", ctx);
    }
    AtlasEdge ret = null;
    String guid = getGuid(ctx.getValue());
    AtlasVertex entityVertex = context.getDiscoveryContext().getResolvedEntityVertex(guid);
    if (entityVertex == null) {
        AtlasObjectId objId = getObjectId(ctx.getValue());
        if (objId != null) {
            entityVertex = context.getDiscoveryContext().getResolvedEntityVertex(objId);
        }
    }
    if (entityVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, (ctx.getValue() == null ? null : ctx.getValue().toString()));
    }
    if (ctx.getCurrentEdge() != null) {
        ret = updateEdge(ctx.getAttributeDef(), ctx.getValue(), ctx.getCurrentEdge(), entityVertex);
    } else if (ctx.getValue() != null) {
        String edgeLabel = AtlasGraphUtilsV1.getEdgeLabel(ctx.getVertexProperty());
        try {
            ret = graphHelper.getOrCreateEdge(ctx.getReferringVertex(), entityVertex, edgeLabel);
        } catch (RepositoryException e) {
            throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== mapObjectIdValue({})", ctx);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) RepositoryException(org.apache.atlas.repository.RepositoryException) 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