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

The following examples show how to use org.apache.tinkerpop.gremlin.structure.Edge#value() . 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: PropertyCoreTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Override
protected <V> V propertySet(String key, Object... values) {
    HugeGraph graph = graph();
    Vertex vertex1 = graph.addVertex(T.label, "person", "id", 1);
    Vertex vertex2 = graph.addVertex(T.label, "person", "id", 2);
    key = "set_" + key;
    Edge edge = vertex1.addEdge("transfer", vertex2, "id", 3,
                                key, Arrays.asList(values));
    graph.tx().commit();

    edge = graph.edges(edge.id()).next();
    Assert.assertTrue(TraversalUtil.testProperty(edge.property(key),
                                    ImmutableSet.copyOf(values)));
    Assert.assertFalse(TraversalUtil.testProperty(edge.property(key),
                                     ImmutableList.copyOf(values)));
    return edge.value(key);
}
 
Example 2
Source File: FileLogOutput.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void newEdge(Edge edge) {
  String modifiedString = edge.value("modified");
  try {
    Change modified = objectMapper.readValue(modifiedString, Change.class);
    writeAndFlush(
      String.format(
        "%d - Edge with tim_id '%s' between Vertex with tim_id '%s' and Vertex with tim_id '%s' created.%n",
        modified.getTimeStamp(),
        edge.value("tim_id"),
        edge.outVertex().value("tim_id"),
        edge.inVertex().value("tim_id")));
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example 3
Source File: DatabaseFixer.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
private void addMissingEdgeVersions(Edge edge) {
  int rev = edge.value("rev");
  if (rev > 1) {
    Optional<Edge> previousVersion = getPreviousVersion(edge);
    if (previousVersion.isPresent()) {
      addMissingEdgeVersions(previousVersion.get());
    } else {
      // FIXME stop using EdgeManipulator
      Edge duplicate = EdgeManipulator.duplicateEdge(edge);
      for (Iterator<Property<Object>> properties = edge.properties(); properties.hasNext(); ) {
        Property<Object> property = properties.next();
        if (Objects.equals(property.key(), "isLatest")) {
          duplicate.property("isLatest", false);
        } else if (Objects.equals(property.key(), "rev")) {
          duplicate.property("rev", rev - 1);
        } else if (Objects.equals(property.key(), "modified")) {
          duplicate.property("modified", edge.value("created"));
        } else if (property.key().endsWith("_accepted")) {
          duplicate.property(property.key(), true);
        }
      }
      addMissingEdgeVersions(duplicate);
    }
  }
}
 
Example 4
Source File: LogEntryFactory.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
public LogEntry createForEdge(Edge edge) throws IllegalArgumentException {
  Property<Integer> revProp = edge.property("rev");
  if (!revProp.isPresent()) {
    String id = edge.value("tim_id");
    throw new IllegalArgumentException(
      String.format("Edge with id '%s' has no property 'rev'. This edge will be ignored.", id)
    );
  }
  Integer rev = revProp.value();

  if (rev > 1) {
    Edge prevEdge = edgeRetriever.getPreviousVersion(edge);

    return new UpdateEdgeLogEntry(edge, prevEdge);
  }
  return new CreateEdgeLogEntry(edge);

}
 
Example 5
Source File: PropertyCoreTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
protected <V> V propertyList(String key, Object... values) {
    HugeGraph graph = graph();
    Vertex vertex1 = graph.addVertex(T.label, "person", "id", 1);
    Vertex vertex2 = graph.addVertex(T.label, "person", "id", 2);
    key = "list_" + key;
    Edge edge = vertex1.addEdge("transfer", vertex2, "id", 2,
                                key, Arrays.asList(values));
    graph.tx().commit();

    edge = graph.edges(edge.id()).next();
    Assert.assertTrue(TraversalUtil.testProperty(edge.property(key),
                                                 Arrays.asList(values)));
    return edge.value(key);
}
 
Example 6
Source File: RelatedPropertyDescriptor.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
private boolean getPropOrTrue(Edge edge, String propertyName) {
  if (edge.property(propertyName).isPresent()) {
    Object accepted = edge.value(propertyName);
    if (accepted instanceof Boolean) {
      return (boolean) accepted;
    } else {
      LOG.error(propertyName + " is not a boolean");
    }
  }
  return true;
}
 
Example 7
Source File: TinkerPopOperations.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
private void replaceRelation(Collection collection, UUID id, int rev, boolean accepted, String userId,
                             Instant instant)
  throws NotFoundException {

  requireCommit = true;

  // FIXME: string concatenating methods like this should be delegated to a configuration class
  final String acceptedPropName = collection.getEntityTypeName() + "_accepted";


  // FIXME: throw a AlreadyUpdatedException when the rev of the client is not the latest
  Optional<Edge> origEdgeOpt = indexHandler.findEdgeById(id);

  if (!origEdgeOpt.isPresent()) {
    throw new NotFoundException();
  }

  Edge origEdge = origEdgeOpt.get();
  if (!origEdge.property("isLatest").isPresent() || !(origEdge.value("isLatest") instanceof Boolean) ||
    !origEdge.<Boolean>value("isLatest")) {
    LOG.error("edge {} is not the latest edge, or it has no valid isLatest property.", origEdge.id());
  }

  //FIXME: throw a distinct Exception when the client tries to save a relation with wrong source, target or type.

  Edge edge = duplicateEdge(origEdge);
  edge.property(acceptedPropName, accepted);
  edge.property("rev", getProp(origEdge, "rev", Integer.class).orElse(1) + 1);
  setModified(edge, userId, instant);

  listener.onEdgeUpdate(collection, origEdge, edge);
}
 
Example 8
Source File: FileLogOutput.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateEdge(Edge edge) {
  String modifiedString = edge.value("modified");
  try {
    Change modified = objectMapper.readValue(modifiedString, Change.class);
    writeAndFlush(String.format(
      "%d - Edge with tim_id '%s' between Vertex with tim_id '%s' and Vertex with tim_id '%s' updated.%n",
      modified.getTimeStamp(),
      edge.value("tim_id"),
      edge.outVertex().value("tim_id"),
      edge.inVertex().value("tim_id")));
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example 9
Source File: DatabaseFixer.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
public Optional<Edge> getPreviousVersion(Edge edge) {
  int rev = edge.value("rev");
  Optional<Edge> prev = Optional.empty();
  for (Iterator<Edge> edges = edge.outVertex().edges(Direction.OUT, edge.label()); edges.hasNext(); ) {
    Edge next = edges.next();
    if (next.<Integer>value("rev") == (rev - 1) && Objects.equals(next.inVertex().id(), edge.inVertex().id())) {
      prev = Optional.of(next);
    }
  }

  return prev;
}
 
Example 10
Source File: EdgeRetriever.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
public Edge getPreviousVersion(Edge edge) {
  Integer rev = edge.<Integer>value("rev");
  Edge previousVersion = null;
  for (Iterator<Edge> edges = edge.outVertex().edges(Direction.OUT, edge.label()); edges.hasNext(); ) {
    Edge next = edges.next();
    if (next.<Integer>value("rev") == (rev - 1) && Objects.equals(next.inVertex().id(), edge.inVertex().id())) {
      previousVersion = next;
    }
  }

  return previousVersion;
}
 
Example 11
Source File: TestBatchNormalPrimitiveArrays.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void testPrimitiveArray() throws InterruptedException {
    this.sqlgGraph.tx().normalBatchModeOn();
    Vertex a = this.sqlgGraph.addVertex(T.label, "A", "array", this.value);
    Vertex b = this.sqlgGraph.addVertex(T.label, "B");
    Edge e = a.addEdge("ab", b, "array", this.value);
    this.sqlgGraph.tx().commit();
    a = this.sqlgGraph.traversal().V(a.id()).next();
    Object array = a.value("array");
    Class<?> clazz = array.getClass().getComponentType();
    test(array, clazz);

    e = this.sqlgGraph.traversal().E(e.id()).next();
    array = e.value("array");
    clazz = array.getClass().getComponentType();
    test(array, clazz);

    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);

        a = this.sqlgGraph1.traversal().V(a.id()).next();
        array = a.value("array");
        clazz = array.getClass().getComponentType();
        test(array, clazz);

        e = this.sqlgGraph1.traversal().E(e.id()).next();
        array = e.value("array");
        clazz = array.getClass().getComponentType();
        test(array, clazz);
    }

}
 
Example 12
Source File: PropertyCoreTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
protected <V> V property(String key, V value) {
    HugeGraph graph = graph();
    Vertex vertex1 = graph.addVertex(T.label, "person", "id", 1);
    Vertex vertex2 = graph.addVertex(T.label, "person", "id", 2);
    Edge edge = vertex1.addEdge("transfer", vertex2, "id", 1,
                                key, value);
    graph.tx().commit();

    edge = graph.edges(edge.id()).next();
    Assert.assertTrue(TraversalUtil.testProperty(edge.property(key),
                                                 value));
    return edge.value(key);
}
 
Example 13
Source File: FactEdgeTest.java    From act-platform with ISC License 4 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testGetValueThatIsNotPresentOnEdge() {
  Edge edge = createEdge();
  edge.value("something");
}
 
Example 14
Source File: FactEdgeTest.java    From act-platform with ISC License 4 votes vote down vote up
@Test
public void testAutotypeFloatProperties() {
  Edge edge = createEdge(list(new PropertyEntry<>("trust", 0.3f)));
  float trust = edge.value("trust");
  assertEquals(0.3f, trust, 0.0);
}
 
Example 15
Source File: FactEdgeTest.java    From act-platform with ISC License 4 votes vote down vote up
@Test
public void testAutotypeLongProperties() {
  Edge edge = createEdge(list(new PropertyEntry<>("timestamp", 123456789L)));
  long timestamp = edge.value("timestamp");
  assertEquals(123456789L, timestamp);
}
 
Example 16
Source File: FactEdgeTest.java    From act-platform with ISC License 4 votes vote down vote up
@Test
public void testAutotypeStringProperties() {
  Edge edge = createEdge(list(new PropertyEntry<>("value", "value")));
  String value = edge.value("value");
  assertEquals("value", value);
}
 
Example 17
Source File: FactEdgeTest.java    From act-platform with ISC License 4 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testGetValueThatIsNotPresentOnEdge() {
  Edge edge = createEdge();
  edge.value("something");
}
 
Example 18
Source File: FactEdgeTest.java    From act-platform with ISC License 4 votes vote down vote up
@Test
public void testAutotypeFloatProperties() {
  Edge edge = createEdge();
  float trust = edge.value("trust");
  assertEquals(0.3f, trust, 0.0);
}
 
Example 19
Source File: FactEdgeTest.java    From act-platform with ISC License 4 votes vote down vote up
@Test
public void testAutotypeLongProperties() {
  Edge edge = createEdge();
  long timestamp = edge.value("timestamp");
  assertEquals(123456789L, timestamp);
}
 
Example 20
Source File: FactEdgeTest.java    From act-platform with ISC License 4 votes vote down vote up
@Test
public void testAutotypeStringProperties() {
  Edge edge = createEdge();
  String value = edge.value("value");
  assertEquals("value", value);
}