Java Code Examples for org.apache.tinkerpop.gremlin.structure.Edge#outVertex()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.Edge#outVertex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryServiceImpl.java    From janusgraph-visualization with Apache License 2.0 6 votes vote down vote up
private GraphEdge convert(Edge edge) {
    GraphEdge graphEdge = new GraphEdge();
    graphEdge.setId(edge.id().toString());
    graphEdge.setLabel(edge.label());

    Vertex inVertex = edge.inVertex();
    Vertex outVertex = edge.outVertex();

    graphEdge.setFrom(outVertex.id().toString());
    graphEdge.setTo(inVertex.id().toString());

    GraphVertex intGraphVertex = new GraphVertex();
    intGraphVertex.setId(inVertex.id().toString());
    intGraphVertex.setLabel(inVertex.label());

    GraphVertex outGraphVertex = new GraphVertex();
    outGraphVertex.setId(outVertex.id().toString());
    outGraphVertex.setLabel(outVertex.id().toString());

    graphEdge.setSource(convert(outVertex));
    graphEdge.setTarget(convert(inVertex));

    return graphEdge;
}
 
Example 2
Source File: ShortestPathVertexProgram.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
private void processEdges(final Vertex vertex, final Path currentPath, final Number currentDistance,
                          final Messenger<Triplet<Path, Edge, Number>> messenger) {

    final Traversal.Admin<Vertex, Edge> edgeTraversal = this.edgeTraversal.getPure();
    edgeTraversal.addStart(edgeTraversal.getTraverserGenerator().generate(vertex, edgeTraversal.getStartStep(), 1));

    while (edgeTraversal.hasNext()) {
        final Edge edge = edgeTraversal.next();
        final Number distance = getDistance(edge);

        Vertex otherV = edge.inVertex();
        if (otherV.equals(vertex))
            otherV = edge.outVertex();

        // only send message if the adjacent vertex is not yet part of the current path
        if (!currentPath.objects().contains(otherV)) {
            messenger.sendMessage(MessageScope.Global.of(otherV),
                    Triplet.with(currentPath, this.includeEdges ? edge : null,
                            NumberHelper.add(currentDistance, distance)));
        }
    }
}
 
Example 3
Source File: ReceptionSearchDescription.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@Override
public EntityRef createRef(Vertex vertex) {
  Edge inEdge = vertex.edges(Direction.IN, getRelationNames()).next();
  Vertex otherVertex = inEdge.outVertex();

  EntityRef targetRef = super.createRef(vertex);

  EntityRef sourceRef = otherSearch.getSearchDescription().createRef(otherVertex);

  EntityRef ref = new EntityRef("wwrelation", (String) inEdge.property("tim_id").value());

  ref.setRelationName(inEdge.label());
  ref.setTargetData(targetRef.getData());
  ref.setTargetName(targetRef.getDisplayName());
  ref.setSourceData(sourceRef.getData());
  ref.setSourceName(sourceRef.getDisplayName());

  return ref;
}
 
Example 4
Source File: D3GraphGeneratorService.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
private void loadLinks(String relationTypeName, String vreId, D3Graph d3Graph, List<String> relationNames,
                       int depth, int currentDepth, Edge edge) {

  Vertex source = edge.inVertex();
  Vertex target = edge.outVertex();
  final Optional<Collection> sourceCollection = GraphReadUtils.getCollectionByVreId(source, mappings, vreId);
  final Optional<Collection> targetCollection = GraphReadUtils.getCollectionByVreId(target, mappings, vreId);

  if (sourceCollection.isPresent() && targetCollection.isPresent()) {
    final String sourceEntityTypeName = sourceCollection.get().getEntityTypeName();
    final String targetEntityTypeName = targetCollection.get().getEntityTypeName();
    d3Graph.addNode(source, sourceEntityTypeName);
    d3Graph.addNode(target, targetEntityTypeName);
    d3Graph.addLink(edge, source, target, sourceEntityTypeName, targetEntityTypeName);

    if (currentDepth < depth) {
      generateD3Graph(relationTypeName, vreId, d3Graph, source, relationNames, depth, currentDepth + 1);
      generateD3Graph(relationTypeName, vreId, d3Graph, target, relationNames, depth, currentDepth + 1);
    }
  }
}
 
Example 5
Source File: MapInAdjacentVerticesHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Getter.
 */
private static Map<String, WindupVertexFrame> handleGetter(Vertex vertex, Method method, Object[] arguments,
            MapInAdjacentVertices annotation, FramedGraph framedGraph)
{
    if (arguments != null && arguments.length != 0)
        throw new WindupException("Method must take zero arguments: " + method.getName());

    Map<String, WindupVertexFrame> result = new HashMap<>();
    Iterator<Edge> edges = vertex.edges(Direction.IN, annotation.label());
    while (edges.hasNext())
    {
        Edge edge = edges.next();
        Property<String> property = edge.property(annotation.mapKeyField());
        if (property == null)
            continue;

        Vertex v = edge.outVertex();
        WindupVertexFrame frame = framedGraph.frameElement(v, WindupVertexFrame.class);
        result.put(property.value(), frame);
    }
    return result;
}
 
