From b0c7241ede42d129bbd080798595dbff09dc3451 Mon Sep 17 00:00:00 2001 From: j2blake Date: Fri, 30 Mar 2012 22:08:58 +0000 Subject: [PATCH] NIHVIVO-3404 Improve the hierarchy of statement-based RequestedActions. Add constructors that accept either individual URIs or PropertyStatements. Don't ask for or hold the value of a DataProperty, because it is never used by a policy or permission (at least so far). --- .../webapp/auth/policy/PolicyHelper.java | 4 +- .../AbstractDataPropertyStatementAction.java | 16 +++++-- ...AbstractObjectPropertyStatementAction.java | 22 +++++++--- .../AbstractPropertyStatementAction.java | 13 ++++++ .../propstmt/AddDataPropertyStatement.java | 41 ++++++------------ .../propstmt/AddObjectPropertyStatement.java | 15 +++++-- .../propstmt/DropDataPropertyStatement.java | 42 +++++-------------- .../propstmt/DropObjectPropertyStatement.java | 12 +++++- .../propstmt/EditDataPropertyStatement.java | 24 +++++------ .../propstmt/EditObjectPropertyStatement.java | 12 +++--- .../BaseIndividualTemplateModel.java | 3 +- .../individual/DataPropertyTemplateModel.java | 3 +- .../auth/policy/SelfEditingPolicyTest.java | 10 ++--- 13 files changed, 112 insertions(+), 105 deletions(-) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AbstractPropertyStatementAction.java diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/PolicyHelper.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/PolicyHelper.java index cbef95b92..f9ffbf5aa 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/PolicyHelper.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/PolicyHelper.java @@ -105,7 +105,7 @@ public class PolicyHelper { predicate.getURI(), objectNode.asResource().getURI()); } else { action = new AddDataPropertyStatement(subject.getURI(), - predicate.getURI(), objectNode.asLiteral()); + predicate.getURI()); } return isAuthorizedForActions(req, action); } @@ -157,7 +157,7 @@ public class PolicyHelper { predicate.getURI(), objectNode.asResource().getURI()); } else { action = new DropDataPropertyStatement(subject.getURI(), - predicate.getURI(), objectNode.asLiteral()); + predicate.getURI()); } return isAuthorizedForActions(req, action); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AbstractDataPropertyStatementAction.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AbstractDataPropertyStatementAction.java index 5d3ba5453..f61d3dd3e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AbstractDataPropertyStatementAction.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AbstractDataPropertyStatementAction.java @@ -3,19 +3,29 @@ package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction; +import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; /** - * A base class for requestion actions that relate to data properties. + * A base class for requested actions that involve adding, editing, or dropping + * data property statements from a model. */ -public abstract class AbstractDataPropertyStatementAction extends RequestedAction { +public abstract class AbstractDataPropertyStatementAction extends + RequestedAction { private final String subjectUri; private final String predicateUri; - public AbstractDataPropertyStatementAction(String subjectUri, String predicateUri) { + public AbstractDataPropertyStatementAction(String subjectUri, + String predicateUri) { this.subjectUri = subjectUri; this.predicateUri = predicateUri; } + public AbstractDataPropertyStatementAction(DataPropertyStatement dps) { + this.subjectUri = (dps.getIndividual() == null) ? dps + .getIndividualURI() : dps.getIndividual().getURI(); + this.predicateUri = dps.getDatapropURI(); + } + public String getSubjectUri() { return subjectUri; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AbstractObjectPropertyStatementAction.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AbstractObjectPropertyStatementAction.java index aa696e90f..53ba6d5d4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AbstractObjectPropertyStatementAction.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AbstractObjectPropertyStatementAction.java @@ -2,24 +2,34 @@ package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt; -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction; +import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; /** - * A base class for requested actions that involve manipulating an object - * property. + * A base class for requested actions that involve adding, editing, or deleting + * object property statements from a model. */ -public abstract class AbstractObjectPropertyStatementAction extends RequestedAction { +public abstract class AbstractObjectPropertyStatementAction extends + AbstractPropertyStatementAction { private final String subjectUri; private final String predicateUri; private final String objectUri; - public AbstractObjectPropertyStatementAction(String subjectUri, String predicateUri, - String objectUri) { + public AbstractObjectPropertyStatementAction(String subjectUri, + String predicateUri, String objectUri) { this.subjectUri = subjectUri; this.predicateUri = predicateUri; this.objectUri = objectUri; } + public AbstractObjectPropertyStatementAction(ObjectPropertyStatement ops) { + this.subjectUri = (ops.getSubject() == null) ? ops.getSubjectURI() + : ops.getSubject().getURI(); + this.predicateUri = (ops.getProperty() == null) ? ops.getPropertyURI() + : ops.getProperty().getURI(); + this.objectUri = (ops.getObject() == null) ? ops.getObjectURI() : ops + .getObject().getURI(); + } + public String getSubjectUri() { return subjectUri; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AbstractPropertyStatementAction.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AbstractPropertyStatementAction.java new file mode 100644 index 000000000..c0c64589b --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AbstractPropertyStatementAction.java @@ -0,0 +1,13 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt; + +import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction; + +/** + * A base class for requested actions that involve adding, editing, or deleting + * statements from a model. + */ +public abstract class AbstractPropertyStatementAction extends RequestedAction { + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AddDataPropertyStatement.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AddDataPropertyStatement.java index 02dad0792..0bf2d9721 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AddDataPropertyStatement.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AddDataPropertyStatement.java @@ -2,37 +2,20 @@ package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt; -import com.hp.hpl.jena.rdf.model.Literal; +import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; -/** Should we allow the user to add this DataPropertyStatement? */ -public class AddDataPropertyStatement extends AbstractDataPropertyStatementAction { - protected String data; - protected String dataType; - protected String lang; - - public AddDataPropertyStatement(String subjectUri, String predicateUri, String value, String dataType, String lang) { - super(subjectUri, predicateUri); - this.data= value; - this.dataType = dataType; - this.lang = lang; - } +/** + * Should we allow the user to add this DataPropertyStatement to this model? + */ +public class AddDataPropertyStatement extends + AbstractDataPropertyStatementAction { - public AddDataPropertyStatement(String subjectUri, String predicateUri, Literal literal) { - super(subjectUri, predicateUri); - this.data= literal.getValue().toString(); - this.dataType = literal.getDatatypeURI(); - this.lang = literal.getLanguage(); - } - - public String getData() { - return data; - } + public AddDataPropertyStatement(String subjectUri, String predicateUri) { + super(subjectUri, predicateUri); + } - public String getDataType() { - return dataType; - } + public AddDataPropertyStatement(DataPropertyStatement dps) { + super(dps); + } - public String getLang() { - return lang; - } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AddObjectPropertyStatement.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AddObjectPropertyStatement.java index 81179ea47..f73059ab6 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AddObjectPropertyStatement.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/AddObjectPropertyStatement.java @@ -2,10 +2,19 @@ package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt; -/** Should we allow the user to add this ObjectPropertyStatement? */ -public class AddObjectPropertyStatement extends AbstractObjectPropertyStatementAction { +import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; - public AddObjectPropertyStatement(String uriOfSub, String uriOfPred, String uriOfObj) { +/** + * Should we allow the user to add this ObjectPropertyStatement to this model? + */ +public class AddObjectPropertyStatement extends + AbstractObjectPropertyStatementAction { + public AddObjectPropertyStatement(String uriOfSub, String uriOfPred, + String uriOfObj) { super(uriOfSub, uriOfPred, uriOfObj); } + + public AddObjectPropertyStatement(ObjectPropertyStatement ops) { + super(ops); + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/DropDataPropertyStatement.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/DropDataPropertyStatement.java index 7495e3780..1d9d3c925 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/DropDataPropertyStatement.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/DropDataPropertyStatement.java @@ -2,40 +2,20 @@ package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt; -import com.hp.hpl.jena.rdf.model.Literal; - import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; -import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl; -/** Should we allow the user to delete this DataPropertyStatement? */ -public class DropDataPropertyStatement extends AbstractDataPropertyStatementAction { +/** + * Should we allow the user to delete this DataPropertyStatement from this + * model? + */ +public class DropDataPropertyStatement extends + AbstractDataPropertyStatementAction { - private final DataPropertyStatement dataPropStmt; - - public DropDataPropertyStatement(DataPropertyStatement dps){ - super(dps.getIndividualURI(),dps.getDatapropURI() ); - this.dataPropStmt = dps; - } - - public DropDataPropertyStatement(String subjectUri, String predicateUri, String data) { - super(subjectUri, predicateUri); - dataPropStmt = new DataPropertyStatementImpl(); - dataPropStmt.setIndividualURI(subjectUri); - dataPropStmt.setDatapropURI(predicateUri); - dataPropStmt.setData(data); - } - - public DropDataPropertyStatement(String subjectUri, String predicateUri, Literal data) { - super(subjectUri, predicateUri); - dataPropStmt = new DataPropertyStatementImpl(); - dataPropStmt.setIndividualURI(subjectUri); - dataPropStmt.setDatapropURI(predicateUri); - dataPropStmt.setData(data.getValue().toString()); + public DropDataPropertyStatement(String subjectUri, String predicateUri) { + super(subjectUri, predicateUri); } - public String data(){ return dataPropStmt.getData(); } - public String lang(){ return dataPropStmt.getLanguage(); } - public String datatype(){return dataPropStmt.getDatatypeURI(); } - - // TODO: needs to be fixed to work with lang/datatype literals + public DropDataPropertyStatement(DataPropertyStatement dps) { + super(dps); + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/DropObjectPropertyStatement.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/DropObjectPropertyStatement.java index 3f2315f2b..6f4c33b07 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/DropObjectPropertyStatement.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/DropObjectPropertyStatement.java @@ -2,10 +2,18 @@ package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt; -/** Should we allow the user to delete this ObjectPropertyStatement? */ -public class DropObjectPropertyStatement extends AbstractObjectPropertyStatementAction { +import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; +/** + * Should we allow the user to delete this ObjectPropertyStatement from this + * model? + */ +public class DropObjectPropertyStatement extends AbstractObjectPropertyStatementAction { public DropObjectPropertyStatement(String sub, String pred, String obj) { super(sub, pred, obj); } + + public DropObjectPropertyStatement(ObjectPropertyStatement ops) { + super(ops); + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/EditDataPropertyStatement.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/EditDataPropertyStatement.java index 700dfd5ab..e10479c54 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/EditDataPropertyStatement.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/EditDataPropertyStatement.java @@ -4,18 +4,16 @@ package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; -/** Should we allow the user to edit this DataPropertyStatement? */ -public class EditDataPropertyStatement extends AbstractDataPropertyStatementAction { +/** + * Should we allow the user to edit this DataPropertyStatement in this model? + */ +public class EditDataPropertyStatement extends + AbstractDataPropertyStatementAction { + public EditDataPropertyStatement(String subjectUri, String predicateUri) { + super(subjectUri, predicateUri); + } - private final DataPropertyStatement dataPropStmt; - - public EditDataPropertyStatement(DataPropertyStatement dps){ - super(dps.getIndividualURI(), dps.getDatapropURI()); - this.dataPropStmt = dps; - } - - public String data(){ return dataPropStmt.getData(); } - public String lang(){ return dataPropStmt.getLanguage(); } - public String datatype(){return dataPropStmt.getDatatypeURI(); } - + public EditDataPropertyStatement(DataPropertyStatement dps) { + super(dps); + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/EditObjectPropertyStatement.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/EditObjectPropertyStatement.java index 70b833b70..359365ac4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/EditObjectPropertyStatement.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/requestedAction/propstmt/EditObjectPropertyStatement.java @@ -4,16 +4,16 @@ package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt; import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; -/** Should we allow the user to edit this ObjectPropertyStatement? */ +/** + * Should we allow the user to edit this ObjectPropertyStatement in this model? + */ public class EditObjectPropertyStatement extends AbstractObjectPropertyStatementAction { - - public EditObjectPropertyStatement(ObjectPropertyStatement ops) { - super(ops.getSubjectURI(), ops.getPropertyURI(), ops.getObjectURI()); - } - public EditObjectPropertyStatement(String subjectUri, String keywordPredUri, String objectUri) { super(subjectUri, keywordPredUri, objectUri); } + public EditObjectPropertyStatement(ObjectPropertyStatement ops) { + super(ops); + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/BaseIndividualTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/BaseIndividualTemplateModel.java index 88dc6e3d8..0fe1b1f23 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/BaseIndividualTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/BaseIndividualTemplateModel.java @@ -113,8 +113,7 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel { */ public boolean isEditable() { AddDataPropertyStatement adps = new AddDataPropertyStatement(individual.getURI(), - RequestActionConstants.SOME_URI, - RequestActionConstants.SOME_LITERAL, null, null); + RequestActionConstants.SOME_URI); AddObjectPropertyStatement aops = new AddObjectPropertyStatement(individual.getURI(), RequestActionConstants.SOME_URI, RequestActionConstants.SOME_URI); 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 88b08c901..da5e5b609 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 @@ -11,7 +11,6 @@ import org.apache.commons.logging.LogFactory; import com.hp.hpl.jena.rdf.model.Literal; import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper; -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.AddDataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.DataProperty; @@ -77,7 +76,7 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel { } // Determine whether a new statement can be added - RequestedAction action = new AddDataPropertyStatement(subjectUri, propertyUri, RequestActionConstants.SOME_LITERAL, null, null); + RequestedAction action = new AddDataPropertyStatement(subjectUri, propertyUri); if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) { return; } diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicyTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicyTest.java index a7c2d5207..28b240fdd 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicyTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicyTest.java @@ -118,21 +118,19 @@ public class SelfEditingPolicyTest extends AbstractTestClass { // now with dataprop statements whatToAuth = new AddDataPropertyStatement(SELFEDITOR_URI, - "http://mannlib.cornell.edu/bad#prp234", "someString", null, - null); + "http://mannlib.cornell.edu/bad#prp234"); assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth)); whatToAuth = new AddDataPropertyStatement(SELFEDITOR_URI, - "http://mannlib.cornell.edu/bad#prp999", "someString", null, - null); + "http://mannlib.cornell.edu/bad#prp999"); assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth)); whatToAuth = new AddDataPropertyStatement(SELFEDITOR_URI, - SAFE_PREDICATE, "someString", null, null); + SAFE_PREDICATE); assertDecision(AUTHORIZED, policy.isAuthorized(ids, whatToAuth)); whatToAuth = new AddDataPropertyStatement(SELFEDITOR_URI, - UNSAFE_PREDICATE, "someString", null, null); + UNSAFE_PREDICATE); assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth)); }