Search in sources :

Example 31 with AtlasEdge

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

the class GraphHelper method getPropagatedClassificationEdge.

public static AtlasEdge getPropagatedClassificationEdge(AtlasVertex entityVertex, String classificationName, String associatedEntityGuid) {
    AtlasEdge ret = null;
    Iterable edges = entityVertex.query().direction(AtlasEdgeDirection.OUT).label(CLASSIFICATION_LABEL).has(CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY, true).has(CLASSIFICATION_EDGE_NAME_PROPERTY_KEY, classificationName).edges();
    if (edges != null) {
        Iterator<AtlasEdge> iterator = edges.iterator();
        while (iterator.hasNext()) {
            AtlasEdge edge = iterator.next();
            AtlasVertex classificationVertex = (edge != null) ? edge.getInVertex() : null;
            if (classificationVertex != null) {
                String guid = AtlasGraphUtilsV1.getProperty(classificationVertex, CLASSIFICATION_ENTITY_GUID, String.class);
                if (StringUtils.equals(guid, associatedEntityGuid)) {
                    ret = edge;
                    break;
                }
            }
        }
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 32 with AtlasEdge

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

the class AtlasGraphSONUtility method objectNodeFromElement.

/**
 * Creates GraphSON for a single graph element.
 */
private ObjectNode objectNodeFromElement(final AtlasElement element) {
    final boolean isEdge = element instanceof AtlasEdge;
    final boolean showTypes = mode == AtlasGraphSONMode.EXTENDED;
    final List<String> propertyKeys = isEdge ? this.edgePropertyKeys : this.vertexPropertyKeys;
    final ElementPropertiesRule elementPropertyConfig = isEdge ? this.edgePropertiesRule : this.vertexPropertiesRule;
    final ObjectNode jsonElement = createJSONMap(createPropertyMap(element, propertyKeys, elementPropertyConfig, normalized), propertyKeys, showTypes);
    if ((isEdge && this.includeReservedEdgeId) || (!isEdge && this.includeReservedVertexId)) {
        putObject(jsonElement, AtlasGraphSONTokens.INTERNAL_ID, element.getId());
    }
    // are graph implementations that have AtlasEdge extend from AtlasVertex
    if (element instanceof AtlasEdge) {
        final AtlasEdge edge = (AtlasEdge) element;
        if (this.includeReservedEdgeId) {
            putObject(jsonElement, AtlasGraphSONTokens.INTERNAL_ID, element.getId());
        }
        if (this.includeReservedEdgeType) {
            jsonElement.put(AtlasGraphSONTokens.INTERNAL_TYPE, AtlasGraphSONTokens.EDGE);
        }
        if (this.includeReservedEdgeOutV) {
            putObject(jsonElement, AtlasGraphSONTokens.INTERNAL_OUT_V, edge.getOutVertex().getId());
        }
        if (this.includeReservedEdgeInV) {
            putObject(jsonElement, AtlasGraphSONTokens.INTERNAL_IN_V, edge.getInVertex().getId());
        }
        if (this.includeReservedEdgeLabel) {
            jsonElement.put(AtlasGraphSONTokens.INTERNAL_LABEL, edge.getLabel());
        }
    } else if (element instanceof AtlasVertex) {
        if (this.includeReservedVertexId) {
            putObject(jsonElement, AtlasGraphSONTokens.INTERNAL_ID, element.getId());
        }
        if (this.includeReservedVertexType) {
            jsonElement.put(AtlasGraphSONTokens.INTERNAL_TYPE, AtlasGraphSONTokens.VERTEX);
        }
    }
    return jsonElement;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ElementPropertiesRule(org.apache.atlas.repository.graphdb.janus.graphson.AtlasElementPropertyConfig.ElementPropertiesRule) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 33 with AtlasEdge

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

the class AtlasJanusVertex method getEdges.

@Override
public Iterable<AtlasEdge<AtlasJanusVertex, AtlasJanusEdge>> getEdges(AtlasEdgeDirection in) {
    Direction d = AtlasJanusObjectFactory.createDirection(in);
    Iterator<Edge> edges = getWrappedElement().edges(d);
    return graph.wrapEdges(edges);
}
Also used : AtlasEdgeDirection(org.apache.atlas.repository.graphdb.AtlasEdgeDirection) Direction(org.apache.tinkerpop.gremlin.structure.Direction) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 34 with AtlasEdge

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

the class AtlasJanusVertex method getEdges.

@Override
public Iterable<AtlasEdge<AtlasJanusVertex, AtlasJanusEdge>> getEdges(AtlasEdgeDirection dir, String edgeLabel) {
    Direction d = AtlasJanusObjectFactory.createDirection(dir);
    Iterator<Edge> edges = getWrappedElement().edges(d, edgeLabel);
    return graph.wrapEdges(edges);
}
Also used : AtlasEdgeDirection(org.apache.atlas.repository.graphdb.AtlasEdgeDirection) Direction(org.apache.tinkerpop.gremlin.structure.Direction) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 35 with AtlasEdge

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

the class TinkerpopGraphQuery method edges.

@Override
public Iterable<AtlasEdge<V, E>> edges(int offset, int limit) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Executing: " + queryCondition);
    }
    Preconditions.checkArgument(offset >= 0, "Offset must be non-negative");
    Preconditions.checkArgument(limit >= 0, "Limit must be non-negative");
    // Compute the overall result by combining the results of all the AndConditions (nested within OR) together.
    Set<AtlasEdge<V, E>> result = new HashSet<>();
    long resultIdx = 0;
    for (AndCondition andExpr : queryCondition.getAndTerms()) {
        if (result.size() == limit) {
            break;
        }
        NativeTinkerpopGraphQuery<V, E> andQuery = andExpr.create(getQueryFactory());
        for (AtlasEdge<V, E> edge : andQuery.edges(offset + limit)) {
            if (resultIdx >= offset) {
                result.add(edge);
                if (result.size() == limit) {
                    break;
                }
            }
            resultIdx++;
        }
    }
    return result;
}
Also used : AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) HashSet(java.util.HashSet) AndCondition(org.apache.atlas.repository.graphdb.tinkerpop.query.expr.AndCondition)

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