Example 6
Source File: GraphUtil.java    From janusgraph-visualization with Apache License 2.0 5 votes vote down vote up
public static GraphEdge convert(Edge edge) {
    GraphEdge graphEdge = new GraphEdge();
    graphEdge.setId(edge.id().toString());
    graphEdge.setLabel(edge.label());

    Vertex inVertex = edge.inVertex();
    Vertex outVertex = edge.outVertex();
    GraphVertex inGraphVertex = convert(inVertex);
    GraphVertex outGraphVertex = convert(outVertex);
    graphEdge.setSource(outGraphVertex);
    graphEdge.setTarget(inGraphVertex);
    return graphEdge;
}
 
Example 7
Source File: TransactionImpl.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
private void mergeRolePlayerEdge(Vertex mergeTargetV, GraphTraversal<Vertex, Edge> rolePlayerEdge) {
    Edge edge = rolePlayerEdge.next();
    Vertex relationVertex = edge.outVertex();
    Object[] properties = propertiesToArray(Lists.newArrayList(edge.properties()));
    relationVertex.addEdge(Schema.EdgeLabel.ROLE_PLAYER.getLabel(), mergeTargetV, properties);
    edge.remove();
}
 
Example 8
Source File: WomenWritersJsonCrudService.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(ReadEntityImpl entity, Vertex entityVertex) {
  Set<String> languages = new HashSet<>();
  final Iterator<Edge> isCreatorOf = entityVertex.edges(Direction.IN, "isCreatedBy");

  while (isCreatorOf.hasNext()) {
    final Edge next = isCreatorOf.next();
    final Boolean creatorOfIsAccepted = next.property("wwrelation_accepted").isPresent() ?
      (Boolean) next.property("wwrelation_accepted").value() : false;
    final Boolean creatorOfIsLatest = next.property("isLatest").isPresent() ?
      (Boolean) next.property("isLatest").value() : false;

    if (creatorOfIsAccepted && creatorOfIsLatest) {
      final Vertex publication = next.outVertex();
      final Iterator<Edge> hasWorkLanguage = publication.edges(Direction.OUT, "hasWorkLanguage");
      while (hasWorkLanguage.hasNext()) {
        final Edge nextLanguage = hasWorkLanguage.next();
        final Boolean languageIsAccepted = nextLanguage.property("wwrelation_accepted").isPresent() ?
          (Boolean) nextLanguage.property("wwrelation_accepted").value() : false;
        final Boolean languageIsLatest = nextLanguage.property("isLatest").isPresent() ?
          (Boolean) nextLanguage.property("isLatest").value() : false;

        if (languageIsAccepted && languageIsLatest) {
          final Vertex languageVertex = nextLanguage.inVertex();
          final String language = getProp(languageVertex, "wwlanguage_name", String.class).orElse(null);
          if (language != null) {
            languages.add(language);
          }
        }
      }
    }
  }
  entity.addExtraPoperty("languages", languages);
}
 
Example 9
Source File: FulltextIndexChangeListener.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
private void handleRelationChange(Collection collection, Edge edge) {
  if ("isCreatedBy".equals(edge.label()) && "wwrelation".equals(collection.getEntityTypeName())) {
    Vertex document = edge.outVertex();
    Vertex oldDocument = document.vertices(Direction.IN, "VERSION_OF").next();
    Collection wwdocuments = collection.getVre().getCollectionForTypeName("wwdocument");
    handleChange(wwdocuments, document, oldDocument);
  }
}
 
