public void testPropertyFilter2() {
   Graph graph = TinkerGraphFactory.createTinkerGraph();
   Vertex marko = graph.getVertex("1");
   Pipe<Vertex, Edge> pipe1 = new OutEdgesPipe();
   Pipe<Edge, Vertex> pipe2 = new InVertexPipe();
   Pipe pipe3 =
       new PropertyFilterPipe<Vertex, String>("lang", "java", FilterPipe.Filter.NOT_EQUAL);
   Pipeline<Vertex, Vertex> pipeline =
       new Pipeline<Vertex, Vertex>(Arrays.asList(pipe1, pipe2, pipe3));
   pipeline.setStarts(Arrays.asList(marko).iterator());
   assertTrue(pipeline.hasNext());
   int counter = 0;
   while (pipeline.hasNext()) {
     counter++;
     Vertex vertex = pipeline.next();
     assertTrue(vertex.getId().equals("2") || vertex.getId().equals("4"));
     assertTrue(
         vertex.getProperty("name").equals("josh") || vertex.getProperty("name").equals("vadas"));
     assertTrue(vertex.getProperty("age").equals(27) || vertex.getProperty("age").equals(32));
   }
   assertEquals(counter, 2);
   try {
     pipeline.next();
     assertTrue(false);
   } catch (NoSuchElementException e) {
     assertFalse(false);
   }
 }
  private void verifyLineageGraph(
      String feedType,
      List<String> expectedFeeds,
      List<String> secureFeeds,
      List<String> ownedAndSecureFeeds) {
    // feeds owned by a user
    List<String> feedNamesOwnedByUser = getFeedsOwnedByAUser(feedType);
    Assert.assertTrue(feedNamesOwnedByUser.containsAll(expectedFeeds));

    Graph graph = service.getGraph();

    Iterator<Vertex> vertices =
        graph.getVertices("name", "impression-feed/2014-01-01T00:00Z").iterator();
    Assert.assertTrue(vertices.hasNext());
    Vertex feedInstanceVertex = vertices.next();
    Assert.assertEquals(
        feedInstanceVertex.getProperty(RelationshipProperty.TYPE.getName()),
        RelationshipType.FEED_INSTANCE.getName());

    Object vertexId = feedInstanceVertex.getId();
    Vertex vertexById = graph.getVertex(vertexId);
    Assert.assertEquals(vertexById, feedInstanceVertex);

    // feeds classified as secure
    verifyFeedsClassifiedAsSecure(feedType, secureFeeds);

    // feeds owned by a user and classified as secure
    verifyFeedsOwnedByUserAndClassification(feedType, "Financial", ownedAndSecureFeeds);
  }
Example #3
0
 static void addGraph(Graph graph, Graph addition) {
   for (Vertex vertex : addition.getVertices()) {
     addElement(graph, vertex);
   }
   for (Edge edge : addition.getEdges()) {
     addElement(graph, edge);
   }
 }
Example #4
0
 static Vertex addNode(Graph graph, Vertex node) {
   Vertex vertex = graph.getVertex(node.getId());
   if (null == vertex) {
     vertex = graph.addVertex(node.getId());
     copyProperties(node, vertex);
   }
   return vertex;
 }
Example #5
0
 private void populateLists(List<Vertex> verticies, List<Edge> edges) {
   for (Vertex v : graph.getVertices()) {
     verticies.add(v);
   }
   for (Edge e : graph.getEdges()) {
     edges.add(e);
   }
 }
Example #6
0
 // TODO unit test that
 static boolean removeEdge(Graph graph, Relationship relationship) {
   Edge edge = graph.getEdge(relationship.getId());
   if (null != edge) {
     graph.removeEdge(edge);
     return true;
   } else {
     return false;
   }
 }
  @Override
  protected void onExecute() throws Exception {

    Graph g = getGraph();
    Iterable<Edge> itr = g.getEdges(key, value);
    int count = 0;
    for (@SuppressWarnings("unused") Edge e : itr) count++;
    GraphUtils.close(itr);

    setResult(count);
  }
  private void cleanupGraphStore(Graph graph) {
    for (Edge edge : graph.getEdges()) {
      graph.removeEdge(edge);
    }

    for (Vertex vertex : graph.getVertices()) {
      graph.removeVertex(vertex);
    }

    graph.shutdown();
  }
