use of org.apache.tinkerpop.gremlin.structure.Property in project timbuctoo by HuygensING.
the class TinkerPopOperations method replaceEntity.
@Override
public int replaceEntity(Collection collection, UpdateEntity updateEntity) throws NotFoundException, AlreadyUpdatedException, IOException {
requireCommit = true;
GraphTraversal<Vertex, Vertex> entityTraversal = entityFetcher.getEntity(this.traversal, updateEntity.getId(), null, collection.getCollectionName());
if (!entityTraversal.hasNext()) {
throw new NotFoundException();
}
Vertex entityVertex = entityTraversal.next();
int curRev = getProp(entityVertex, "rev", Integer.class).orElse(1);
if (curRev != updateEntity.getRev()) {
throw new AlreadyUpdatedException();
}
int newRev = updateEntity.getRev() + 1;
entityVertex.property("rev", newRev);
// update properties
TinkerPopPropertyConverter tinkerPopPropertyConverter = new TinkerPopPropertyConverter(collection);
for (TimProperty<?> property : updateEntity.getProperties()) {
try {
Tuple<String, Object> nameValue = property.convert(tinkerPopPropertyConverter);
collection.getWriteableProperties().get(nameValue.getLeft()).setValue(entityVertex, nameValue.getRight());
} catch (IOException e) {
throw new IOException(property.getName() + " could not be saved. " + e.getMessage(), e);
}
}
// Set removed values to null.
Set<String> propertyNames = updateEntity.getProperties().stream().map(prop -> prop.getName()).collect(Collectors.toSet());
for (String name : Sets.difference(collection.getWriteableProperties().keySet(), propertyNames)) {
collection.getWriteableProperties().get(name).setJson(entityVertex, null);
}
String entityTypesStr = getProp(entityVertex, "types", String.class).orElse("[]");
boolean wasAddedToCollection = false;
if (!entityTypesStr.contains("\"" + collection.getEntityTypeName() + "\"")) {
try {
ArrayNode entityTypes = arrayToEncodedArray.tinkerpopToJson(entityTypesStr);
entityTypes.add(collection.getEntityTypeName());
entityVertex.property("types", entityTypes.toString());
wasAddedToCollection = true;
} catch (IOException e) {
// FIXME potential bug?
LOG.error(Logmarkers.databaseInvariant, "property 'types' was not parseable: " + entityTypesStr);
}
}
setModified(entityVertex, updateEntity.getModified());
entityVertex.property("pid").remove();
Vertex duplicate = duplicateVertex(traversal, entityVertex, indexHandler);
listener.onPropertyUpdate(collection, Optional.of(entityVertex), duplicate);
if (wasAddedToCollection) {
listener.onAddToCollection(collection, Optional.of(entityVertex), duplicate);
}
return newRev;
}
use of org.apache.tinkerpop.gremlin.structure.Property in project timbuctoo by HuygensING.
the class VertexDuplicator method moveOutgoingEdges.
static void moveOutgoingEdges(Vertex vertex, Vertex duplicate, IndexHandler indexHandler) {
for (Iterator<Edge> edges = vertex.edges(Direction.OUT); edges.hasNext(); ) {
Edge edge = edges.next();
if (edge.label().equals(VERSION_OF)) {
continue;
}
Edge duplicateEdge = duplicate.addEdge(edge.label(), edge.inVertex());
for (Iterator<Property<Object>> properties = edge.properties(); properties.hasNext(); ) {
Property<Object> property = properties.next();
duplicateEdge.property(property.key(), property.value());
}
if (duplicateEdge.<Boolean>property("isLatest").orElse(false)) {
duplicateEdge.<String>property("tim_id").ifPresent(p -> indexHandler.upsertIntoEdgeIdIndex(UUID.fromString(p), duplicateEdge));
}
edge.remove();
}
}
use of org.apache.tinkerpop.gremlin.structure.Property in project timbuctoo by HuygensING.
the class VertexDuplicator method moveIncomingEdges.
static void moveIncomingEdges(Vertex vertex, Vertex duplicate, IndexHandler indexHandler) {
for (Iterator<Edge> edges = vertex.edges(Direction.IN); edges.hasNext(); ) {
Edge edge = edges.next();
if (edge.label().equals(VERSION_OF)) {
continue;
}
Edge duplicateEdge = edge.outVertex().addEdge(edge.label(), duplicate);
for (Iterator<Property<Object>> properties = edge.properties(); properties.hasNext(); ) {
Property<Object> property = properties.next();
duplicateEdge.property(property.key(), property.value());
}
if (duplicateEdge.<Boolean>property("isLatest").orElse(false)) {
duplicateEdge.<String>property("tim_id").ifPresent(p -> indexHandler.upsertIntoEdgeIdIndex(UUID.fromString(p), duplicateEdge));
}
edge.remove();
}
}
use of org.apache.tinkerpop.gremlin.structure.Property in project timbuctoo by HuygensING.
the class EdgeMockBuilder method addEdgeProperty.
private void addEdgeProperty(Edge edge, String key, Object value, List<Property> allProps) {
Property property = mock(Property.class);
when(property.key()).thenReturn(key);
when(property.isPresent()).thenReturn(true);
when(property.value()).thenReturn(value);
when(edge.property(key)).thenReturn(property);
when(edge.value(key)).thenReturn(value);
allProps.add(property);
}
Aggregations