Search in sources :

Example 36 with VertexProperty

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);
        }
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty)

Example 37 with VertexProperty

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()));
    }
}
Also used : VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Aggregations

VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)37 Edge (org.apache.tinkerpop.gremlin.structure.Edge)18 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)14 JanusGraphVertexProperty (org.janusgraph.core.JanusGraphVertexProperty)14 Test (org.junit.jupiter.api.Test)13 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)12 JanusGraphEdge (org.janusgraph.core.JanusGraphEdge)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 Test (org.junit.Test)9 PropertyKey (org.janusgraph.core.PropertyKey)7 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)5 EdgeLabel (org.janusgraph.core.EdgeLabel)5 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)4 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)4 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)4 TitanVertexProperty (com.thinkaurelius.titan.core.TitanVertexProperty)4 Instant (java.time.Instant)4 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)4 VertexLabel (org.janusgraph.core.VertexLabel)4 AbstractEdge (org.janusgraph.graphdb.relations.AbstractEdge)4