Merge r8732 from maint-rel-vivo-1.3

This commit is contained in:
ryounes 2011-07-19 23:07:18 +00:00
parent c9b589c52b
commit 54b8d9ab2c
2 changed files with 50 additions and 41 deletions

View file

@ -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<String,Object> map = getResultsForVClass(
@ -99,32 +108,16 @@ public class IndividualListController extends FreemarkerHttpServlet {
@SuppressWarnings("unchecked")
List<Individual> inds = (List<Individual>)map.get("entities");
List<ListedIndividual> indsTm = new ArrayList<ListedIndividual>();
if (inds != null) {
for ( Individual ind : inds ) {
indsTm.add(new ListedIndividual(ind,vreq));
}
}
body.put("individuals", indsTm);
List<TemplateModel> wpages = new ArrayList<TemplateModel>();
@SuppressWarnings("unchecked")
List<PageRecord> pages = (List<PageRecord>)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()));
}
} 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) {
@ -132,7 +125,6 @@ public class IndividualListController extends FreemarkerHttpServlet {
}
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<String,Object> getResultsForVClass(String vclassURI, int page, String alpha, IndividualDao indDao, ServletContext context)
throws IOException, ServletException{
throws IOException, SearchException{
Map<String,Object> rvMap = new HashMap<String,Object>();
try{
//make query for this rdf:type
@ -193,6 +193,11 @@ public class IndividualListController extends FreemarkerHttpServlet {
List<Individual> individuals = (List<Individual>) rvMap.get("entities");
if (individuals == null)
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);
}

View file

@ -7,16 +7,20 @@
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/css/browseIndex.css" />')}
<section class="individualList">
<h2>${title} <span class="rdfLink"><a class="icon-rdf" href="${rdfUrl}" title="View the ${title} list in RDF format">RDF</a></span></h2>
<#if subtitle??>
<h2>${title}
<#if rdfUrl?has_content>
<span class="rdfLink"><a class="icon-rdf" href="${rdfUrl}" title="View the ${title} list in RDF format">RDF</a></span>
</#if>
</h2>
<#if subtitle?has_content>
<h4>${subtitle}</h4>
</#if>
<#if message??>
<p>${message}</p>
<#if errorMessage?has_content>
<p>${errorMessage}</p>
<#else>
<#assign pagination>
<#if (pages?size > 1) >
<#if (pages?has_content && pages?size > 1)>
pages:
<ul class="pagination">
<#list pages as page>