Search in sources :

Example 91 with AtlasEdge

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

the class AtlasRelationshipStoreV1 method createRelationship.

private AtlasEdge createRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, AtlasRelationship relationship) throws AtlasBaseException {
    AtlasEdge ret = null;
    try {
        ret = getRelationshipEdge(end1Vertex, end2Vertex, relationship.getTypeName());
        if (ret == null) {
            ret = createRelationshipEdge(end1Vertex, end2Vertex, relationship);
            AtlasRelationshipType relationType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName());
            if (MapUtils.isNotEmpty(relationType.getAllAttributes())) {
                for (AtlasAttribute attr : relationType.getAllAttributes().values()) {
                    String attrName = attr.getName();
                    String attrVertexProperty = attr.getVertexPropertyName();
                    Object attrValue = relationship.getAttribute(attrName);
                    AtlasGraphUtilsV1.setProperty(ret, attrVertexProperty, attrValue);
                }
            }
        } else {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_ALREADY_EXISTS, relationship.getTypeName(), AtlasGraphUtilsV1.getIdFromVertex(end1Vertex), AtlasGraphUtilsV1.getIdFromVertex(end2Vertex));
        }
    } catch (RepositoryException e) {
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
    }
    return ret;
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 92 with AtlasEdge

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

the class AtlasRelationshipStoreV1 method getById.

@Override
@GraphTransaction
public AtlasRelationship getById(String guid) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> getById({})", guid);
    }
    AtlasRelationship ret;
    AtlasEdge edge = graphHelper.getEdgeForGUID(guid);
    ret = entityRetriever.mapEdgeToAtlasRelationship(edge);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== getById({}): {}", guid, ret);
    }
    return ret;
}
Also used : AtlasRelationship(org.apache.atlas.model.instance.AtlasRelationship) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 93 with AtlasEdge

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

the class AtlasTypeDefGraphStoreV1 method deleteTypeVertex.

void deleteTypeVertex(AtlasVertex vertex) throws AtlasBaseException {
    Iterator<AtlasEdge> inEdges = vertex.getEdges(AtlasEdgeDirection.IN).iterator();
    if (inEdges.hasNext()) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES);
    }
    Iterable<AtlasEdge> edges = vertex.getEdges(AtlasEdgeDirection.OUT);
    for (AtlasEdge edge : edges) {
        atlasGraph.removeEdge(edge);
    }
    atlasGraph.removeVertex(vertex);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 94 with AtlasEdge

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

the class AtlasTypeDefGraphStoreV1 method getOrCreateEdge.

AtlasEdge getOrCreateEdge(AtlasVertex outVertex, AtlasVertex inVertex, String edgeLabel) {
    AtlasEdge ret = null;
    Iterable<AtlasEdge> edges = outVertex.getEdges(AtlasEdgeDirection.OUT, edgeLabel);
    for (AtlasEdge edge : edges) {
        if (edge.getInVertex().getId().equals(inVertex.getId())) {
            ret = edge;
            break;
        }
    }
    if (ret == null) {
        ret = addEdge(outVertex, inVertex, edgeLabel);
    }
    return ret;
}
Also used : AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 95 with AtlasEdge

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

the class AtlasTypeDefGraphStoreV1 method getTypeNamesFromEdges.

/**
 * Get the typename properties from the edges, that are associated with the vertex and have the supplied edge label.
 * @param vertex
 * @param edgeLabel
 * @return set of type names
 */
private Set<String> getTypeNamesFromEdges(AtlasVertex vertex, String edgeLabel) {
    Set<String> ret = new HashSet<>();
    Iterable<AtlasEdge> edges = vertex.getEdges(AtlasEdgeDirection.OUT, edgeLabel);
    for (AtlasEdge edge : edges) {
        ret.add(edge.getInVertex().getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class));
    }
    return ret;
}
Also used : AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) HashSet(java.util.HashSet)

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