Skip to content

Commit

Permalink
Use any uri or literal result values for SPARQL Query results checks
Browse files Browse the repository at this point in the history
  • Loading branch information
litvinovg committed Dec 14, 2023
1 parent 82e9463 commit bc01776
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static boolean sparqlQueryContains(Check attr, AuthorizationRequest ar,
List<String> resourceUris = Arrays.asList(ao.getResourceUris());
return ProximityChecker.isAnyRelated(m, resourceUris, personUris, queryTemplate);
}

private static boolean contains(Check attr, String... inputValues) {
AttributeValueSet values = attr.getValues();
for (String inputValue : inputValues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.logging.Log;
Expand All @@ -16,6 +17,7 @@
import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.RDFNode;

public class ProximityChecker {
private static final Log log = LogFactory.getLog(ProximityChecker.class);
Expand All @@ -39,8 +41,7 @@ private static List<String> getRelatedUris(Model model, String personUri, String
if (queryMap.containsKey(queryMapKey)) {
return queryMap.get(queryMapKey);
}

List<String> resourceUris = new ArrayList<>();
List<String> results = new ArrayList<>();
ParameterizedSparqlString pss = new ParameterizedSparqlString();
pss.setCommandText(queryTemplate);
pss.setIri("personUri", personUri);
Expand All @@ -52,15 +53,28 @@ private static List<String> getRelatedUris(Model model, String personUri, String
ResultSet resultSet = queryExecution.execSelect();
while (resultSet.hasNext()) {
QuerySolution qs = resultSet.nextSolution();
resourceUris.add(qs.getResource("resourceUri").getURI());
addSolutionValues(results, qs);
}
} finally {
queryExecution.close();
}
debug("query results: " + resourceUris);
queryMap.put(queryMapKey, resourceUris);
debug("query results: " + results);
queryMap.put(queryMapKey, results);
QueryResultsMapCache.update(queryMap);
return resourceUris;
return results;
}

private static void addSolutionValues(List<String> results, QuerySolution qs) {
Iterator<String> names = qs.varNames();
while (names.hasNext()) {
String name = names.next();
RDFNode node = qs.get(name);
if (node.isURIResource()) {
results.add(node.asResource().getURI());
} else if (node.isLiteral()) {
results.add(node.asLiteral().toString());
}
}
}

private static void debug(String queryText) {
Expand Down

0 comments on commit bc01776

Please sign in to comment.