diff --git a/productMods/edit/forms/addRoleToPersonTwoStage.jsp b/productMods/edit/forms/addRoleToPersonTwoStage.jsp index b89fd415..4493d89d 100644 --- a/productMods/edit/forms/addRoleToPersonTwoStage.jsp +++ b/productMods/edit/forms/addRoleToPersonTwoStage.jsp @@ -25,10 +25,15 @@ <%@ page import="java.util.List" %> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.Arrays" %> +<%@ page import="java.util.Set" %> +<%@ page import="java.util.HashSet" %> <%@ 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="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> @@ -218,40 +223,19 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp. SELECT ?existingRoleLabel WHERE { ?role <${label}> ?existingRoleLabel . } -<% -String objectClassUri = vreq.getParameter("roleActivityType_objectClassUri"); -if (StringUtils.isNotBlank(objectClassUri)) { %> - +<%-- - PREFIX core: <${vivoCore}> - PREFIX rdfs: <${rdfs}> - SELECT ?existingActivityType WHERE { - ?role core:roleIn ?existingActivity . - ?existingActivity a ?existingActivityType . - ?existingActivityType rdfs:subClassOf <${objectClassUri}> . - } + PREFIX core: <${vivoCore}> + SELECT ?existingActivityType WHERE { + ?role core:roleIn ?existingActivity . + ?existingActivity a ?existingActivityType . + } -<% -/* -} else { - // Need to get the hardcoded literals and filter for them - String optionsType = vreq.getParameter("roleActivityType_optionsType"); - if ("HARCODED_LITERALS".equals(optionsType)) { - String typeLiteralOptions = vreq.getParameter("roleActivityType_literalOptions"); - if (StringUtils.isNotBlank(typeLiteralOptions)) { - List types = new ArrayList(); - } -*/ -} else { +--%> +<% +request.setAttribute("typeQuery", getActivityTypeQuery(vreq)); %> - - PREFIX core: <${vivoCore}> - SELECT ?existingActivityType WHERE { - ?role core:roleIn ?existingActivity . - ?existingActivity a ?existingActivityType . - } - -<% } %> +${typeQuery} SELECT ?existingIntervalNode WHERE { @@ -550,4 +534,53 @@ if (StringUtils.isNotBlank(objectClassUri)) { %> <% } %> - \ No newline at end of file + + +<%! +// 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 rdfs: <" + VitroVocabulary.RDFS + ">\n" + + "SELECT ?existingActivityType WHERE {\n" + + "?role core:roleIn ?existingActivity . \n" + + "?existingActivity a ?existingActivityType . \n" + + "?existingActivityType rdfs:subClassOf <" + objectClassUri + "> . \n" + + "}"; + } else { + String optionsType = vreq.getParameter("roleActivityType_optionsType"); + // Select options are hardcoded + if ("HARDCODED_LITERALS".equals(optionsType)) { + String typeLiteralOptions = vreq.getParameter("roleActivityType_literalOptions"); + if (StringUtils.isNotBlank(typeLiteralOptions)) { + try { + JSONObject json = new JSONObject(typeLiteralOptions); + Set selectOptions = new HashSet(); + } catch (JSONException e) { + activityTypeQuery = defaultActivityTypeQuery; + } + } + activityTypeQuery = defaultActivityTypeQuery; // temporary + } else { + activityTypeQuery = defaultActivityTypeQuery; + } + } + log.debug("Activity type query: " + activityTypeQuery); + return activityTypeQuery; +} +%> \ No newline at end of file