Example 10
Source File: GraphOMRSMetadataStore.java    From egeria with Apache License 2.0 4 votes vote down vote up
synchronized Relationship getRelationshipFromStore(String guid)
        throws RepositoryErrorException
{
    String methodName = "getRelationshipFromStore";

    Relationship relationship = null;

    GraphTraversalSource g = instanceGraph.traversal();

    Iterator<Edge> edgeIt = g.E().hasLabel("Relationship").has(PROPERTY_KEY_RELATIONSHIP_GUID, guid);
    if (edgeIt.hasNext()) {
        Edge edge = edgeIt.next();
        log.debug("{} found existing edge {}", methodName, edge);

        relationship = new Relationship();

        // Map the properties
        relationshipMapper.mapEdgeToRelationship(edge, relationship);

        // Set the relationship ends...
        Vertex vertex = null;
        try {

            vertex = edge.outVertex();

            // Could test here whether each vertex is for a proxy, but it doesn't matter whether the vertex represents a full entity
            // (i.e. EntityDetail of a local/reference copy) as opposed to an EntityProxy. It can be retrieved as a proxy anyway...

            if (vertex != null) {
                log.debug("{} entity vertex {}", methodName, vertex);
                EntityProxy entityOneProxy = new EntityProxy();
                entityMapper.mapVertexToEntityProxy(vertex, entityOneProxy);
                log.debug("{} entityOneProxy {}", methodName, entityOneProxy);
                relationship.setEntityOneProxy(entityOneProxy);
            }

            vertex = edge.inVertex();

            if (vertex != null) {
                log.debug("{} entity vertex {}", methodName, vertex);
                EntityProxy entityTwoProxy = new EntityProxy();
                entityMapper.mapVertexToEntityProxy(vertex, entityTwoProxy);
                log.debug("{} entityTwoProxy {}", methodName, entityTwoProxy);
                relationship.setEntityTwoProxy(entityTwoProxy);
            }

        } catch (Exception e) {
            log.error("{} Caught exception from entity mapper {}", methodName, e.getMessage());
            g.tx().rollback();

            throw new RepositoryErrorException(GraphOMRSErrorCode.RELATIONSHIP_NOT_FOUND.getMessageDefinition(entityMapper.getEntityGUID(vertex), methodName,
                                                                                                              this.getClass().getName(),
                                                                                                              repositoryName),
                    this.getClass().getName(),
                    methodName, e);
        }
    }

    g.tx().commit();

    return relationship;

}
 
Example 11
Source File: GraphOMRSMetadataStore.java    From egeria with Apache License 2.0 4 votes vote down vote up
synchronized List<Relationship> getRelationshipsForEntity(String entityGUID)

            throws
            TypeErrorException,
            RepositoryErrorException
    {
        final String methodName = "getRelationshipsForEntity";

        List<Relationship> relationships = new ArrayList<>();

        // Look in the graph
        GraphTraversalSource g = instanceGraph.traversal();
        Iterator<Vertex> vi = g.V().hasLabel("Entity").has(PROPERTY_KEY_ENTITY_GUID, entityGUID);
        if (vi.hasNext()) {
            Vertex vertex = vi.next();
            log.debug("{} found entity vertex {}", methodName, vertex);

            Iterator<Edge> edges = vertex.edges(Direction.BOTH, "Relationship");
            log.debug("{} entity has these edges {}", methodName, edges);
            while (edges.hasNext()) {
                Edge edge = edges.next();
                log.debug("{} entity has edge {}", methodName, edge);

                Relationship relationship = new Relationship();
                relationshipMapper.mapEdgeToRelationship(edge, relationship);

                // Set the relationship ends...
                try {

                    vertex = edge.outVertex();

                    // Could test here whether each vertex is for a proxy, but it doesn't matter whether the vertex represents a full entity
                    // (i.e. EntityDetail of a local/reference copy) as opposed to an EntityProxy. It can be retrieved as a proxy anyway...

                    if (vertex != null) {
                        log.debug("{} entity vertex {}", methodName, vertex);
                        EntityProxy entityOneProxy = new EntityProxy();
                        entityMapper.mapVertexToEntityProxy(vertex, entityOneProxy);
                        log.debug("{} entityOneProxy {}", methodName, entityOneProxy);
                        relationship.setEntityOneProxy(entityOneProxy);
                    }

                    vertex = edge.inVertex();

                    if (vertex != null) {
                        log.debug("{} entity vertex {}", methodName, vertex);
                        EntityProxy entityTwoProxy = new EntityProxy();
                        entityMapper.mapVertexToEntityProxy(vertex, entityTwoProxy);
                        log.debug("{} entityTwoProxy {}", methodName, entityTwoProxy);
                        relationship.setEntityTwoProxy(entityTwoProxy);
                    }

                } catch (Exception e) {
                    log.error("{} Caught exception from entity mapper {}", methodName, e.getMessage());
                    g.tx().rollback();

                    throw new RepositoryErrorException(GraphOMRSErrorCode.RELATIONSHIP_NOT_FOUND.getMessageDefinition(entityMapper.getEntityGUID(vertex), methodName,
                                                                                                                      this.getClass().getName(),
                                                                                                                      repositoryName),
                            this.getClass().getName(),
                            methodName, e);
                }

                relationships.add(relationship);
            }
        }

        g.tx().commit();

        return relationships;
    }
 
Example 12
Source File: ReferenceEdge.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
public ReferenceEdge(final Edge edge) {
    super(edge);
    this.inVertex = new ReferenceVertex(edge.inVertex());
    this.outVertex = new ReferenceVertex(edge.outVertex());
}
 
Example 13
Source File: EdgeManipulator.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
private static Edge createDuplicate(Edge edgeToDuplicate) {
  Vertex sourceOfEdge = edgeToDuplicate.outVertex();
  Vertex targetOfEdge = edgeToDuplicate.inVertex();

  return sourceOfEdge.addEdge(edgeToDuplicate.label(), targetOfEdge);
}