NIHVIVO-1853 Display statement in object property deletion form

This commit is contained in:
rjy7 2011-02-01 23:54:41 +00:00
parent 6ffe9daa64
commit d671cc9716
8 changed files with 69 additions and 63 deletions

View file

@ -34,6 +34,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Tem
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
import edu.cornell.mannlib.vitro.webapp.web.BreadCrumbsUtil;
import edu.cornell.mannlib.vitro.webapp.web.PortalWebUtil;
import edu.cornell.mannlib.vitro.webapp.web.functions.IndividualLocalNameMethod;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.User;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.files.Scripts;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.files.Stylesheets;
@ -311,7 +312,6 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
* Add any Java directives the templates should have access to.
* This is public and static so that these may be used by other classes during
* the transition from JSP to Freemarker.
* @return
*/
public static Map<String, Object> getDirectives() {
Map<String, Object> map = new HashMap<String, Object>();
@ -324,9 +324,10 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
return map;
}
protected Map<String, Object> getMethods() {
public static Map<String, Object> getMethods() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("profileUrl", new edu.cornell.mannlib.vitro.webapp.web.functions.IndividualProfileUrlMethod());
map.put("localName", new edu.cornell.mannlib.vitro.webapp.web.functions.IndividualLocalNameMethod());
return map;
}

View file

@ -130,8 +130,7 @@ public class IndividualController extends FreemarkerHttpServlet {
* into the data model: no real data can be modified.
*/
body.put("individual", getNonDefaultBeansWrapper(BeansWrapper.EXPOSE_SAFE).wrap(itm));
body.put("headContent", getRdfLinkTag(itm));
body.put("localName", new IndividualLocalNameMethod());
body.put("headContent", getRdfLinkTag(itm));
String template = getIndividualTemplate(individual, vreq);

View file

@ -26,16 +26,14 @@ public class TemplateProcessingHelper {
private Configuration config = null;
private HttpServletRequest request = null;
private ServletContext context = null;
//private Map<String, Object> templateDataModel = null;
TemplateProcessingHelper(Configuration config, HttpServletRequest request, ServletContext context) {
public TemplateProcessingHelper(Configuration config, HttpServletRequest request, ServletContext context) {
this.config = config;
this.request = request;
this.context = context;
//this.templateDataModel = new HashMap<String, Object>();
}
protected StringWriter processTemplate(String templateName, Map<String, Object> map) {
public StringWriter processTemplate(String templateName, Map<String, Object> map) {
Template template = getTemplate(templateName);
StringWriter sw = new StringWriter();
processTemplate(template, map, sw);
@ -65,8 +63,9 @@ public class TemplateProcessingHelper {
}
}
// In fact, we can put StringWriter objects directly into the data model, so perhaps we should eliminate the processTemplateToString() methods.
protected String processTemplateToString(String templateName, Map<String, Object> map) {
// For cases where we need a String instead of a StringWriter. StringWriter objects can be put in the template data model,
// but we can use this method from a jsp, for example.
public String processTemplateToString(String templateName, Map<String, Object> map) {
return processTemplate(templateName, map).toString();
}

View file

@ -217,7 +217,7 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
subclassMap.put(subclassName, currentList);
}
currentList.add(new ObjectPropertyStatementTemplateModel(subjectUri,
propertyUri, objectKey, map, policyHelper));
propertyUri, objectKey, map, policyHelper, getTemplateName()));
}
return subclassMap;
}

View file

@ -28,13 +28,16 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
// Used for editing
private String objectUri = null;
private String templateName = null;
ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri,
String objectKey, Map<String, String> data, EditingPolicyHelper policyHelper) {
ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri, String objectKey,
Map<String, String> data, EditingPolicyHelper policyHelper, String templateName) {
super(subjectUri, propertyUri, policyHelper);
this.data = data;
objectUri = data.get(objectKey);
this.objectUri = data.get(objectKey);
this.templateName = templateName;
setEditAccess(policyHelper);
}
@ -107,6 +110,11 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
"predicateUri", propertyUri,
"objectUri", objectUri,
"cmd", "delete");
for ( String key : data.keySet() ) {
params.put("statement_" + key, data.get(key));
}
params.put("templateName", templateName);
deleteUrl = UrlBuilder.getUrl(EDIT_PATH, params);
}

View file

@ -55,7 +55,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
Pattern.compile("ORDER\\s+BY\\s+((DESC\\()?\\?subclass\\)?\\s+)?DESC\\s*\\(\\s*\\?" +
END_DATE_TIME_VARIABLE + "\\)", Pattern.CASE_INSENSITIVE);
private static String KEY_SUBJECT = "subject";
private static final String KEY_SUBJECT = "subject";
private static final String KEY_PROPERTY = "property";
private static final String DEFAULT_LIST_VIEW_QUERY_OBJECT_VARIABLE_NAME = "object";
private static final Pattern SUBJECT_PROPERTY_OBJECT_PATTERN =
@ -85,12 +85,13 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
}
private PropertyListConfig config;
private String objectKey;
private String objectKey;
// Used for editing
private boolean addAccess = false;
ObjectPropertyTemplateModel(ObjectProperty op, Individual subject, VitroRequest vreq, EditingPolicyHelper policyHelper)
ObjectPropertyTemplateModel(ObjectProperty op, Individual subject, VitroRequest vreq,
EditingPolicyHelper policyHelper)
throws InvalidConfigurationException {
super(op, subject, policyHelper);
@ -133,6 +134,10 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
protected Set<String> getConstructQueries() {
return config.constructQueries;
}
protected String getTemplateName() {
return config.templateName;
}
protected boolean hasDefaultListView() {
return config.isDefaultConfig;

View file

@ -46,7 +46,7 @@ public class UncollatedObjectPropertyTemplateModel extends ObjectPropertyTemplat
String objectKey = getObjectKey();
for (Map<String, String> map : statementData) {
statements.add(new ObjectPropertyStatementTemplateModel(subjectUri,
propertyUri, objectKey, map, policyHelper));
propertyUri, objectKey, map, policyHelper, getTemplateName()));
}
postprocessStatementList(statements);

