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));
}
}
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);
}
}
Aggregations