use of org.trellisldp.vocabulary.Trellis.PreferAudit in project trellis by trellis-ldp.
the class TriplestoreResourceService method buildUpdateRequest.
/**
* This is equivalent to the SPARQL below.
*
* <p><pre><code>
* DELETE WHERE { GRAPH IDENTIFIER { ?s ?p ?o } };
* DELETE WHERE { GRAPH IDENTIFIER?ext=acl { ?s ?p ?o } };
* DELETE WHERE { GRAPH trellis:PreferServerManaged {
* IDENTIFIER a ldp:NonRDFSource .
* IDENTIFIER dc:hasPart ?s .
* ?s ?p ?o .
* };
* DELETE WHERE { GRAPH trellis:PreferServerManaged { IDENTIFIER ?p ?o } };
* INSERT DATA {
* GRAPH IDENTIFIER { ... }
* GRAPH IDENTIFIER?ext=acl { ... }
* GRAPH trellis:PreferServerManaged { ... }
* GRAPH IDENTIFIER?ext=audit { ... }
* }
* </code></pre></p>
*/
private UpdateRequest buildUpdateRequest(final IRI identifier, final Literal time, final Dataset dataset, final OperationType operation) {
// Set the time
dataset.add(PreferServerManaged, identifier, DC.modified, time);
final UpdateRequest req = new UpdateRequest();
req.add(new UpdateDeleteWhere(new QuadAcc(singletonList(new Quad(toJena(identifier), SUBJECT, PREDICATE, OBJECT)))));
extensions.forEach((ext, graph) -> req.add(new UpdateDeleteWhere(new QuadAcc(singletonList(new Quad(getExtIRI(identifier, ext), SUBJECT, PREDICATE, OBJECT))))));
req.add(new UpdateDeleteWhere(new QuadAcc(asList(new Quad(toJena(PreferServerManaged), toJena(identifier), toJena(type), toJena(LDP.NonRDFSource)), new Quad(toJena(PreferServerManaged), toJena(identifier), toJena(DC.hasPart), SUBJECT), new Quad(toJena(PreferServerManaged), SUBJECT, PREDICATE, OBJECT)))));
req.add(new UpdateDeleteWhere(new QuadAcc(singletonList(new Quad(toJena(PreferServerManaged), toJena(identifier), PREDICATE, OBJECT)))));
final QuadDataAcc sink = new QuadDataAcc(synchronizedList(new ArrayList<>()));
if (operation == OperationType.DELETE) {
dataset.stream().filter(q -> q.getGraphName().filter(PreferServerManaged::equals).isPresent()).map(JenaCommonsRDF::toJena).forEach(sink::addQuad);
} else {
dataset.stream().filter(q -> q.getGraphName().filter(PreferServerManaged::equals).isPresent()).map(JenaCommonsRDF::toJena).forEach(sink::addQuad);
dataset.getGraph(PreferUserManaged).ifPresent(g -> g.stream().map(t -> new Quad(toJena(identifier), toJena(t))).forEach(sink::addQuad));
dataset.getGraph(PreferAudit).ifPresent(g -> g.stream().map(t -> new Quad(getExtIRI(identifier, "audit"), toJena(t))).forEach(sink::addQuad));
extensions.forEach((ext, graph) -> dataset.getGraph(graph).ifPresent(g -> g.stream().map(t -> new Quad(getExtIRI(identifier, ext), toJena(t))).forEach(sink::addQuad)));
}
req.add(new UpdateDataInsert(sink));
return req;
}
use of org.trellisldp.vocabulary.Trellis.PreferAudit in project trellis by trellis-ldp.
the class TriplestoreResourceService method add.
@Override
public CompletionStage<Void> add(final IRI id, final Dataset dataset) {
return runAsync(() -> {
final IRI graphName = rdf.createIRI(id.getIRIString() + "?ext=audit");
try (final Dataset data = rdf.createDataset()) {
dataset.getGraph(PreferAudit).ifPresent(g -> g.stream().forEach(t -> data.add(graphName, t.getSubject(), t.getPredicate(), t.getObject())));
executeWrite(rdfConnection, () -> rdfConnection.loadDataset(wrap(toJena(data))));
} catch (final Exception ex) {
throw new TrellisRuntimeException("Error storing audit dataset for " + id, ex);
}
});
}
Aggregations