NIHVIVO-1923 Handle hard-coded literal select elements in building query that limits activity type returned to the types in the select list
This commit is contained in:
parent
6ddecbbddb
commit
0ef2fda7a9
1 changed files with 26 additions and 13 deletions
|
@ -27,12 +27,14 @@
|
|||
<%@ page import="java.util.Arrays" %>
|
||||
<%@ page import="java.util.Set" %>
|
||||
<%@ page import="java.util.HashSet" %>
|
||||
<%@ page import="java.util.Iterator" %>
|
||||
|
||||
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
|
||||
<%@ page import="com.hp.hpl.jena.vocabulary.XSD" %>
|
||||
|
||||
<%@ page import="org.json.JSONObject" %>
|
||||
<%@ page import="org.json.JSONException" %>
|
||||
<%@ page import="org.json.JSONArray" %>
|
||||
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary" %>
|
||||
|
@ -537,25 +539,26 @@ request.setAttribute("typeQuery", getActivityTypeQuery(vreq));
|
|||
<jsp:include page="${postForm}"/>
|
||||
|
||||
<%!
|
||||
|
||||
private static final String VIVO_CORE = "http://vivoweb.org/ontology/core#";
|
||||
private static final String DEFAULT_ACTIVITY_TYPE_QUERY =
|
||||
"PREFIX core: <" + VIVO_CORE + ">\n" +
|
||||
"SELECT ?existingActivityType WHERE { \n" +
|
||||
"?role core:roleIn ?existingActivity . \n" +
|
||||
"?existingActivity a ?existingActivityType . \n" +
|
||||
"}";
|
||||
// The activity type query results must be limited to the values in the activity type select element.
|
||||
// Sometimes the query returns a superclass such as owl:Thing instead.
|
||||
private String getActivityTypeQuery(VitroRequest vreq) {
|
||||
|
||||
String activityTypeQuery = null;
|
||||
String vivoCore = "http://vivoweb.org/ontology/core#";
|
||||
String defaultActivityTypeQuery =
|
||||
"PREFIX core: <" + vivoCore + ">\n" +
|
||||
"SELECT ?existingActivityType WHERE { \n" +
|
||||
"?role core:roleIn ?existingActivity . \n" +
|
||||
"?existingActivity a ?existingActivityType . \n" +
|
||||
"}";
|
||||
|
||||
// Select options are subclasses of a specified class
|
||||
String objectClassUri = vreq.getParameter("roleActivityType_objectClassUri");
|
||||
if (StringUtils.isNotBlank(objectClassUri)) {
|
||||
log.debug("objectClassUri = " + objectClassUri);
|
||||
activityTypeQuery =
|
||||
"PREFIX core: <" + vivoCore + ">\n" +
|
||||
"PREFIX core: <" + VIVO_CORE + ">\n" +
|
||||
"PREFIX rdfs: <" + VitroVocabulary.RDFS + ">\n" +
|
||||
"SELECT ?existingActivityType WHERE {\n" +
|
||||
"?role core:roleIn ?existingActivity . \n" +
|
||||
|
@ -569,15 +572,25 @@ private String getActivityTypeQuery(VitroRequest vreq) {
|
|||
String typeLiteralOptions = vreq.getParameter("roleActivityType_literalOptions");
|
||||
if (StringUtils.isNotBlank(typeLiteralOptions)) {
|
||||
try {
|
||||
JSONObject json = new JSONObject(typeLiteralOptions);
|
||||
Set<String> selectOptions = new HashSet<String>();
|
||||
JSONObject json = new JSONObject("{values: [" + typeLiteralOptions + "]}");
|
||||
Set<String> typeUris = new HashSet<String>();
|
||||
JSONArray values = json.getJSONArray("values");
|
||||
int valueCount = values.length();
|
||||
for (int i = 0; i < valueCount; i++) {
|
||||
JSONArray option = values.getJSONArray(i);
|
||||
String uri = option.getString(0);
|
||||
if (StringUtils.isNotBlank(uri)) {
|
||||
typeUris.add("(?existingTypeActivity = \"" + uri + "\")");
|
||||
}
|
||||
}
|
||||
String typeFilters = "FILTER (" + StringUtils.join(typeUris, "||") + ")";
|
||||
activityTypeQuery = DEFAULT_ACTIVITY_TYPE_QUERY.replace("}", "") + typeFilters + "}";
|
||||
} catch (JSONException e) {
|
||||
activityTypeQuery = defaultActivityTypeQuery;
|
||||
activityTypeQuery = DEFAULT_ACTIVITY_TYPE_QUERY;
|
||||
}
|
||||
}
|
||||
activityTypeQuery = defaultActivityTypeQuery; // temporary
|
||||
} else {
|
||||
activityTypeQuery = defaultActivityTypeQuery;
|
||||
activityTypeQuery = DEFAULT_ACTIVITY_TYPE_QUERY;
|
||||
}
|
||||
}
|
||||
log.debug("Activity type query: " + activityTypeQuery);
|
||||
|
|
Loading…
Add table
Reference in a new issue