NIHVIVO-2449 On individual list page, display preferredTitle with fallback to mostSpecificTypes. Don't show mostSpecificTypes that are the same as the type being displayed on the page, to avoid redundancy.

This commit is contained in:
ryounes 2011-07-06 20:20:36 +00:00
parent d6112ea52a
commit faa9b35399
9 changed files with 68 additions and 27 deletions

View file

@ -81,7 +81,9 @@ public class SolrIndividualListController extends FreemarkerHttpServlet {
+ VClass.class.getName() + "."); + VClass.class.getName() + ".");
} }
body.put("vclassId", vclass.getURI()); String vclassUri = vclass.getURI();
body.put("vclassId", vclassUri);
vreq.setAttribute("displayType", vclassUri); // used by the template model object
if (vclass != null) { if (vclass != null) {
String alpha = getAlphaParameter(vreq); String alpha = getAlphaParameter(vreq);

View file

@ -35,5 +35,6 @@ public interface ObjectPropertyStatementDao {
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(String subjectUri, String propertyUri, String objectKey, String query, Set<String> constructQueries); public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(String subjectUri, String propertyUri, String objectKey, String query, Set<String> constructQueries);
public List<String> getMostSpecificTypesForIndividual(String subjectUri); public Map<String, String> getMostSpecificTypesForIndividual(String subjectUri);
} }

View file

@ -95,7 +95,7 @@ class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements Objec
} }
@Override @Override
public List<String> getMostSpecificTypesForIndividual(String subjectUri) { public Map<String, String> getMostSpecificTypesForIndividual(String subjectUri) {
return innerObjectPropertyStatementDao.getMostSpecificTypesForIndividual(subjectUri); return innerObjectPropertyStatementDao.getMostSpecificTypesForIndividual(subjectUri);
} }

View file

@ -385,7 +385,7 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
protected static final String MOST_SPECIFIC_TYPE_QUERY = protected static final String MOST_SPECIFIC_TYPE_QUERY =
"PREFIX rdfs: <" + VitroVocabulary.RDFS + "> \n" + "PREFIX rdfs: <" + VitroVocabulary.RDFS + "> \n" +
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" + "PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
"SELECT ?label WHERE { \n" + "SELECT ?label ?type WHERE { \n" +
" ?subject vitro:mostSpecificType ?type . \n" + " ?subject vitro:mostSpecificType ?type . \n" +
" ?type rdfs:label ?label \n" + " ?type rdfs:label ?label \n" +
"} ORDER BY ?label "; "} ORDER BY ?label ";
@ -395,7 +395,7 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
* Finds all mostSpecificTypes of an individual. * Finds all mostSpecificTypes of an individual.
* Returns a list of type labels. * Returns a list of type labels.
* **/ * **/
public List<String> getMostSpecificTypesForIndividual(String subjectUri) { public Map<String, String> getMostSpecificTypesForIndividual(String subjectUri) {
String queryString = QueryUtils.subUriForQueryVar(MOST_SPECIFIC_TYPE_QUERY, "subject", subjectUri); String queryString = QueryUtils.subUriForQueryVar(MOST_SPECIFIC_TYPE_QUERY, "subject", subjectUri);
@ -407,10 +407,10 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
} catch(Throwable th){ } catch(Throwable th){
log.error("Could not create SPARQL query for query string. " + th.getMessage()); log.error("Could not create SPARQL query for query string. " + th.getMessage());
log.error(queryString); log.error(queryString);
return Collections.emptyList(); return Collections.emptyMap();
} }
List<String> types = new ArrayList<String>(); Map<String, String> types = new HashMap<String, String>();
DatasetWrapper w = dwf.getDatasetWrapper(); DatasetWrapper w = dwf.getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
@ -420,13 +420,22 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
qexec = QueryExecutionFactory.create(query, dataset); qexec = QueryExecutionFactory.create(query, dataset);
ResultSet results = qexec.execSelect(); ResultSet results = qexec.execSelect();
while (results.hasNext()) { while (results.hasNext()) {
QuerySolution soln = results.nextSolution(); QuerySolution soln = results.nextSolution();
RDFNode node = soln.get("label");
if (node.isLiteral()) { RDFNode typeNode = soln.get("type");
String label = node.asLiteral().getLexicalForm(); String type = null;
if (! StringUtils.isBlank(label)) { if (typeNode.isURIResource()) {
types.add(label); type = typeNode.asResource().getURI();
} }
RDFNode labelNode = soln.get("label");
String label = null;
if (labelNode.isLiteral()) {
label = labelNode.asLiteral().getLexicalForm();
}
if (StringUtils.isNotBlank(type) && StringUtils.isNotBlank(label)) {
types.put(type, label);
} }
} }

