use of org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertex in project timbuctoo by HuygensING.
the class VertexBuilder method build.
@Override
public Tuple<Vertex, String> build(Graph graph, Consumer<RelationData> relationRequestor) {
Vertex vertex;
if (labels.size() == 1) {
// If there is exactly one label, it is still a valid tinkerpop vertex and needs to be passed to the
// addVertex method. Otherwise the vertex also gets the label "vertex" and hasLabel will stop working
vertex = graph.addVertex(labels.get(0));
} else {
vertex = graph.addVertex();
}
try {
if (vres == null) {
vres = Lists.newArrayList("");
}
if (type == null) {
type = "<type>";
}
vertex.property("types", objectMapper.writeValueAsString(Lists.newArrayList(vres.stream().map(vre -> vre + type).iterator())));
if (timId != null) {
vertex.property("tim_id", timId);
}
vertex.property("isLatest", isLatest);
for (Map.Entry<String, Object> entry : properties.entrySet()) {
vertex.property(entry.getKey(), entry.getValue());
}
if (labels.size() > 1) {
for (String label : labels.subList(1, labels.size())) {
((Neo4jVertex) vertex).addLabel(label);
}
}
relationList.forEach(relationDataBuilder -> {
// can't be done earlier because vres might not be complete
RelationData relationData = relationDataBuilder.build(vres);
relationRequestor.accept(relationData);
});
return tuple(vertex, id);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
use of org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertex in project timbuctoo by HuygensING.
the class LoadSaveVreTest method saveAddsVreCollectionsToTheVre.
@Test
public void saveAddsVreCollectionsToTheVre() {
Vre vre = vre("VreName", "prefix").withCollection("prefixpersons").withCollection("prefixdocuments").build();
Optional<Vertex> vreVertex = save(vre, initGraph()).stream().filter(x -> ((Neo4jVertex) x).labels().contains(Vre.DATABASE_LABEL)).findAny();
if (!vreVertex.isPresent()) {
throw new RuntimeException("No Vre vertex found!");
} else {
List<Vertex> edges = Lists.newArrayList(vreVertex.get().vertices(Direction.OUT, HAS_COLLECTION_RELATION_NAME));
assertThat(edges, containsInAnyOrder(likeVertex().withLabel(Collection.DATABASE_LABEL).withProperty(Collection.COLLECTION_NAME_PROPERTY_NAME, "prefixpersons"), likeVertex().withLabel(Collection.DATABASE_LABEL).withProperty(Collection.COLLECTION_NAME_PROPERTY_NAME, "prefixdocuments")));
}
}
use of org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertex in project timbuctoo by HuygensING.
the class VertexDuplicator method duplicateVertex.
public static Vertex duplicateVertex(GraphTraversalSource traversal, Vertex vertex, IndexHandler indexHandler) {
Vertex duplicate = traversal.addV().next();
for (Iterator<VertexProperty<Object>> properties = vertex.properties(); properties.hasNext(); ) {
VertexProperty<Object> property = properties.next();
duplicate.property(property.key(), property.value());
}
for (String label : ((Neo4jVertex) vertex).labels()) {
((Neo4jVertex) duplicate).addLabel(label);
}
moveIncomingEdges(vertex, duplicate, indexHandler);
moveOutgoingEdges(vertex, duplicate, indexHandler);
vertex.property(IS_LATEST, false);
duplicate.property(IS_LATEST, true);
vertex.addEdge(VERSION_OF, duplicate);
return duplicate;
}
Aggregations