NIHVIVO-2057 Add additional values to login widget template data model.

This commit is contained in:
rjy7 2011-02-07 18:23:42 +00:00
parent 22be097879
commit ccfb017593
4 changed files with 59 additions and 50 deletions

View file

@ -92,7 +92,7 @@ public class SiteAdminController extends FreemarkerHttpServlet {
// Create map for data input entry form options list // Create map for data input entry form options list
List classGroups = wadf.getVClassGroupDao().getPublicGroupsWithVClasses(true,true,false); // order by displayRank, include uninstantiated classes, don't get the counts of individuals List classGroups = wadf.getVClassGroupDao().getPublicGroupsWithVClasses(true,true,false); // order by displayRank, include uninstantiated classes, don't get the counts of individuals
boolean classGroupDisplayAssumptionsMeet = checkClassGroupDisplayAssumptions(classGroups); //boolean classGroupDisplayAssumptionsMet = checkClassGroupDisplayAssumptions(classGroups);
Set<String> seenGroupNames = new HashSet<String>(); Set<String> seenGroupNames = new HashSet<String>();
@ -102,10 +102,10 @@ public class SiteAdminController extends FreemarkerHttpServlet {
VClassGroup group = (VClassGroup)classGroupIt.next(); VClassGroup group = (VClassGroup)classGroupIt.next();
List opts = FormUtils.makeOptionListFromBeans(group.getVitroClassList(),"URI","PickListName",null,null,false); List opts = FormUtils.makeOptionListFromBeans(group.getVitroClassList(),"URI","PickListName",null,null,false);
if( seenGroupNames.contains(group.getPublicName() )){ if( seenGroupNames.contains(group.getPublicName() )){
//have a duplicat classgroup name, stick in the URI //have a duplicate classgroup name, stick in the URI
orderedClassGroups.put(group.getPublicName() + " ("+group.getURI()+")", opts); orderedClassGroups.put(group.getPublicName() + " ("+group.getURI()+")", opts);
}else if( group.getPublicName() == null ){ }else if( group.getPublicName() == null ){
//have an unlabeled group, use stick in the URI //have an unlabeled group, stick in the URI
orderedClassGroups.put("unnamed group ("+group.getURI()+")", opts); orderedClassGroups.put("unnamed group ("+group.getURI()+")", opts);
}else{ }else{
orderedClassGroups.put(group.getPublicName(),opts); orderedClassGroups.put(group.getPublicName(),opts);
@ -199,11 +199,11 @@ public class SiteAdminController extends FreemarkerHttpServlet {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
Map<String, String> urls = new HashMap<String, String>(); Map<String, String> urls = new HashMap<String, String>();
urls.put("ingest", urlBuilder.getUrl("/ingest")); urls.put("ingest", UrlBuilder.getUrl("/ingest"));
urls.put("rdfData", urlBuilder.getPortalUrl("/uploadRDFForm")); urls.put("rdfData", urlBuilder.getPortalUrl("/uploadRDFForm"));
urls.put("rdfExport", urlBuilder.getPortalUrl("/export")); urls.put("rdfExport", urlBuilder.getPortalUrl("/export"));
urls.put("sparqlQuery", urlBuilder.getUrl("/admin/sparqlquery")); urls.put("sparqlQuery", UrlBuilder.getUrl("/admin/sparqlquery"));
urls.put("sparqlQueryBuilder", urlBuilder.getUrl("/admin/sparqlquerybuilder")); urls.put("sparqlQueryBuilder", UrlBuilder.getUrl("/admin/sparqlquerybuilder"));
map.put("urls", urls); map.put("urls", urls);
return map; return map;
@ -218,33 +218,33 @@ public class SiteAdminController extends FreemarkerHttpServlet {
* Check the assumptions and use the URIs as the key if the assumptions are not * Check the assumptions and use the URIs as the key if the assumptions are not
* meet. see issue NIHVIVO-1635. * meet. see issue NIHVIVO-1635.
*/ */
private boolean checkClassGroupDisplayAssumptions( List<VClassGroup> groups){ // private boolean checkClassGroupDisplayAssumptions( List<VClassGroup> groups){
//Assumption A: all of the classgroups have a non-null rdfs:label // //Assumption A: all of the classgroups have a non-null rdfs:label
//Assumption B: none of the classgroups have the same rdfs:label // //Assumption B: none of the classgroups have the same rdfs:label
//the assumption that all classgroups have only one rdfs:label is not checked // //the assumption that all classgroups have only one rdfs:label is not checked
boolean rvalue = true; // boolean rvalue = true;
Set<String> seenPublicNames = new HashSet<String>(); // Set<String> seenPublicNames = new HashSet<String>();
//
for( VClassGroup group :groups ){ // for( VClassGroup group :groups ){
//check Assumption A // //check Assumption A
if( group.getPublicName() == null){ // if( group.getPublicName() == null){
rvalue = false; // rvalue = false;
break; // break;
} // }
//
//check Assumption B // //check Assumption B
if( seenPublicNames.contains(group.getPublicName()) ){ // if( seenPublicNames.contains(group.getPublicName()) ){
rvalue = false; // rvalue = false;
break; // break;
} // }
seenPublicNames.add(group.getPublicName()); // seenPublicNames.add(group.getPublicName());
} // }
//
//
if( !rvalue ) // if( !rvalue )
log.error("The rdfs:labels on the classgroups in the system do " + // log.error("The rdfs:labels on the classgroups in the system do " +
"not meet the display assumptions. Falling back to alternative."); // "not meet the display assumptions. Falling back to alternative.");
return rvalue; // return rvalue;
} // }
} }

View file

@ -26,7 +26,6 @@ public class DumpAllDirective extends BaseTemplateDirectiveModel {
private static final Log log = LogFactory.getLog(DumpAllDirective.class); private static final Log log = LogFactory.getLog(DumpAllDirective.class);
@SuppressWarnings({ "unchecked" })
@Override @Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, public void execute(Environment env, Map params, TemplateModel[] loopVars,
TemplateDirectiveBody body) throws TemplateException, IOException { TemplateDirectiveBody body) throws TemplateException, IOException {
@ -45,12 +44,12 @@ public class DumpAllDirective extends BaseTemplateDirectiveModel {
} }
TemplateHashModel dataModel = env.getDataModel(); TemplateHashModel dataModel = env.getDataModel();
@SuppressWarnings("unchecked")
Map<String, Object> dm = (Map<String, Object>) DeepUnwrap.permissiveUnwrap(dataModel); Map<String, Object> dm = (Map<String, Object>) DeepUnwrap.permissiveUnwrap(dataModel);
List<String> varNames = new ArrayList(dm.keySet()); List<String> varNames = new ArrayList<String>(dm.keySet());
Collections.sort(varNames); Collections.sort(varNames);
DumpHelper helper = new DumpHelper(env); DumpHelper helper = new DumpHelper(env);
Configuration config = env.getConfiguration();
List<String> models = new ArrayList<String>(); List<String> models = new ArrayList<String>();
List<String> directives = new ArrayList<String>(); List<String> directives = new ArrayList<String>();

View file

@ -3,8 +3,6 @@
package edu.cornell.mannlib.vitro.webapp.web.widgets; package edu.cornell.mannlib.vitro.webapp.web.widgets;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map; import java.util.Map;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@ -20,8 +18,10 @@ 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.controller.freemarker.UrlBuilder.Route;
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean; import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean;
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.State; import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.State;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.User;
import freemarker.core.Environment; import freemarker.core.Environment;
import freemarker.template.TemplateModel; import freemarker.template.TemplateHashModel;
import freemarker.template.utility.DeepUnwrap;
public class LoginWidget extends Widget { public class LoginWidget extends Widget {
private static final Log log = LogFactory.getLog(LoginWidget.class); private static final Log log = LogFactory.getLog(LoginWidget.class);
@ -74,15 +74,14 @@ public class LoginWidget extends Widget {
HttpServletRequest request, ServletContext context) { HttpServletRequest request, ServletContext context) {
WidgetTemplateValues values = null; WidgetTemplateValues values = null;
TemplateModel urls = null;
try { try {
urls = env.getDataModel().get("urls");
State state = getCurrentLoginState(request); State state = getCurrentLoginState(request);
log.debug("State on exit: " + state); log.debug("State on exit: " + state);
String siteName = env.getDataModel().get("siteName").toString(); TemplateHashModel dataModel = env.getDataModel();
switch (state) { switch (state) {
case LOGGED_IN: case LOGGED_IN:
// On the login page itself, show a message that the user is already logged in. // On the login page itself, show a message that the user is already logged in.
@ -98,15 +97,24 @@ public class LoginWidget extends Widget {
values = showPasswordChangeScreen(request); values = showPasswordChangeScreen(request);
break; break;
default: default:
values = showLoginScreen(request, siteName); values = showLoginScreen(request, dataModel.get("siteName").toString());
} }
values.put("urls", dataModel.get("urls"));
values.put("currentPage", dataModel.get("currentPage"));
@SuppressWarnings("unchecked")
Map<String, Object> dm = (Map<String, Object>) DeepUnwrap.permissiveUnwrap(dataModel);
User user = (User) dm.get("user");
values.put("user", user);
} catch (Exception e) { } catch (Exception e) {
log.error(e, e); log.error(e, e);
// This widget should display an error message rather than throwing the exception // This widget should display an error message rather than throwing the exception
// up to the doMarkup() method, which would result in no display. // up to the doMarkup() method, which would result in no display.
values = showError(e); values = showError(e);
} }
values.put("urls", urls);
return values; return values;
} }

View file

@ -3,8 +3,10 @@
<#-- Login widget --> <#-- Login widget -->
<#macro assets> <#macro assets>
<#-- RY This test should be replaced by widget controller logic which doesn't display any assets if the user is logged in. <#-- RY This test should be replaced by login widget controller logic which displays different assets macros depending
See NIHVIVO-1357. This test does nothing, since user has not been put into the data model. on login status, but currently there's no widget-specific doAssets() method. See NIHVIVO-1357. The test doesn't work
because we don't have the user in the template data model when we generate the assets. This can also be fixed by
NIHVIVO-1357.
<#if ! user.loggedIn> --> <#if ! user.loggedIn> -->
${stylesheets.add("/css/login.css")} ${stylesheets.add("/css/login.css")}
<#-- ${scripts.add("")} --> <#-- ${scripts.add("")} -->