Search in sources :

Example 46 with AtlasEdge

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

the class GraphBackedMetadataRepositoryTest method assertEdge.

private boolean assertEdge(String id, String typeName) throws Exception {
    AtlasGraph graph = TestUtils.getGraph();
    Iterable<AtlasVertex> vertices = graph.query().has(Constants.GUID_PROPERTY_KEY, id).vertices();
    AtlasVertex AtlasVertex = vertices.iterator().next();
    Iterable<AtlasEdge> edges = AtlasVertex.getEdges(AtlasEdgeDirection.OUT, Constants.INTERNAL_PROPERTY_KEY_PREFIX + typeName + ".ref");
    if (!edges.iterator().hasNext()) {
        ITypedReferenceableInstance entity = repositoryService.getEntityDefinition(id);
        assertNotNull(entity.get("ref"));
        return true;
    }
    return false;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 47 with AtlasEdge

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

the class GraphHelperTest method testGetOutgoingEdgesByLabel.

@Test
public void testGetOutgoingEdgesByLabel() throws Exception {
    AtlasGraph graph = TestUtils.getGraph();
    AtlasVertex v1 = graph.addVertex();
    AtlasVertex v2 = graph.addVertex();
    graph.addEdge(v1, v2, "l1");
    graph.addEdge(v1, v2, "l2");
    Iterator<AtlasEdge> iterator = GraphHelper.getInstance().getOutGoingEdgesByLabel(v1, "l1");
    assertTrue(iterator.hasNext());
    assertTrue(iterator.hasNext());
    assertNotNull(iterator.next());
    assertNull(iterator.next());
    assertFalse(iterator.hasNext());
    assertFalse(iterator.hasNext());
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) Test(org.testng.annotations.Test)

Example 48 with AtlasEdge

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

the class Titan1Graph method removeEdge.

@Override
public void removeEdge(AtlasEdge<Titan1Vertex, Titan1Edge> edge) {
    Edge wrapped = edge.getE().getWrappedElement();
    wrapped.remove();
}
Also used : AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 49 with AtlasEdge

use of org.apache.atlas.repository.graphdb.AtlasEdge in project incubator-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.titan1.graphson.AtlasElementPropertyConfig.ElementPropertiesRule) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 50 with AtlasEdge

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

the class AtlasRelationshipStoreV1 method createRelationship.

private AtlasRelationship createRelationship(AtlasRelationship relationship, AtlasVertex end1Vertex, AtlasVertex end2Vertex) throws AtlasBaseException {
    AtlasRelationship ret;
    try {
        AtlasEdge relationshipEdge = getRelationshipEdge(end1Vertex, end2Vertex, relationship);
        if (relationshipEdge == null) {
            relationshipEdge = 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(relationshipEdge, attrVertexProperty, attrValue);
                }
            }
            ret = mapEdgeToAtlasRelationship(relationshipEdge);
        } else {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_ALREADY_EXISTS, relationship.getTypeName(), relationship.getEnd1().getGuid(), relationship.getEnd2().getGuid());
        }
    } 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) AtlasRelationship(org.apache.atlas.model.instance.AtlasRelationship) 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