Search in sources :

Example 16 with Type

use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type in project timbuctoo by HuygensING.

the class JsonProvenanceToRdfPatchTest method retractsPreviousRevision.

@Test
public void retractsPreviousRevision() throws Exception {
    String testRetractsRevision = "{\n" + "   \"@type\":\"prov:Activity\",\n" + "   \"http://www.w3.org/ns/prov#generates\":[\n" + "      {\n" + "         \"@type\":\"prov:Entity\",\n" + "         \"@id\":\"_:b2\",\n" + "         \"specializationOf\":{\n" + "            \"@id\":\"http://example.com/the/actual/entitys\"\n" + "         },\n" + "         \"wasRevisionOf\":{\n" + "            \"@id\":\"http://example.org/revision1\"\n" + "         },\n" + "         \"replacements\":[\n" + "            {\n" + "               \"@type\":\"http://timbuctoo.huygens.knaw.nl/v5/vocabulary#mutation\",\n" + "               \"predicate\":\"http://example.org/pred1\",\n" + "               \"value\":\"value1\"\n" + "            }\n" + "         ]\n" + "      }\n" + "   ],\n" + context + "}";
    QuadStore testQuadStore = new DummyQuadStore().with("http://example.org/revision1", PROV_SPECIALIZATION_OF, "http://example.com/the/actual/entitys", null).with("http://example.com/the/actual/entitys", TIM_LATEST_REVISION, "http://example.org/revision1");
    JsonProvenanceToRdfPatch creator = fromCurrentState(new DocumentLoader(), testRetractsRevision, testQuadStore, EDITOR_URI, "test", CLOCK);
    creator.sendQuads(basicRdfPatchSerializer, s -> {
    }, null);
    List<String> filteredResult = Lists.newArrayList(Collections2.filter(result, Predicates.containsPattern("latestRevision")));
    assertThat(filteredResult, containsInAnyOrder("-<http://example.com/the/actual/entitys> <" + TIM_LATEST_REVISION + "> <http://example.org/revision1" + "> <" + defaultGraph + "> .\n", "+<http://example.com/the/actual/entitys> <" + TIM_LATEST_REVISION + "> <http://timbuctoo.huygens.knaw.nl/static/v5/skolemized/test/b1> <" + defaultGraph + "> .\n"));
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) DocumentLoader(com.github.jsonldjava.core.DocumentLoader) Test(org.junit.Test)

Example 17 with Type

use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type in project timbuctoo by HuygensING.

the class TypeTest method isSerializable.

@Test
public void isSerializable() throws IOException {
    Type type = new Type("http://example.org/myType");
    type.getOrCreatePredicate("http://example.org/myPredicate", Direction.OUT);
    type.getOrCreatePredicate("http://example.org/myPredicate", Direction.IN);
    ObjectMapper mapper = new ObjectMapper().registerModule(new Jdk8Module()).registerModule(new GuavaModule()).registerModule(new TimbuctooCustomSerializers()).enable(SerializationFeature.INDENT_OUTPUT);
    String result = mapper.writeValueAsString(type);
    Type loadedType = mapper.readValue(result, Type.class);
    assertThat(loadedType, is(type));
}
Also used : Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) TimbuctooCustomSerializers(nl.knaw.huygens.timbuctoo.v5.jacksonserializers.TimbuctooCustomSerializers) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) Test(org.junit.Test)

Example 18 with Type

use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type in project timbuctoo by HuygensING.

the class RawUploadRdfSaverTest method usageTest.

