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