Search in sources :

Example 1 with Collection

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));
}
Also used : Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) Collection(nl.knaw.huygens.timbuctoo.rdf.Collection)

Example 2 with Collection

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);
    }
}
Also used : Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) Collection(nl.knaw.huygens.timbuctoo.rdf.Collection)

Example 3 with Collection

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);
}
Also used : Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) RdfImportSession(nl.knaw.huygens.timbuctoo.core.RdfImportSession) RdfImportErrorReporter(nl.knaw.huygens.timbuctoo.core.RdfImportErrorReporter) Database(nl.knaw.huygens.timbuctoo.rdf.Database) Collection(nl.knaw.huygens.timbuctoo.rdf.Collection) Test(org.junit.Test)

Example 4 with Collection

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);
}
Also used : Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) RdfImportSession(nl.knaw.huygens.timbuctoo.core.RdfImportSession) InOrder(org.mockito.InOrder) Database(nl.knaw.huygens.timbuctoo.rdf.Database) Collection(nl.knaw.huygens.timbuctoo.rdf.Collection) Test(org.junit.Test)

Example 5 with Collection

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);
}
Also used : Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) RdfImportSession(nl.knaw.huygens.timbuctoo.core.RdfImportSession) Database(nl.knaw.huygens.timbuctoo.rdf.Database) Collection(nl.knaw.huygens.timbuctoo.rdf.Collection) Test(org.junit.Test)

Aggregations

Collection (nl.knaw.huygens.timbuctoo.rdf.Collection)6 Entity (nl.knaw.huygens.timbuctoo.rdf.Entity)6 RdfImportSession (nl.knaw.huygens.timbuctoo.core.RdfImportSession)3 Database (nl.knaw.huygens.timbuctoo.rdf.Database)3 Test (org.junit.Test)3 RdfImportErrorReporter (nl.knaw.huygens.timbuctoo.core.RdfImportErrorReporter)1 InOrder (org.mockito.InOrder)1