View file

@ -21,8 +21,15 @@
<%@ page import="edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils" %>
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
<%@page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%>
<%@page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfigurationLoader"%>
<%@page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet"%>
<%@page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.TemplateProcessingHelper"%>
<%@page import="freemarker.template.Configuration"%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %>
@ -90,58 +97,45 @@ public WebappDaoFactory getUnfilteredDaoFactory() {
Individual subject = wdf.getIndividualDao().getIndividualByURI(subjectUri);
if( subject == null ) throw new Error("could not find subject " + subjectUri);
request.setAttribute("subjectName",subject.getName());
boolean foundClass = false;
String customShortView = null;
String shortViewPrefix = "/templates/entity/";
Individual object = getUnfilteredDaoFactory().getIndividualDao().getIndividualByURI(objectUri);
if( object == null ) {
//log.warn("Could not find object individual "+objectUri+" via wdf.getIndividualDao().getIndividualByURI(objectUri)");
request.setAttribute("objectName","(name unspecified)");
} else if (FrontEndEditingUtils.isVitroNsObjProp(predicateUri)) {
Model model = (Model)application.getAttribute("jenaOntModel");
request.setAttribute("individual", object);
request.setAttribute("objectName", FrontEndEditingUtils.getVitroNsObjDisplayName(predicateUri, object, model));
log.debug("setting object name " + (String)request.getAttribute("objectName") + " for vitro namespace object property " + predicateUri);
} else {
customShortView = MiscWebUtils.getCustomShortView(object, request);
if (customShortView != null) {
foundClass = true;
log.debug("setting object name from VClass custom short view");
request.setAttribute("customShortView",shortViewPrefix + customShortView.trim());
request.setAttribute("individual",object);
// Put keys statement_x into map as x => value
// get the fm config
// pass the statement map to the template
// put into string
// output string in form
String templateName = request.getParameter("templateName");
Map params = request.getParameterMap();
Map<String, String> statement = new HashMap<String, String>();
for (Object key : params.keySet()) {
String keyString = (String) key; //key.toString()
if (keyString.startsWith("statement_")) {
keyString = keyString.replaceFirst("statement_", "");
String value = ( (String[]) params.get(key))[0];
statement.put(keyString, value);
}
if (!foundClass) {
VClass clas = prop.getRangeVClass();
if (clas != null) {
customShortView = clas.getCustomShortView();
if (customShortView != null && customShortView.trim().length()>0) {
log.warn("setting object name from VClass custom short view \""+customShortView.trim()+"\"");
request.setAttribute("customShortView",shortViewPrefix + customShortView.trim());
request.setAttribute("individual",object);
} else {
log.error("No custom short view jsp set for VClass "+clas.getName()+" so cannot render link name correctly");
request.setAttribute("objectName",object.getName());
}
}
}
}%>
}
String statementDisplay = null;
if (! statement.isEmpty()) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("statement", statement);
map.putAll(FreemarkerHttpServlet.getDirectives());
map.putAll(FreemarkerHttpServlet.getMethods());
ServletContext context = getServletContext();
FreemarkerConfigurationLoader loader =
FreemarkerConfigurationLoader.getFreemarkerConfigurationLoader(context);
Configuration fmConfig = loader.getConfig(vreq);
TemplateProcessingHelper helper = new TemplateProcessingHelper(fmConfig, vreq, context);
statementDisplay = helper.processTemplateToString(templateName, map);
}
request.setAttribute("statementDisplay", statementDisplay);
%>
<jsp:include page="${preForm}"/>
<form action="editRequestDispatch.jsp" method="get">
<label for="submit"><h2>Are you sure you want to delete the following entry from <em>${propertyName}</em>?</h2></label>
<div class="toBeDeleted objProp">
<c:choose>
<c:when test="${!empty customShortView}">
<c:set scope="request" var="individual" value="${individual}"/>
<jsp:include page="${customShortView}" flush="true"/>
<c:remove var="customShortView"/>
</c:when>
<c:otherwise>${objectName}</c:otherwise>
</c:choose>
</div>
<div class="toBeDeleted objProp">${statementDisplay}</div>
<input type="hidden" name="subjectUri" value="${param.subjectUri}"/>
<input type="hidden" name="predicateUri" value="${param.predicateUri}"/>
<input type="hidden" name="objectUri" value="${param.objectUri}"/>