NIHVIVO-1853 Display statement in object property deletion form
This commit is contained in:
parent
6ffe9daa64
commit
d671cc9716
8 changed files with 69 additions and 63 deletions
|
@ -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.utils.StringUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.BreadCrumbsUtil;
|
import edu.cornell.mannlib.vitro.webapp.web.BreadCrumbsUtil;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.PortalWebUtil;
|
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.User;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.files.Scripts;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.files.Scripts;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.files.Stylesheets;
|
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.
|
* 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
|
* This is public and static so that these may be used by other classes during
|
||||||
* the transition from JSP to Freemarker.
|
* the transition from JSP to Freemarker.
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static Map<String, Object> getDirectives() {
|
public static Map<String, Object> getDirectives() {
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
@ -324,9 +324,10 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<String, Object> getMethods() {
|
public static Map<String, Object> getMethods() {
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
map.put("profileUrl", new edu.cornell.mannlib.vitro.webapp.web.functions.IndividualProfileUrlMethod());
|
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;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,6 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
*/
|
*/
|
||||||
body.put("individual", getNonDefaultBeansWrapper(BeansWrapper.EXPOSE_SAFE).wrap(itm));
|
body.put("individual", getNonDefaultBeansWrapper(BeansWrapper.EXPOSE_SAFE).wrap(itm));
|
||||||
body.put("headContent", getRdfLinkTag(itm));
|
body.put("headContent", getRdfLinkTag(itm));
|
||||||
body.put("localName", new IndividualLocalNameMethod());
|
|
||||||
|
|
||||||
String template = getIndividualTemplate(individual, vreq);
|
String template = getIndividualTemplate(individual, vreq);
|
||||||
|
|
||||||
|
|
|
@ -26,16 +26,14 @@ public class TemplateProcessingHelper {
|
||||||
private Configuration config = null;
|
private Configuration config = null;
|
||||||
private HttpServletRequest request = null;
|
private HttpServletRequest request = null;
|
||||||
private ServletContext context = 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.config = config;
|
||||||
this.request = request;
|
this.request = request;
|
||||||
this.context = context;
|
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);
|
Template template = getTemplate(templateName);
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
processTemplate(template, map, sw);
|
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.
|
// For cases where we need a String instead of a StringWriter. StringWriter objects can be put in the template data model,
|
||||||
protected String processTemplateToString(String templateName, Map<String, Object> map) {
|
// 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();
|
return processTemplate(templateName, map).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -217,7 +217,7 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
||||||
subclassMap.put(subclassName, currentList);
|
subclassMap.put(subclassName, currentList);
|
||||||
}
|
}
|
||||||
currentList.add(new ObjectPropertyStatementTemplateModel(subjectUri,
|
currentList.add(new ObjectPropertyStatementTemplateModel(subjectUri,
|
||||||
propertyUri, objectKey, map, policyHelper));
|
propertyUri, objectKey, map, policyHelper, getTemplateName()));
|
||||||
}
|
}
|
||||||
return subclassMap;
|
return subclassMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,13 +28,16 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
|
||||||
|
|
||||||
// Used for editing
|
// Used for editing
|
||||||
private String objectUri = null;
|
private String objectUri = null;
|
||||||
|
private String templateName = null;
|
||||||
|
|
||||||
ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri,
|
ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri, String objectKey,
|
||||||
String objectKey, Map<String, String> data, EditingPolicyHelper policyHelper) {
|
Map<String, String> data, EditingPolicyHelper policyHelper, String templateName) {
|
||||||
super(subjectUri, propertyUri, policyHelper);
|
super(subjectUri, propertyUri, policyHelper);
|
||||||
|
|
||||||
this.data = data;
|
this.data = data;
|
||||||
objectUri = data.get(objectKey);
|
this.objectUri = data.get(objectKey);
|
||||||
|
this.templateName = templateName;
|
||||||
|
|
||||||
setEditAccess(policyHelper);
|
setEditAccess(policyHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +110,11 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
|
||||||
"predicateUri", propertyUri,
|
"predicateUri", propertyUri,
|
||||||
"objectUri", objectUri,
|
"objectUri", objectUri,
|
||||||
"cmd", "delete");
|
"cmd", "delete");
|
||||||
|
for ( String key : data.keySet() ) {
|
||||||
|
params.put("statement_" + key, data.get(key));
|
||||||
|
}
|
||||||
|
params.put("templateName", templateName);
|
||||||
|
|
||||||
deleteUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
deleteUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
Pattern.compile("ORDER\\s+BY\\s+((DESC\\()?\\?subclass\\)?\\s+)?DESC\\s*\\(\\s*\\?" +
|
Pattern.compile("ORDER\\s+BY\\s+((DESC\\()?\\?subclass\\)?\\s+)?DESC\\s*\\(\\s*\\?" +
|
||||||
END_DATE_TIME_VARIABLE + "\\)", Pattern.CASE_INSENSITIVE);
|
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 KEY_PROPERTY = "property";
|
||||||
private static final String DEFAULT_LIST_VIEW_QUERY_OBJECT_VARIABLE_NAME = "object";
|
private static final String DEFAULT_LIST_VIEW_QUERY_OBJECT_VARIABLE_NAME = "object";
|
||||||
private static final Pattern SUBJECT_PROPERTY_OBJECT_PATTERN =
|
private static final Pattern SUBJECT_PROPERTY_OBJECT_PATTERN =
|
||||||
|
@ -90,7 +90,8 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
// Used for editing
|
// Used for editing
|
||||||
private boolean addAccess = false;
|
private boolean addAccess = false;
|
||||||
|
|
||||||
ObjectPropertyTemplateModel(ObjectProperty op, Individual subject, VitroRequest vreq, EditingPolicyHelper policyHelper)
|
ObjectPropertyTemplateModel(ObjectProperty op, Individual subject, VitroRequest vreq,
|
||||||
|
EditingPolicyHelper policyHelper)
|
||||||
throws InvalidConfigurationException {
|
throws InvalidConfigurationException {
|
||||||
|
|
||||||
super(op, subject, policyHelper);
|
super(op, subject, policyHelper);
|
||||||
|
@ -134,6 +135,10 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
return config.constructQueries;
|
return config.constructQueries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String getTemplateName() {
|
||||||
|
return config.templateName;
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean hasDefaultListView() {
|
protected boolean hasDefaultListView() {
|
||||||
return config.isDefaultConfig;
|
return config.isDefaultConfig;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class UncollatedObjectPropertyTemplateModel extends ObjectPropertyTemplat
|
||||||
String objectKey = getObjectKey();
|
String objectKey = getObjectKey();
|
||||||
for (Map<String, String> map : statementData) {
|
for (Map<String, String> map : statementData) {
|
||||||
statements.add(new ObjectPropertyStatementTemplateModel(subjectUri,
|
statements.add(new ObjectPropertyStatementTemplateModel(subjectUri,
|
||||||
propertyUri, objectKey, map, policyHelper));
|
propertyUri, objectKey, map, policyHelper, getTemplateName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
postprocessStatementList(statements);
|
postprocessStatementList(statements);
|
||||||
|
|
|
@ -21,8 +21,15 @@
|
||||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils" %>
|
<%@ page import="edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils" %>
|
||||||
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
|
<%@ 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.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.List" %>
|
||||||
|
<%@ page import="java.util.Map" %>
|
||||||
|
<%@ page import="java.util.HashMap" %>
|
||||||
|
|
||||||
<%@ page import="org.apache.commons.logging.Log" %>
|
<%@ page import="org.apache.commons.logging.Log" %>
|
||||||
<%@ page import="org.apache.commons.logging.LogFactory" %>
|
<%@ page import="org.apache.commons.logging.LogFactory" %>
|
||||||
|
@ -91,57 +98,44 @@ public WebappDaoFactory getUnfilteredDaoFactory() {
|
||||||
if( subject == null ) throw new Error("could not find subject " + subjectUri);
|
if( subject == null ) throw new Error("could not find subject " + subjectUri);
|
||||||
request.setAttribute("subjectName",subject.getName());
|
request.setAttribute("subjectName",subject.getName());
|
||||||
|
|
||||||
boolean foundClass = false;
|
// Put keys statement_x into map as x => value
|
||||||
String customShortView = null;
|
// get the fm config
|
||||||
String shortViewPrefix = "/templates/entity/";
|
// pass the statement map to the template
|
||||||
Individual object = getUnfilteredDaoFactory().getIndividualDao().getIndividualByURI(objectUri);
|
// 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( object == null ) {
|
String statementDisplay = null;
|
||||||
//log.warn("Could not find object individual "+objectUri+" via wdf.getIndividualDao().getIndividualByURI(objectUri)");
|
if (! statement.isEmpty()) {
|
||||||
request.setAttribute("objectName","(name unspecified)");
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
} else if (FrontEndEditingUtils.isVitroNsObjProp(predicateUri)) {
|
map.put("statement", statement);
|
||||||
Model model = (Model)application.getAttribute("jenaOntModel");
|
map.putAll(FreemarkerHttpServlet.getDirectives());
|
||||||
request.setAttribute("individual", object);
|
map.putAll(FreemarkerHttpServlet.getMethods());
|
||||||
request.setAttribute("objectName", FrontEndEditingUtils.getVitroNsObjDisplayName(predicateUri, object, model));
|
ServletContext context = getServletContext();
|
||||||
log.debug("setting object name " + (String)request.getAttribute("objectName") + " for vitro namespace object property " + predicateUri);
|
FreemarkerConfigurationLoader loader =
|
||||||
} else {
|
FreemarkerConfigurationLoader.getFreemarkerConfigurationLoader(context);
|
||||||
customShortView = MiscWebUtils.getCustomShortView(object, request);
|
Configuration fmConfig = loader.getConfig(vreq);
|
||||||
if (customShortView != null) {
|
TemplateProcessingHelper helper = new TemplateProcessingHelper(fmConfig, vreq, context);
|
||||||
foundClass = true;
|
statementDisplay = helper.processTemplateToString(templateName, map);
|
||||||
log.debug("setting object name from VClass custom short view");
|
|
||||||
request.setAttribute("customShortView",shortViewPrefix + customShortView.trim());
|
|
||||||
request.setAttribute("individual",object);
|
|
||||||
}
|
}
|
||||||
if (!foundClass) {
|
request.setAttribute("statementDisplay", statementDisplay);
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}%>
|
|
||||||
|
|
||||||
<jsp:include page="${preForm}"/>
|
<jsp:include page="${preForm}"/>
|
||||||
|
|
||||||
<form action="editRequestDispatch.jsp" method="get">
|
<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>
|
<label for="submit"><h2>Are you sure you want to delete the following entry from <em>${propertyName}</em>?</h2></label>
|
||||||
<div class="toBeDeleted objProp">
|
<div class="toBeDeleted objProp">${statementDisplay}</div>
|
||||||
<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>
|
|
||||||
<input type="hidden" name="subjectUri" value="${param.subjectUri}"/>
|
<input type="hidden" name="subjectUri" value="${param.subjectUri}"/>
|
||||||
<input type="hidden" name="predicateUri" value="${param.predicateUri}"/>
|
<input type="hidden" name="predicateUri" value="${param.predicateUri}"/>
|
||||||
<input type="hidden" name="objectUri" value="${param.objectUri}"/>
|
<input type="hidden" name="objectUri" value="${param.objectUri}"/>
|
||||||
|
|
Loading…
Add table
Reference in a new issue