NIHVIVO-1332 Add object property statement edit links
This commit is contained in:
parent
a504b703bd
commit
94b9fa9091
11 changed files with 113 additions and 69 deletions
|
@ -154,13 +154,13 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
private Map<String, Object> getEditingData(VitroRequest vreq) {
|
private Map<String, Object> getEditingData(VitroRequest vreq) {
|
||||||
|
|
||||||
LoginStatusBean loginBean = LoginStatusBean.getBean(vreq);
|
LoginStatusBean loginBean = LoginStatusBean.getBean(vreq);
|
||||||
|
|
||||||
Map<String, Object> editingData = new HashMap<String, Object>();
|
Map<String, Object> editingData = new HashMap<String, Object>();
|
||||||
|
|
||||||
editingData.put("showEditLinks", VitroRequestPrep.isSelfEditing(vreq) || loginBean.isLoggedInAtLeast(LoginStatusBean.NON_EDITOR));
|
// RY This will be improved later. What is important is not whether the user is a self-editor,
|
||||||
|
// but whether he has editing privileges on this profile.
|
||||||
boolean showAdminPanel = loginBean.isLoggedInAtLeast(LoginStatusBean.EDITOR);
|
editingData.put("showEditingLinks", VitroRequestPrep.isSelfEditing(vreq) ||
|
||||||
editingData.put("showAdminPanel", showAdminPanel);
|
loginBean.isLoggedInAtLeast(LoginStatusBean.NON_EDITOR));
|
||||||
|
editingData.put("showAdminPanel", loginBean.isLoggedInAtLeast(LoginStatusBean.EDITOR));
|
||||||
|
|
||||||
return editingData;
|
return editingData;
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,6 +102,7 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
||||||
new HashMap<String, List<ObjectPropertyStatementTemplateModel>>();
|
new HashMap<String, List<ObjectPropertyStatementTemplateModel>>();
|
||||||
String currentSubclassUri = null;
|
String currentSubclassUri = null;
|
||||||
List<ObjectPropertyStatementTemplateModel> currentList = null;
|
List<ObjectPropertyStatementTemplateModel> currentList = null;
|
||||||
|
String objectKey = getObjectKey();
|
||||||
for (Map<String, String> map : statementData) {
|
for (Map<String, String> map : statementData) {
|
||||||
String subclassUri = map.get("subclass");
|
String subclassUri = map.get("subclass");
|
||||||
// Rows with no subclass are put into a subclass map with an empty name.
|
// Rows with no subclass are put into a subclass map with an empty name.
|
||||||
|
@ -114,7 +115,7 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
||||||
String subclassName = getSubclassName(subclassUri, vreq);
|
String subclassName = getSubclassName(subclassUri, vreq);
|
||||||
subclassMap.put(subclassName, currentList);
|
subclassMap.put(subclassName, currentList);
|
||||||
}
|
}
|
||||||
currentList.add(new ObjectPropertyStatementTemplateModel(subjectUri, propertyUri, map));
|
currentList.add(new ObjectPropertyStatementTemplateModel(subjectUri, propertyUri, objectKey, map, vreq));
|
||||||
}
|
}
|
||||||
return subclassMap;
|
return subclassMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,14 @@ public class DataPropertyStatementTemplateModel extends BaseTemplateModel {
|
||||||
return statement.getData();
|
return statement.getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEditLink() {
|
public String getEditUrl() {
|
||||||
return null;
|
String editUrl = "";
|
||||||
|
return editUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDeleteLink() {
|
public String getDeleteUrl() {
|
||||||
return null;
|
String deleteUrl = "";
|
||||||
|
return deleteUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,24 +42,11 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAddLink() {
|
public String getAddUrl() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public String getEditLink() {
|
|
||||||
// // TODO Auto-generated method stub
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public String getDeleteLink() {
|
|
||||||
// // TODO Auto-generated method stub
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public List<DataPropertyStatementTemplateModel> getStatements() {
|
public List<DataPropertyStatementTemplateModel> getStatements() {
|
||||||
return statements;
|
return statements;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,31 +22,40 @@ public class EditLinkHelper {
|
||||||
|
|
||||||
private VitroRequest vreq;
|
private VitroRequest vreq;
|
||||||
private ServletContext context;
|
private ServletContext context;
|
||||||
|
private PolicyIface policy;
|
||||||
|
private IdentifierBundle ids;
|
||||||
|
|
||||||
protected EditLinkHelper(VitroRequest vreq) {
|
protected EditLinkHelper(VitroRequest vreq) {
|
||||||
this.vreq = vreq;
|
this.vreq = vreq;
|
||||||
this.context = BaseTemplateModel.getServletContext();
|
this.context = BaseTemplateModel.getServletContext();
|
||||||
|
setPolicy();
|
||||||
|
setIds();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PolicyIface getPolicy() {
|
private void setPolicy() {
|
||||||
PolicyIface policy = RequestPolicyList.getPolicies(vreq);
|
policy = RequestPolicyList.getPolicies(vreq);
|
||||||
if( policy == null || ( policy instanceof PolicyList && ((PolicyList)policy).size() == 0 )){
|
if( policy == null || ( policy instanceof PolicyList && ((PolicyList)policy).size() == 0 )){
|
||||||
policy = ServletPolicyList.getPolicies( context );
|
policy = ServletPolicyList.getPolicies( context );
|
||||||
if( policy == null || ( policy instanceof PolicyList && ((PolicyList)policy).size() == 0 )){
|
if( policy == null || ( policy instanceof PolicyList && ((PolicyList)policy).size() == 0 )){
|
||||||
log.error("No policy found in request at " + RequestPolicyList.POLICY_LIST);
|
log.error("No policy found in request at " + RequestPolicyList.POLICY_LIST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return policy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IdentifierBundle getIds() {
|
private void setIds() {
|
||||||
IdentifierBundle ids = (IdentifierBundle)ServletIdentifierBundleFactory
|
ids = (IdentifierBundle)ServletIdentifierBundleFactory
|
||||||
.getIdBundleForRequest(vreq, vreq.getSession(), context);
|
.getIdBundleForRequest(vreq, vreq.getSession(), context);
|
||||||
|
|
||||||
if (ids == null) {
|
if (ids == null) {
|
||||||
log.error("No IdentifierBundle objects for request");
|
log.error("No IdentifierBundle objects for request");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PolicyIface getPolicy() {
|
||||||
|
return policy;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IdentifierBundle getIds() {
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,34 +2,59 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
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.auth.policy.ifaces.Authorization;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.EditObjPropStmt;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
||||||
|
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;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
||||||
|
|
||||||
public class ObjectPropertyStatementTemplateModel extends BaseTemplateModel {
|
public class ObjectPropertyStatementTemplateModel extends BaseTemplateModel {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(ObjectPropertyStatementTemplateModel.class);
|
private static final Log log = LogFactory.getLog(ObjectPropertyStatementTemplateModel.class);
|
||||||
|
|
||||||
// RY WE may want to instead store the ObjectPropertyStatement; get the object from the data
|
private static final String EDIT_PATH = "edit/editRequestDispatch.jsp";
|
||||||
// the same way we do in BaseObjectPropertyDataPostProcessor.getQueryObjectVariableName, then
|
|
||||||
// getting the value from the data.
|
// RY WE may want to instead store the ObjectPropertyStatement
|
||||||
private String subjectUri; // we'll use these to make the edit links
|
private String subjectUri; // we'll use these to make the edit links
|
||||||
private String propertyUri;
|
private String propertyUri;
|
||||||
|
private String objectUri;
|
||||||
private Map<String, String> data;
|
private Map<String, String> data;
|
||||||
|
private VitroRequest vreq;
|
||||||
|
private ObjectPropertyStatement objectPropertyStatement;
|
||||||
|
private EditLinkHelper editLinkHelper;
|
||||||
|
|
||||||
ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri, Map<String, String> data) {
|
ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri,
|
||||||
|
String objectKey, Map<String, String> data, VitroRequest vreq) {
|
||||||
this.subjectUri = subjectUri;
|
this.subjectUri = subjectUri;
|
||||||
this.propertyUri = propertyUri;
|
this.propertyUri = propertyUri;
|
||||||
|
this.objectUri = data.get(objectKey);
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
this.vreq = vreq;
|
||||||
|
// Don't set these until needed (when edit links are requested)
|
||||||
|
this.objectPropertyStatement = null;
|
||||||
|
this.editLinkHelper = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void doEditingLinkPrep() {
|
||||||
|
// Assign the objectPropertyStatement and editLinkHelper to instance variables, so we don't
|
||||||
|
// have to do it twice, once for edit link and once for delete link.
|
||||||
|
if (objectPropertyStatement == null) {
|
||||||
|
objectPropertyStatement = new ObjectPropertyStatementImpl(subjectUri, propertyUri, objectUri);
|
||||||
|
}
|
||||||
|
if (editLinkHelper == null) {
|
||||||
|
editLinkHelper = new EditLinkHelper(vreq);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Access methods for templates */
|
/* Access methods for templates */
|
||||||
|
|
||||||
|
@ -37,11 +62,25 @@ public class ObjectPropertyStatementTemplateModel extends BaseTemplateModel {
|
||||||
return data.get(key);
|
return data.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEditLink() {
|
public String getEditUrl() {
|
||||||
return null;
|
String editUrl = "";
|
||||||
|
doEditingLinkPrep();
|
||||||
|
RequestedAction action = new EditObjPropStmt(objectPropertyStatement);
|
||||||
|
PolicyDecision decision = editLinkHelper.getPolicy().isAuthorized(editLinkHelper.getIds(), action);
|
||||||
|
if (decision != null && decision.getAuthorized() == Authorization.AUTHORIZED) {
|
||||||
|
ParamMap params = new ParamMap(
|
||||||
|
"subjectUri", subjectUri,
|
||||||
|
"predicateUri", propertyUri,
|
||||||
|
"objectUri", objectUri);
|
||||||
|
editUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
return editUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDeleteLink() {
|
public String getDeleteUrl() {
|
||||||
return null;
|
String deleteUrl = "";
|
||||||
|
doEditingLinkPrep();
|
||||||
|
return deleteUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -328,22 +328,9 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
public abstract boolean isCollatedBySubclass();
|
public abstract boolean isCollatedBySubclass();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAddLink() {
|
public String getAddUrl() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public String getEditLink() {
|
|
||||||
// // TODO Auto-generated method stub
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public String getDeleteLink() {
|
|
||||||
// // TODO Auto-generated method stub
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,10 +43,6 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getAddLink();
|
public abstract String getAddUrl();
|
||||||
|
|
||||||
// public abstract String getEditLink();
|
|
||||||
//
|
|
||||||
// public abstract String getDeleteLink();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,9 @@ public class UncollatedObjectPropertyTemplateModel extends ObjectPropertyTemplat
|
||||||
|
|
||||||
/* Put into data structure to send to template */
|
/* Put into data structure to send to template */
|
||||||
statements = new ArrayList<ObjectPropertyStatementTemplateModel>(statementData.size());
|
statements = new ArrayList<ObjectPropertyStatementTemplateModel>(statementData.size());
|
||||||
|
String objectKey = getObjectKey();
|
||||||
for (Map<String, String> map : statementData) {
|
for (Map<String, String> map : statementData) {
|
||||||
statements.add(new ObjectPropertyStatementTemplateModel(subjectUri, propertyUri, map));
|
statements.add(new ObjectPropertyStatementTemplateModel(subjectUri, propertyUri, objectKey, map, vreq));
|
||||||
}
|
}
|
||||||
|
|
||||||
postprocessStatementList(statements);
|
postprocessStatementList(statements);
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<#assign core = "http://vivoweb.org/ontology/core#">
|
<#assign core = "http://vivoweb.org/ontology/core#">
|
||||||
|
|
||||||
<#assign editingClass>
|
<#assign editingClass>
|
||||||
<#if editStatus.showEditLinks>editing<#else></#if>
|
<#if editStatus.showEditingLinks>editing<#else></#if>
|
||||||
</#assign>
|
</#assign>
|
||||||
|
|
||||||
<#if editStatus.showAdminPanel>
|
<#if editStatus.showAdminPanel>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<#macro dataPropertyList statements>
|
<#macro dataPropertyList statements>
|
||||||
<#list statements as statement>
|
<#list statements as statement>
|
||||||
<@propertyListItem>${statement.value}</@propertyListItem>
|
<@propertyListItem statement>${statement.value}</@propertyListItem>
|
||||||
</#list>
|
</#list>
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
||||||
|
@ -28,10 +28,32 @@
|
||||||
|
|
||||||
<#macro objectPropertyList statements template>
|
<#macro objectPropertyList statements template>
|
||||||
<#list statements as statement>
|
<#list statements as statement>
|
||||||
<@propertyListItem><#include "${template}"></@propertyListItem>
|
<@propertyListItem statement><#include "${template}"></@propertyListItem>
|
||||||
</#list>
|
</#list>
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
||||||
<#macro propertyListItem>
|
<#macro propertyListItem statement>
|
||||||
<li role="listitem"><#nested></li>
|
<li role="listitem">
|
||||||
|
<@editLink statement />
|
||||||
|
<@deleteLink statement />
|
||||||
|
<#nested>
|
||||||
|
</li>
|
||||||
|
</#macro>
|
||||||
|
|
||||||
|
<#macro editLink statement>
|
||||||
|
<#if editStatus.showEditingLinks>
|
||||||
|
<#local url = statement.editUrl>
|
||||||
|
<#if url?has_content>
|
||||||
|
<a href="${url}">edit</a>
|
||||||
|
</#if>
|
||||||
|
</#if>
|
||||||
|
</#macro>
|
||||||
|
|
||||||
|
<#macro deleteLink statement>
|
||||||
|
<#if editStatus.showEditingLinks>
|
||||||
|
<#local url = statement.deleteUrl>
|
||||||
|
<#if url?has_content>
|
||||||
|
<a href="${url}">delete</a>
|
||||||
|
</#if>
|
||||||
|
</#if>
|
||||||
</#macro>
|
</#macro>
|
Loading…
Add table
Reference in a new issue