Search in sources :

Example 16 with VresBuilder

use of nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder in project timbuctoo by HuygensING.

the class RdfImportSessionTest method setUp.

@Before
public void setUp() throws Exception {
    dataStoreOperations = mock(DataStoreOperations.class);
    Vres vres = new VresBuilder().withVre(VRE_NAME, "prefix", vre -> vre.withCollection("prefixanyCols")).build();
    vre = vres.getVre(VRE_NAME);
    given(dataStoreOperations.ensureVreExists(VRE_NAME)).willReturn(vre);
    given(dataStoreOperations.loadVres()).willReturn(vres);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RdfImportSessionStubs.rdfImportSessionWithErrorReporter(nl.knaw.huygens.timbuctoo.core.RdfImportSessionStubs.rdfImportSessionWithErrorReporter) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) CreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.CreateProperty) ArrayList(java.util.ArrayList) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Lists(com.google.common.collect.Lists) BDDMockito.given(org.mockito.BDDMockito.given) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) Before(org.junit.Before) PredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse) InOrder(org.mockito.InOrder) Test(org.junit.Test) RdfImportSessionStubs.rdfImportSessionWithPropertyFactory(nl.knaw.huygens.timbuctoo.core.RdfImportSessionStubs.rdfImportSessionWithPropertyFactory) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) Mockito.never(org.mockito.Mockito.never) PropertyFactory(nl.knaw.huygens.timbuctoo.core.rdf.PropertyFactory) Mockito.inOrder(org.mockito.Mockito.inOrder) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Mockito.mock(org.mockito.Mockito.mock) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) Before(org.junit.Before)

Example 17 with VresBuilder

use of nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder in project timbuctoo by HuygensING.

the class ScaffoldMigrator method execute.

// FIXME move to DataAccess (allow ScaffoldVresConfig.mappings to be injected as an argument)
public void execute() {
    // The code below will add vertices, so a second launch will not run this code
    try (TinkerPopOperations db = forInitDb(graphManager)) {
        if (db.databaseIsEmptyExceptForMigrations()) {
            LOG.info("Setting up a new scaffold for empty database");
            Vres mappings = new VresBuilder().withVre("Admin", "", vre -> vre.withCollection("persons", collection -> collection.withDescription("People with at least a name, birthdate and birthplace.").withDisplayName(localProperty("person_names", defaultFullPersonNameConverter)).withProperty("names", localProperty("person_names", personNames)).withProperty("gender", localProperty("person_gender")).withProperty("birthDate", localProperty("person_birthDate", datable)).withProperty("deathDate", localProperty("person_deathDate", datable))).withCollection("locations", collection -> collection.withDescription("Countries, cities, villages, streets, etc.").withDisplayName(localProperty("location_name")).withProperty("name", localProperty("location_name")).withProperty("country", localProperty("location_country"))).withCollection("collectives", collection -> collection.withDescription("Institutes, multiple persons, companies, etc.").withDisplayName(localProperty("collective_name")).withProperty("name", localProperty("collective_name"))).withCollection("documents", collection -> collection.withDescription("Stories, novels, letters, diaries, plays, films, etc.").withDisplayName(localProperty("document_title")).withProperty("title", localProperty("document_title")).withProperty("documentType", localProperty("document_documentType")).withProperty("date", localProperty("document_date", datable))).withCollection("keywords", collection -> collection.withDescription("").withDisplayName(localProperty("keyword_value")).withProperty("value", localProperty("keyword_value")).withProperty("type", localProperty("keyword_type"))).withCollection("concepts", collection -> collection.withDescription("Concepts which do not conform to a specific archetype.").withDisplayName(localProperty("label"))).withCollection("relations", CollectionBuilder::isRelationCollection)).build();
            db.initDb(mappings, relationType("person", "hasBirthPlace", "location", "isBirthPlaceOf", false, false, false, UUID.randomUUID()), relationType("person", "hasDeathPlace", "location", "isDeathPlaceOf", false, false, false, UUID.randomUUID()), relationType("collective", "hasMember", "person", "isMemberOf", false, false, false, UUID.randomUUID()), relationType("collective", "locatedAt", "location", "isHomeOf", false, false, false, UUID.randomUUID()), relationType("document", "isCreatedBy", "person", "isCreatorOf", false, false, false, UUID.randomUUID()), // person to person relations
            relationType("concept", "hasFirstPerson", "person", "isFirstPersonInRelation", false, false, false, UUID.randomUUID()), relationType("concept", "hasSecondPerson", "person", "isSecondPersonInRelation", false, false, false, UUID.randomUUID()), relationType("concept", "hasPersonToPersonRelationType", "concept", "isPersonToPersonRelationTypeOf", false, false, false, UUID.randomUUID()), // states of persons
            relationType("concept", "hasStateType", "concept", "isStateTypeOf", false, false, false, UUID.randomUUID()), relationType("concept", "isStateOfPerson", "person", "hasPersonState", false, false, false, UUID.randomUUID()), relationType("concept", "isStateLinkedToInstitute", "collective", "isInstituteLinkedToState", false, false, false, UUID.randomUUID()), relationType("concept", "isStateLinkedToLocation", "location", "isLocationLinkedToState", false, false, false, UUID.randomUUID()), // data lines for persons
            relationType("concept", "hasDataLineType", "concept", "isDataLineTypeOf", false, false, false, UUID.randomUUID()), relationType("concept", "isDataLineForPerson", "person", "hasDataLine", false, false, false, UUID.randomUUID()), // scientist_bios for persons
            relationType("concept", "hasFieldOfInterest", "concept", "isFieldOfInterestOf", false, false, false, UUID.randomUUID()), relationType("concept", "isScientistBioOf", "person", "hasScientistBio", false, false, false, UUID.randomUUID()));
        }
        db.success();
    }
}
Also used : Converters.datable(nl.knaw.huygens.timbuctoo.model.properties.converters.Converters.datable) Logger(org.slf4j.Logger) Converters.defaultFullPersonNameConverter(nl.knaw.huygens.timbuctoo.model.properties.converters.Converters.defaultFullPersonNameConverter) TinkerPopOperations(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperations) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) CollectionBuilder(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder) LoggerFactory(org.slf4j.LoggerFactory) Converters.personNames(nl.knaw.huygens.timbuctoo.model.properties.converters.Converters.personNames) UUID(java.util.UUID) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) TinkerPopOperationsForMigrations.forInitDb(nl.knaw.huygens.timbuctoo.server.databasemigration.TinkerPopOperationsForMigrations.forInitDb) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) RelationType.relationType(nl.knaw.huygens.timbuctoo.core.dto.RelationType.relationType) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) CollectionBuilder(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) TinkerPopOperations(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperations)

Aggregations

VresBuilder (nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder)17 Test (org.junit.Test)16 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)15 PropertyTypes.localProperty (nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty)15 List (java.util.List)11 UUID (java.util.UUID)11 Matchers.hasProperty (org.hamcrest.Matchers.hasProperty)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 IOException (java.io.IOException)10 UpdateEntity (nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity)10 TimProperty (nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty)10 JsonToEntityMapper (nl.knaw.huygens.timbuctoo.crud.conversion.JsonToEntityMapper)10 JsonBuilder (nl.knaw.huygens.timbuctoo.util.JsonBuilder)10 JsonBuilder.jsn (nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn)10 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)10 Matchers.allOf (org.hamcrest.Matchers.allOf)10 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)10 Matchers.equalTo (org.hamcrest.Matchers.equalTo)10 Matchers.hasItem (org.hamcrest.Matchers.hasItem)10 Matchers.is (org.hamcrest.Matchers.is)10