@Test
public void usageTest() throws LogStorageFailedException {
    RdfToStringFaker rdfSerializer = new RdfToStringFaker();
    RawUploadRdfSaver instance = instanceWithRdfSerializer(rdfSerializer, dataSetMetadata);
    final String collection1 = instance.addCollection("collection1");
    ImportPropertyDescriptions importPropertyDescriptions = new ImportPropertyDescriptions();
    importPropertyDescriptions.getOrCreate(1).setPropertyName("propName1");
    importPropertyDescriptions.getOrCreate(2).setPropertyName("propName2");
    instance.addPropertyDescriptions(collection1, importPropertyDescriptions);
    instance.addEntity(collection1, ImmutableMap.of("propName1", "value1", "propName2", "val2"));
    instance.addEntity(collection1, ImmutableMap.of("propName1", "entVal1", "propName2", "entVal2"));
    final String collection2 = instance.addCollection("collection2");
    ImportPropertyDescriptions importPropertyDescriptions1 = new ImportPropertyDescriptions();
    importPropertyDescriptions1.getOrCreate(1).setPropertyName("prop3");
    importPropertyDescriptions1.getOrCreate(2).setPropertyName("prop4");
    instance.addPropertyDescriptions(collection2, importPropertyDescriptions1);
    instance.addEntity(collection2, ImmutableMap.of("prop3", "value1", "prop4", "val2"));
    instance.addEntity(collection2, ImmutableMap.of("prop3", "entVal1", "prop4", "entVal2"));
    String generatedRdf = rdfSerializer.toString();
    // Use assertEquals because the failing Hamcrest output is hard to compare
    String graphName = dataSetMetadata.getBaseUri();
    String fileUri = dataSetMetadata.getUriPrefix() + "rawData/fileName/";
    String prop = fileUri + "props/";
    String rowData = fileUri + "entities/";
    assertEquals(fileUri + " " + RDF_TYPE + " " + TIM_TABULAR_FILE + " " + graphName + "\n" + graphName + " " + PROV_DERIVED_FROM + " " + fileUri + " " + graphName + "\n" + fileUri + " " + TIM_MIMETYPE + " " + "application/octet-stream" + "^^" + STRING + " " + graphName + "\n" + fileUri + " " + RDFS_LABEL + " " + FILE_NAME + "^^" + STRING + " " + graphName + "\n" + fileUri + " " + PROV_ATTIME + " " + DATE + "^^" + XSD_DATETIMESTAMP + " " + graphName + "\n" + collection1 + " " + RDF_TYPE + " " + collection1 + "type " + graphName + "\n" + collection1 + " " + RDF_TYPE + " " + TIM_TABULAR_COLLECTION + " " + graphName + "\n" + collection1 + " " + RDFS_LABEL + " collection1" + "^^" + STRING + " " + graphName + "\n" + fileUri + " " + TIM_HASCOLLECTION + " " + collection1 + " " + graphName + "\n" + fileUri + " " + TIMBUCTOO_NEXT + " " + collection1 + " " + graphName + "\n" + prop + "tim_id " + RDF_TYPE + " " + TIM_PROP_DESC + " " + graphName + "\n" + collection1 + " " + TIM_HAS_PROPERTY + " " + prop + "tim_id " + graphName + "\n" + prop + "tim_id " + TIM_PROP_ID + " -1" + "^^" + INTEGER + " " + graphName + "\n" + prop + "tim_id " + RDFS_LABEL + " tim_id" + "^^" + STRING + " " + graphName + "\n" + prop + "propName1 " + RDF_TYPE + " " + TIM_PROP_DESC + " " + graphName + "\n" + collection1 + " " + TIM_HAS_PROPERTY + " " + prop + "propName1 " + graphName + "\n" + prop + "propName1 " + TIM_PROP_ID + " 1" + "^^" + INTEGER + " " + graphName + "\n" + prop + "propName1 " + RDFS_LABEL + " propName1" + "^^" + STRING + " " + graphName + "\n" + prop + "tim_id " + TIMBUCTOO_NEXT + " " + prop + "propName1 " + graphName + "\n" + prop + "propName2 " + RDF_TYPE + " " + TIM_PROP_DESC + " " + graphName + "\n" + collection1 + " " + TIM_HAS_PROPERTY + " " + prop + "propName2 " + graphName + "\n" + prop + "propName2 " + TIM_PROP_ID + " 2" + "^^" + INTEGER + " " + graphName + "\n" + prop + "propName2 " + RDFS_LABEL + " propName2" + "^^" + STRING + " " + graphName + "\n" + prop + "propName1 " + TIMBUCTOO_NEXT + " " + prop + "propName2 " + graphName + "\n" + rowData + "1 " + RDF_TYPE + " " + collection1 + " " + graphName + "\n" + collection1 + " " + TIM_HAS_ROW + " " + rowData + "1 " + graphName + "\n" + rowData + "1 " + prop + "propName1" + " value1" + "^^" + STRING + " " + graphName + "\n" + rowData + "1 " + prop + "propName2" + " val2" + "^^" + STRING + " " + graphName + "\n" + rowData + "1 " + prop + "tim_id" + " {UUID}" + "^^" + STRING + " " + graphName + "\n" + rowData + "2 " + RDF_TYPE + " " + collection1 + " " + graphName + "\n" + collection1 + " " + TIM_HAS_ROW + " " + rowData + "2 " + graphName + "\n" + rowData + "2 " + prop + "propName1" + " entVal1" + "^^" + STRING + " " + graphName + "\n" + rowData + "2 " + prop + "propName2" + " entVal2" + "^^" + STRING + " " + graphName + "\n" + rowData + "2 " + prop + "tim_id" + " {UUID}" + "^^" + STRING + " " + graphName + "\n" + collection2 + " " + RDF_TYPE + " " + collection2 + "type " + graphName + "\n" + collection2 + " " + RDF_TYPE + " " + TIM_TABULAR_COLLECTION + " " + graphName + "\n" + collection2 + " " + RDFS_LABEL + " collection2" + "^^" + STRING + " " + graphName + "\n" + fileUri + " " + TIM_HASCOLLECTION + " " + collection2 + " " + graphName + "\n" + collection1 + " " + TIMBUCTOO_NEXT + " " + collection2 + " " + graphName + "\n" + prop + "tim_id " + RDF_TYPE + " " + TIM_PROP_DESC + " " + graphName + "\n" + collection2 + " " + TIM_HAS_PROPERTY + " " + prop + "tim_id " + graphName + "\n" + prop + "tim_id " + TIM_PROP_ID + " -1" + "^^" + INTEGER + " " + graphName + "\n" + prop + "tim_id " + RDFS_LABEL + " tim_id" + "^^" + STRING + " " + graphName + "\n" + prop + "prop3 " + RDF_TYPE + " " + TIM_PROP_DESC + " " + graphName + "\n" + collection2 + " " + TIM_HAS_PROPERTY + " " + prop + "prop3 " + graphName + "\n" + prop + "prop3 " + TIM_PROP_ID + " 1" + "^^" + INTEGER + " " + graphName + "\n" + prop + "prop3 " + RDFS_LABEL + " prop3" + "^^" + STRING + " " + graphName + "\n" + prop + "tim_id " + TIMBUCTOO_NEXT + " " + prop + "prop3 " + graphName + "\n" + prop + "prop4 " + RDF_TYPE + " " + TIM_PROP_DESC + " " + graphName + "\n" + collection2 + " " + TIM_HAS_PROPERTY + " " + prop + "prop4 " + graphName + "\n" + prop + "prop4 " + TIM_PROP_ID + " 2" + "^^" + INTEGER + " " + graphName + "\n" + prop + "prop4 " + RDFS_LABEL + " prop4" + "^^" + STRING + " " + graphName + "\n" + prop + "prop3 " + TIMBUCTOO_NEXT + " " + prop + "prop4 " + graphName + "\n" + rowData + "3 " + RDF_TYPE + " " + collection2 + " " + graphName + "\n" + collection2 + " " + TIM_HAS_ROW + " " + rowData + "3 " + graphName + "\n" + rowData + "3 " + prop + "prop3" + " value1" + "^^" + STRING + " " + graphName + "\n" + rowData + "3 " + prop + "prop4" + " val2" + "^^" + STRING + " " + graphName + "\n" + rowData + "3 " + prop + "tim_id" + " {UUID}" + "^^" + STRING + " " + graphName + "\n" + rowData + "4 " + RDF_TYPE + " " + collection2 + " " + graphName + "\n" + collection2 + " " + TIM_HAS_ROW + " " + rowData + "4 " + graphName + "\n" + rowData + "4 " + prop + "prop3" + " entVal1" + "^^" + STRING + " " + graphName + "\n" + rowData + "4 " + prop + "prop4" + " entVal2" + "^^" + STRING + " " + graphName + "\n" + rowData + "4 " + prop + "tim_id" + " {UUID}" + "^^" + STRING + " " + graphName + "\n", generatedRdf.replaceAll("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", "{UUID}"));
}
Also used : RawUploadRdfSaver(nl.knaw.huygens.timbuctoo.v5.bulkupload.RawUploadRdfSaver) ImportPropertyDescriptions(nl.knaw.huygens.timbuctoo.bulkupload.parsingstatemachine.ImportPropertyDescriptions) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 19 with Type