Example #9
0
 static Edge addEdge(Graph graph, Edge edge) {
   Edge newEdge = graph.getEdge(edge.getId());
   if (null == newEdge) {
     Vertex outVertex = addNode(graph, edge.getVertex(Direction.OUT));
     Vertex inVertex = addNode(graph, edge.getVertex(Direction.IN));
     String label = edge.getLabel();
     newEdge = graph.addEdge(edge.getId(), outVertex, inVertex, label);
     copyProperties(edge, edge);
   }
   return newEdge;
 }
  public static void debug(final Graph graph) {
    System.out.println("*****Vertices of " + graph);
    for (Vertex vertex : graph.getVertices()) {
      System.out.println(GraphUtils.vertexString(vertex));
    }

    System.out.println("*****Edges of " + graph);
    for (Edge edge : graph.getEdges()) {
      System.out.println(GraphUtils.edgeString(edge));
    }
  }
Example #11
0
  public void testOuterParens() throws Exception {
    final String doTest = System.getProperty("testRexsterGraph", "true");
    if (doTest.equals("true")) {
      final Graph g = generateGraph();
      this.resetGraph();

      final Vertex v = g.addVertex(null);
      v.setProperty("test", "(sometext)");

      Assert.assertEquals("(sometext)", g.getVertex(v.getId()).getProperty("test"));
    }
  }
Example #12
0
 static Edge addEdge(Graph graph, Relationship relationship) {
   Edge edge = graph.getEdge(relationship.getId());
   if (null == edge) {
     Vertex outVertex = addNode(graph, relationship.getStartNode());
     Vertex inVertex = addNode(graph, relationship.getEndNode());
     String label = relationship.getType().name();
     // TODO #152 add CurieUtil to resolve IRI to Curie
     edge = graph.addEdge(relationship.getId(), outVertex, inVertex, label);
     copyProperties(relationship, edge);
   }
   return edge;
 }
Example #13
0
 static Vertex addNode(Graph graph, Node node) {
   Vertex vertex = graph.getVertex(node.getId());
   if (null == vertex) {
     vertex = graph.addVertex(node.getId());
     copyProperties(node, vertex);
     Set<String> labels = new HashSet<>();
     for (Label label : node.getLabels()) {
       labels.add(label.name());
     }
     vertex.setProperty("types", labels);
   }
   return vertex;
 }
Example #14
0
  public static void dumpToLog(final Graph graph) {
    LOG.debug("*******************Graph Dump****************************");
    LOG.debug("Vertices of {}", graph);
    for (Vertex vertex : graph.getVertices()) {
      LOG.debug(vertexString(vertex));
    }

    LOG.debug("Edges of {}", graph);
    for (Edge edge : graph.getEdges()) {
      LOG.debug(edgeString(edge));
    }
    LOG.debug("*******************Graph Dump****************************");
  }
Example #15
0
 public final <T extends BeanVertex> T createAdjacentVertex(
     BeanVertex from, Class<T> beanClass, String edgeLabel, String... edgeProperties) {
   T to = createVertex(beanClass);
   Edge edge = graph.addEdge(null, from.element(), to.element(), edgeLabel);
   ElementHelper.setProperties(edge, edgeProperties);
   return to;
 }
  public long getEdgesCount(final Graph graph) {
    long count = 0;
    for (Edge ignored : graph.getEdges()) {
      count++;
    }

    return count;
  }
  public long getVerticesCount(final Graph graph) {
    long count = 0;
    for (Vertex ignored : graph.getVertices()) {
      count++;
    }

    return count;
  }
  @Override
  public void destroy() throws FalconException {
    Services.get()
        .<WorkflowJobEndNotificationService>getService(
            WorkflowJobEndNotificationService.SERVICE_NAME)
        .unregisterListener(this);

    LOG.info("Shutting down graph db");
    graph.shutdown();
  }
Example #19
0
 public static void project(Graph graph, Collection<String> projection) {
   if (projection.contains("*")) {
     return;
   }
   for (Vertex vertex : graph.getVertices()) {
     for (String key : vertex.getPropertyKeys()) {
       if (!projection.contains(key) && !PROTECTED_PROPERTY_KEYS.contains(key)) {
         vertex.removeProperty(key);
       }
     }
   }
 }
  public static void main(String[] args) {

    Graph usergrid =
        GraphFactory.open(
            "/Users/nishitarao/dev/usergrid-blueprints/src/main/resources/usergrid.properties");

    Vertex v1 = usergrid.addVertex("person:Nishita"); // Adds a vertex
    Vertex testGet =
        usergrid.getVertex(v1.getId()); // Gets vertex using getVetex which in turn uses getId
    System.out.println(testGet);
    usergrid.removeVertex(v1); // Delete a vertex

    Vertex v2 = usergrid.addVertex("restaurant:Amici"); // Adds a vertex
    v2.setProperty("tag", "Amici"); // Sets a property
    System.out.println(v2.getProperty("tag")); // Gets a property
    System.out.println(v2);

    // v2.removeProperty("tag"); //TODO: Have to check whether Usergrid supports this
    // System.out.println(v2);

    v2.remove(); // Deletes the vertex
  }
