use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deleteEntityRemovesTypeWhenOtherTypesExist.
@Test
public void deleteEntityRemovesTypeWhenOtherTypesExist() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
String idString = id.toString();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(idString).withVre("test").withVre("other").withType("thing").withProperty("isLatest", true).withProperty("rev", 1).withLabel("testthing").withLabel("otherthing")).wrap();
GremlinEntityFetcher entityFetcher = new GremlinEntityFetcher();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
instance.deleteEntity(collection, id, new Change(Instant.now().toEpochMilli(), "userId", null));
String types = (String) graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).properties("types").value().next();
assertThat(types, is("[\"otherthing\"]"));
// Type should also be removed from the Neo4j labels
assertThat(graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).has(T.label, LabelP.of("testthing")).hasNext(), is(false));
// Other type should not be removed from the Neo4j labels
assertThat(graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).has(T.label, LabelP.of("otherthing")).hasNext(), is(true));
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityPreparesABackupCopyAfterMakingTheChanges.
@Test
public void replaceEntityPreparesABackupCopyAfterMakingTheChanges() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id).withVre("test").withType("thing").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
List<TimProperty<?>> properties = Lists.newArrayList(new StringProperty("prop1", "newValue"));
UpdateEntity updateEntity = new UpdateEntity(id, properties, 1);
long timeStamp = Instant.now().toEpochMilli();
updateEntity.setModified(new Change(timeStamp, "userId", null));
Vertex beforeUpdate = graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).next();
instance.replaceEntity(collection, updateEntity);
Vertex afterUpdate = graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).next();
assertThat(afterUpdate.id(), is(not(beforeUpdate.id())));
assertThat(afterUpdate.edges(Direction.IN).next().outVertex().id(), is(beforeUpdate.id()));
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityThrowsAnAlreadyUpdatedExceptionWhenTheRevDoesNotMatch.
@Test(expected = AlreadyUpdatedException.class)
public void replaceEntityThrowsAnAlreadyUpdatedExceptionWhenTheRevDoesNotMatch() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id).withVre("test").withType("thing").withProperty("isLatest", true).withProperty("rev", 2)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
UpdateEntity updateEntity = new UpdateEntity(id, Lists.newArrayList(), 1);
long timeStamp = Instant.now().toEpochMilli();
updateEntity.setModified(new Change(timeStamp, "userId", null));
instance.replaceEntity(collection, updateEntity);
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceRelationUpdatesTheModifiedInformation.
@Test
public void replaceRelationUpdatesTheModifiedInformation() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testrelations").get();
UUID typeId = UUID.randomUUID();
UUID sourceId = UUID.randomUUID();
UUID targetId = UUID.randomUUID();
UUID relId = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(typeId.toString()).withType("relationtype").withProperty("relationtype_regularName", "regularName").withProperty("rev", 1).withProperty("isLatest", true)).withVertex(v -> v.withTimId(sourceId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true).withOutgoingRelation("regularName", "otherVertex", r -> r.withTim_id(relId).withAccepted("testrelation", true).withTypeId(typeId).withRev(1).addType("testrelation"))).withVertex("otherVertex", v -> v.withTimId(targetId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true)).wrap();
IndexHandler indexHandler = mock(IndexHandler.class);
when(indexHandler.findEdgeById(relId)).thenReturn(Optional.of(graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).next()));
TinkerPopOperations instance = forGraphMappingsAndIndex(graphManager, vres, indexHandler);
UpdateRelation updateRelation = new UpdateRelation(relId, 1, false);
long timeStamp = Instant.now().toEpochMilli();
String userId = "userId";
updateRelation.setModified(new Change(timeStamp, userId, null));
instance.replaceRelation(collection, updateRelation);
Edge newEdge = graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).has("isLatest", true).next();
assertThat(getModificationInfo("modified", newEdge), is(jsnO("timeStamp", jsn(timeStamp), "userId", jsn(userId))));
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deleteEntityMovesRelationsToNewestVertex.
@Test
public void deleteEntityMovesRelationsToNewestVertex() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
String idString = id.toString();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(idString).withVre("test").withType("thing").withProperty("isLatest", true).withProperty("rev", 1).withOutgoingRelation("hasWritten", "stuff").withIncomingRelation("isFriendOf", "friend")).withVertex("stuff", v -> v.withVre("test").withType("stuff").withProperty("isLatest", true).withProperty("rev", 1)).withVertex("friend", v -> v.withVre("test").withType("thing").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
Vertex orig = graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).next();
assertThat(stream(orig.edges(Direction.BOTH, "hasWritten", "isFriendOf")).count(), is(2L));
instance.deleteEntity(collection, id, new Change(Instant.now().toEpochMilli(), "userId", null));
Vertex replacement = graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).next();
assertThat(stream(orig.edges(Direction.BOTH, "hasWritten", "isFriendOf")).count(), is(0L));
assertThat(stream(replacement.edges(Direction.BOTH, "hasWritten", "isFriendOf")).count(), is(2L));
}
Aggregations