use of nl.knaw.huygens.timbuctoo.core.dto.CreateRelation in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method acceptRelationsThrowsARelationNotPossibleExceptionIfTheTypeOfTheSourceIsInvalid.
@Test(expected = RelationNotPossibleException.class)
public void acceptRelationsThrowsARelationNotPossibleExceptionIfTheTypeOfTheSourceIsInvalid() 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", "isRelatedTo").withProperty("relationtype_sourceTypeName", "teststuff").withProperty("relationtype_targeTypeName", "testthing").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));
instance.acceptRelation(collection, createRelation);
}
use of nl.knaw.huygens.timbuctoo.core.dto.CreateRelation 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.CreateRelation 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.CreateRelation in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method acceptRelationsThrowsARelationNotPossibleExceptionIfTheTypeOfTheTargetIsInvalid.
@Test(expected = RelationNotPossibleException.class)
public void acceptRelationsThrowsARelationNotPossibleExceptionIfTheTypeOfTheTargetIsInvalid() 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", "isRelatedTo").withProperty("relationtype_sourceTypeName", "testthing").withProperty("relationtype_targeTypeName", "teststuff").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));
instance.acceptRelation(collection, createRelation);
}
use of nl.knaw.huygens.timbuctoo.core.dto.CreateRelation in project timbuctoo by HuygensING.
the class JsonCrudService method createRelation.
private UUID createRelation(Collection collection, ObjectNode input, User user) throws IOException, PermissionFetchingException {
UUID sourceId = asUuid(input, "^sourceId");
UUID targetId = asUuid(input, "^targetId");
UUID typeId = asUuid(input, "^typeId");
CreateRelation createRelation = new CreateRelation(sourceId, typeId, targetId);
return timDbAccess.createRelation(collection, createRelation, user);
}
Aggregations