NIHVIVO-650 Display label, moniker, and sparkline visualization on Freemarker version of individual profile page

This commit is contained in:
rjy7 2010-09-09 21:57:13 +00:00
parent 85b3c1f398
commit 61956f4cf5
5 changed files with 221 additions and 100 deletions

View file

@ -12,7 +12,6 @@ import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.mail.Session;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
@ -35,6 +34,7 @@ import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean; import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
@ -49,12 +49,14 @@ import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission;
import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo; import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo;
import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep;
import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQuery; import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQuery;
import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQueryWrapper; import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQueryWrapper;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper; import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory; import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
import edu.cornell.mannlib.vitro.webapp.web.ContentType; import edu.cornell.mannlib.vitro.webapp.web.ContentType;
import edu.cornell.mannlib.vitro.webapp.web.jsptags.StringProcessorTag; import edu.cornell.mannlib.vitro.webapp.web.jsptags.StringProcessorTag;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.IndividualTemplateModel;
import freemarker.template.Configuration; import freemarker.template.Configuration;
/** /**
@ -75,7 +77,11 @@ public class IndividualController extends FreemarkerHttpServlet {
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) { protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
try { try {
cleanUpSession(vreq); HttpSession session = vreq.getSession();
cleanUpSession(session);
// get URL without hostname or servlet context // get URL without hostname or servlet context
String url = vreq.getRequestURI().substring(vreq.getContextPath().length()); String url = vreq.getRequestURI().substring(vreq.getContextPath().length());
@ -95,28 +101,33 @@ public class IndividualController extends FreemarkerHttpServlet {
return ""; return "";
} }
Individual indiv = null; Individual individual = null;
try{ try{
indiv = getEntityFromRequest( vreq); individual = getEntityFromRequest( vreq);
}catch(Throwable th){ }catch(Throwable th){
//doHelp(res); //doHelp(res);
return ""; return "";
} }
if( indiv == null || checkForHidden(vreq, indiv) || checkForSunset(vreq, indiv)){ if( individual == null || checkForHidden(vreq, individual) || checkForSunset(vreq, individual)){
//doNotFound(vreq, res); //doNotFound(vreq, res);
return ""; return "";
} }
// If this is an uploaded file, redirect to its "alias URL". // If this is an uploaded file, redirect to its "alias URL".
String aliasUrl = getAliasUrlForBytestreamIndividual(vreq, indiv); String aliasUrl = getAliasUrlForBytestreamIndividual(vreq, individual);
if (aliasUrl != null) { if (aliasUrl != null) {
//res.sendRedirect(vreq.getContextPath() + aliasUrl); //res.sendRedirect(vreq.getContextPath() + aliasUrl);
return ""; return "";
} }
body.put("individual", getIndividualData( vreq, indiv));
body.put("title", indiv.getName()); int securityLevel = getSecurityLevel(session);
UrlBuilder urlBuilder = new UrlBuilder(vreq.getPortal());
body.put("editStatus", getEditingData(vreq, securityLevel, individual, urlBuilder));
body.put("visualization", getVisualizationData(vreq, individual));
body.putAll(getIndividualData( vreq, individual));
body.put("title", individual.getName());
String bodyTemplate = "individual.ftl"; String bodyTemplate = "individual.ftl";
return mergeBodyToTemplate(bodyTemplate, body, config); return mergeBodyToTemplate(bodyTemplate, body, config);
@ -130,114 +141,166 @@ public class IndividualController extends FreemarkerHttpServlet {
} }
} }
private void cleanUpSession(HttpServletRequest request) { private void cleanUpSession(HttpSession session) {
// Session cleanup: anytime we are at an entity page we shouldn't have an editing config or submission // Session cleanup: anytime we are at an entity page we shouldn't have an editing config or submission
HttpSession session = request.getSession();
session.removeAttribute("editjson"); session.removeAttribute("editjson");
EditConfiguration.clearAllConfigsInSession(session); EditConfiguration.clearAllConfigsInSession(session);
EditSubmission.clearAllEditSubmissionsInSession(session); EditSubmission.clearAllEditSubmissionsInSession(session);
} }
private Map<String, Object> getIndividualData(VitroRequest vreq, Individual indiv) throws ServletException, IOException { private int getSecurityLevel(HttpSession session) {
Map<String, Object> data = new HashMap<String, Object>(); String loginStatus = null;
int securityLevel = LoginFormBean.ANYBODY;
LoginFormBean loginHandler = (LoginFormBean)session.getAttribute("loginHandler");
if (loginHandler != null) {
loginStatus = loginHandler.getLoginStatus();
if ("authenticated".equals(loginStatus)) {
securityLevel = Integer.parseInt(loginHandler.getLoginRole());
}
}
return securityLevel;
}
private Map<String, Object> getEditingData(VitroRequest vreq, int securityLevel, Individual individual, UrlBuilder urlBuilder) {
// Set values related to access privileges
Map<String, Object> editingData = new HashMap<String, Object>();
editingData.put("showEditLinks", VitroRequestPrep.isSelfEditing(vreq) || securityLevel >= LoginFormBean.NON_EDITOR);
boolean showAdminPanel = securityLevel >= LoginFormBean.EDITOR;
editingData.put("showAdminPanel", showAdminPanel);
if (showAdminPanel) {
editingData.put("editingUrl", urlBuilder.getPortalUrl("/entityEdit", "uri", individual.getURI()));
}
return editingData;
}
private Map<String, Object> getVisualizationData(VitroRequest vreq, Individual individual) {
Map<String, Object> map = new HashMap<String, Object>();
// RY We should not have references to a specific ontology in the vitro code!
if (individual.isVClass("http://xmlns.com/foaf/0.1/Person")) {
String visualizationUrl = UrlBuilder.getUrl("/visualization",
"render_mode", "dynamic",
"vis", "person_pub_count",
"vis_mode", "short",
"uri", individual.getURI());
map.put("url", visualizationUrl);
}
return map;
}
private Map<String, Object> getIndividualData(VitroRequest vreq, Individual individual) throws ServletException, IOException {
Map<String, Object> map = new HashMap<String, Object>();
IndividualDao iwDao = vreq.getWebappDaoFactory().getIndividualDao(); IndividualDao iwDao = vreq.getWebappDaoFactory().getIndividualDao();
ObjectPropertyDao opDao = vreq.getWebappDaoFactory().getObjectPropertyDao(); ObjectPropertyDao opDao = vreq.getWebappDaoFactory().getObjectPropertyDao();
//Check if a "relatedSubjectUri" parameter has been supplied, and, // Check if a "relatedSubjectUri" parameter has been supplied, and,
//if so, retrieve the related individual.t // if so, retrieve the related individual.
//Some individuals make little sense standing alone and should // Some individuals make little sense standing alone and should
//be displayed in the context of their relationship to another. // be displayed in the context of their relationship to another.
String relatedSubjectUri = vreq.getParameter("relatedSubjectUri"); String relatedSubjectUri = vreq.getParameter("relatedSubjectUri");
if (relatedSubjectUri != null) { if (relatedSubjectUri != null) {
Individual relatedSubjectInd = iwDao.getIndividualByURI(relatedSubjectUri); Individual relatedSubjectInd = iwDao.getIndividualByURI(relatedSubjectUri);
if (relatedSubjectInd != null) { if (relatedSubjectInd != null) {
data.put("relatedSubject", relatedSubjectInd); Map<String, Object> relatedSubject = new HashMap<String, Object>();
} relatedSubject.put("name", relatedSubjectInd.getName());
} relatedSubject.put("url", (new IndividualTemplateModel(relatedSubjectInd)).getProfileUrl());
String relatingPredicateUri = vreq.getParameter("relatingPredicateUri"); String relatingPredicateUri = vreq.getParameter("relatingPredicateUri");
if (relatingPredicateUri != null) { if (relatingPredicateUri != null) {
ObjectProperty relatingPredicateProp = opDao.getObjectPropertyByURI(relatingPredicateUri); ObjectProperty relatingPredicateProp = opDao.getObjectPropertyByURI(relatingPredicateUri);
if (relatingPredicateProp != null) { if (relatingPredicateProp != null) {
data.put("relatingPredicate", relatingPredicateProp); relatedSubject.put("relatingPredicateDomainPublic", relatingPredicateProp.getDomainPublic());
}
}
map.put("relatedSubject", relatedSubject);
} }
} }
indiv.setKeywords(iwDao.getKeywordsForIndividualByMode(indiv.getURI(),"visible")); individual.setKeywords(iwDao.getKeywordsForIndividualByMode(individual.getURI(),"visible"));
indiv.sortForDisplay(); individual.sortForDisplay();
String vclassName = "unknown"; // String vclassName = "unknown";
String customView = null; // String customView = null;
//
// if( indiv.getVClass() != null ){
// vclassName = indiv.getVClass().getName();
// List<VClass> clasList = indiv.getVClasses(true);
// for (VClass clas : clasList) {
// customView = clas.getCustomDisplayView();
// if (customView != null) {
// if (customView.length()>0) {
// vclassName = clas.getName(); // reset entity vclassname to name of class where a custom view
// log.debug("Found direct class ["+clas.getName()+"] with custom view "+customView+"; resetting entity vclassName to this class");
// break;
// } else {
// customView = null;
// }
// }
// }
// if (customView == null) { //still
// clasList = indiv.getVClasses(false);
// for (VClass clas : clasList) {
// customView = clas.getCustomDisplayView();
// if (customView != null) {
// if (customView.length()>0) {
// // note that NOT changing entity vclassName here yet
// log.debug("Found inferred class ["+clas.getName()+"] with custom view "+customView);
// break;
// } else {
// customView = null;
// }
// }
// }
// }
// } else {
// log.error("Entity " + indiv.getURI() + " with vclass URI " +
// indiv.getVClassURI() + ", no vclass with that URI exists");
// }
// if (customView!=null) {
// // insert test for whether a css files of the same name exists, and populate the customCss string for use when construction the header
// }
//String netid = iwDao.getNetId(indiv.getURI());
if( indiv.getVClass() != null ){ //data.put("netid", netid);
vclassName = indiv.getVClass().getName(); //data.put("vclassName", vclassName);
List<VClass> clasList = indiv.getVClasses(true);
for (VClass clas : clasList) {
customView = clas.getCustomDisplayView();
if (customView != null) {
if (customView.length()>0) {
vclassName = clas.getName(); // reset entity vclassname to name of class where a custom view
log.debug("Found direct class ["+clas.getName()+"] with custom view "+customView+"; resetting entity vclassName to this class");
break;
} else {
customView = null;
}
}
}
if (customView == null) { //still
clasList = indiv.getVClasses(false);
for (VClass clas : clasList) {
customView = clas.getCustomDisplayView();
if (customView != null) {
if (customView.length()>0) {
// note that NOT changing entity vclassName here yet
log.debug("Found inferred class ["+clas.getName()+"] with custom view "+customView);
break;
} else {
customView = null;
}
}
}
}
} else {
log.error("Entity " + indiv.getURI() + " with vclass URI " +
indiv.getVClassURI() + ", no vclass with that URI exists");
}
if (customView!=null) {
// insert test for whether a css files of the same name exists, and populate the customCss string for use when construction the header
}
String netid = iwDao.getNetId(indiv.getURI());
data.put("netid", netid); // RY Would like to use IndividualTemplateModel object, but may just end up copying all methods. Since object is put in template
data.put("vclassName", vclassName); // with a read-only wrapper, it should be restrictive enough.
data.put("entity",indiv); map.put("individual",individual); //data.put("individual", new IndividualTemplateModel(indiv));
Portal portal = vreq.getPortal(); //Portal portal = vreq.getPortal();
data.put("portal",String.valueOf(portal)); //data.put("portal",String.valueOf(portal));
String view= getViewFromRequest(vreq); // String view= getViewFromRequest(vreq);
if( view == null){ // if( view == null){
if (customView == null) { // if (customView == null) {
view = default_jsp; // view = default_jsp;
data.put("bodyJsp","/"+Controllers.ENTITY_JSP); // data.put("bodyJsp","/"+Controllers.ENTITY_JSP);
log.debug("no custom view and no view parameter in request for rendering "+indiv.getName()); // log.debug("no custom view and no view parameter in request for rendering "+indiv.getName());
} else { // } else {
view = default_jsp; // view = default_jsp;
log.debug("setting custom view templates/entity/"+ customView + " for rendering "+indiv.getName()); // log.debug("setting custom view templates/entity/"+ customView + " for rendering "+indiv.getName());
data.put("bodyJsp", "/templates/entity/"+customView); // data.put("bodyJsp", "/templates/entity/"+customView);
} // }
data.put("entityPropsListJsp",Controllers.ENTITY_PROP_LIST_JSP); // data.put("entityPropsListJsp",Controllers.ENTITY_PROP_LIST_JSP);
data.put("entityDatapropsListJsp",Controllers.ENTITY_DATAPROP_LIST_JSP); // data.put("entityDatapropsListJsp",Controllers.ENTITY_DATAPROP_LIST_JSP);
data.put("entityMergedPropsListJsp",Controllers.ENTITY_MERGED_PROP_LIST_GROUPED_JSP); // data.put("entityMergedPropsListJsp",Controllers.ENTITY_MERGED_PROP_LIST_GROUPED_JSP);
data.put("entityKeywordsListJsp",Controllers.ENTITY_KEYWORDS_LIST_JSP); // data.put("entityKeywordsListJsp",Controllers.ENTITY_KEYWORDS_LIST_JSP);
} else { // } else {
log.debug("Found view parameter "+view+" in request for rendering "+indiv.getName()); // log.debug("Found view parameter "+view+" in request for rendering "+indiv.getName());
} // }
//setup highlighter for search terms //setup highlighter for search terms
checkForSearch(vreq, indiv); checkForSearch(vreq, individual);
if( indiv.getURI().startsWith( vreq.getWebappDaoFactory().getDefaultNamespace() )){ if( individual.getURI().startsWith( vreq.getWebappDaoFactory().getDefaultNamespace() )){
data.put("entityLinkedDataURL", indiv.getURI() + "/" + indiv.getLocalName() + ".rdf"); map.put("entityLinkedDataURL", individual.getURI() + "/" + individual.getLocalName() + ".rdf");
} }
@ -251,7 +314,7 @@ public class IndividualController extends FreemarkerHttpServlet {
//RequestDispatcher rd = vreq.getRequestDispatcher( view ); //RequestDispatcher rd = vreq.getRequestDispatcher( view );
//rd.forward(vreq,res); //rd.forward(vreq,res);
return data; return map;
} }
private void doRdf(VitroRequest vreq, HttpServletResponse res, private void doRdf(VitroRequest vreq, HttpServletResponse res,

View file

@ -134,6 +134,11 @@ public class UrlBuilder {
return getUrl(path, params); return getUrl(path, params);
} }
public String getPortalUrl(String path, String...params) {
ParamMap urlParams = new ParamMap(params);
return getPortalUrl(path, urlParams);
}
public String getPortalUrl(Route route) { public String getPortalUrl(Route route) {
return getPortalUrl(route.path()); return getPortalUrl(route.path());
} }

View file

@ -2,12 +2,48 @@
<#-- Template for individual profile page --> <#-- Template for individual profile page -->
<h2>${title}</h2> <div id="personWrap">
<#if editStatus.showAdminPanel>
<#include "individual-adminPanel.ftl">
</#if>
test <div class="contents entity <#if editStatus.showEditLinks>editing</#if>">
<div id="labelAndMoniker">
${stylesheets.addFromTheme("/css/entity.css", <#if relatedSubject??>
"/css/visualization/visualization.css")} <h2>${relatedSubject.relatingPredicateDomainPublic} for ${relatedSubject.name}</h2>
<p><a href="${relatedSubject.url}">&larr; return to ${relatedSubject.name}</a></p>
<#else>
<#-- Label -->
<div class="datatypePropertyValue" id="label">
<div class="statementWrap">
<h2>${individual.name}</h2>
<#if editStatus.showEditLinks>
</#if>
</div>
</div>
<#-- Moniker -->
<#if individual.moniker?has_content>
<div class="datatypeProperties">
<div class="datatypePropertyValue" id="moniker">
<div class="statementWrap">
<em class="moniker">${individual.moniker}</em>
</div>
</div>
</div>
</#if>
</#if>
</div> <!-- labelAndMoniker -->
<#include "individual-sparklineVisualization.ftl">
</div> <!-- #contents -->
</div> <!-- #personWrap -->
${stylesheets.addFromTheme("/entity.css")}
<#-- RY Figure out which of these scripts really need to go into the head, and which are needed at all (e.g., tinyMCE??) --> <#-- RY Figure out which of these scripts really need to go into the head, and which are needed at all (e.g., tinyMCE??) -->
${headScripts.add("/js/jquery.js", ${headScripts.add("/js/jquery.js",

View file

@ -0,0 +1,11 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#-- Template for admin panel on individual profile page -->
<div class="admin top">
<h3 class="toggle">Admin Panel</h3>
<div class="panelContents">
<a href="${editStatus.editingUrl}"> edit this individual</a>
<p>Resource URI: ${individual.URI}</p>
</div>
</div>

View file

@ -0,0 +1,6 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#--
Template for sparkline visualization on person profile page
Vitro version is empty: VIVO version is in /vivo/productMods
-->