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) {
|
||||
|
||||
LoginStatusBean loginBean = LoginStatusBean.getBean(vreq);
|
||||
|
||||
Map<String, Object> editingData = new HashMap<String, Object>();
|
||||
|
||||
editingData.put("showEditLinks", VitroRequestPrep.isSelfEditing(vreq) || loginBean.isLoggedInAtLeast(LoginStatusBean.NON_EDITOR));
|
||||
|
||||
boolean showAdminPanel = loginBean.isLoggedInAtLeast(LoginStatusBean.EDITOR);
|
||||
editingData.put("showAdminPanel", showAdminPanel);
|
||||
// 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.
|
||||
editingData.put("showEditingLinks", VitroRequestPrep.isSelfEditing(vreq) ||
|
||||
loginBean.isLoggedInAtLeast(LoginStatusBean.NON_EDITOR));
|
||||
editingData.put("showAdminPanel", loginBean.isLoggedInAtLeast(LoginStatusBean.EDITOR));
|
||||
|
||||
return editingData;
|
||||
}
|
||||
|
|
|
@ -102,6 +102,7 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
|||
new HashMap<String, List<ObjectPropertyStatementTemplateModel>>();
|
||||
String currentSubclassUri = null;
|
||||
List<ObjectPropertyStatementTemplateModel> currentList = null;
|
||||
String objectKey = getObjectKey();
|
||||
for (Map<String, String> map : statementData) {
|
||||
String subclassUri = map.get("subclass");
|
||||
// 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);
|
||||
subclassMap.put(subclassName, currentList);
|
||||
}
|
||||
currentList.add(new ObjectPropertyStatementTemplateModel(subjectUri, propertyUri, map));
|
||||
currentList.add(new ObjectPropertyStatementTemplateModel(subjectUri, propertyUri, objectKey, map, vreq));
|
||||
}
|
||||
return subclassMap;
|
||||
}
|
||||
|
|
|
@ -24,12 +24,14 @@ public class DataPropertyStatementTemplateModel extends BaseTemplateModel {
|
|||
return statement.getData();
|
||||
}
|
||||
|
||||
public String getEditLink() {
|
||||
return null;
|
||||
public String getEditUrl() {
|
||||
String editUrl = "";
|
||||
return editUrl;
|
||||
}
|
||||
|
||||
public String getDeleteLink() {
|
||||
return null;
|
||||
public String getDeleteUrl() {
|
||||
String deleteUrl = "";
|
||||
return deleteUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,24 +42,11 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getAddLink() {
|
||||
public String getAddUrl() {
|
||||
// TODO Auto-generated method stub
|
||||
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() {
|
||||
return statements;
|
||||
}
|
||||
|
|
|
@ -22,31 +22,40 @@ public class EditLinkHelper {
|
|||
|
||||
private VitroRequest vreq;
|
||||
private ServletContext context;
|
||||
private PolicyIface policy;
|
||||
private IdentifierBundle ids;
|
||||
|
||||
protected EditLinkHelper(VitroRequest vreq) {
|
||||
this.vreq = vreq;
|
||||
this.context = BaseTemplateModel.getServletContext();
|
||||
setPolicy();
|
||||
setIds();
|
||||
}
|
||||
|
||||
protected PolicyIface getPolicy() {
|
||||
PolicyIface policy = RequestPolicyList.getPolicies(vreq);
|
||||
private void setPolicy() {
|
||||
policy = RequestPolicyList.getPolicies(vreq);
|
||||
if( policy == null || ( policy instanceof PolicyList && ((PolicyList)policy).size() == 0 )){
|
||||
policy = ServletPolicyList.getPolicies( context );
|
||||
if( policy == null || ( policy instanceof PolicyList && ((PolicyList)policy).size() == 0 )){
|
||||
log.error("No policy found in request at " + RequestPolicyList.POLICY_LIST);
|
||||
}
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
|
||||
protected IdentifierBundle getIds() {
|
||||
IdentifierBundle ids = (IdentifierBundle)ServletIdentifierBundleFactory
|
||||
private void setIds() {
|
||||
ids = (IdentifierBundle)ServletIdentifierBundleFactory
|
||||
.getIdBundleForRequest(vreq, vreq.getSession(), context);
|
||||
|
||||
if (ids == null) {
|
||||
log.error("No IdentifierBundle objects for request");
|
||||
}
|
||||
}
|
||||
|
||||
protected PolicyIface getPolicy() {
|
||||
return policy;
|
||||
}
|
||||
|
||||
protected IdentifierBundle getIds() {
|
||||
return ids;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,34 +2,59 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
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.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
||||
|
||||
public class ObjectPropertyStatementTemplateModel extends BaseTemplateModel {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ObjectPropertyStatementTemplateModel.class);
|
||||
|
||||
// RY WE may want to instead store the ObjectPropertyStatement; get the object from the data
|
||||
// the same way we do in BaseObjectPropertyDataPostProcessor.getQueryObjectVariableName, then
|
||||
// getting the value from the data.
|
||||
private static final String EDIT_PATH = "edit/editRequestDispatch.jsp";
|
||||
|
||||
// RY WE may want to instead store the ObjectPropertyStatement
|
||||
private String subjectUri; // we'll use these to make the edit links
|
||||
private String propertyUri;
|
||||
private String objectUri;
|
||||
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.propertyUri = propertyUri;
|
||||
this.objectUri = data.get(objectKey);
|
||||
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 */
|
||||
|
||||
|
@ -37,11 +62,25 @@ public class ObjectPropertyStatementTemplateModel extends BaseTemplateModel {
|
|||
return data.get(key);
|
||||
}
|
||||
|
||||
public String getEditLink() {
|
||||
return null;
|
||||
public String getEditUrl() {
|
||||
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);
|
||||
}
|
||||
|
||||
public String getDeleteLink() {
|
||||
return null;
|
||||
return editUrl;
|
||||
}
|
||||
|
||||
public String getDeleteUrl() {
|
||||
String deleteUrl = "";
|
||||
doEditingLinkPrep();
|
||||
return deleteUrl;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -328,22 +328,9 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
public abstract boolean isCollatedBySubclass();
|
||||
|
||||
@Override
|
||||
public String getAddLink() {
|
||||
public String getAddUrl() {
|
||||
// TODO Auto-generated method stub
|
||||
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;
|
||||
}
|
||||
|
||||
public abstract String getAddLink();
|
||||
|
||||
// public abstract String getEditLink();
|
||||
//
|
||||
// public abstract String getDeleteLink();
|
||||
public abstract String getAddUrl();
|
||||
|
||||
}
|
||||
|
|
|
@ -37,8 +37,9 @@ public class UncollatedObjectPropertyTemplateModel extends ObjectPropertyTemplat
|
|||
|
||||
/* Put into data structure to send to template */
|
||||
statements = new ArrayList<ObjectPropertyStatementTemplateModel>(statementData.size());
|
||||
String objectKey = getObjectKey();
|
||||
for (Map<String, String> map : statementData) {
|
||||
statements.add(new ObjectPropertyStatementTemplateModel(subjectUri, propertyUri, map));
|
||||
statements.add(new ObjectPropertyStatementTemplateModel(subjectUri, propertyUri, objectKey, map, vreq));
|
||||
}
|
||||
|
||||
postprocessStatementList(statements);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<#assign core = "http://vivoweb.org/ontology/core#">
|
||||
|
||||
<#assign editingClass>
|
||||
<#if editStatus.showEditLinks>editing<#else></#if>
|
||||
<#if editStatus.showEditingLinks>editing<#else></#if>
|
||||
</#assign>
|
||||
|
||||
<#if editStatus.showAdminPanel>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<#macro dataPropertyList statements>
|
||||
<#list statements as statement>
|
||||
<@propertyListItem>${statement.value}</@propertyListItem>
|
||||
<@propertyListItem statement>${statement.value}</@propertyListItem>
|
||||
</#list>
|
||||
</#macro>
|
||||
|
||||
|
@ -28,10 +28,32 @@
|
|||
|
||||
<#macro objectPropertyList statements template>
|
||||
<#list statements as statement>
|
||||
<@propertyListItem><#include "${template}"></@propertyListItem>
|
||||
<@propertyListItem statement><#include "${template}"></@propertyListItem>
|
||||
</#list>
|
||||
</#macro>
|
||||
|
||||
<#macro propertyListItem>
|
||||
<li role="listitem"><#nested></li>
|
||||
<#macro propertyListItem statement>
|
||||
<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>
|
Loading…
Add table
Reference in a new issue