use of nl.knaw.huygens.timbuctoo.core.dto.RelationType in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getCollectionReturnsRelationsIfRequested.
@Test
public void getCollectionReturnsRelationsIfRequested() {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID thingId = UUID.randomUUID();
UUID stuffId = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex("v1", v -> v.withLabel("testthing").withVre("test").withType("thing").isLatest(true).withTimId(thingId.toString()).withOutgoingRelation("isCreatorOf", "stuff")).withVertex("stuff", v -> v.withVre("test").withType("stuff").withTimId(stuffId.toString())).withVertex(v -> v.withProperty("relationtype_regularName", "isCreatedBy").withProperty("relationtype_inverseName", "isCreatorOf")).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
DataStream<ReadEntity> entities = instance.getCollection(collection, 0, 1, true, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
ReadEntity readEntity = entities.map(entity -> entity).get(0);
assertThat(readEntity.getRelations(), contains(allOf(hasProperty("entityId", equalTo(stuffId.toString())), hasProperty("collectionName", equalTo("teststuffs")), hasProperty("entityType", equalTo("teststuff")), hasProperty("relationType", equalTo("isCreatorOf")))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.RelationType in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityUsesTheInverseRelationName.
@Test
public void getEntityUsesTheInverseRelationName() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
UUID stuffId = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex("source", v -> v.withIncomingRelation("isCreatedBy", "stuff").withVre("test").withVre("").withType("thing").isLatest(true).withTimId(id.toString())).withVertex("stuff", v -> v.withVre("test").withVre("").withType("stuff").withTimId(stuffId.toString())).withVertex(v -> v.withProperty("relationtype_regularName", "isCreatedBy").withProperty("relationtype_inverseName", "isCreatorOf")).withVertex(v -> v.withProperty("relationtype_regularName", "otherRelationType").withProperty("relationtype_inverseName", "otherInverseType")).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ReadEntity entity = instance.getEntity(id, null, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
assertThat(entity.getRelations(), contains(allOf(hasProperty("entityId", equalTo(stuffId.toString())), hasProperty("relationType", equalTo("isCreatorOf")))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.RelationType in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceRelationCallsTheChangeListener.
@Test
public void replaceRelationCallsTheChangeListener() 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();
ChangeListener changeListener = mock(ChangeListener.class);
IndexHandler indexHandler = mock(IndexHandler.class);
when(indexHandler.findEdgeById(relId)).thenReturn(Optional.of(graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).next()));
TinkerPopOperations instance = forGraphMappingsListenerAndIndex(graphManager, vres, changeListener, 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);
String acceptedProp = createPropName(collection.getEntityTypeName(), "accepted");
verify(changeListener).onEdgeUpdate(argThat(is(sameInstance(collection))), argThat(is(likeEdge().withProperty(acceptedProp, true))), argThat(is(likeEdge().withProperty(acceptedProp, false))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.RelationType in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method acceptRelationThrowsARelationNotPossibleExceptionIfTheSourceIsNotInTheRightVre.
@Test(expected = RelationNotPossibleException.class)
public void acceptRelationThrowsARelationNotPossibleExceptionIfTheSourceIsNotInTheRightVre() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testrelations").get();
UUID typeId = UUID.randomUUID();
UUID sourceId = UUID.randomUUID();
UUID targetId = 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("other").withType("thing").withProperty("isLatest", true)).withVertex(v -> v.withTimId(targetId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
CreateRelation createRelation = new CreateRelation(sourceId, typeId, targetId);
createRelation.setCreated(new Change(Instant.now().toEpochMilli(), "userId", null));
instance.acceptRelation(collection, createRelation);
}
use of nl.knaw.huygens.timbuctoo.core.dto.RelationType in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method acceptRelationSetsTheCreatedInformation.
@Test
public void acceptRelationSetsTheCreatedInformation() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testrelations").get();
UUID typeId = UUID.randomUUID();
UUID sourceId = UUID.randomUUID();
UUID targetId = 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)).withVertex(v -> v.withTimId(targetId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
CreateRelation createRelation = new CreateRelation(sourceId, typeId, targetId);
long timeStamp = Instant.now().toEpochMilli();
String userId = "userId";
createRelation.setCreated(new Change(timeStamp, userId, null));
UUID relId = instance.acceptRelation(collection, createRelation);
Edge newEdge = graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).next();
assertThat(getModificationInfo("modified", newEdge), is(jsnO("timeStamp", jsn(timeStamp), "userId", jsn(userId))));
assertThat(getModificationInfo("created", newEdge), is(jsnO("timeStamp", jsn(timeStamp), "userId", jsn(userId))));
}
Aggregations