From 9a344cfc890cf050276ae7f910713a911594b6bb Mon Sep 17 00:00:00 2001 From: rjy7 Date: Tue, 11 Jan 2011 22:18:37 +0000 Subject: [PATCH] NIHVIVO-1332 Links to add new data property statement. --- .../individual/DataPropertyTemplateModel.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyTemplateModel.java index 4eefa6fcd..10591f610 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyTemplateModel.java @@ -8,10 +8,17 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +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.AddDataPropStmt; import edu.cornell.mannlib.vitro.webapp.beans.DataProperty; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.Individual; 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.DataPropertyStatementDao; public class DataPropertyTemplateModel extends PropertyTemplateModel { @@ -19,6 +26,7 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel { private static final Log log = LogFactory.getLog(DataPropertyTemplateModel.class); private static final String TYPE = "data"; + private static final String EDIT_PATH = "edit/editDatapropStmtRequestDispatch.jsp"; private List statements; @@ -27,6 +35,15 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel { setName(dp.getPublicName()); + // Determine whether a new statement can be added + if (policyHelper != null) { + RequestedAction action = new AddDataPropStmt(subjectUri, propertyUri,RequestActionConstants.SOME_LITERAL, null, null); + PolicyDecision decision = policyHelper.getPolicyDecision(action); + if( decision != null && decision.getAuthorized() == Authorization.AUTHORIZED ) { + addAccess = true; + } + } + // Get the data property statements via a sparql query DataPropertyStatementDao dpDao = vreq.getWebappDaoFactory().getDataPropertyStatementDao(); List dpStatements = dpDao.getDataPropertyStatementsForIndividualByProperty(subject, dp); @@ -45,6 +62,12 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel { @Override public String getAddUrl() { String addUrl = ""; + if (addAccess) { + ParamMap params = new ParamMap( + "subjectUri", subjectUri, + "predicateUri", propertyUri); + addUrl = UrlBuilder.getUrl(EDIT_PATH, params); + } return addUrl; }