VIVO-268 Restore data values to DataProperty RequestedAction classes.
This commit is contained in:
parent
8419ce184a
commit
2026a40943
10 changed files with 45 additions and 32 deletions
|
@ -11,7 +11,6 @@ import com.hp.hpl.jena.ontology.OntModel;
|
|||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Property;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
|
@ -20,7 +19,6 @@ import com.hp.hpl.jena.rdf.model.StmtIterator;
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ActiveIdentifierBundleFactories;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyIface;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
|
@ -136,7 +134,8 @@ public class PolicyHelper {
|
|||
.asResource().getURI());
|
||||
} else {
|
||||
action = new AddDataPropertyStatement(modelToBeModified,
|
||||
subject.getURI(), predicate.getURI());
|
||||
subject.getURI(), predicate.getURI(), objectNode
|
||||
.asLiteral().getString());
|
||||
}
|
||||
return isAuthorizedForActions(req, action);
|
||||
}
|
||||
|
@ -169,7 +168,8 @@ public class PolicyHelper {
|
|||
.asResource().getURI());
|
||||
} else {
|
||||
action = new DropDataPropertyStatement(modelToBeModified,
|
||||
subject.getURI(), predicate.getURI());
|
||||
subject.getURI(), predicate.getURI(), objectNode
|
||||
.asLiteral().getString());
|
||||
}
|
||||
return isAuthorizedForActions(req, action);
|
||||
}
|
||||
|
|
|
@ -16,15 +16,17 @@ public abstract class AbstractDataPropertyStatementAction extends
|
|||
private final String subjectUri;
|
||||
private final String predicateUri;
|
||||
private final Property predicate;
|
||||
private final String dataValue;
|
||||
|
||||
public AbstractDataPropertyStatementAction(OntModel ontModel,
|
||||
String subjectUri, String predicateUri) {
|
||||
String subjectUri, String predicateUri, String dataValue) {
|
||||
super(ontModel);
|
||||
this.subjectUri = subjectUri;
|
||||
this.predicateUri = predicateUri;
|
||||
Property dataProperty = new Property();
|
||||
dataProperty.setURI(predicateUri);
|
||||
this.predicate = dataProperty;
|
||||
this.dataValue = dataValue;
|
||||
}
|
||||
|
||||
public AbstractDataPropertyStatementAction(OntModel ontModel,
|
||||
|
@ -36,12 +38,14 @@ public abstract class AbstractDataPropertyStatementAction extends
|
|||
Property dataProperty = new Property();
|
||||
dataProperty.setURI(predicateUri);
|
||||
this.predicate = dataProperty;
|
||||
this.dataValue = dps.getData();
|
||||
}
|
||||
|
||||
public String getSubjectUri() {
|
||||
return subjectUri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property getPredicate() {
|
||||
return predicate;
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ public class AddDataPropertyStatement extends
|
|||
AbstractDataPropertyStatementAction {
|
||||
|
||||
public AddDataPropertyStatement(OntModel ontModel, String subjectUri,
|
||||
String predicateUri) {
|
||||
super(ontModel, subjectUri, predicateUri);
|
||||
String predicateUri, String dataValue) {
|
||||
super(ontModel, subjectUri, predicateUri, dataValue);
|
||||
}
|
||||
|
||||
public AddDataPropertyStatement(OntModel ontModel, DataPropertyStatement dps) {
|
||||
|
|
|
@ -14,8 +14,8 @@ public class DropDataPropertyStatement extends
|
|||
AbstractDataPropertyStatementAction {
|
||||
|
||||
public DropDataPropertyStatement(OntModel ontModel, String subjectUri,
|
||||
String predicateUri) {
|
||||
super(ontModel, subjectUri, predicateUri);
|
||||
String predicateUri, String dataValue) {
|
||||
super(ontModel, subjectUri, predicateUri, dataValue);
|
||||
}
|
||||
|
||||
public DropDataPropertyStatement(OntModel ontModel,
|
||||
|
|
|
@ -12,8 +12,8 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
|||
public class EditDataPropertyStatement extends
|
||||
AbstractDataPropertyStatementAction {
|
||||
public EditDataPropertyStatement(OntModel ontModel, String subjectUri,
|
||||
String predicateUri) {
|
||||
super(ontModel, subjectUri, predicateUri);
|
||||
String predicateUri, String dataValue) {
|
||||
super(ontModel, subjectUri, predicateUri, dataValue);
|
||||
}
|
||||
|
||||
public EditDataPropertyStatement(OntModel ontModel,
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_LITERAL;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_PREDICATE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_URI;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -24,14 +28,12 @@ import com.hp.hpl.jena.vocabulary.RDFS;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddDataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
|
@ -271,11 +273,10 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
|
|||
Individual individual = EditConfigurationUtils.getIndividual(vreq, config.getSubjectUri());
|
||||
AddDataPropertyStatement adps = new AddDataPropertyStatement(
|
||||
vreq.getJenaOntModel(), individual.getURI(),
|
||||
RequestActionConstants.SOME_URI);
|
||||
SOME_URI, SOME_LITERAL);
|
||||
AddObjectPropertyStatement aops = new AddObjectPropertyStatement(
|
||||
vreq.getJenaOntModel(), individual.getURI(),
|
||||
RequestActionConstants.SOME_PREDICATE,
|
||||
RequestActionConstants.SOME_URI);
|
||||
SOME_PREDICATE, SOME_URI);
|
||||
return PolicyHelper.isAuthorizedForActions(vreq, new Actions(adps).or(aops));
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_LITERAL;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_PREDICATE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_URI;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -16,7 +20,6 @@ import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddDataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
|
@ -116,11 +119,10 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
|
|||
public boolean isEditable() {
|
||||
AddDataPropertyStatement adps = new AddDataPropertyStatement(
|
||||
vreq.getJenaOntModel(), individual.getURI(),
|
||||
RequestActionConstants.SOME_URI);
|
||||
SOME_URI, SOME_LITERAL);
|
||||
AddObjectPropertyStatement aops = new AddObjectPropertyStatement(
|
||||
vreq.getJenaOntModel(), individual.getURI(),
|
||||
RequestActionConstants.SOME_PREDICATE,
|
||||
RequestActionConstants.SOME_URI);
|
||||
SOME_PREDICATE, SOME_URI);
|
||||
return PolicyHelper.isAuthorizedForActions(vreq, new Actions(adps).or(aops));
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_LITERAL;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -118,7 +120,7 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
|||
|
||||
// Determine whether a new statement can be added
|
||||
RequestedAction action = new AddDataPropertyStatement(
|
||||
vreq.getJenaOntModel(), subjectUri, propertyUri);
|
||||
vreq.getJenaOntModel(), subjectUri, propertyUri, SOME_LITERAL);
|
||||
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.auth.policy;
|
|||
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization.AUTHORIZED;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization.INCONCLUSIVE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_LITERAL;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
|
@ -31,6 +32,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.RebuildTextIn
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.RemoveUser;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.ServerStatus;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.UpdateTextIndex;
|
||||
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.ontology.CreateOwlClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.DefineDataProperty;
|
||||
|
@ -125,19 +127,19 @@ public class SelfEditingPolicyTest extends AbstractTestClass {
|
|||
|
||||
// now with dataprop statements
|
||||
whatToAuth = new AddDataPropertyStatement(ontModel, SELFEDITOR_URI,
|
||||
"http://mannlib.cornell.edu/bad#prp234");
|
||||
"http://mannlib.cornell.edu/bad#prp234", SOME_LITERAL);
|
||||
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||
|
||||
whatToAuth = new AddDataPropertyStatement(ontModel, SELFEDITOR_URI,
|
||||
"http://mannlib.cornell.edu/bad#prp999");
|
||||
"http://mannlib.cornell.edu/bad#prp999", SOME_LITERAL);
|
||||
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||
|
||||
whatToAuth = new AddDataPropertyStatement(ontModel, SELFEDITOR_URI,
|
||||
SAFE_PREDICATE.getURI());
|
||||
SAFE_PREDICATE.getURI(), SOME_LITERAL);
|
||||
assertDecision(AUTHORIZED, policy.isAuthorized(ids, whatToAuth));
|
||||
|
||||
whatToAuth = new AddDataPropertyStatement(ontModel, SELFEDITOR_URI,
|
||||
UNSAFE_PREDICATE.getURI());
|
||||
UNSAFE_PREDICATE.getURI(), SOME_LITERAL);
|
||||
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||
}
|
||||
|
||||
|
@ -219,16 +221,16 @@ public class SelfEditingPolicyTest extends AbstractTestClass {
|
|||
//
|
||||
@Test
|
||||
public void testVisitIdentifierBundleEditDataPropStmt() {
|
||||
whatToAuth = new EditDataPropertyStatement(ontModel, SELFEDITOR_URI,SAFE_PREDICATE.getURI());
|
||||
whatToAuth = new EditDataPropertyStatement(ontModel, SELFEDITOR_URI,SAFE_PREDICATE.getURI(), SOME_LITERAL);
|
||||
assertDecision(AUTHORIZED, policy.isAuthorized(ids, whatToAuth));
|
||||
|
||||
whatToAuth = new EditDataPropertyStatement(ontModel, SELFEDITOR_URI, UNSAFE_PREDICATE.getURI());
|
||||
whatToAuth = new EditDataPropertyStatement(ontModel, SELFEDITOR_URI, UNSAFE_PREDICATE.getURI(), SOME_LITERAL);
|
||||
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||
|
||||
whatToAuth = new EditDataPropertyStatement(ontModel, UNSAFE_RESOURCE, SAFE_PREDICATE.getURI());
|
||||
whatToAuth = new EditDataPropertyStatement(ontModel, UNSAFE_RESOURCE, SAFE_PREDICATE.getURI(), SOME_LITERAL);
|
||||
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||
|
||||
whatToAuth = new EditDataPropertyStatement(ontModel, SAFE_RESOURCE, SAFE_PREDICATE.getURI());
|
||||
whatToAuth = new EditDataPropertyStatement(ontModel, SAFE_RESOURCE, SAFE_PREDICATE.getURI(), SOME_LITERAL);
|
||||
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||
}
|
||||
|
||||
|
@ -288,7 +290,7 @@ public class SelfEditingPolicyTest extends AbstractTestClass {
|
|||
public void twoSEIsFindDataPropertySubject() {
|
||||
setUpTwoSEIs();
|
||||
|
||||
whatToAuth = new EditDataPropertyStatement(ontModel, SELFEDITOR_URI, SAFE_PREDICATE.getURI());
|
||||
whatToAuth = new EditDataPropertyStatement(ontModel, SELFEDITOR_URI, SAFE_PREDICATE.getURI(), SOME_LITERAL);
|
||||
assertDecision(AUTHORIZED, policy.isAuthorized(ids, whatToAuth));
|
||||
}
|
||||
|
||||
|
@ -296,7 +298,7 @@ public class SelfEditingPolicyTest extends AbstractTestClass {
|
|||
public void twoSEIsDontFindInDataProperty() {
|
||||
setUpTwoSEIs();
|
||||
|
||||
whatToAuth = new EditDataPropertyStatement(ontModel, SAFE_RESOURCE, SAFE_PREDICATE.getURI());
|
||||
whatToAuth = new EditDataPropertyStatement(ontModel, SAFE_RESOURCE, SAFE_PREDICATE.getURI(), SOME_LITERAL);
|
||||
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.auth.policy;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_LITERAL;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -306,7 +308,7 @@ public class SelfEditingPolicy_2_Test extends AbstractTestClass {
|
|||
private void assertEditDataPropStmt(String individualURI,
|
||||
String datapropURI, String data, Authorization expectedAuthorization) {
|
||||
EditDataPropertyStatement whatToAuth = new EditDataPropertyStatement(
|
||||
ontModel, individualURI, datapropURI);
|
||||
ontModel, individualURI, datapropURI, SOME_LITERAL);
|
||||
PolicyDecision dec = policy.isAuthorized(ids, whatToAuth);
|
||||
log.debug(dec);
|
||||
Assert.assertNotNull(dec);
|
||||
|
|
Loading…
Add table
Reference in a new issue