View file

@ -2,7 +2,10 @@
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -145,9 +148,10 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
return individual.getName(); return individual.getName();
} }
public List<String> getMostSpecificTypes() { public Collection<String> getMostSpecificTypes() {
ObjectPropertyStatementDao opsDao = vreq.getWebappDaoFactory().getObjectPropertyStatementDao(); ObjectPropertyStatementDao opsDao = vreq.getWebappDaoFactory().getObjectPropertyStatementDao();
return opsDao.getMostSpecificTypesForIndividual(getUri()); Map<String, String> types = opsDao.getMostSpecificTypesForIndividual(getUri());
return types.values();
} }
public String getUri() { public String getUri() {

View file

@ -4,18 +4,15 @@ package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.Link;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route; import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.web.ViewFinder;
import edu.cornell.mannlib.vitro.webapp.web.ViewFinder.ClassView;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
public abstract class BaseListedIndividual extends BaseTemplateModel { public abstract class BaseListedIndividual extends BaseTemplateModel {
@ -60,7 +57,21 @@ public abstract class BaseListedIndividual extends BaseTemplateModel {
public String getUri() { public String getUri() {
return individual.getURI(); return individual.getURI();
} }
public List<String> getMostSpecificTypes() {
ObjectPropertyStatementDao opsDao = vreq.getWebappDaoFactory().getObjectPropertyStatementDao();
Map<String, String> types = opsDao.getMostSpecificTypesForIndividual(individual.getURI());
List<String> typeLabels = new ArrayList<String>(types.size());
String displayedType = (String) vreq.getAttribute("displayType");
for (String type : types.keySet()) {
// Don't display a mostSpecificType that is the same as the type being displayed on the page
if ( ! type.equals(displayedType) ) {
typeLabels.add(types.get(type));
}
}
return typeLabels;
}
} }

View file

@ -3,7 +3,9 @@
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.searchresult; package edu.cornell.mannlib.vitro.webapp.web.templatemodels.searchresult;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -51,9 +53,10 @@ public abstract class BaseIndividualSearchResult extends BaseTemplateModel {
return individual.getName(); return individual.getName();
} }
public List<String> getMostSpecificTypes() { public Collection<String> getMostSpecificTypes() {
ObjectPropertyStatementDao opsDao = vreq.getWebappDaoFactory().getObjectPropertyStatementDao(); ObjectPropertyStatementDao opsDao = vreq.getWebappDaoFactory().getObjectPropertyStatementDao();
return opsDao.getMostSpecificTypesForIndividual(individual.getURI()); Map<String, String> types = opsDao.getMostSpecificTypesForIndividual(individual.getURI());
return types.values();
} }
public String getSearchView() { public String getSearchView() {

View file

@ -44,4 +44,11 @@
} }
.individualList li a { .individualList li a {
font-weight: normal; font-weight: normal;
} }
.individualList .display-title {
font-size: .825em;
color: #5e6363;
border-left: 1px solid #A6B1B0;
padding-left: .35em;
padding-right: .35em;
}

View file

@ -1,5 +1,9 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> <#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#-- Display of an individual in a list (/individuallist). --> <#-- Display of an individual in a list (on /individuallist and menu pages). -->
<a href="${individual.profileUrl}">${individual.name}</a> <#import "lib-properties.ftl" as p>
<a href="${individual.profileUrl}">${individual.name}</a>
<@p.mostSpecificTypes individual />