Search in sources :

Example 11 with DataSet

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.

the class JsonProvenanceToRdfPatch method sendQuads.

@Override
public void sendQuads(RdfPatchSerializer saver, Consumer<String> importStatus, DataSet dataSet) throws LogStorageFailedException {
    for (JsonNode revision : activity.get(PROV_GENERATES)) {
        final String entityUri = revision.get(PROV_SPECIALIZATION_OF).get(0).get("@id").asText();
        final String revisionUri = revision.get("@id").asText();
        String wasRevisionOf = null;
        if (revision.get(PROV_REVISION_OF) != null) {
            wasRevisionOf = revision.get(PROV_REVISION_OF).get(0).get("@id").asText();
        }
        generateRevisionInfo(saver, revisionUri, entityUri, wasRevisionOf);
        generatePatch(saver, revision.get(TIM_ADDITIONS), entityUri, true);
        for (CursorQuad quad : toReplace.getOrDefault(revisionUri, new ArrayList<>())) {
            saver.delQuad(quad.getSubject(), quad.getPredicate(), quad.getObject(), quad.getValuetype().orElse(null), quad.getLanguage().orElse(null), null);
        }
        generatePatch(saver, revision.get(TIM_REPLACEMENTS), entityUri, true);
        generatePatch(saver, revision.get(TIM_DELETIONS), entityUri, false);
    }
    try {
        final HashMap map = OBJECT_MAPPER.treeToValue(activity, HashMap.class);
        final RDFDataset dataset = (RDFDataset) JsonLdProcessor.toRDF(map);
        for (String graphName : dataset.graphNames()) {
            for (RDFDataset.Quad quad : dataset.getQuads(graphName)) {
                saver.onQuad(quad.getSubject().getValue(), quad.getPredicate().getValue(), quad.getObject().getValue(), quad.getObject().isLiteral() ? quad.getObject().getDatatype() : null, quad.getObject().getLanguage(), quad.getGraph() == null ? null : quad.getGraph().getValue());
            }
        }
    } catch (JsonProcessingException | JsonLdError e) {
        throw new LogStorageFailedException(e);
    }
}
Also used : RDFDataset(com.github.jsonldjava.core.RDFDataset) CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) HashMap(java.util.HashMap) LogStorageFailedException(nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonLdError(com.github.jsonldjava.core.JsonLdError)

Example 12 with DataSet

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.

the class ViewConfigFetcher method get.

@Override
public Object get(DataFetchingEnvironment env) {
    SubjectReference source = env.getSource();
    final DataSet dataSet = source.getDataSet();
    final QuadStore qs = dataSet.getQuadStore();
    final Map<String, Type> schema = dataSet.getSchemaStore().getStableTypes();
    final TypeNameStore typeNameStore = dataSet.getTypeNameStore();
    try (Stream<CursorQuad> quads = qs.getQuads(source.getSubjectUri(), HAS_VIEW_CONFIG, Direction.OUT, "")) {
        return quads.findFirst().flatMap(q -> {
            try {
                return Optional.ofNullable(objectMapper.readValue(q.getObject(), List.class));
            } catch (IOException e) {
                LOG.error("view config is not a valid JSON object", e);
                return Optional.empty();
            }
        }).orElseGet(() -> makeDefaultViewConfig(source.getSubjectUri(), schema, typeNameStore));
    }
}
Also used : CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type) LoggerFactory(org.slf4j.LoggerFactory) QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) Predicate(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate) SubjectReference(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) HAS_VIEW_CONFIG(nl.knaw.huygens.timbuctoo.v5.util.RdfConstants.HAS_VIEW_CONFIG) Map(java.util.Map) JsonBuilder.jsnA(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnA) DataFetcher(graphql.schema.DataFetcher) JsonNode(com.fasterxml.jackson.databind.JsonNode) TypeNameStore(nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) Direction(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type) QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) SubjectReference(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference) IOException(java.io.IOException) TypeNameStore(nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore)

Example 13 with DataSet

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.

the class MutationHelpers method getDataSet.

public static DataSet getDataSet(DataFetchingEnvironment env, DataSetFetcher fetcher) {
    String dataSetId = env.getArgument("dataSetId");
    Tuple<String, String> userAndDataSet = DataSetMetaData.splitCombinedId(dataSetId);
    User user = getUser(env);
    String ownerId = userAndDataSet.getLeft();
    String dataSetName = userAndDataSet.getRight();
    return fetcher.getDataSet(user, ownerId, dataSetName).orElseThrow(() -> new RuntimeException("Dataset does not exist"));
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User)

Example 14 with DataSet

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.

the class ViewConfigMutation method get.

@Override
public Object get(DataFetchingEnvironment env) {
    String collectionUri = env.getArgument("collectionUri");
    Object viewConfig = env.getArgument("viewConfig");
    DataSet dataSet = MutationHelpers.getDataSet(env, dataSetRepository::getDataSet);
    MutationHelpers.checkAdminPermissions(env, dataSet.getMetadata());
    try {
        MutationHelpers.addMutation(dataSet, new PredicateMutation().entity(collectionUri, replace(HAS_VIEW_CONFIG, value(OBJECT_MAPPER.writeValueAsString(viewConfig)))));
        return viewConfig;
    } 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)

Example 15 with DataSet

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.

the class EntityDescriptionFetcher method get.

@Override
public TypedValue get(DataFetchingEnvironment env) {
    if (env.getSource() instanceof SubjectReference) {
        SubjectReference source = env.getSource();
        DataSet dataSet = source.getDataSet();
        Optional<TypedValue> desc = summaryPropDataRetriever.createSummaryProperty(source, dataSet);
        if (desc.isPresent()) {
            return desc.get();
        }
    }
    return null;
}
Also used : DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) SubjectReference(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference) TypedValue(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue)

Aggregations

DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)44 DataSetRepository (nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository)12 DataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData)12 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)12 Test (org.junit.Test)12 IOException (java.io.IOException)11 LogStorageFailedException (nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException)11 Map (java.util.Map)10 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)7 GraphQLFieldsContainer (graphql.schema.GraphQLFieldsContainer)7 List (java.util.List)7 Optional (java.util.Optional)7 ExecutionException (java.util.concurrent.ExecutionException)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 HashMap (java.util.HashMap)6 Collectors (java.util.stream.Collectors)6 ImportManager (nl.knaw.huygens.timbuctoo.v5.dataset.ImportManager)6 ImportStatus (nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus)6 DataStoreCreationException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException)6