diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/SolrIndividualListController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/SolrIndividualListController.java index e749cdfbd..b4e84db37 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/SolrIndividualListController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/SolrIndividualListController.java @@ -81,7 +81,9 @@ public class SolrIndividualListController extends FreemarkerHttpServlet { + 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) { String alpha = getAlphaParameter(vreq); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyStatementDao.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyStatementDao.java index c6fed81c7..7a905a880 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyStatementDao.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyStatementDao.java @@ -35,5 +35,6 @@ public interface ObjectPropertyStatementDao { public List> getObjectPropertyStatementsForIndividualByProperty(String subjectUri, String propertyUri, String objectKey, String query, Set constructQueries); - public List getMostSpecificTypesForIndividual(String subjectUri); + public Map getMostSpecificTypesForIndividual(String subjectUri); + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/ObjectPropertyStatementDaoFiltering.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/ObjectPropertyStatementDaoFiltering.java index 05bed6541..1d3fc1598 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/ObjectPropertyStatementDaoFiltering.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/ObjectPropertyStatementDaoFiltering.java @@ -95,7 +95,7 @@ class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements Objec } @Override - public List getMostSpecificTypesForIndividual(String subjectUri) { + public Map getMostSpecificTypesForIndividual(String subjectUri) { return innerObjectPropertyStatementDao.getMostSpecificTypesForIndividual(subjectUri); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyStatementDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyStatementDaoJena.java index 2f0f1fbd1..b8128fb45 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyStatementDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyStatementDaoJena.java @@ -385,7 +385,7 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec protected static final String MOST_SPECIFIC_TYPE_QUERY = "PREFIX rdfs: <" + VitroVocabulary.RDFS + "> \n" + "PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" + - "SELECT ?label WHERE { \n" + + "SELECT ?label ?type WHERE { \n" + " ?subject vitro:mostSpecificType ?type . \n" + " ?type rdfs:label ?label \n" + "} ORDER BY ?label "; @@ -395,7 +395,7 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec * Finds all mostSpecificTypes of an individual. * Returns a list of type labels. * **/ - public List getMostSpecificTypesForIndividual(String subjectUri) { + public Map getMostSpecificTypesForIndividual(String 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){ log.error("Could not create SPARQL query for query string. " + th.getMessage()); log.error(queryString); - return Collections.emptyList(); + return Collections.emptyMap(); } - List types = new ArrayList(); + Map types = new HashMap(); DatasetWrapper w = dwf.getDatasetWrapper(); Dataset dataset = w.getDataset(); dataset.getLock().enterCriticalSection(Lock.READ); @@ -420,13 +420,22 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec qexec = QueryExecutionFactory.create(query, dataset); ResultSet results = qexec.execSelect(); while (results.hasNext()) { - QuerySolution soln = results.nextSolution(); - RDFNode node = soln.get("label"); - if (node.isLiteral()) { - String label = node.asLiteral().getLexicalForm(); - if (! StringUtils.isBlank(label)) { - types.add(label); - } + QuerySolution soln = results.nextSolution(); + + RDFNode typeNode = soln.get("type"); + String type = null; + if (typeNode.isURIResource()) { + 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); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/BaseIndividualTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/BaseIndividualTemplateModel.java index f47c708db..0a1faeec3 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/BaseIndividualTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/BaseIndividualTemplateModel.java @@ -2,7 +2,10 @@ package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -145,9 +148,10 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel { return individual.getName(); } - public List getMostSpecificTypes() { + public Collection getMostSpecificTypes() { ObjectPropertyStatementDao opsDao = vreq.getWebappDaoFactory().getObjectPropertyStatementDao(); - return opsDao.getMostSpecificTypesForIndividual(getUri()); + Map types = opsDao.getMostSpecificTypesForIndividual(getUri()); + return types.values(); } public String getUri() { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individuallist/BaseListedIndividual.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individuallist/BaseListedIndividual.java index d94d4d121..a24e485d7 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individuallist/BaseListedIndividual.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individuallist/BaseListedIndividual.java @@ -4,18 +4,15 @@ package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist; import java.util.ArrayList; 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.LogFactory; 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.freemarker.UrlBuilder; -import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route; -import edu.cornell.mannlib.vitro.webapp.web.ViewFinder; -import edu.cornell.mannlib.vitro.webapp.web.ViewFinder.ClassView; +import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel; public abstract class BaseListedIndividual extends BaseTemplateModel { @@ -60,7 +57,21 @@ public abstract class BaseListedIndividual extends BaseTemplateModel { public String getUri() { return individual.getURI(); - } + } + + public List getMostSpecificTypes() { + ObjectPropertyStatementDao opsDao = vreq.getWebappDaoFactory().getObjectPropertyStatementDao(); + Map types = opsDao.getMostSpecificTypesForIndividual(individual.getURI()); + List typeLabels = new ArrayList(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; + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/searchresult/BaseIndividualSearchResult.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/searchresult/BaseIndividualSearchResult.java index 2bfd7079b..e497c108e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/searchresult/BaseIndividualSearchResult.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/searchresult/BaseIndividualSearchResult.java @@ -3,7 +3,9 @@ package edu.cornell.mannlib.vitro.webapp.web.templatemodels.searchresult; import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -51,9 +53,10 @@ public abstract class BaseIndividualSearchResult extends BaseTemplateModel { return individual.getName(); } - public List getMostSpecificTypes() { + public Collection getMostSpecificTypes() { ObjectPropertyStatementDao opsDao = vreq.getWebappDaoFactory().getObjectPropertyStatementDao(); - return opsDao.getMostSpecificTypesForIndividual(individual.getURI()); + Map types = opsDao.getMostSpecificTypesForIndividual(individual.getURI()); + return types.values(); } public String getSearchView() { diff --git a/webapp/web/css/browseIndex.css b/webapp/web/css/browseIndex.css index 47fc0f716..3fa419663 100644 --- a/webapp/web/css/browseIndex.css +++ b/webapp/web/css/browseIndex.css @@ -44,4 +44,11 @@ } .individualList li a { font-weight: normal; -} \ No newline at end of file +} +.individualList .display-title { + font-size: .825em; + color: #5e6363; + border-left: 1px solid #A6B1B0; + padding-left: .35em; + padding-right: .35em; +} diff --git a/webapp/web/templates/freemarker/body/partials/listedIndividual.ftl b/webapp/web/templates/freemarker/body/partials/listedIndividual.ftl index bb294d383..725bed092 100644 --- a/webapp/web/templates/freemarker/body/partials/listedIndividual.ftl +++ b/webapp/web/templates/freemarker/body/partials/listedIndividual.ftl @@ -1,5 +1,9 @@ <#-- $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). --> -${individual.name} \ No newline at end of file +<#import "lib-properties.ftl" as p> + +${individual.name} + +<@p.mostSpecificTypes individual /> \ No newline at end of file