use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityOnlyReturnsAcceptedRelations.
@Test
public void getEntityOnlyReturnsAcceptedRelations() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
UUID relatedId = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex("source", v -> v.withOutgoingRelation("isRelatedTo", "relatedThing", rel -> rel.withIsLatest(true).withAccepted("testrelation", true)).withOutgoingRelation("hasOtherRelation", "relatedThing", rel -> rel.withIsLatest(true).withAccepted("testrelation", false)).withVre("test").withVre("").withType("thing").isLatest(true).withTimId(id.toString())).withVertex("relatedThing", v -> v.withVre("test").withVre("").withType("thing").withTimId(relatedId.toString())).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ReadEntity entity = instance.getEntity(id, null, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
assertThat(entity.getRelations(), hasSize(1));
assertThat(entity.getRelations(), contains(hasProperty("relationType", equalTo("isRelatedTo"))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getCollectionReturnsTheKnowsDisplayNameForEachItem.
@Test
public void getCollectionReturnsTheKnowsDisplayNameForEachItem() {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id1 = UUID.randomUUID();
UUID id2 = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withLabel("testthing").withVre("test").withType("thing").isLatest(true).withTimId(id1.toString()).withProperty("testthing_displayName", // configured in JsonCrudServiceBuilder
"displayName1")).withVertex(v -> v.withLabel("testthing").withVre("test").withType("thing").isLatest(true).withTimId(id2.toString()).withProperty("testthing_displayName", // configured in JsonCrudServiceBuilder
"displayName2")).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
DataStream<ReadEntity> entities = instance.getCollection(collection, 0, 2, true, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
List<String> displayNames = entities.map(ReadEntity::getDisplayName);
assertThat(displayNames, containsInAnyOrder("displayName1", "displayName2"));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method acceptRelationCreatesANewRelationWhenItDoesNotExist.
@Test
public void acceptRelationCreatesANewRelationWhenItDoesNotExist() 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);
createRelation.setCreated(new Change(Instant.now().toEpochMilli(), "userId", null));
UUID relId = instance.acceptRelation(collection, createRelation);
assertThat(graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).next(), is(likeEdge().withSourceWithId(sourceId).withTargetWithId(targetId).withTypeId(typeId)));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method acceptRelationThrowsARelationNotPossibleExceptionIfTheTargetIsNotInTheRightVre.
@Test(expected = RelationNotPossibleException.class)
public void acceptRelationThrowsARelationNotPossibleExceptionIfTheTargetIsNotInTheRightVre() 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("other").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.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceRelationDuplicatesTheEdge.
@Test
public void replaceRelationDuplicatesTheEdge() 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);
assertThat(graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).count().next(), is(2L));
}
Aggregations