NIHVIVO-1332 Add object property add links
This commit is contained in:
parent
35e722f47a
commit
c02c26a393
9 changed files with 74 additions and 33 deletions
|
@ -104,7 +104,7 @@ public class IndividualListController extends FreemarkerHttpServlet {
|
||||||
title = classGroup.getPublicName();
|
title = classGroup.getPublicName();
|
||||||
body.put("subtitle", vclass.getName());
|
body.put("subtitle", vclass.getName());
|
||||||
}
|
}
|
||||||
body.put("title", title);
|
body.put("title", title);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
|
||||||
|
|
||||||
public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
|
|
||||||
|
@ -22,10 +21,9 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
private static final String TYPE = "data";
|
private static final String TYPE = "data";
|
||||||
|
|
||||||
private List<DataPropertyStatementTemplateModel> statements;
|
private List<DataPropertyStatementTemplateModel> statements;
|
||||||
private EditingHelper editingHelper;
|
|
||||||
|
|
||||||
DataPropertyTemplateModel(DataProperty dp, Individual subject, VitroRequest vreq, EditingHelper editingHelper) {
|
DataPropertyTemplateModel(DataProperty dp, Individual subject, VitroRequest vreq, EditingHelper editingHelper) {
|
||||||
super(dp, editingHelper);
|
super(dp, subject, editingHelper);
|
||||||
|
|
||||||
setName(dp.getPublicName());
|
setName(dp.getPublicName());
|
||||||
|
|
||||||
|
@ -46,8 +44,8 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAddUrl() {
|
public String getAddUrl() {
|
||||||
// TODO Auto-generated method stub
|
String addUrl = "";
|
||||||
return null;
|
return addUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DataPropertyStatementTemplateModel> getStatements() {
|
public List<DataPropertyStatementTemplateModel> getStatements() {
|
||||||
|
|
|
@ -12,7 +12,9 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.ServletIdentifierBundleF
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyList;
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyList;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.RequestPolicyList;
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.RequestPolicyList;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList;
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyIface;
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyIface;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
|
||||||
public class EditingHelper {
|
public class EditingHelper {
|
||||||
|
@ -49,13 +51,8 @@ public class EditingHelper {
|
||||||
log.error("No IdentifierBundle objects for request");
|
log.error("No IdentifierBundle objects for request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PolicyIface getPolicy() {
|
|
||||||
return policy;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IdentifierBundle getIds() {
|
|
||||||
return ids;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
protected PolicyDecision getPolicyDecision(RequestedAction action) {
|
||||||
|
return policy.isAuthorized(ids, action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,38 +29,40 @@ public class ObjectPropertyStatementTemplateModel extends BaseTemplateModel {
|
||||||
private static enum EditAccess {
|
private static enum EditAccess {
|
||||||
EDIT, DELETE;
|
EDIT, DELETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String subjectUri; // we'll use these to make the edit links
|
|
||||||
private String propertyUri;
|
|
||||||
private Map<String, String> data;
|
private Map<String, String> data;
|
||||||
|
|
||||||
|
// Used for editing
|
||||||
|
private String subjectUri = null;
|
||||||
|
private String propertyUri = null;
|
||||||
private String objectUri = null;
|
private String objectUri = null;
|
||||||
private List<EditAccess> editAccessList;
|
private List<EditAccess> editAccessList;
|
||||||
|
|
||||||
ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri,
|
ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri,
|
||||||
String objectKey, Map<String, String> data, EditingHelper editingHelper) {
|
String objectKey, Map<String, String> data, EditingHelper editingHelper) {
|
||||||
this.subjectUri = subjectUri;
|
|
||||||
this.propertyUri = propertyUri;
|
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
|
||||||
// If the editingHelper is non-null, we are in edit mode, so create the list of editing permissions.
|
// If the editingHelper is non-null, we are in edit mode, so create the list of editing permissions.
|
||||||
// We do this now rather than in getEditUrl() and getDeleteUrl(), because getEditUrl() also needs to know
|
// We do this now rather than in getEditUrl() and getDeleteUrl(), because getEditUrl() also needs to know
|
||||||
// whether a delete is allowed.
|
// whether a delete is allowed.
|
||||||
if (editingHelper != null) {
|
if (editingHelper != null) {
|
||||||
|
this.subjectUri = subjectUri;
|
||||||
|
this.propertyUri = propertyUri;
|
||||||
objectUri = data.get(objectKey);
|
objectUri = data.get(objectKey);
|
||||||
editAccessList = new ArrayList<EditAccess>(); // limit size to number of elements in EditAccess
|
editAccessList = new ArrayList<EditAccess>();
|
||||||
ObjectPropertyStatement objectPropertyStatement = new ObjectPropertyStatementImpl(subjectUri, propertyUri, objectUri);
|
ObjectPropertyStatement objectPropertyStatement = new ObjectPropertyStatementImpl(subjectUri, propertyUri, objectUri);
|
||||||
|
|
||||||
// Determine whether the statement can be edited
|
// Determine whether the statement can be edited
|
||||||
RequestedAction action = new EditObjPropStmt(objectPropertyStatement);
|
RequestedAction action = new EditObjPropStmt(objectPropertyStatement);
|
||||||
PolicyDecision decision = editingHelper.getPolicy().isAuthorized(editingHelper.getIds(), action);
|
PolicyDecision decision = editingHelper.getPolicyDecision(action);
|
||||||
if (decision != null && decision.getAuthorized() == Authorization.AUTHORIZED) {
|
if (decision != null && decision.getAuthorized() == Authorization.AUTHORIZED) {
|
||||||
editAccessList.add(EditAccess.EDIT);
|
editAccessList.add(EditAccess.EDIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine whether the statement can be deleted
|
// Determine whether the statement can be deleted
|
||||||
action = new DropObjectPropStmt(subjectUri, propertyUri, objectUri);
|
action = new DropObjectPropStmt(subjectUri, propertyUri, objectUri);
|
||||||
decision = editingHelper.getPolicy().isAuthorized(editingHelper.getIds(), action);
|
decision = editingHelper.getPolicyDecision(action);
|
||||||
if (decision != null && decision.getAuthorized() == Authorization.AUTHORIZED) {
|
if (decision != null && decision.getAuthorized() == Authorization.AUTHORIZED) {
|
||||||
editAccessList.add(EditAccess.DELETE);
|
editAccessList.add(EditAccess.DELETE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,16 @@ import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddObjectPropStmt;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import freemarker.cache.TemplateLoader;
|
import freemarker.cache.TemplateLoader;
|
||||||
|
@ -34,6 +41,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(ObjectPropertyTemplateModel.class);
|
private static final Log log = LogFactory.getLog(ObjectPropertyTemplateModel.class);
|
||||||
private static final String TYPE = "object";
|
private static final String TYPE = "object";
|
||||||
|
private static final String EDIT_PATH = "edit/editRequestDispatch.jsp";
|
||||||
|
|
||||||
/* NB The default post-processor is not the same as the post-processor for the default view. The latter
|
/* NB The default post-processor is not the same as the post-processor for the default view. The latter
|
||||||
* actually defines its own post-processor, whereas the default post-processor is used for custom views
|
* actually defines its own post-processor, whereas the default post-processor is used for custom views
|
||||||
|
@ -60,9 +68,12 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
|
|
||||||
private PropertyListConfig config;
|
private PropertyListConfig config;
|
||||||
private String objectKey;
|
private String objectKey;
|
||||||
|
|
||||||
|
// Used for editing
|
||||||
|
private boolean addAccess = false;
|
||||||
|
|
||||||
ObjectPropertyTemplateModel(ObjectProperty op, Individual subject, VitroRequest vreq, EditingHelper editingHelper) {
|
ObjectPropertyTemplateModel(ObjectProperty op, Individual subject, VitroRequest vreq, EditingHelper editingHelper) {
|
||||||
super(op, editingHelper);
|
super(op, subject, editingHelper);
|
||||||
setName(op.getDomainPublic());
|
setName(op.getDomainPublic());
|
||||||
|
|
||||||
// Get the config for this object property
|
// Get the config for this object property
|
||||||
|
@ -73,6 +84,15 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
}
|
}
|
||||||
|
|
||||||
objectKey = getQueryObjectVariableName();
|
objectKey = getQueryObjectVariableName();
|
||||||
|
|
||||||
|
// Determine whether a new statement can be added
|
||||||
|
if (editingHelper != null) {
|
||||||
|
RequestedAction action = new AddObjectPropStmt(subjectUri, propertyUri, RequestActionConstants.SOME_URI);
|
||||||
|
PolicyDecision decision = editingHelper.getPolicyDecision(action);
|
||||||
|
if( decision != null && decision.getAuthorized() == Authorization.AUTHORIZED ) {
|
||||||
|
addAccess = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getQueryString() {
|
protected String getQueryString() {
|
||||||
|
@ -331,8 +351,14 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAddUrl() {
|
public String getAddUrl() {
|
||||||
// TODO Auto-generated method stub
|
String addUrl = "";
|
||||||
return null;
|
if (addAccess) {
|
||||||
|
ParamMap params = new ParamMap(
|
||||||
|
"subjectUri", subjectUri,
|
||||||
|
"predicateUri", propertyUri);
|
||||||
|
addUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
||||||
|
}
|
||||||
|
return addUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
||||||
|
|
||||||
|
@ -16,17 +17,24 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
|
||||||
private static final Log log = LogFactory.getLog(PropertyTemplateModel.class);
|
private static final Log log = LogFactory.getLog(PropertyTemplateModel.class);
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String uri;
|
|
||||||
protected Property property; // needed to get the edit links
|
|
||||||
protected EditingHelper editingHelper;
|
|
||||||
|
|
||||||
PropertyTemplateModel(Property property, EditingHelper editingHelper) {
|
// For editing
|
||||||
|
protected String subjectUri = null;
|
||||||
|
protected String propertyUri = null;
|
||||||
|
protected Property property; // RY DO WE NEED THIS, or just the uri??
|
||||||
|
protected boolean addAccess = false;
|
||||||
|
|
||||||
|
PropertyTemplateModel(Property property, Individual subject, EditingHelper editingHelper) {
|
||||||
// Do in subclass constructor. The label has not been set on the property, and getting the
|
// Do in subclass constructor. The label has not been set on the property, and getting the
|
||||||
// label differs between object and data properties.
|
// label differs between object and data properties.
|
||||||
// this.name = property.getLabel();
|
// this.name = property.getLabel();
|
||||||
this.uri = property.getURI();
|
this.propertyUri = property.getURI();
|
||||||
this.property = property;
|
this.property = property;
|
||||||
this.editingHelper = editingHelper;
|
|
||||||
|
if (editingHelper != null) {
|
||||||
|
subjectUri = subject.getURI();
|
||||||
|
propertyUri = property.getURI();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setName(String name) {
|
protected void setName(String name) {
|
||||||
|
@ -42,7 +50,7 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUri() {
|
public String getUri() {
|
||||||
return uri;
|
return propertyUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getAddUrl();
|
public abstract String getAddUrl();
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
<div class="contents">
|
<div class="contents">
|
||||||
<div class="individualList">
|
<div class="individualList">
|
||||||
|
|
||||||
<h2>${title}</h2>
|
<h2>${title}</h2>
|
||||||
<#if subtitle??>
|
<#if subtitle??>
|
||||||
<h4>${subtitle}</h4>
|
<h4>${subtitle}</h4>
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
<#list group.properties as property>
|
<#list group.properties as property>
|
||||||
<article class="property" role="article">
|
<article class="property" role="article">
|
||||||
<#-- Property display name -->
|
<#-- Property display name -->
|
||||||
<h3>${property.name}</h3>
|
<h3>${property.name}</h3> <@p.addLink property showEditingLinks />
|
||||||
|
|
||||||
<#-- List the statements for each property -->
|
<#-- List the statements for each property -->
|
||||||
<ul class="property-list" role="list">
|
<ul class="property-list" role="list">
|
||||||
|
|
|
@ -32,6 +32,15 @@
|
||||||
</#list>
|
</#list>
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
||||||
|
<#macro addLink property showEditingLinks>
|
||||||
|
<#if showEditingLinks>
|
||||||
|
<#local url = property.addUrl>
|
||||||
|
<#if url?has_content>
|
||||||
|
<a href="${url}">add</a>
|
||||||
|
</#if>
|
||||||
|
</#if>
|
||||||
|
</#macro>
|
||||||
|
|
||||||
<#macro propertyListItem statement showEditingLinks>
|
<#macro propertyListItem statement showEditingLinks>
|
||||||
<li role="listitem">
|
<li role="listitem">
|
||||||
<#nested>
|
<#nested>
|
||||||
|
|
Loading…
Add table
Reference in a new issue