use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deleteVreRemovesAllTheVresCollectionsFromDatabase.
@Test
public void deleteVreRemovesAllTheVresCollectionsFromDatabase() {
TinkerPopGraphManager graphManager = newGraph().withVertex("vreName", v -> v.withLabel("VRE").withProperty(Vre.VRE_NAME_PROPERTY_NAME, "vreName").withOutgoingRelation(HAS_COLLECTION_RELATION_NAME, "collection1").withOutgoingRelation(HAS_COLLECTION_RELATION_NAME, "collection2")).withVertex("collection1", v -> v.withProperty(COLLECTION_NAME_PROPERTY_NAME, "collection1").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "entityType1").withProperty(IS_RELATION_COLLECTION_PROPERTY_NAME, true).withOutgoingRelation(HAS_DISPLAY_NAME_RELATION_NAME, "displayName").withOutgoingRelation(HAS_PROPERTY_RELATION_NAME, "property").withOutgoingRelation(HAS_ENTITY_NODE_RELATION_NAME, "entityNode")).withVertex("displayName", v -> v.withProperty("displayName", true).withProperty("propertyType", "string")).withVertex("property", v -> v.withProperty("property", true).withProperty("propertyType", "string")).withVertex("entityNode", v -> v.withOutgoingRelation(HAS_ENTITY_RELATION_NAME, "entity")).withVertex("entity", v -> v.withProperty("entity", true)).withVertex("collection2", v -> v.withProperty(COLLECTION_NAME_PROPERTY_NAME, "collection2").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "entityType2").withProperty(IS_RELATION_COLLECTION_PROPERTY_NAME, false)).withVertex("otherVreCollection", v -> v.withProperty(COLLECTION_NAME_PROPERTY_NAME, "otherVreCollection").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "entityType3").withProperty(IS_RELATION_COLLECTION_PROPERTY_NAME, false)).wrap();
TinkerPopOperations instance = forGraphWrapper(graphManager);
instance.deleteVre("vreName");
Graph graph = graphManager.getGraph();
assertThat(graph.traversal().V().has(Vre.VRE_NAME_PROPERTY_NAME, "vreName").hasNext(), equalTo(false));
assertThat(graph.traversal().V().has(COLLECTION_NAME_PROPERTY_NAME, "collection1").hasNext(), equalTo(false));
assertThat(graph.traversal().V().has(COLLECTION_NAME_PROPERTY_NAME, "collection2").hasNext(), equalTo(false));
assertThat(graph.traversal().V().has(COLLECTION_NAME_PROPERTY_NAME, "otherVreCollection").hasNext(), equalTo(true));
assertThat(graph.traversal().V().has("entity").hasNext(), equalTo(false));
assertThat(graph.traversal().V().has("displayName").hasNext(), equalTo(false));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME in project timbuctoo by HuygensING.
the class CollectionTest method removeRemovesTheCollectionPropertiesFromTheVertex.
@Test
public void removeRemovesTheCollectionPropertiesFromTheVertex() {
GraphWrapper graphWrapper = newGraph().withVertex("collection", v -> v.withLabel(DATABASE_LABEL).withOutgoingRelation(HAS_ENTITY_NODE_RELATION_NAME, "entityNode").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, ENTITY_NAME).withProperty(COLLECTION_NAME_PROPERTY_NAME, COLLECTION_NAME)).withVertex("entityNode", v -> v.withOutgoingRelation(HAS_ENTITY_RELATION_NAME, "entity")).withVertex("entity", v -> v.withLabel("entity")).wrap();
Vertex collectionVertex = graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of("collection")).next();
Vertex entityVertex = graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of("entity")).next();
CollectionDescription description = CollectionDescription.createCollectionDescription(ENTITY_NAME, VRE_NAME);
PropertyHelper propertyHelper = mock(PropertyHelper.class);
Collection instance = new Collection(VRE_NAME, collectionVertex, graphWrapper, description, propertyHelper);
instance.remove(entityVertex);
verify(propertyHelper).removeProperties(entityVertex, description);
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME in project timbuctoo by HuygensING.
the class DatabaseTest method findEntitiesByCollectionReturnsAllTheEntitiesOfTheCollection.
@Test
public void findEntitiesByCollectionReturnsAllTheEntitiesOfTheCollection() {
CollectionDescription desc = CollectionDescription.createCollectionDescription("collection", VRE_NAME);
TinkerPopGraphManager graphWrapper = newGraph().withVertex("collection", v -> v.withLabel(DATABASE_LABEL).withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, desc.getEntityTypeName()).withProperty(COLLECTION_NAME_PROPERTY_NAME, desc.getCollectionName()).withOutgoingRelation(HAS_ENTITY_NODE_RELATION_NAME, "entityVertex")).withVertex("entityVertex", v -> v.withOutgoingRelation(HAS_ENTITY_RELATION_NAME, "entity1").withOutgoingRelation(HAS_ENTITY_RELATION_NAME, "entity2")).withVertex("entity1", v -> {
}).withVertex("entity2", v -> {
}).withVertex("entityOfOtherCollection", v -> {
}).wrap();
Database instance = new Database(graphWrapper);
Collection collection = mock(Collection.class);
when(collection.getDescription()).thenReturn(desc);
Set<Entity> entitiesByCollection = instance.findEntitiesByCollection(collection);
assertThat(entitiesByCollection, hasSize(2));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME in project timbuctoo by HuygensING.
the class CollectionTest method removeRemovesEdgeBetweenTheVertexAndTheCollection.
@Test
public void removeRemovesEdgeBetweenTheVertexAndTheCollection() {
GraphWrapper graphWrapper = newGraph().withVertex("collection", v -> v.withLabel(DATABASE_LABEL).withOutgoingRelation(HAS_ENTITY_NODE_RELATION_NAME, "entityNode").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, ENTITY_NAME).withProperty(COLLECTION_NAME_PROPERTY_NAME, COLLECTION_NAME)).withVertex("entityNode", v -> v.withOutgoingRelation(HAS_ENTITY_RELATION_NAME, "entity")).withVertex("entity", v -> v.withLabel("entity")).wrap();
Vertex collectionVertex = graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of("collection")).next();
Vertex entityVertex = graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of("entity")).next();
Collection instance = new Collection(VRE_NAME, collectionVertex, graphWrapper, mock(CollectionDescription.class), mock(PropertyHelper.class));
instance.remove(entityVertex);
assertThat(graphWrapper.getGraph().traversal().V(collectionVertex.id()).out(HAS_ENTITY_NODE_RELATION_NAME).out(HAS_ENTITY_RELATION_NAME).hasId(entityVertex.id()).hasNext(), is(false));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME in project timbuctoo by HuygensING.
the class DatabaseTest method findOrCreateEntityAddsANewlyCreatedEntityToTheDefaultCollection.
@Test
public void findOrCreateEntityAddsANewlyCreatedEntityToTheDefaultCollection() {
TinkerPopGraphManager graphWrapper = newGraph().withVertex(v -> v.withLabel(Vre.DATABASE_LABEL).withProperty("name", VRE_NAME)).withVertex(v -> {
v.withLabel(Vre.DATABASE_LABEL);
v.withProperty(Vre.VRE_NAME_PROPERTY_NAME, "Admin");
v.withOutgoingRelation(Vre.HAS_COLLECTION_RELATION_NAME, "defaultArchetype");
}).withVertex("defaultArchetype", v -> {
v.withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "concept");
v.withProperty(COLLECTION_NAME_PROPERTY_NAME, "concepts");
v.withOutgoingRelation(HAS_ENTITY_NODE_RELATION_NAME, "entityCollection");
}).withVertex("entityCollection", v -> {
}).wrap();
final Database instance = new Database(graphWrapper, modifier);
Entity entity = instance.findOrCreateEntity(VRE_NAME, entityNode);
assertThat(entity, is(notNullValue()));
assertThat(graphWrapper.getGraph().traversal().V(entity.vertex.id()).in(HAS_ENTITY_RELATION_NAME).in(HAS_ENTITY_NODE_RELATION_NAME).has(ENTITY_TYPE_NAME_PROPERTY_NAME, DEFAULT_COLLECTION).hasNext(), is(true));
assertThat(graphWrapper.getGraph().traversal().V(entity.vertex.id()).next(), is(likeVertex().withLabel(DEFAULT_COLLECTION).withType(DEFAULT_COLLECTION)));
}
Aggregations