use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type in project timbuctoo by HuygensING.

the class BdbSchemaStore method finish.

@Override
public void finish() {
    LOG.info("Finished processing entities");
    importStatus.setStatus("Finished processing entities");
    // Step 3: Add type information to inverse predicates
    for (Map.Entry<String, Type> typeEntry : types.entrySet()) {
        Type type = typeEntry.getValue();
        String typeName = typeEntry.getKey();
        for (Predicate predicate : type.getPredicates()) {
            predicate.finish();
            if (predicate.getDirection() == Direction.IN) {
                continue;
            }
            for (String referenceType : predicate.getReferenceTypes().keySet()) {
                try {
                    types.get(referenceType).getPredicate(predicate.getName(), // There must be an inverse for each outward predicate
                    Direction.IN).incReferenceType(type.getName(), 1);
                } catch (Exception e) {
                    String cause = "Referenced type " + referenceType + " not found";
                    try {
                        if (types.containsKey(referenceType)) {
                            cause = "type does not have the inverse predicate " + predicate.getName();
                            if (types.get(referenceType).getPredicate(predicate.getName(), Direction.IN) != null) {
                                cause = "Something failed during addreferencetype(" + typeName + ")";
                            }
                        }
                        LOG.error("Error during inverse generation (ignored): " + cause, e);
                        importStatus.addError("Error during inverse generation (ignored): " + cause, e);
                    } catch (Exception e2) {
                        LOG.error("Error during inverse generation " + cause, e);
                        importStatus.addError("Error during inverse generation " + cause, e);
                        LOG.error("Error during recovery generation ", e2);
                        importStatus.addError("Error during recovery generation ", e2);
                    }
                }
            }
        }
    }
    try {
        try {
            String serializedValue = objectMapper.writeValueAsString(types);
            dataStore.setValue(serializedValue);
            dataStore.commit();
            stableTypes = readTypes(serializedValue);
        } catch (IOException | DatabaseWriteException e) {
            throw new SchemaUpdateException(e);
        }
    } catch (SchemaUpdateException e) {
        e.printStackTrace();
    }
}
Also used : Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type) ChangeType(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.ChangeType) DatabaseWriteException(nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.DatabaseWriteException) IOException(java.io.IOException) SchemaUpdateException(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.SchemaUpdateException) HashMap(java.util.HashMap) Map(java.util.Map) DatabaseWriteException(nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.DatabaseWriteException) IOException(java.io.IOException) SchemaUpdateException(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.SchemaUpdateException) Predicate(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate)

