Skip to content

Commit d1ee769

Browse files
author
anquetil
committed
Remove access to core methods in SparqlHttpClient
1 parent 64d82b3 commit d1ee769

File tree

1 file changed

+7
-27
lines changed

1 file changed

+7
-27
lines changed

src/main/java/fr/inria/corese/command/utils/http/SparqlHttpClient.java

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
import fr.inria.corese.command.VersionProvider;
1212
import fr.inria.corese.command.utils.coreseCoreWrapper.CoreseSparqlQuery;
1313
import fr.inria.corese.core.sparql.exceptions.EngineException;
14-
import fr.inria.corese.core.sparql.triple.parser.Constant;
15-
import fr.inria.corese.core.sparql.triple.update.ASTUpdate;
16-
import fr.inria.corese.core.sparql.triple.update.Composite;
17-
import fr.inria.corese.core.sparql.triple.update.Update;
1814
import jakarta.ws.rs.client.Client;
1915
import jakarta.ws.rs.client.ClientBuilder;
2016
import jakarta.ws.rs.client.Entity;
@@ -189,19 +185,15 @@ public String sendRequest(String query, List<String> defaultGraphUris, List<Stri
189185
* @param defaultGraphUris default graph URIs to use
190186
* @param namedGraphUris named graph URIs to use
191187
*/
192-
private void validateQuery(String queryString, List<String> defaultGraphUris, List<String> namedGraphUris) {
188+
protected void validateQuery(String queryString, List<String> defaultGraphUris, List<String> namedGraphUris) {
193189

194190
// Check if the query is defined
195191
if (queryString == null || queryString.isEmpty()) {
196192
throw new IllegalArgumentException("SPARQL query must be specified");
197193
}
198194

199-
// Check if the query is a valid SPARQL query
200-
if (! CoreseSparqlQuery.isValidSparqlQuery(queryString)) {
201-
throw new IllegalArgumentException("Invalid SPARQL query");
202-
}
203-
204195
// Try to build a SPARQL query from the queryString
196+
// (Check if the query is a valid SPARQL query)
205197
CoreseSparqlQuery query = null;
206198
try {
207199
query = new CoreseSparqlQuery(queryString);
@@ -231,7 +223,7 @@ private void validateQuery(String queryString, List<String> defaultGraphUris, Li
231223
// Check if the query contains FROM clause and default/named graph URIs
232224
// which is not allowed by the SPARQL specification
233225
// (see https://www.w3.org/TR/sparql11-protocol/#query-operation)
234-
if (query.containsFromClause() && !(defaultGraphUris.isEmpty() && namedGraphUris.isEmpty())) {
226+
if (query.containsFromClause() && (!defaultGraphUris.isEmpty() || !namedGraphUris.isEmpty())) {
235227
throw new IllegalArgumentException(
236228
"SPARQL query contains FROM clause, but default and named graph URIs are specified. It is not allowed to specify both FROM clause and default/named graph URIs. Please remove FROM clause from the query or remove default/named graph URIs.");
237229
}
@@ -240,23 +232,11 @@ private void validateQuery(String queryString, List<String> defaultGraphUris, Li
240232
// and the using-graph-uri/using-named-graph-uri parameters are also specified
241233
// which is not allowed by the SPARQL specification
242234
// (see https://www.w3.org/TR/sparql11-protocol/#update-operation)
243-
List<String> sparqlConstants = new ArrayList<>();
244-
ASTUpdate astUpdate = query.getAstUpdate();
245-
if (astUpdate != null) {
246-
for (Update update : astUpdate.getUpdates()) {
247-
Composite composite = update.getComposite();
248-
if (composite != null) {
249-
Constant with = composite.getWith();
250-
if (with != null) {
251-
sparqlConstants.add(with.getLabel());
252-
}
253-
}
254-
}
255-
}
256-
257-
if (!sparqlConstants.isEmpty() && (!defaultGraphUris.isEmpty() || !namedGraphUris.isEmpty())) {
235+
if (query.containsWithClause() && (!defaultGraphUris.isEmpty() || !namedGraphUris.isEmpty())) {
258236
throw new IllegalArgumentException(
259-
"SPARQL update query contains USING, USING NAMED, or WITH clause and the using-graph-uri/using-named-graph-uri parameters are also specified. It is not allowed to specify both USING, USING NAMED, or WITH clause and the using-graph-uri/using-named-graph-uri parameters. Please remove USING, USING NAMED, or WITH clause from the query or remove the using-graph-uri/using-named-graph-uri parameters.");
237+
"SPARQL update query contains USING, USING NAMED, or WITH clause and the using-graph-uri/using-named-graph-uri parameters are also specified."
238+
+ " It is not allowed to specify both USING, USING NAMED, or WITH clause and the using-graph-uri/using-named-graph-uri parameters."
239+
+ "Please remove USING, USING NAMED, or WITH clause from the query or remove the using-graph-uri/using-named-graph-uri parameters.");
260240
}
261241

262242
}

0 commit comments

Comments
 (0)