use of nl.knaw.huygens.timbuctoo.rdf.Collection in project timbuctoo by HuygensING.
the class ArchetypeTripleProcessor method processRetraction.
@Override
protected void processRetraction(String vreName, String subject, String predicate, String object) {
Collection collection = database.findOrCreateCollection(vreName, subject, getLocalName(subject));
// collection must have an archetype
Collection previousArchetype = collection.getArchetype().get();
Optional<Collection> archetypeCollectionOptional = database.findArchetypeCollection(getLocalName(object));
if (!archetypeCollectionOptional.isPresent()) {
return;
}
// FIXME: assert that triple's archetype is equal to current archetype
Collection defaultArchetype = database.getConcepts();
// The concepts archetype does not have a URI, so we use an empty string of the original uri of the archetype
collection.setArchetype(defaultArchetype, "");
Set<Entity> entities = database.findEntitiesByCollection(collection);
entities.forEach(entity -> entity.moveToOtherArchetype(previousArchetype, defaultArchetype));
}
use of nl.knaw.huygens.timbuctoo.rdf.Collection in project timbuctoo by HuygensING.
the class CollectionMembershipTripleProcessor method processAssertion.
@Override
protected void processAssertion(String vreName, String subject, String predicate, String object) {
Entity entity = database.findOrCreateEntity(vreName, subject);
if (entity.isInKnownCollection()) {
rdfImportSession.getErrorReporter().multipleRdfTypes(subject, object);
} else {
Collection newCollection = database.findOrCreateCollection(vreName, object, getLocalName(object));
Collection defaultCollection = database.getDefaultCollection(vreName);
entity.moveToNewCollection(defaultCollection, newCollection);
}
}
use of nl.knaw.huygens.timbuctoo.rdf.Collection in project timbuctoo by HuygensING.
the class CollectionMembershipTripleProcessorTest method processLogsAnExceptionWhenTheEntityAlreadyIsPartOfACollectionWhenAsserted.
@Test
public void processLogsAnExceptionWhenTheEntityAlreadyIsPartOfACollectionWhenAsserted() {
Database database = mock(Database.class);
Collection collectionFromTriple = mock(Collection.class);
Collection archetypeCollection = mock(Collection.class);
when(collectionFromTriple.getArchetype()).thenReturn(Optional.of(archetypeCollection));
when(database.findOrCreateCollection(anyString(), anyString(), anyString())).thenReturn(collectionFromTriple);
Collection defaultCollection = mock(Collection.class);
when(database.getDefaultCollection("vreName")).thenReturn(defaultCollection);
Entity entity = mock(Entity.class);
when(entity.isInKnownCollection()).thenReturn(true);
when(database.findOrCreateEntity("vreName", SUBJECT_URI)).thenReturn(entity);
RdfImportSession rdfImportSession = mock(RdfImportSession.class);
RdfImportErrorReporter errorReporter = mock(RdfImportErrorReporter.class);
when(rdfImportSession.getErrorReporter()).thenReturn(errorReporter);
CollectionMembershipTripleProcessor instance = new CollectionMembershipTripleProcessor(database, rdfImportSession);
instance.process("vreName", SUBJECT_URI, PREDICATE_URI, OBJECT_URI, true);
verify(errorReporter).multipleRdfTypes(SUBJECT_URI, OBJECT_URI);
}
use of nl.knaw.huygens.timbuctoo.rdf.Collection in project timbuctoo by HuygensING.
the class CollectionMembershipTripleProcessorTest method processRemovesTheEntityToTheRequestedCollectionIfItIsARetraction.
@Test
public void processRemovesTheEntityToTheRequestedCollectionIfItIsARetraction() {
Database database = mock(Database.class);
Collection collectionFromTriple = mock(Collection.class);
Collection archetypeCollection = mock(Collection.class);
when(collectionFromTriple.getArchetype()).thenReturn(Optional.of(archetypeCollection));
when(database.findOrCreateCollection(anyString(), anyString(), anyString())).thenReturn(collectionFromTriple);
Collection defaultCollection = mock(Collection.class);
when(database.getDefaultCollection("vreName")).thenReturn(defaultCollection);
Entity entity = mock(Entity.class);
when(database.findOrCreateEntity("vreName", SUBJECT_URI)).thenReturn(entity);
CollectionMembershipTripleProcessor instance = new CollectionMembershipTripleProcessor(database, mock(RdfImportSession.class));
instance.process("vreName", SUBJECT_URI, PREDICATE_URI, OBJECT_URI, false);
InOrder inOrder = inOrder(entity, database);
inOrder.verify(database).findOrCreateCollection("vreName", OBJECT_URI, OBJECT_NAME);
inOrder.verify(entity).removeFromCollection(collectionFromTriple);
}
use of nl.knaw.huygens.timbuctoo.rdf.Collection in project timbuctoo by HuygensING.
the class CollectionMembershipTripleProcessorTest method processMovesTheEntityToTheKnownCollectionIfItIsAnAssertion.
@Test
public void processMovesTheEntityToTheKnownCollectionIfItIsAnAssertion() {
Database database = mock(Database.class);
Collection collectionFromTriple = mock(Collection.class);
Collection archetypeCollection = mock(Collection.class);
when(collectionFromTriple.getArchetype()).thenReturn(Optional.of(archetypeCollection));
when(database.findOrCreateCollection(anyString(), anyString(), anyString())).thenReturn(collectionFromTriple);
Collection defaultCollection = mock(Collection.class);
when(database.getDefaultCollection("vreName")).thenReturn(defaultCollection);
Entity entity = mock(Entity.class);
when(database.findOrCreateEntity("vreName", SUBJECT_URI)).thenReturn(entity);
CollectionMembershipTripleProcessor instance = new CollectionMembershipTripleProcessor(database, mock(RdfImportSession.class));
instance.process("vreName", SUBJECT_URI, PREDICATE_URI, OBJECT_URI, true);
verify(entity).moveToNewCollection(defaultCollection, collectionFromTriple);
}
Aggregations