use of it.unibo.arces.wot.sepa.commons.exceptions.SEPASparqlParsingException in project SEPA by arces-wot.
the class JenaSparqlParsing method getUpdateGraphURIs.
/*
* 2.2.3 Specifying an RDF Dataset
*
* SPARQL Update requests are executed against a Graph Store, a mutable
* container of RDF graphs managed by a SPARQL service.
*
* The WHERE clause of a SPARQL update DELETE/INSERT operation [UPDATE] matches
* against data in an RDF Dataset, which is a subset of the Graph Store.
*
* The RDF Dataset for an update operation may be specified either in the
* operation string itself using the USING, USING NAMED, and/or WITH keywords,
* or it may be specified via the using-graph-uri and using-named-graph-uri
* parameters.
*
* It is an error to supply the using-graph-uri or using-named-graph-uri
* parameters when using this protocol to convey a SPARQL 1.1 Update request
* that contains an operation that uses the USING, USING NAMED, or WITH clause.
*
* A SPARQL Update processor should treat each occurrence of the
* using-graph-uri=g parameter in an update protocol operation as if a USING <g>
* clause were included for every operation in the SPARQL 1.1 Update request.
*
* Similarly, a SPARQL Update processor should treat each occurrence of the
* using-named-graph-uri=g parameter in an update protocol operation as if a
* USING NAMED <g> clause were included for every operation in the SPARQL 1.1
* Update request.
*/
public Set<String> getUpdateGraphURIs(String sparql) throws SEPASparqlParsingException {
UpdateRequest upd = new UpdateRequest();
UpdateRequestSink sink = new UpdateRequestSink(upd);
Set<String> rdfDataSet = new HashSet<String>();
try {
new ParserSPARQL11Update().parse(sink, new Prologue(), sparql);
} catch (Exception e) {
logger.error("SPARQL: " + sparql + " MESSAGE: " + e.getMessage());
throw new SEPASparqlParsingException("SPARQL: " + sparql + " MESSAGE: " + e.getMessage());
// logger.warn("Parsing exception "+e.getMessage());
// rdfDataSet.add("*");
// return rdfDataSet;
}
for (Update op : upd.getOperations()) {
if (op instanceof UpdateModify) {
UpdateModify tmp = (UpdateModify) op;
// WITH
Node node = tmp.getWithIRI();
if (node != null)
if (node.isURI()) {
rdfDataSet.add(node.getURI());
}
// USING
for (Node n : tmp.getUsing()) {
if (n.isURI())
rdfDataSet.add(n.getURI());
else if (n.isVariable())
// TODO: check
rdfDataSet.add("*");
}
// USING NAMED
for (Node n : tmp.getUsingNamed()) {
if (n.isURI())
rdfDataSet.add(n.getURI());
else if (n.isVariable())
// TODO: check
rdfDataSet.add("*");
}
// QUADS
for (Quad q : tmp.getInsertQuads()) {
Node n = q.getGraph();
if (n.isURI())
if (!n.getURI().equals(arqDefaultGraphNodeUri))
rdfDataSet.add(n.getURI());
else if (n.isVariable())
// TODO: check
rdfDataSet.add("*");
}
for (Quad q : tmp.getDeleteQuads()) {
Node n = q.getGraph();
if (n.isURI())
if (!n.getURI().equals(arqDefaultGraphNodeUri))
rdfDataSet.add(n.getURI());
else if (n.isVariable())
// TODO: check
rdfDataSet.add("*");
}
} else if (op instanceof UpdateBinaryOp) {
UpdateBinaryOp tmp = (UpdateBinaryOp) op;
Node node = tmp.getDest().getGraph();
// ADD, COPY, MOVE
if (node.isURI())
rdfDataSet.add(node.getURI());
else if (node.isVariable())
// TODO: check
rdfDataSet.add("*");
} else if (op instanceof UpdateCreate) {
UpdateCreate tmp = (UpdateCreate) op;
Node node = tmp.getGraph();
// CREATE
if (node.isURI())
rdfDataSet.add(node.getURI());
else if (node.isVariable())
// TODO: check
rdfDataSet.add("*");
} else if (op instanceof UpdateData) {
UpdateData tmp = (UpdateData) op;
// UPDATE DATA
for (Quad q : tmp.getQuads()) {
Node node = q.getGraph();
if (node.isURI())
rdfDataSet.add(node.getURI());
else if (node.isVariable())
// TODO: check
rdfDataSet.add("*");
}
} else if (op instanceof UpdateDeleteWhere) {
UpdateDeleteWhere tmp = (UpdateDeleteWhere) op;
// UPDATE DELETE WHERE
for (Quad q : tmp.getQuads()) {
Node node = q.getGraph();
if (node.isURI())
rdfDataSet.add(node.getURI());
else if (node.isVariable())
// TODO: check
rdfDataSet.add("*");
}
} else if (op instanceof UpdateDropClear) {
UpdateDropClear tmp = (UpdateDropClear) op;
Node node = tmp.getGraph();
// DROP, CLEAR
if (node.isURI())
rdfDataSet.add(node.getURI());
else if (node.isVariable())
// TODO: check
rdfDataSet.add("*");
} else if (op instanceof UpdateLoad) {
UpdateLoad tmp = (UpdateLoad) op;
Node node = tmp.getDest();
// LOAD
if (node.isURI())
rdfDataSet.add(node.getURI());
else if (node.isVariable())
// TODO: check
rdfDataSet.add("*");
}
}
return rdfDataSet;
}
Aggregations