On Fri, Jun 10, 2022 at 5:13 PM Martynas Jusevičius <marty...@atomgraph.com> wrote: > > On Tue, Jun 7, 2022 at 9:15 PM Andy Seaborne <a...@apache.org> wrote: > > > > On 07/06/2022 10:47, Martynas Jusevičius wrote: > > > Hi, > > > > > > I have implemented PATCH method for the Graph Store Protocol: > > > https://www.w3.org/TR/sparql11-http-rdf-update/#http-patch > > > > > > The PATCH is applied to a named graph. I am missing this bit however: > > > " If a SPARQL 1.1 Update request is used as the RDF payload for a > > > PATCH request that makes changes to more than one graph or the graph > > > it modifies is not the one indicated, it would be prudent for the > > > server to respond with a 422 Unprocessable Entity status." > > > > I read that in the context of GSP resource naming. > > > > ?graph=<uri> > > > > and so the update does not name a graph - it'll look like the default > > graph in the update. > > > > So look for GRAPH in the update. > > > > > What would be the way to make sure that an update only affects a > > > single specific graph? > > > > A dataset of one graph and no others. c.f. DatasetGraphOne but for a > > single named graph and read-only dft graph. > > > > Or a dataset which yields read-only graphs except for the target graph. > > > > Or analyse the update - no GRAPH in templates if the target comes from > > the URL. > > It seems that it's not so easy to check for GRAPH in the update after all... > > What is the way to "analyse the update - no GRAPH in templates" that > you speak of? I need to check both DELETE and INSERT templates. > > I thought I had found a way: > > updateRequest.getOperations().get(0).getDeleteAcc().getGraph() > > but it returns <urn:x-arq:DefaultGraphNode> for the following update, > which probably means it doesn't do what I think it does: > > PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> > > WITH <https://localhost:4443/> > INSERT { > GRAPH ?g { > <https://localhost:4443/> rdf:_2 <https://localhost:4443/#whateverest> . > } > } > WHERE > { GRAPH ?g > { ?s ?p ?o } > }
I think I figured it out. In case anyone needs it: public class PatchUpdateVisitor extends UpdateVisitorBase { private boolean containsNamedGraph = false; @Override public void visit(UpdateModify update) { update.getDeleteAcc().getQuads().forEach(quad -> { if (!quad.getGraph().equals(Quad.defaultGraphNodeGenerated)) containsNamedGraph = true; }); update.getInsertAcc().getQuads().forEach(quad -> { if (!quad.getGraph().equals(Quad.defaultGraphNodeGenerated)) containsNamedGraph = true; }); } public boolean containsNamedGraph() { return containsNamedGraph; } } > > > > > > > > > > > > Martynas > > > atomgraph.com