NIHVIVO-1965 Better message for authenticated users with access to the site admin when accessing the site with little or no content. Also refactored BrowseController so that it doesn't attempt to override template and provide it's own message if no content is found.

This commit is contained in:
nac26 2011-02-05 17:24:40 +00:00
parent 2e9cd79352
commit 20ab4cc157
4 changed files with 45 additions and 38 deletions

View file

@ -43,56 +43,51 @@ import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassGroupTemplateMo
public class BrowseController extends FreemarkerHttpServlet { public class BrowseController extends FreemarkerHttpServlet {
static final long serialVersionUID=2006030721126L; static final long serialVersionUID=2006030721126L;
private static final Log log = LogFactory.getLog(BrowseController.class); private static final Log log = LogFactory.getLog(BrowseController.class);
private static final String TEMPLATE_DEFAULT = "classGroups.ftl"; private static final String TEMPLATE_DEFAULT = "classGroups.ftl";
@Override @Override
protected String getTitle(String siteName, VitroRequest vreq) { protected String getTitle(String siteName, VitroRequest vreq) {
return "Index to " + siteName + " Contents"; return "Index of Contents";
} }
@Override @Override
protected ResponseValues processRequest(VitroRequest vreq) { protected ResponseValues processRequest(VitroRequest vreq) {
Map<String, Object> body = new HashMap<String, Object>(); Map<String, Object> body = new HashMap<String, Object>();
String message = null; String message = null;
String templateName = TEMPLATE_DEFAULT; String templateName = TEMPLATE_DEFAULT;
if( vreq.getParameter("clearcache") != null ) //mainly for debugging if ( vreq.getParameter("clearcache") != null ) //mainly for debugging
clearGroupCache(); clearGroupCache();
int portalId = vreq.getPortalId(); int portalId = vreq.getPortalId();
List<VClassGroup> groups = null; List<VClassGroup> groups = null;
VClassGroupCache vcgc = VClassGroupCache.getVClassGroupCache(getServletContext()); VClassGroupCache vcgc = VClassGroupCache.getVClassGroupCache(getServletContext());
if( vcgc == null ){ if ( vcgc == null ) {
log.error("Could not get VClassGroupCache"); log.error("Could not get VClassGroupCache");
message = "The system is not configured correctly. Please check your logs for error messages."; message = "The system is not configured correctly. Please check your logs for error messages.";
}else{ } else {
groups =vcgc.getGroups( vreq.getPortalId()); groups =vcgc.getGroups( vreq.getPortalId());
if (groups == null || groups.isEmpty()) { List<VClassGroupTemplateModel> vcgroups = new ArrayList<VClassGroupTemplateModel>(groups.size());
message = "There are not yet any items in the system."; for (VClassGroup group : groups) {
vcgroups.add(new VClassGroupTemplateModel(group));
} }
else { body.put("classGroups", vcgroups);
List<VClassGroupTemplateModel> vcgroups = new ArrayList<VClassGroupTemplateModel>(groups.size()); }
for (VClassGroup group : groups) {
vcgroups.add(new VClassGroupTemplateModel(group)); if (message != null) {
} body.put("message", message);
body.put("classGroups", vcgroups); templateName = Template.TITLED_MESSAGE.toString();
} }
}
if (message != null) {
body.put("message", message);
templateName = Template.TITLED_MESSAGE.toString();
}
return new TemplateResponseValues(templateName, body); return new TemplateResponseValues(templateName, body);
} }
protected void clearGroupCache(){ protected void clearGroupCache(){
VClassGroupCache.getVClassGroupCache(getServletContext()).clearGroupCache(); VClassGroupCache.getVClassGroupCache(getServletContext()).clearGroupCache();
} }
} }

View file

@ -90,9 +90,13 @@ ${stylesheets.add("/css/browseClassGroups.css")}
<#-- <#include "classgroups-checkForData.ftl"> --> <#-- <#include "classgroups-checkForData.ftl"> -->
<h3>There is currently no content in the system</h3> <h3>There is currently no content in the system</h3>
<#if !user.loggedIn> <#if user.loggedIn>
<#if user.hasSiteAdminAccess>
<p>You can <a href="${urls.siteAdmin}" title="Manage content">add content and manage this site</a> from the Site Administration page.</p>
</#if>
<#else>
<p>Please <a href="${urls.login}" title="log in to manage this site">log in</a> to manage content.</p> <p>Please <a href="${urls.login}" title="log in to manage this site">log in</a> to manage content.</p>
</#if> </#if>
</#if> </#if>
</#macro> </#macro>

View file

@ -17,7 +17,11 @@
<#assign noDataNotification> <#assign noDataNotification>
<h3>There is currently no content in the system</h3> <h3>There is currently no content in the system</h3>
<#if !user.loggedIn> <#if user.loggedIn>
<#if user.hasSiteAdminAccess>
<p>You can <a href="${urls.siteAdmin}" title="Manage content">add content and manage this site</a> from the Site Administration page.</p>
</#if>
<#else>
<p>Please <a href="${urls.login}" title="log in to manage this site">log in</a> to manage content.</p> <p>Please <a href="${urls.login}" title="log in to manage this site">log in</a> to manage content.</p>
</#if> </#if>
</#assign> </#assign>

View file

@ -19,7 +19,11 @@
<#assign noDataNotification> <#assign noDataNotification>
<h3>There is currently no ${page.title} content in the system</h3> <h3>There is currently no ${page.title} content in the system</h3>
<#if !user.loggedIn> <#if user.loggedIn>
<#if user.hasSiteAdminAccess>
<p>You can <a href="${urls.siteAdmin}" title="Manage content">add content and manage this site</a> from the Site Administration page.</p>
</#if>
<#else>
<p>Please <a href="${urls.login}" title="log in to manage this site">log in</a> to manage content.</p> <p>Please <a href="${urls.login}" title="log in to manage this site">log in</a> to manage content.</p>
</#if> </#if>