From 1c52d91b089853b258872353770ab4a1f33aab08 Mon Sep 17 00:00:00 2001 From: ryounes Date: Tue, 5 Jul 2011 22:00:10 +0000 Subject: [PATCH] NIHVIVO-2449 Display mostSpecificTypes in search results in place of moniker. Create new template model class for individual in search results, since the display increasingly diverges from the individualList display. --- .../jena/ObjectPropertyStatementDaoJena.java | 6 +- .../controller/PagedSearchController.java | 2 +- .../controller/SolrPagedSearchController.java | 8 +-- .../BaseIndividualTemplateModel.java | 1 - .../individual/IndividualSearchResult.java | 64 +++++++++++++++++++ .../ListedIndividualTemplateModel.java | 29 ++------- webapp/web/css/search.css | 14 +++- .../class/view/search/view-search-default.ftl | 9 ++- .../partials/individual/lib-properties.ftl | 3 +- 9 files changed, 95 insertions(+), 41 deletions(-) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualSearchResult.java 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 446f80706..2f0f1fbd1 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 @@ -414,9 +414,10 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec DatasetWrapper w = dwf.getDatasetWrapper(); Dataset dataset = w.getDataset(); dataset.getLock().enterCriticalSection(Lock.READ); + QueryExecution qexec = null; try { - QueryExecution qexec = QueryExecutionFactory.create(query, dataset); + qexec = QueryExecutionFactory.create(query, dataset); ResultSet results = qexec.execSelect(); while (results.hasNext()) { QuerySolution soln = results.nextSolution(); @@ -431,6 +432,9 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec } finally { dataset.getLock().leaveCriticalSection(); + if (qexec != null) { + qexec.close(); + } w.close(); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java index 51af0bb26..0f904f00a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java @@ -358,7 +358,7 @@ public class PagedSearchController extends FreemarkerHttpServlet implements Sear // Convert search result individuals to template model objects body.put("individuals", ListedIndividualTemplateModel - .getIndividualTemplateModelList(beans, vreq)); + .getIndividualTemplateModels(beans, vreq)); body.put("querytext", qtxt); body.put("title", qtxt + " - " + appBean.getApplicationName() diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/SolrPagedSearchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/SolrPagedSearchController.java index 6c7f3876a..6ca136107 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/SolrPagedSearchController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/SolrPagedSearchController.java @@ -52,6 +52,7 @@ import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQuery; import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQueryFactory; import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.LinkTemplateModel; +import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualSearchResult; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ListedIndividualTemplateModel; import freemarker.template.Configuration; @@ -301,11 +302,8 @@ public class SolrPagedSearchController extends FreemarkerHttpServlet { } } - // Convert search result individuals to template model objects - // RY If this diverges significantly from what's used on the index page, - // create a different template model. - body.put("individuals", ListedIndividualTemplateModel - .getIndividualTemplateModelList(individuals, vreq)); + body.put("individuals", IndividualSearchResult + .getIndividualTemplateModels(individuals, vreq)); body.put("querytext", qtxt); body.put("title", qtxt + " - " + appBean.getApplicationName() 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 4da55a204..d68f8c7eb 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 @@ -154,7 +154,6 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel { return opsDao.getMostSpecificTypesForIndividual(getUri()); } - public String getUri() { return individual.getURI(); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualSearchResult.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualSearchResult.java new file mode 100644 index 000000000..e076a8eb6 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualSearchResult.java @@ -0,0 +1,64 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; + +import java.util.ArrayList; +import java.util.List; + +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.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.web.ViewFinder; +import edu.cornell.mannlib.vitro.webapp.web.ViewFinder.ClassView; +import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel; + +public class IndividualSearchResult extends BaseTemplateModel { + + private static final Log log = LogFactory.getLog(IndividualSearchResult.class); + + protected Individual individual; + protected VitroRequest vreq; + + public IndividualSearchResult(Individual individual, VitroRequest vreq) { + this.individual = individual; + this.vreq = vreq; + + } + + private String getView(ClassView view) { + ViewFinder vf = new ViewFinder(view); + return vf.findClassView(individual, vreq); + } + + public static List getIndividualTemplateModels(List individuals, VitroRequest vreq) { + List models = new ArrayList(individuals.size()); + for (Individual individual : individuals) { + models.add(new IndividualSearchResult(individual, vreq)); + } + return models; + } + + /* Access methods for templates */ + + public String getProfileUrl() { + return UrlBuilder.getIndividualProfileUrl(individual, vreq.getWebappDaoFactory()); + } + + public String getName() { + return individual.getName(); + } + + public List getMostSpecificTypes() { + ObjectPropertyStatementDao opsDao = vreq.getWebappDaoFactory().getObjectPropertyStatementDao(); + return opsDao.getMostSpecificTypesForIndividual(individual.getURI()); + } + + public String getSearchView() { + return getView(ClassView.SEARCH); + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ListedIndividualTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ListedIndividualTemplateModel.java index 013fd8036..3cffb0307 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ListedIndividualTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ListedIndividualTemplateModel.java @@ -21,22 +21,16 @@ import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel; public class ListedIndividualTemplateModel extends BaseTemplateModel { private static final Log log = LogFactory.getLog(ListedIndividualTemplateModel.class); - - private static final String PATH = Route.INDIVIDUAL.path(); - + protected Individual individual; - protected VitroRequest vreq; - protected UrlBuilder urlBuilder; - + protected VitroRequest vreq; public ListedIndividualTemplateModel(Individual individual, VitroRequest vreq) { this.individual = individual; this.vreq = vreq; - // Needed for getting portal-sensitive urls. Remove if multi-portal support is removed. - this.urlBuilder = new UrlBuilder(vreq.getAppBean()); } - public static List getIndividualTemplateModelList(List individuals, VitroRequest vreq) { + public static List getIndividualTemplateModels(List individuals, VitroRequest vreq) { List models = new ArrayList(individuals.size()); for (Individual individual : individuals) { models.add(new ListedIndividualTemplateModel(individual, vreq)); @@ -44,11 +38,6 @@ public class ListedIndividualTemplateModel extends BaseTemplateModel { return models; } - private String getView(ClassView view) { - ViewFinder vf = new ViewFinder(view); - return vf.findClassView(individual, vreq); - } - /* Access methods for templates */ public String getProfileUrl() { @@ -105,18 +94,8 @@ public class ListedIndividualTemplateModel extends BaseTemplateModel { return individual.getName(); } - @Deprecated - public String getMoniker() { - return ""; -// return individual.getMoniker(); - } - public String getUri() { return individual.getURI(); - } - - public String getSearchView() { - return getView(ClassView.SEARCH); - } + } } diff --git a/webapp/web/css/search.css b/webapp/web/css/search.css index a501b8dcd..1819eec6e 100644 --- a/webapp/web/css/search.css +++ b/webapp/web/css/search.css @@ -49,4 +49,16 @@ a:visited span.SearchTerm { /* Search tips */ div.searchTips li { line-height: 2em; -} \ No newline at end of file +} + +/* Search results */ +.most-specific-type { + font-size: .825em; + color: #5e6363; + border-left: 1px solid #A6B1B0; + padding-left: .35em; + padding-right: .35em; +} + + + */ \ No newline at end of file diff --git a/webapp/web/templates/freemarker/body/partials/class/view/search/view-search-default.ftl b/webapp/web/templates/freemarker/body/partials/class/view/search/view-search-default.ftl index a1a2c580d..b89def48a 100644 --- a/webapp/web/templates/freemarker/body/partials/class/view/search/view-search-default.ftl +++ b/webapp/web/templates/freemarker/body/partials/class/view/search/view-search-default.ftl @@ -2,9 +2,8 @@ <#-- Default individual search view --> -${individual.name} -<#-- <#if individual.moniker?has_content> | ${individual.moniker} --> +<#import "lib-properties.ftl" as p> -<#if individual.description?has_content> -
${individual.description}
- \ No newline at end of file +${individual.name} + +<@p.mostSpecificTypes individual /> \ No newline at end of file diff --git a/webapp/web/templates/freemarker/body/partials/individual/lib-properties.ftl b/webapp/web/templates/freemarker/body/partials/individual/lib-properties.ftl index 6b5a32ab1..87f1d660d 100644 --- a/webapp/web/templates/freemarker/body/partials/individual/lib-properties.ftl +++ b/webapp/web/templates/freemarker/body/partials/individual/lib-properties.ftl @@ -249,8 +249,7 @@ name will be used as the label. --> <#-- Most specific types --> <#macro mostSpecificTypes individual> - <#local types = individual.mostSpecificTypes /> - <#list types as type> + <#list individual.mostSpecificTypes as type> ${type}