Example #21
0
  public void test_g_v1_out_stepXnext_nameX() {
    super.test_g_v1_out_stepXnext_nameX(
        new GremlinPipeline(g.getVertex(1))
            .out()
            .step(
                new PipeFunction<Iterator<Vertex>, Vertex>() {
                  public Vertex compute(Iterator<Vertex> iterator) {
                    return iterator.next();
                  }
                })
            .property("name"));

    super.test_g_v1_out_stepXnext_nameX(
        new GremlinPipeline(g.getVertex(1))
            .optimize(false)
            .out()
            .step(
                new PipeFunction<Iterator<Vertex>, Vertex>() {
                  public Vertex compute(Iterator<Vertex> iterator) {
                    return iterator.next();
                  }
                })
            .property("name"));
  }
  @Override
  public void outputGraph(Graph graph, OutputStream out) throws IOException {

    Iterable<Edge> iterable = graph.getEdges();
    Iterator<Edge> it = iterable.iterator();
    writeCSVField("SourceId", out, true, false);
    writeCSVField("SourceVirtual", out, false, false);
    writeCSVField("SourceFileType", out, false, false);
    writeCSVField("SourceName", out, false, false);
    writeCSVField("SourceAuthor", out, false, false);
    writeCSVField("SourceModified", out, false, false);
    writeCSVField("LinkType", out, false, false);
    writeCSVField("DestinationId", out, false, false);
    writeCSVField("DestinationVirtual", out, false, false);
    writeCSVField("DestinationFileType", out, false, false);
    writeCSVField("DestinationName", out, false, false);
    writeCSVField("DestinationAuthor", out, false, false);
    writeCSVField("DestinationModified", out, false, true);
    while (it.hasNext()) {
      Edge edge = it.next();
      Vertex fromV = edge.getVertex(Direction.OUT);
      Vertex toV = edge.getVertex(Direction.IN);
      writeCSVField(fromV.getId(), out, true, false);
      writeCSVField(fromV.getProperty(DictionaryConst.NODE_VIRTUAL), out, false, false);
      writeCSVField(fromV.getProperty(DictionaryConst.PROPERTY_TYPE), out, false, false);
      writeCSVField(fromV.getProperty(DictionaryConst.PROPERTY_NAME), out, false, false);
      writeCSVField(fromV.getProperty(DictionaryConst.PROPERTY_AUTHOR), out, false, false);
      writeCSVField(fromV.getProperty(DictionaryConst.PROPERTY_LAST_MODIFIED), out, false, false);
      writeCSVField(edge.getLabel(), out, false, false);
      writeCSVField(toV.getId(), out, false, false);
      writeCSVField(toV.getProperty(DictionaryConst.NODE_VIRTUAL), out, false, false);
      writeCSVField(toV.getProperty(DictionaryConst.PROPERTY_TYPE), out, false, false);
      writeCSVField(toV.getProperty(DictionaryConst.PROPERTY_NAME), out, false, false);
      writeCSVField(toV.getProperty(DictionaryConst.PROPERTY_AUTHOR), out, false, false);
      writeCSVField(toV.getProperty(DictionaryConst.PROPERTY_LAST_MODIFIED), out, false, true);
    }
  }
Example #23
0
 /**
  * Add a vertex to the graph
  *
  * @param kind The kind of the frame.
  * @return The framed vertex.
  */
 public <T extends FramedVertex> T addVertex(Class<T> kind) {
   T framedVertex = frameNewElement(delegate.addVertex(null), kind);
   framedVertex.init();
   return framedVertex;
 }
 @Override
 public Iterable<Vertex> vertices() {
   return graph.getVertices();
 }
Example #25
0
 /** Close the delegate graph. */
 public void close() {
   delegate.shutdown();
 }
Example #26
0
 public final <T extends BeanVertex> T createVertex(Class<T> beanClass) {
   Vertex vertex = graph.addVertex(null);
   return beans.wrap(vertex, beanClass, this);
 }
 @Override
 public Iterable<GraphEdge<Vertex, Edge>> edges() {
   return convertEdges(graph.getEdges());
 }
Example #28
0
 /**
  * Generates a synthetic network for all vertices in the given graph such that the provided
  * expected number of communities are generated with the specified expected number of edges.
  *
  * @param graph
  * @param expectedNumCommunities
  * @param expectedNumEdges
  * @return The actual number of edges generated. May be different from the expected number.
  */
 public int generate(Graph graph, int expectedNumCommunities, int expectedNumEdges) {
   return generate(graph, graph.getVertices(), expectedNumCommunities, expectedNumEdges);
 }
