Search in sources :

Example 1 with HAS_VIEW_CONFIG

use of nl.knaw.huygens.timbuctoo.v5.util.RdfConstants.HAS_VIEW_CONFIG 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 2 with HAS_VIEW_CONFIG

use of nl.knaw.huygens.timbuctoo.v5.util.RdfConstants.HAS_VIEW_CONFIG 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)

Aggregations

DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 DataFetcher (graphql.schema.DataFetcher)1 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 JsonBuilder.jsn (nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn)1 JsonBuilder.jsnA (nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnA)1 TypeNameStore (nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore)1