diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java index 8c97562e5..90bf0a36e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java @@ -31,10 +31,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Tem import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup; -import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.BaseListedIndividual; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.ListedIndividual; -import freemarker.ext.beans.BeansWrapper; -import freemarker.template.TemplateModel; /** * Generates a list of individuals for display in a template @@ -86,6 +83,18 @@ public class IndividualListController extends FreemarkerHttpServlet { vreq.setAttribute("displayType", vclassUri); // used by the template model object if (vclass != null) { + + // Set title and subtitle. + VClassGroup classGroup = vclass.getGroup(); + String title; + if (classGroup == null) { + title = vclass.getName(); + } else { + title = classGroup.getPublicName(); + body.put("subtitle", vclass.getName()); + } + body.put("title", title); + String alpha = getAlphaParameter(vreq); int page = getPageParameter(vreq); Map map = getResultsForVClass( @@ -99,40 +108,23 @@ public class IndividualListController extends FreemarkerHttpServlet { @SuppressWarnings("unchecked") List inds = (List)map.get("entities"); List indsTm = new ArrayList(); - for ( Individual ind : inds ) { - indsTm.add(new ListedIndividual(ind,vreq)); + if (inds != null) { + for ( Individual ind : inds ) { + indsTm.add(new ListedIndividual(ind,vreq)); + } } - body.put("individuals", indsTm); - - List wpages = new ArrayList(); - @SuppressWarnings("unchecked") - List pages = (List)body.get("pages"); - BeansWrapper wrapper = new BeansWrapper(); - for( PageRecord pr: pages ){ - wpages.add( wrapper.wrap(pr) ); - } - - // Set title and subtitle. Title will be retrieved later in getTitle(). - VClassGroup classGroup = vclass.getGroup(); - String title; - if (classGroup == null) { - title = vclass.getName(); - } else { - title = classGroup.getPublicName(); - body.put("subtitle", vclass.getName()); - } - body.put("title", title); - body.put("rdfUrl", UrlBuilder.getUrl("/listrdf", "vclass", vclass.getURI())); + body.put("individuals", indsTm); + body.put("rdfUrl", UrlBuilder.getUrl("/listrdf", "vclass", vclass.getURI())); } - + } catch (SearchException e) { + errorMessage = "Error retrieving results for display."; } catch (HelpException help){ errorMessage = "Request attribute 'vclass' or request parameter 'vclassId' must be set before calling. Its value must be a class uri."; } catch (Throwable e) { return new ExceptionResponseValues(e); } - + if (errorMessage != null) { - templateName = Template.ERROR_MESSAGE.toString(); body.put("errorMessage", errorMessage); } @@ -147,6 +139,14 @@ public class IndividualListController extends FreemarkerHttpServlet { } } + public static class SearchException extends Throwable { + private static final long serialVersionUID = 1L; + + public SearchException(String string) { + super(string); + } + } + public static String getAlphaParameter(VitroRequest request){ return request.getParameter("alpha"); } @@ -182,7 +182,7 @@ public class IndividualListController extends FreemarkerHttpServlet { } public static Map getResultsForVClass(String vclassURI, int page, String alpha, IndividualDao indDao, ServletContext context) - throws IOException, ServletException{ + throws IOException, SearchException{ Map rvMap = new HashMap(); try{ //make query for this rdf:type @@ -192,10 +192,15 @@ public class IndividualListController extends FreemarkerHttpServlet { rvMap = getResultsForVClassQuery(query, page, alpha, indDao, context); List individuals = (List) rvMap.get("entities"); if (individuals == null) - log.debug("entities list is null for vclass " + vclassURI ); - } catch(Throwable th) { - log.error("An error occurred retrieving results for vclass query", th); - } + log.debug("entities list is null for vclass " + vclassURI ); + } catch (ServletException e) { + String msg = "An error occurred retrieving results for vclass query"; + log.error(msg, e); + // Throw this up to processRequest, so the template gets the error message. + throw new SearchException(msg); + } catch(Throwable th) { + log.error("An error occurred retrieving results for vclass query", th); + } return rvMap; } @@ -209,7 +214,7 @@ public class IndividualListController extends FreemarkerHttpServlet { rvMap = getResultsForVClassQuery(query, page, alpha, indDao, context); List individuals = (List) rvMap.get("entities"); if (individuals == null) - log.debug("entities list is null for vclass " + vclassURIs.toString() ); + log.debug("entities list is null for vclass " + vclassURIs.toString() ); } catch(Throwable th) { log.error("Error retrieving individuals corresponding to intersection multiple classes." + vclassURIs.toString(), th); } @@ -276,7 +281,7 @@ public class IndividualListController extends FreemarkerHttpServlet { rvMap.put("pages", pageRecords); }else{ rvMap.put("showPages", Boolean.FALSE); - rvMap.put("pages", Collections.emptyList()); + rvMap.put("pages", Collections.emptyList()); } rvMap.put("alpha",alpha); diff --git a/webapp/web/templates/freemarker/body/individualList.ftl b/webapp/web/templates/freemarker/body/individualList.ftl index a0db63e6f..8484ba94b 100644 --- a/webapp/web/templates/freemarker/body/individualList.ftl +++ b/webapp/web/templates/freemarker/body/individualList.ftl @@ -7,16 +7,20 @@ ${stylesheets.add('')}
-

${title} RDF

- <#if subtitle??> +

${title} + <#if rdfUrl?has_content> + RDF + +

+ <#if subtitle?has_content>

${subtitle}

- <#if message??> -

${message}

+ <#if errorMessage?has_content> +

${errorMessage}

<#else> <#assign pagination> - <#if (pages?size > 1) > + <#if (pages?has_content && pages?size > 1)> pages:
    <#list pages as page>