Example #29
0
  public static void load(final Graph graph) {

    // vertices

    final Vertex saturn = graph.addVertex(null);
    saturn.setProperty("name", "saturn");
    saturn.setProperty("age", 10000);
    saturn.setProperty("type", "titan");
    saturn.setProperty(TYPE_RESOLUTION_KEY, God.class.getName());

    final Vertex sky = graph.addVertex(null);
    ElementHelper.setProperties(
        sky, "name", "sky", "type", "location", "other", "more useless info");

    final Vertex sea = graph.addVertex(null);
    ElementHelper.setProperties(sea, "name", "sea", "type", "location");

    final Vertex jupiter = graph.addVertex(null);
    ElementHelper.setProperties(
        jupiter,
        "name",
        "jupiter",
        "age",
        5000,
        "type",
        "god",
        TYPE_RESOLUTION_KEY,
        God.class.getName());

    final Vertex neptune = graph.addVertex(null);
    ElementHelper.setProperties(
        neptune,
        "name",
        "neptune",
        "age",
        4500,
        "type",
        "god",
        TYPE_RESOLUTION_KEY,
        God.class.getName());

    final Vertex hercules = graph.addVertex(null);
    ElementHelper.setProperties(
        hercules,
        "name",
        "hercules",
        "age",
        30,
        "type",
        "demigod",
        TYPE_RESOLUTION_KEY,
        GodExtended.class.getName());

    final Vertex alcmene = graph.addVertex(null);
    ElementHelper.setProperties(
        alcmene,
        "name",
        "alcmene",
        "age",
        45,
        "type",
        "human",
        TYPE_RESOLUTION_KEY,
        God.class.getName());

    final Vertex pluto = graph.addVertex(null);
    ElementHelper.setProperties(
        pluto,
        "name",
        "pluto",
        "age",
        4000,
        "type",
        "god",
        TYPE_RESOLUTION_KEY,
        God.class.getName());

    final Vertex nemean = graph.addVertex(null);
    ElementHelper.setProperties(
        nemean, "name", "nemean", "type", "monster", TYPE_RESOLUTION_KEY, God.class.getName());

    final Vertex hydra = graph.addVertex(null);
    ElementHelper.setProperties(
        hydra, "name", "hydra", "type", "monster", TYPE_RESOLUTION_KEY, God.class.getName());

    final Vertex cerberus = graph.addVertex(null);
    ElementHelper.setProperties(
        cerberus, "name", "cerberus", "type", "monster", TYPE_RESOLUTION_KEY, God.class.getName());

    final Vertex tartarus = graph.addVertex(null);
    ElementHelper.setProperties(
        tartarus, "name", "tartarus", "type", "location", TYPE_RESOLUTION_KEY, God.class.getName());

    // edges

    ElementHelper.setProperties(
        jupiter.addEdge("father", saturn), TYPE_RESOLUTION_KEY, FatherEdge.class.getName());
    jupiter.addEdge("lives", sky).setProperty("reason", "loves fresh breezes");
    jupiter.addEdge("brother", neptune);
    jupiter.addEdge("brother", pluto);

    ElementHelper.setProperties(
        neptune.addEdge("father", saturn), TYPE_RESOLUTION_KEY, FatherEdge.class.getName());
    neptune.addEdge("lives", sea).setProperty("reason", "loves waves");
    neptune.addEdge("brother", jupiter);
    neptune.addEdge("brother", pluto);

    ElementHelper.setProperties(
        hercules.addEdge("father", jupiter),
        TYPE_RESOLUTION_KEY,
        FatherEdgeExtended.class.getName());
    hercules.addEdge("lives", sky).setProperty("reason", "loves heights");
    ElementHelper.setProperties(hercules.addEdge("battled", nemean), "time", 1);
    ElementHelper.setProperties(hercules.addEdge("battled", hydra), "time", 2);
    ElementHelper.setProperties(hercules.addEdge("battled", cerberus), "time", 12);

    ElementHelper.setProperties(
        pluto.addEdge("father", saturn), TYPE_RESOLUTION_KEY, FatherEdge.class.getName());
    pluto.addEdge("brother", jupiter);
    pluto.addEdge("brother", neptune);
    pluto.addEdge("lives", tartarus).setProperty("reason", "no fear of death");
    pluto.addEdge("pet", cerberus);

    cerberus.addEdge("lives", tartarus);
    ElementHelper.setProperties(cerberus.addEdge("battled", alcmene), "time", 5);

    // commit the transaction to disk
    if (graph instanceof TransactionalGraph) ((TransactionalGraph) graph).commit();
  }