use of org.apache.tinkerpop.gremlin.structure.VertexProperty in project timbuctoo by HuygensING.
the class DatabaseFixer method addMissingVertexVersions.
private void addMissingVertexVersions(Vertex vertex) {
int rev = vertex.value("rev");
if (rev > 1) {
Iterator<Vertex> previousVersions = vertex.vertices(Direction.IN, "VERSION_OF");
if (previousVersions.hasNext()) {
addMissingVertexVersions(previousVersions.next());
} else {
Vertex duplicate = vertex.graph().addVertex();
duplicate.addEdge("VERSION_OF", vertex);
for (Iterator<VertexProperty<Object>> properties = vertex.properties(); properties.hasNext(); ) {
VertexProperty<Object> property = properties.next();
if (Objects.equals(property.key(), "isLatest")) {
duplicate.property(property.key(), false);
} else if (Objects.equals(property.key(), "rev")) {
duplicate.property(property.key(), rev - 1);
} else if (Objects.equals(property.key(), "modified")) {
duplicate.property("modified", vertex.value("created"));
} else {
duplicate.property(property.key(), property.value());
}
}
addMissingVertexVersions(duplicate);
}
}
}
use of org.apache.tinkerpop.gremlin.structure.VertexProperty in project timbuctoo by HuygensING.
the class Gremlin method dumpVertex.
private void dumpVertex(Vertex vertex, StringBuilder result) {
result.append(String.format("Vertex [%s]:\n", vertex.id()));
ArrayList<VertexProperty<Object>> properties = Lists.newArrayList(vertex.properties());
properties.sort((o1, o2) -> java.text.Collator.getInstance().compare(o1.label(), o2.label()));
for (VertexProperty<Object> property : properties) {
String stringified;
try {
stringified = mapper.writeValueAsString(property.value());
} catch (JsonProcessingException e) {
stringified = String.format("%s", mapper);
}
result.append(String.format(" %s: %s\n", property.label(), stringified));
}
for (Edge edge : ImmutableList.copyOf(vertex.edges(IN))) {
result.append(String.format(" <--[%s]-- v[%s]\n", edge.label(), edge.outVertex().id()));
}
for (Edge edge : ImmutableList.copyOf(vertex.edges(OUT))) {
result.append(String.format(" --[%s]--> v[%s]\n", edge.label(), edge.inVertex().id()));
}
}
Aggregations