Search in sources :

Example 11 with Value

use of nl.knaw.huygens.timbuctoo.v5.serializable.dto.Value in project timbuctoo by HuygensING.

the class PredicateTest method mergeCombinesValuesMap.

@Test
public void mergeCombinesValuesMap() throws Exception {
    Predicate predicate1 = createPredicate("predicate", Direction.OUT, "testOwner");
    Map<String, Long> valueTypes1 = new HashMap<>();
    valueTypes1.put("Test Value", 1L);
    valueTypes1.put("Test Value 2", 1L);
    predicate1.setValueTypes(valueTypes1);
    final Predicate predicate2 = createPredicate("predicate", Direction.OUT, "testOwner");
    Map<String, Long> valueTypes2 = new HashMap<>();
    valueTypes2.put("Test Value", 1L);
    valueTypes2.put("Test Value 2", 1L);
    valueTypes2.put("Test Value 3", 1L);
    predicate2.setValueTypes(valueTypes2);
    Predicate mergedPredicate = predicate1.merge(predicate2);
    assertThat(mergedPredicate.getValueTypes(), IsMapContaining.hasEntry("Test Value", 2L));
    assertThat(mergedPredicate.getValueTypes(), IsMapContaining.hasEntry("Test Value 2", 2L));
    assertThat(mergedPredicate.getValueTypes(), IsMapContaining.hasEntry("Test Value 3", 1L));
}
Also used : HashMap(java.util.HashMap) Predicate(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate) Test(org.junit.Test)

Example 12 with Value

use of nl.knaw.huygens.timbuctoo.v5.serializable.dto.Value in project timbuctoo by HuygensING.

the class FlatTableSerialization method writeBody.

private void writeBody(Collection<Serializable> list, TocItem toc) throws IOException {
    WriteBodyDispatcher dispatcher = new WriteBodyDispatcher();
    for (Serializable item : list) {
        List<Value> result = new ArrayList<>();
        dispatcher.dispatch(item, tuple(toc, result));
        writeRow(result);
    }
}
Also used : Serializable(nl.knaw.huygens.timbuctoo.v5.serializable.dto.Serializable) GraphqlIntrospectionValue(nl.knaw.huygens.timbuctoo.v5.serializable.dto.GraphqlIntrospectionValue) Value(nl.knaw.huygens.timbuctoo.v5.serializable.dto.Value) ArrayList(java.util.ArrayList)

Example 13 with Value

use of nl.knaw.huygens.timbuctoo.v5.serializable.dto.Value in project timbuctoo by HuygensING.

the class RdfDescriptionSaver method addValue.

@Override
public void addValue(String subject, String predicate, String value, String dataType, String graph) throws RdfProcessingFailedException {
    try {
        if (Objects.equals(subject, baseUri) && isDescriptionPredicate(predicate)) {
            ValueFactory vf = SimpleValueFactory.getInstance();
            model.add(vf.createIRI(subject), vf.createIRI(predicate), vf.createLiteral(value));
        }
    } catch (Exception e) {
        throw new RdfProcessingFailedException(e);
    }
}
Also used : ValueFactory(org.eclipse.rdf4j.model.ValueFactory) SimpleValueFactory(org.eclipse.rdf4j.model.impl.SimpleValueFactory) RdfProcessingFailedException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.RdfProcessingFailedException) RdfProcessingFailedException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.RdfProcessingFailedException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 14 with Value

use of nl.knaw.huygens.timbuctoo.v5.serializable.dto.Value in project timbuctoo by HuygensING.

the class DataSetMetadataMutation method get.

@Override
public Object get(DataFetchingEnvironment env) {
    DataSet dataSet = MutationHelpers.getDataSet(env, dataSetRepository::getDataSet);
    MutationHelpers.checkAdminPermissions(env, dataSet.getMetadata());
    try {
        Map md = env.getArgument("metadata");
        final String baseUri = dataSet.getMetadata().getBaseUri().endsWith("/") ? dataSet.getMetadata().getBaseUri() : dataSet.getMetadata().getBaseUri() + "/";
        addMutation(dataSet, new PredicateMutation().entity(baseUri, this.<String>parseProp(md, "title", v -> replace("http://purl.org/dc/terms/title", value(v))), this.<String>parseProp(md, "description", v -> replace("http://purl.org/dc/terms/description", value(v, MARKDOWN))), this.<String>parseProp(md, "imageUrl", v -> replace("http://xmlns.com/foaf/0.1/depiction", value(v))), this.<String>parseProp(md, "license", v -> replace("http://purl.org/dc/terms/license", subject(v))), this.<Map>parseProp(md, "owner", owner -> getOrCreate("http://purl.org/dc/terms/rightsHolder", baseUri + "rightsHolder", this.<String>parseProp(owner, "name", v -> replace("http://schema.org/name", value(v))), this.<String>parseProp(owner, "email", v -> replace("http://schema.org/email", value(v))))), this.<Map>parseProp(md, "contact", owner -> getOrCreate("http://schema.org/ContactPoint", baseUri + "ContactPoint", this.<String>parseProp(owner, "name", v -> replace("http://schema.org/name", value(v))), this.<String>parseProp(owner, "email", v -> replace("http://schema.org/email", value(v))))), this.<Map>parseProp(md, "provenanceInfo", owner -> getOrCreate("http://purl.org/dc/terms/provenance", baseUri + "Provenance", this.<String>parseProp(owner, "title", v -> replace("http://purl.org/dc/terms/title", value(v))), this.<String>parseProp(owner, "body", v -> replace("http://purl.org/dc/terms/description", value(v, MARKDOWN)))))));
        return new DataSetWithDatabase(dataSet);
    } catch (LogStorageFailedException | InterruptedException | ExecutionException e) {
        throw new RuntimeException(e);
    }
}
Also used : PredicateMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.PredicateMutation) DataSetWithDatabase(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) LogStorageFailedException(nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map)

Example 15 with Value

use of nl.knaw.huygens.timbuctoo.v5.serializable.dto.Value in project timbuctoo by HuygensING.

the class IndexConfigMutation method get.

@Override
public Object get(DataFetchingEnvironment env) {
    String collectionUri = env.getArgument("collectionUri");
    Object indexConfig = env.getArgument("indexConfig");
    DataSet dataSet = MutationHelpers.getDataSet(env, dataSetRepository::getDataSet);
    MutationHelpers.checkAdminPermissions(env, dataSet.getMetadata());
    try {
        MutationHelpers.addMutation(dataSet, new PredicateMutation().entity(collectionUri, replace(TIM_HASINDEXERCONFIG, value(OBJECT_MAPPER.writeValueAsString(indexConfig)))));
        return indexConfig;
    } catch (LogStorageFailedException | InterruptedException | ExecutionException | JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}
Also used : PredicateMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.PredicateMutation) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) LogStorageFailedException(nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException) ExecutionException(java.util.concurrent.ExecutionException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

Map (java.util.Map)7 QuadStore (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore)7 Test (org.junit.Test)7 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)6 ArrayList (java.util.ArrayList)5 ExecutionException (java.util.concurrent.ExecutionException)5 CursorQuad (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad)5 HashMap (java.util.HashMap)4 List (java.util.List)4 LogStorageFailedException (nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException)4 PredicateMutation (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.PredicateMutation)4 DocumentLoader (com.github.jsonldjava.core.DocumentLoader)3 IOException (java.io.IOException)3 Direction (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction)3 TypedValue (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Cursor (com.sleepycat.je.Cursor)2 OperationStatus (com.sleepycat.je.OperationStatus)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2