use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME in project timbuctoo by HuygensING.
the class DatabaseTest method findOrCreateCollectionAddsTheCollectionToItsArchetype.
@Test
public void findOrCreateCollectionAddsTheCollectionToItsArchetype() {
String rdfUri = "http://www.example.com/entity";
String localName = "entity";
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");
}).wrap();
Node collectionNode = mock(Node.class);
when(collectionNode.getLocalName()).thenReturn(localName);
when(collectionNode.getURI()).thenReturn(rdfUri);
Database instance = new Database(graphWrapper);
Collection collection = instance.findOrCreateCollection(VRE_NAME, collectionNode.getURI(), collectionNode.getLocalName());
assertThat(collection, hasProperty("vreName", equalTo(VRE_NAME)));
assertThat(graphWrapper.getGraph().traversal().V().hasLabel(DATABASE_LABEL).has(RDF_URI_PROP, rdfUri).out(HAS_ARCHETYPE_RELATION_NAME).hasNext(), is(true));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME in project timbuctoo by HuygensING.
the class DatabaseTest method findOrCreateEntityGivesABlankNodeADefaultUri.
@Test
public void findOrCreateEntityGivesABlankNodeADefaultUri() {
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);
Node blankNode = TripleCreator.createBlankNode();
String expectedUri = VRE_NAME + ":" + blankNode.getBlankNodeLabel();
Entity entity = instance.findOrCreateEntity(VRE_NAME, blankNode);
assertThat(entity, is(notNullValue()));
assertThat(entity.vertex.value(RDF_SYNONYM_PROP), is(new String[] { expectedUri }));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_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.COLLECTION_NAME_PROPERTY_NAME in project timbuctoo by HuygensING.
the class TinkerPopOperations method retrieveProperty.
@Override
public Optional<RdfReadProperty> retrieveProperty(Vre vre, String entityRdfUri, String propertyUri) {
Optional<Vertex> entityOpt = indexHandler.findVertexInRdfIndex(vre, entityRdfUri);
if (entityOpt.isPresent()) {
Vertex entity = entityOpt.get();
Iterable<Vertex> collectionOfEntity = () -> collectionsFor(entity);
Optional<Collection> colOpt = StreamSupport.stream(collectionOfEntity.spliterator(), false).map(col -> getProp(col, COLLECTION_NAME_PROPERTY_NAME, String.class)).filter(colNameProp -> colNameProp.isPresent()).map(colNameProp -> colNameProp.get()).map(vre::getCollectionForCollectionName).filter(Optional::isPresent).map(Optional::get).findFirst();
if (colOpt.isPresent()) {
Collection collection = colOpt.get();
VertexProperty<String> property = entity.property(createPropName(collection.getEntityTypeName(), propertyUri));
if (property.isPresent()) {
return Optional.of(new RdfReadProperty(propertyUri, property.value()));
}
}
}
return Optional.empty();
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME in project timbuctoo by HuygensING.
the class LoadSaveCollectionTest method saveThrowsWhenTheCollectionNameIsNotUniqueToThisVre.
@Test(expected = IllegalArgumentException.class)
public void saveThrowsWhenTheCollectionNameIsNotUniqueToThisVre() {
Graph graph = newGraph().withVertex(v -> {
v.withLabel(Collection.DATABASE_LABEL).withProperty(COLLECTION_NAME_PROPERTY_NAME, "persons").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "person").withIncomingRelation(Vre.HAS_COLLECTION_RELATION_NAME, "vre");
}).withVertex("vre", v -> {
v.withLabel(Vre.DATABASE_LABEL).withProperty(Vre.VRE_NAME_PROPERTY_NAME, "OtherVreName");
}).build();
save(new Collection("person", "person", null, Maps.newLinkedHashMap(), "persons", new Vre(vreName), null, false, false, null), graph);
}
Aggregations