Example 20 with Type

use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type in project timbuctoo by HuygensING.

the class BdbSchemaStore method updatePredicateType.

public void updatePredicateType(Type type, CursorQuad quad, boolean inc, ChangeFetcher changeFetcher) {
    final Predicate predicate = type.getOrCreatePredicate(quad.getPredicate(), quad.getDirection());
    if (quad.getValuetype().isPresent()) {
        predicate.incValueType(quad.getValuetype().get(), inc ? 1 : -1);
    } else {
        try (Stream<CursorQuad> typeQs = changeFetcher.getPredicates(quad.getObject(), RDF_TYPE, OUT, !inc, true, inc)) {
            boolean[] hadType = new boolean[] { false };
            typeQs.forEach(typeQ -> {
                hadType[0] = true;
                predicate.incReferenceType(typeQ.getObject(), inc ? 1 : -1);
            });
            if (!hadType[0]) {
                predicate.incReferenceType(UNKNOWN, inc ? 1 : -1);
            }
        }
    }
}
Also used : CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) Predicate(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate)

Aggregations

Type (nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type)17 Test (org.junit.Test)13 HashMap (java.util.HashMap)9 Map (java.util.Map)8 Predicate (nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate)8 MergeSchemas (nl.knaw.huygens.timbuctoo.v5.graphql.customschema.MergeSchemas)8 IOException (java.io.IOException)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 List (java.util.List)5 Optional (java.util.Optional)5 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)5 QuadStore (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore)5 Logger (org.slf4j.Logger)5 ArrayList (java.util.ArrayList)4 ImportStatus (nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus)4 CursorQuad (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad)4 Direction (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction)4 DocumentLoader (com.github.jsonldjava.core.DocumentLoader)3 Collectors (java.util.stream.Collectors)3 LoggerFactory (org.slf4j.LoggerFactory)3