diff --git a/src/edu/cornell/mannlib/vitro/webapp/controller/individuallist/IndividualJsonWrapper.java b/src/edu/cornell/mannlib/vitro/webapp/controller/individuallist/IndividualJsonWrapper.java
new file mode 100644
index 00000000..3c5a629c
--- /dev/null
+++ b/src/edu/cornell/mannlib/vitro/webapp/controller/individuallist/IndividualJsonWrapper.java
@@ -0,0 +1,87 @@
+/* $This file is distributed under the terms of the license in /doc/license.txt$ */
+
+package edu.cornell.mannlib.vitro.webapp.controller.individuallist;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import com.hp.hpl.jena.query.QuerySolution;
+import com.hp.hpl.jena.query.ResultSet;
+
+import edu.cornell.mannlib.vitro.webapp.beans.Individual;
+import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
+import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
+import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
+import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
+import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
+
+/**
+ * Wrap an Individual in a JSON object for display by the script.
+ *
+ * This overrides the Vitro version so we can have more info in the display.
+ */
+public class IndividualJsonWrapper {
+ private static final Log log = LogFactory
+ .getLog(IndividualJsonWrapper.class);
+
+ private static String VCARD_DATA_QUERY = ""
+ + "PREFIX obo: \n"
+ + "PREFIX vcard: \n"
+ + "SELECT DISTINCT ?title \n" + "WHERE { \n"
+ + " ?subject obo:ARG_2000028 ?vIndividual . \n"
+ + " ?vIndividual vcard:hasTitle ?vTitle . \n"
+ + " ?vTitle vcard:title ?title . \n" + "} ";
+
+ static JSONObject packageIndividualAsJson(VitroRequest vreq, Individual ind)
+ throws JSONException {
+ // need an unfiltered dao to get firstnames and lastnames
+ WebappDaoFactory fullWdf = vreq.getUnfilteredWebappDaoFactory();
+
+ JSONObject jo = new JSONObject();
+ jo.put("URI", ind.getURI());
+ jo.put("label", ind.getRdfsLabel());
+ jo.put("name", ind.getName());
+ jo.put("thumbUrl", ind.getThumbUrl());
+ jo.put("imageUrl", ind.getImageUrl());
+ jo.put("profileUrl", UrlBuilder.getIndividualProfileUrl(ind, vreq));
+ jo.put("mostSpecificTypes", getMostSpecificTypes(ind, fullWdf));
+ jo.put("preferredTitle", findPreferredTitle(vreq, ind));
+ return jo;
+ }
+
+ private static String findPreferredTitle(VitroRequest vreq, Individual ind) {
+ String queryStr = QueryUtils.subUriForQueryVar(VCARD_DATA_QUERY,
+ "subject", ind.getURI());
+ log.debug("queryStr = " + queryStr);
+ String value = "";
+ try {
+ ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
+ while (results.hasNext()) {
+ QuerySolution soln = results.nextSolution();
+ String t = QueryUtils.nodeToString(soln.get("title"));
+ if (StringUtils.isNotBlank(t)) {
+ value = t;
+ }
+ }
+ } catch (Exception e) {
+ log.error(e, e);
+ }
+ return value;
+ }
+
+ public static Collection getMostSpecificTypes(
+ Individual individual, WebappDaoFactory wdf) {
+ ObjectPropertyStatementDao opsDao = wdf.getObjectPropertyStatementDao();
+ Map mostSpecificTypes = opsDao
+ .getMostSpecificTypesInClassgroupsForIndividual(individual
+ .getURI());
+ return mostSpecificTypes.values();
+ }
+
+}
diff --git a/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individuallist/ListedIndividual.java b/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individuallist/ListedIndividual.java
index ce9e7899..24615507 100644
--- a/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individuallist/ListedIndividual.java
+++ b/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individuallist/ListedIndividual.java
@@ -2,28 +2,60 @@
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import com.hp.hpl.jena.query.QuerySolution;
+import com.hp.hpl.jena.query.ResultSet;
+
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
-import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.BaseListedIndividual;
-import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.ListedIndividual;
+import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
public class ListedIndividual extends BaseListedIndividual {
-
private static final Log log = LogFactory.getLog(ListedIndividual.class);
- private static final String CORE = "http://vivoweb.org/ontology/core#";
+ private static String VCARD_DATA_QUERY = ""
+ + "PREFIX obo: \n"
+ + "PREFIX vcard: \n"
+ + "SELECT DISTINCT ?title \n"
+ + "WHERE { \n"
+ + " ?subject obo:ARG_2000028 ?vIndividual . \n"
+ + " ?vIndividual vcard:hasTitle ?vTitle . \n"
+ + " ?vTitle vcard:title ?title . \n"
+ + "} " ;
+
+ private final String title;
public ListedIndividual(Individual individual, VitroRequest vreq) {
super(individual, vreq);
+ title = findPreferredTitle();
}
-
+
+ private String findPreferredTitle() {
+ String queryStr = QueryUtils.subUriForQueryVar(VCARD_DATA_QUERY, "subject", individual.getURI());
+ log.debug("queryStr = " + queryStr);
+ String value = "";
+ try {
+ ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
+ while (results.hasNext()) {
+ QuerySolution soln = results.nextSolution();
+ String t = QueryUtils.nodeToString( soln.get("title"));
+ if (StringUtils.isNotBlank(t)) {
+ value = t;
+ }
+ }
+ } catch (Exception e) {
+ log.error(e, e);
+ }
+ return value;
+ }
+
/* Template properties */
public String getPreferredTitle() {
- return cleanTextForDisplay( individual.getDataValue(CORE + "preferredTitle") );
+ return title;
}
}
diff --git a/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/searchresult/IndividualSearchResult.java b/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/searchresult/IndividualSearchResult.java
index 782c2316..efaaccae 100644
--- a/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/searchresult/IndividualSearchResult.java
+++ b/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/searchresult/IndividualSearchResult.java
@@ -2,33 +2,73 @@
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.searchresult;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import com.hp.hpl.jena.query.QuerySolution;
+import com.hp.hpl.jena.query.ResultSet;
+
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
+import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
public class IndividualSearchResult extends BaseIndividualSearchResult {
-
private static final Log log = LogFactory.getLog(IndividualSearchResult.class);
- private static final String CORE = "http://vivoweb.org/ontology/core#";
+ private static String VCARD_DATA_QUERY = ""
+ + "PREFIX obo: \n"
+ + "PREFIX vcard: \n"
+ + "SELECT DISTINCT ?email ?title \n"
+ + "WHERE { \n"
+ + " ?subject obo:ARG_2000028 ?vIndividual . \n"
+ + " OPTIONAL { ?vIndividual vcard:hasEmail ?vEmail . \n"
+ + " ?vEmail vcard:email ?email . \n"
+ + " } \n"
+ + " OPTIONAL { ?vIndividual vcard:hasTitle ?vTitle . \n"
+ + " ?vTitle vcard:title ?title . \n"
+ + " } \n"
+ + "} " ;
+
+ private String email = "";
+ private String title = "";
public IndividualSearchResult(Individual individual, VitroRequest vreq) {
super(individual, vreq);
log.debug("Called Individual Search Result");
+ findVcardInfo();
}
+ private void findVcardInfo() {
+ String queryStr = QueryUtils.subUriForQueryVar(VCARD_DATA_QUERY, "subject", individual.getURI());
+ log.debug("queryStr = " + queryStr);
+ try {
+ ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
+ while (results.hasNext()) {
+ QuerySolution soln = results.nextSolution();
+ String t = QueryUtils.nodeToString( soln.get("title"));
+ if (StringUtils.isNotBlank(t)) {
+ title = t;
+ }
+ String em = QueryUtils.nodeToString( soln.get("email"));
+ if (StringUtils.isNotBlank(em)) {
+ email = em;
+ }
+ }
+ } catch (Exception e) {
+ log.error(e, e);
+ }
+ }
+
+
/* Access methods for templates */
public String getPreferredTitle() {
- log.debug("Called get Title");
- return individual.getDataValue(CORE + "preferredTitle");
+ return title;
}
public String getEmail() {
- log.debug("Called get Email");
- return individual.getDataValue(CORE + "email");
+ return email;
}
}
\ No newline at end of file
diff --git a/utilities/acceptance-tests/suites/ShortViews/shortview_config.n3 b/utilities/acceptance-tests/suites/ShortViews/shortview_config.n3
index 13700e49..37e20113 100644
--- a/utilities/acceptance-tests/suites/ShortViews/shortview_config.n3
+++ b/utilities/acceptance-tests/suites/ShortViews/shortview_config.n3
@@ -67,12 +67,14 @@ mydomain:facultyPreferredTitleDG
a datagetters:SparqlQueryDataGetter ;
display:saveToVar "extra" ;
display:query """
-PREFIX rdfs:
-PREFIX vivo:
-SELECT ?pt
+PREFIX obo:
+PREFIX vcard:
+SELECT DISTINCT ?pt
WHERE {
-?individualUri ?pt
-}
+?individualUri obo:ARG_2000028 ?vIndividual .
+?vIndividual vcard:hasTitle ?vTitle .
+?vTitle vcard:title ?pt .
+}
LIMIT 1
""" .