Merge branch 'maint-rel-1.6' into feature/orcid

This commit is contained in:
Jim Blake 2014-04-01 16:37:26 -04:00
commit b038902ee7
74 changed files with 2375 additions and 490 deletions

View file

@ -47,6 +47,13 @@ import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
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 edu.cornell.mannlib.vitro.webapp.controller.accounts.manageproxies.ProxyRelationshipSelectorTest;
/**
* A collection of useful routines to help when testing.
* <ul>
@ -404,8 +411,22 @@ public abstract class AbstractTestClass {
assertEquals(message, expected, actual);
}
@SuppressWarnings("unchecked")
protected <T> Set<T> buildSet(T... array) {
return new HashSet<T>(Arrays.asList(array));
}
protected OntModel readModelFromFile(String relativePath, String rdfType) throws IOException {
InputStream stream = this.getClass()
.getResourceAsStream(relativePath);
Model model = ModelFactory.createDefaultModel();
model.read(stream, null, rdfType);
stream.close();
OntModel ontModel = ModelFactory.createOntologyModel(
OntModelSpec.OWL_DL_MEM, model);
ontModel.prepare();
return ontModel;
}
}

View file

@ -4,11 +4,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;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Level;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -19,7 +16,6 @@ import stubs.javax.servlet.ServletContextStub;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
@ -81,19 +77,6 @@ public class SelfEditingPolicy_2_Test extends AbstractTestClass {
@Before
public void setUp() throws Exception {
InputStream is = getClass().getResourceAsStream(
"./SelfEditingPolicy_2_Test.xml");
Assert.assertNotNull(is);
// suppress the warning messages from loading the model.
setLoggerLevel(RDFDefaultErrorHandler.class, Level.OFF);
// TODO This doesn't appear to be used for anything. Can it go away, along with the data file?
OntModel model = ModelFactory.createOntologyModel();
model.read(is, "");
Assert.assertNotNull(model);
Assert.assertTrue(model.size() > 0);
ServletContextStub ctx = new ServletContextStub();
PropertyRestrictionPolicyHelper.setBean(ctx,
PropertyRestrictionPolicyHelperStub

View file

@ -1,45 +0,0 @@
<?xml version='1.0' encoding='ISO-8859-1'?>
<!-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<rdf:RDF
xmlns:owl ="http://www.w3.org/2002/07/owl#"
xmlns:rdf ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs ="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd ="http://www.w3.org/2001/XMLSchema#"
xmlns:vitro="http://vitro.mannlib.cornell.edu/ns/vitro/0.7#"
xmlns =""
>
<owl:Ontology rdf:about="">
<rdfs:comment>
An ontology with a property with a prohibited annotation for unit testing.
</rdfs:comment>
</owl:Ontology>
<owl:AnnotationProperty rdf:about="vitro:selfEditProhibitedAnnot"/>
<owl:ObjectProperty rdf:about="vitro:hasSuperPowers">
<vitro:selfEditProhibitedAnnot rdf:datatype="xsd:boolean">true</vitro:selfEditProhibitedAnnot>
</owl:ObjectProperty>
<owl:ObjectProperty rdf:about="vitro:mayPrintMoney">
<vitro:selfEditProhibitedAnnot rdf:datatype="xsd:boolean">true</vitro:selfEditProhibitedAnnot>
</owl:ObjectProperty>
<owl:ObjectProperty rdf:about="vitro:getsOutOfJailFree">
<vitro:selfEditProhibitedAnnot rdf:datatype="xsd:boolean">true</vitro:selfEditProhibitedAnnot>
</owl:ObjectProperty>
<owl:ObjectProperty rdf:about="vitro:canDeleteModel">
<vitro:selfEditProhibitedAnnot rdf:datatype="xsd:boolean">true</vitro:selfEditProhibitedAnnot>
</owl:ObjectProperty>
<owl:DatatypeProperty rdf:about="vitro:felonies">
<vitro:selfEditProhibitedAnnot rdf:datatype="xsd:boolean">true</vitro:selfEditProhibitedAnnot>
</owl:DatatypeProperty>
</rdf:RDF>

View file

@ -35,7 +35,8 @@ import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
/**
* Check that the bean gets built properly, and check that the bean works properly.
* Check that the bean gets built properly, and check that the bean works
* properly.
*/
public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
private static final Log log = LogFactory
@ -43,12 +44,12 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
private static final String PROPERTY_DISPLAY_THRESHOLD = VitroVocabulary.HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT;
private static final String PROPERTY_MODIFY_THRESHOLD = VitroVocabulary.PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT;
private static final String PROPERTY_PUBLISH_THRESHOLD = VitroVocabulary.HIDDEN_FROM_PUBLISH_BELOW_ROLE_LEVEL_ANNOT;
private static final String[] PROHIBITED_NAMESPACES = new String[] {
VitroVocabulary.vitroURI, "" };
private static final String[] PERMITTED_EXCEPTIONS = new String[] {
VitroVocabulary.MONIKER };
private static final String[] PERMITTED_EXCEPTIONS = new String[] { VitroVocabulary.MONIKER };
private OntModel ontModel;
private ModelWrapper wrapper;
@ -56,33 +57,35 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
@Before
public void setLoggingLevel() {
// setLoggerLevel(PropertyRestrictionPolicyHelper.class, Level.DEBUG);
// setLoggerLevel(PropertyRestrictionPolicyHelper.class, Level.DEBUG);
}
private void mapPut(String predicateURI, RoleLevel roleLevel,
Map<Pair<String, Pair<String,String>>, RoleLevel> map) {
map.put(new Pair<String, Pair<String,String>>(
OWL.Thing.getURI(), new Pair<String, String>(
predicateURI, OWL.Thing.getURI())), roleLevel);
private void mapPut(String predicateURI, RoleLevel roleLevel,
Map<Pair<String, Pair<String, String>>, RoleLevel> map) {
map.put(new Pair<String, Pair<String, String>>(OWL.Thing.getURI(),
new Pair<String, String>(predicateURI, OWL.Thing.getURI())),
roleLevel);
}
@Before
public void createTheBean() {
Map<Pair<String, Pair<String,String>>, RoleLevel> displayLevels =
new HashMap<Pair<String, Pair<String,String>>, RoleLevel>();
Map<Pair<String, Pair<String, String>>, RoleLevel> displayLevels = new HashMap<>();
mapPut("http://predicates#display_curator", CURATOR, displayLevels);
mapPut("http://predicates#display_hidden", NOBODY, displayLevels);
Map<Pair<String, Pair<String,String>>, RoleLevel> modifyLevels =
new HashMap<Pair<String, Pair<String,String>>, RoleLevel>();
Map<Pair<String, Pair<String, String>>, RoleLevel> modifyLevels = new HashMap<>();
mapPut("http://predicates#modify_self", SELF, modifyLevels);
mapPut("http://predicates#modify_curator", CURATOR, modifyLevels);
mapPut("http://predicates#modify_hidden", NOBODY, modifyLevels);
Map<Pair<String, Pair<String, String>>, RoleLevel> publishLevels = new HashMap<>();
mapPut("http://predicates#publish_curator", CURATOR, publishLevels);
mapPut("http://predicates#publish_hidden", NOBODY, publishLevels);
bean = new PropertyRestrictionPolicyHelper(
Arrays.asList(PROHIBITED_NAMESPACES),
Arrays.asList(PERMITTED_EXCEPTIONS), displayLevels,
modifyLevels, ModelFactory.createDefaultModel());
modifyLevels, publishLevels);
}
@Before
@ -100,6 +103,11 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
PROPERTY_MODIFY_THRESHOLD, EDITOR.getURI());
wrapper.add("http://thresholds#modify_curator",
PROPERTY_MODIFY_THRESHOLD, CURATOR.getURI());
wrapper.add("http://thresholds#publish_public",
PROPERTY_PUBLISH_THRESHOLD, PUBLIC.getURI());
wrapper.add("http://thresholds#publish_hidden",
PROPERTY_PUBLISH_THRESHOLD, NOBODY.getURI());
}
// ----------------------------------------------------------------------
@ -125,6 +133,12 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
null));
}
@Test
public void publishResource() {
assertEquals("publish a random resource", true,
bean.canPublishResource("http://someRandom#string", null));
}
@Test
public void modifyResourcePermittedException() {
assertEquals("modify a exception resource", true,
@ -133,76 +147,119 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
@Test
public void displayPredicateNoRestriction() {
assertEquals("displayPredicate: open", true,
bean.canDisplayPredicate(createVitroProperty(
"http://predicates#open"), PUBLIC));
assertEquals("displayPredicate: open", true, bean.canDisplayPredicate(
createVitroProperty("http://predicates#open"), PUBLIC));
}
@Test
public void displayPredicateRestrictionLower() {
assertEquals("displayPredicate: lower restriction", true,
bean.canDisplayPredicate(createVitroProperty(
"http://predicates#display_self"), CURATOR));
bean.canDisplayPredicate(
createVitroProperty("http://predicates#display_self"),
CURATOR));
}
@Test
public void displayPredicateRestrictionEqual() {
assertEquals("displayPredicate: equal restriction", true,
bean.canDisplayPredicate(createVitroProperty(
"http://predicates#display_curator"), CURATOR));
assertEquals(
"displayPredicate: equal restriction",
true,
bean.canDisplayPredicate(
createVitroProperty("http://predicates#display_curator"),
CURATOR));
}
@Test
public void displayPredicateRestrictionHigher() {
assertEquals("displayPredicate: higher restriction", false,
bean.canDisplayPredicate(createVitroProperty(
"http://predicates#display_hidden"), CURATOR));
assertEquals(
"displayPredicate: higher restriction",
false,
bean.canDisplayPredicate(
createVitroProperty("http://predicates#display_hidden"),
CURATOR));
}
@Test
public void modifyPredicateNoRestriction() {
assertEquals("modifyPredicate: open", true,
bean.canModifyPredicate(new edu.cornell.mannlib.vitro.webapp.beans.Property(
"http://predicates#open"), PUBLIC));
assertEquals("modifyPredicate: open", true, bean.canModifyPredicate(
new edu.cornell.mannlib.vitro.webapp.beans.Property(
"http://predicates#open"), PUBLIC));
}
@Test
public void modifyPredicateRestrictionLower() {
assertEquals("modifyPredicate: lower restriction", true,
bean.canModifyPredicate(new edu.cornell.mannlib.vitro.webapp.beans.Property(
"http://predicates#modify_self"),
CURATOR));
bean.canModifyPredicate(
new edu.cornell.mannlib.vitro.webapp.beans.Property(
"http://predicates#modify_self"), CURATOR));
}
@Test
public void modifyPredicateRestrictionEqual() {
assertEquals("modifyPredicate: equal restriction", true,
bean.canModifyPredicate(new edu.cornell.mannlib.vitro.webapp.beans.Property(
"http://predicates#modify_curator"),
CURATOR));
bean.canModifyPredicate(
new edu.cornell.mannlib.vitro.webapp.beans.Property(
"http://predicates#modify_curator"), CURATOR));
}
@Test
public void modifyPredicateRestrictionHigher() {
assertEquals("modifyPredicate: higher restriction", false,
bean.canModifyPredicate(new edu.cornell.mannlib.vitro.webapp.beans.Property(
"http://predicates#modify_hidden"),
CURATOR));
bean.canModifyPredicate(
new edu.cornell.mannlib.vitro.webapp.beans.Property(
"http://predicates#modify_hidden"), CURATOR));
}
@Test
public void modifyPredicateProhibitedNamespace() {
assertEquals("modifyPredicate: prohibited namespace", false,
bean.canModifyPredicate(new edu.cornell.mannlib.vitro.webapp.beans.Property(
PROHIBITED_NAMESPACES[0] + "randoom"),
DB_ADMIN));
assertEquals(
"modifyPredicate: prohibited namespace",
false,
bean.canModifyPredicate(
new edu.cornell.mannlib.vitro.webapp.beans.Property(
PROHIBITED_NAMESPACES[0] + "randoom"), DB_ADMIN));
}
@Test
public void modifyPredicatePermittedException() {
assertEquals("modifyPredicate: permitted exception", true,
bean.canModifyPredicate(new edu.cornell.mannlib.vitro.webapp.beans.Property(
PERMITTED_EXCEPTIONS[0]), DB_ADMIN));
bean.canModifyPredicate(
new edu.cornell.mannlib.vitro.webapp.beans.Property(
PERMITTED_EXCEPTIONS[0]), DB_ADMIN));
}
@Test
public void publishPredicateNoRestriction() {
assertEquals("publishPredicate: open", true, bean.canPublishPredicate(
createVitroProperty("http://predicates#open"), PUBLIC));
}
@Test
public void publishPredicateRestrictionLower() {
assertEquals("publishPredicate: lower restriction", true,
bean.canPublishPredicate(
createVitroProperty("http://predicates#publish_self"),
CURATOR));
}
@Test
public void publishPredicateRestrictionEqual() {
assertEquals(
"publishPredicate: equal restriction",
true,
bean.canPublishPredicate(
createVitroProperty("http://predicates#publish_curator"),
CURATOR));
}
@Test
public void publishPredicateRestrictionHigher() {
assertEquals(
"publishPredicate: higher restriction",
false,
bean.canPublishPredicate(
createVitroProperty("http://predicates#publish_hidden"),
CURATOR));
}
// ----------------------------------------------------------------------
@ -211,8 +268,7 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
@Test
public void buildDisplayThresholds() {
Map<Pair<String, Pair<String,String>>, BaseResourceBean.RoleLevel> expectedMap =
new HashMap<Pair<String, Pair<String,String>>, BaseResourceBean.RoleLevel>();
Map<Pair<String, Pair<String, String>>, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>();
mapPut("http://thresholds#display_public", PUBLIC, expectedMap);
mapPut("http://thresholds#display_hidden", NOBODY, expectedMap);
@ -222,8 +278,7 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
@Test
public void buildModifyThresholds() {
Map<Pair<String, Pair<String,String>>, BaseResourceBean.RoleLevel> expectedMap =
new HashMap<Pair<String, Pair<String,String>>, BaseResourceBean.RoleLevel>();
Map<Pair<String, Pair<String, String>>, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>();
mapPut("http://thresholds#modify_editor", EDITOR, expectedMap);
mapPut("http://thresholds#modify_curator", CURATOR, expectedMap);
@ -231,6 +286,16 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
assertEquals("modify thresholds", expectedMap, actualMap);
}
@Test
public void buildPublishThresholds() {
Map<Pair<String, Pair<String, String>>, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>();
mapPut("http://thresholds#publish_public", PUBLIC, expectedMap);
mapPut("http://thresholds#publish_hidden", NOBODY, expectedMap);
Map<String, RoleLevel> actualMap = populateThresholdMap(PROPERTY_PUBLISH_THRESHOLD);
assertEquals("publish thresholds", expectedMap, actualMap);
}
/** Invoke the private static method "populateThresholdMap" */
private Map<String, RoleLevel> populateThresholdMap(String propertyUri) {
Map<String, RoleLevel> map = new HashMap<String, BaseResourceBean.RoleLevel>();
@ -262,9 +327,9 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
model.add(subject, property, object);
}
}
private edu.cornell.mannlib.vitro.webapp.beans.Property createVitroProperty(
String propertyURI) {
return new edu.cornell.mannlib.vitro.webapp.beans.Property(propertyURI);
String propertyURI) {
return new edu.cornell.mannlib.vitro.webapp.beans.Property(propertyURI);
}
}

View file

@ -0,0 +1,154 @@
@prefix ocresd: <http://purl.org/net/OCRe/study_design.owl#> .
@prefix geo: <http://aims.fao.org/aos/geopolitical.owl#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix scires: <http://vivoweb.org/ontology/scientific-research#> .
@prefix cito: <http://purl.org/spar/cito/> .
@prefix fabio: <http://purl.org/spar/fabio/> .
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .
@prefix obo: <http://purl.obolibrary.org/obo/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ocrer: <http://purl.org/net/OCRe/research.owl#> .
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
@prefix event: <http://purl.org/NET/c4dm/event.owl#> .
@prefix bibo: <http://purl.org/ontology/bibo/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix c4o: <http://purl.org/spar/c4o/> .
@prefix vitro-public: <http://vitro.mannlib.cornell.edu/ns/vitro/public#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix vivo: <http://vivoweb.org/ontology/core#> .
<http://vivo.mydomain.edu/individual/n3639>
a vivo:FacultyMember ,
foaf:Person ,
owl:Thing ,
foaf:Agent ,
obo:BFO_0000002 ,
obo:BFO_0000001 ,
obo:BFO_0000004 ;
rdfs:label "Baker, Able "^^xsd:string ;
obo:ARG_2000028 <http://vivo.mydomain.edu/individual/n3972> ;
obo:RO_0000053 <http://vivo.mydomain.edu/individual/n475> ,
<http://vivo.mydomain.edu/individual/n7850> ;
vitro:mostSpecificType
vivo:FacultyMember ;
vivo:freetextKeyword
"Potrezebie, Chattanooga" ;
vivo:hasCollaborator
<http://vivo.mydomain.edu/individual/n7429> ;
vivo:relatedBy <http://vivo.mydomain.edu/individual/n3401> ,
<http://vivo.mydomain.edu/individual/n5855> ,
<http://vivo.mydomain.edu/individual/n2421> ;
vivo:researchOverview
"Whatever strikes my fancy." ;
vivo:scopusId "abaker" .
<http://vivo.mydomain.edu/individual/n3972>
a vcard:Kind ,
obo:BFO_0000031 ,
owl:Thing ,
obo:ARG_2000379 ,
obo:IAO_0000030 ,
obo:BFO_0000002 ,
obo:BFO_0000001 ,
vcard:Individual ;
obo:ARG_2000029 <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n475>
a owl:Thing ,
obo:BFO_0000023 ,
vivo:InvestigatorRole ,
obo:BFO_0000002 ,
obo:BFO_0000017 ,
vivo:PrincipalInvestigatorRole ,
obo:BFO_0000020 ,
obo:BFO_0000001 ,
vivo:ResearcherRole ;
obo:RO_0000052 <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n7850>
a owl:Thing ,
obo:BFO_0000023 ,
obo:BFO_0000017 ,
obo:BFO_0000002 ,
obo:BFO_0000020 ,
obo:BFO_0000001 ,
vivo:LeaderRole ;
rdfs:label "Lead Guitarist"^^xsd:string ;
obo:RO_0000052 <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n7429>
a foaf:Person ,
vivo:FacultyMember ,
foaf:Agent ,
owl:Thing ,
obo:BFO_0000002 ,
obo:BFO_0000001 ,
obo:BFO_0000004 ;
rdfs:label "Yum, Yum " .
<http://vivo.mydomain.edu/individual/n3401>
a owl:Thing ,
vivo:Relationship ,
obo:BFO_0000002 ,
obo:BFO_0000020 ,
obo:BFO_0000001 ,
vivo:Authorship ;
vivo:relates <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n5855>
a vivo:FacultyPosition ,
owl:Thing ,
vivo:Relationship ,
obo:BFO_0000002 ,
obo:BFO_0000020 ,
obo:BFO_0000001 ,
vivo:Position ;
rdfs:label "Functionary"^^xsd:string ;
vivo:relates <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n2421>
a owl:Thing ,
vivo:Relationship ,
obo:BFO_0000002 ,
obo:BFO_0000020 ,
obo:BFO_0000001 ,
vivo:Grant ;
rdfs:label "Cosmogenic Lassitude in Plegmatic Axolotls" ;
vivo:relates <http://vivo.mydomain.edu/individual/n3639> .
obo:BFO_0000001
a owl:Class ;
rdfs:label "Entity" .
obo:BFO_0000002
a owl:Class ;
rdfs:label "Continuant" .
obo:BFO_0000004
a owl:Class ;
rdfs:label "Independent Continuant"@en-US .
vivo:FacultyMember
a owl:Class ;
rdfs:label "Faculty Member"@en-US .
foaf:Person
a owl:Class ;
rdfs:label "Person"@en-US .
foaf:Agent
a owl:Class ;
rdfs:label "Agent"@en-US .
owl:Thing
a owl:Class .
<http://vivo.mydomain.edu/individual/n3639/n3639.n3>
a foaf:Document ;
rdfs:label "RDF description of Baker, Able - http://vivo.mydomain.edu/individual/n3639" ;
<http://purl.org/dc/elements/1.1/date> "2014-03-10T11:08:39"^^xsd:dateTime ;
<http://purl.org/dc/elements/1.1/publisher> <http://vivo.mydomain.edu> ;
<http://purl.org/dc/elements/1.1/rights> <http://vivo.mydomain.edu/termsOfUse> .

View file

@ -0,0 +1,503 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.individual;
import static com.hp.hpl.jena.ontology.OntModelSpec.OWL_MEM;
import static edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary.LABEL;
import static edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary.RDF_TYPE;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.collections.IteratorUtils;
import org.apache.log4j.Level;
import org.junit.Before;
import org.junit.Test;
import stubs.javax.servlet.ServletContextStub;
import stubs.javax.servlet.http.HttpServletRequestStub;
import stubs.javax.servlet.http.HttpSessionStub;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.Statement;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
import edu.cornell.mannlib.vitro.webapp.auth.policy.BasicPolicyDecision;
import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList;
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.policy.ifaces.PolicyIface;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.publish.PublishDataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.publish.PublishObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel;
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
/**
* Start with a set of data and filter it appropriately.
*/
public class IndividualRdfAssemblerTest extends AbstractTestClass {
private static final String INDIVIDUAL_URI = "http://vivo.mydomain.edu/individual/n3639";
private static final String DOCUMENT_URI = "http://vivo.mydomain.edu/individual/n3639/n3639.n3";
/** When comparing, consider all date-stamps to be equal. */
private static final String DATE_DATA_PROPERTY = "http://purl.org/dc/elements/1.1/date";
private static final String DP1 = "http://dataPropertyUri1";
private static final String OP1 = "http://objectPropertyUri1";
private static final String C1 = "http://class1";
private static final String C2 = "http://class2";
private static final String I1 = "http://individual1";
private static final String RAW_RDF_FILENAME = "IndividualRdfAssemblerTest.rawRdf.n3";
private static final String FILTERED_RDF_FILENAME = "IndividualRdfAssemblerTest.filteredRdf.n3";
private static final String UNFILTERED_RDF_FILENAME = "IndividualRdfAssemblerTest.unfilteredRdf.n3";
private static final String[] REAL_WORLD_PROPERTIES = {
"http://vivoweb.org/ontology/core#overview",
"http://vivoweb.org/ontology/core#hasResearchArea",
"http://vivoweb.org/ontology/core#researchAreaOf" };
private OntModel rawRdf;
private OntModel expectedLod;
private OntModel actualLod;
private ServletContextStub ctx;
private HttpSessionStub session;
private HttpServletRequestStub req;
private VitroRequest vreq;
private RDFServiceModel rdfService;
private IndividualRdfAssembler ira;
@Before
public void setLoggingLevels() {
setLoggerLevel(ModelAccess.class, Level.ERROR);
// setLoggerLevel(IndividualRdfAssembler.class, Level.DEBUG);
// setLoggerLevel(RDFServiceStub.class, Level.DEBUG);
}
@Before
public void setup() throws IOException {
ctx = new ServletContextStub();
session = new HttpSessionStub();
session.setServletContext(ctx);
req = new HttpServletRequestStub();
req.setSession(session);
req.setRequestUrl(new URL(DOCUMENT_URI));
}
@Test
public void getOutgoingStatements() {
Statement s1 = dataStmt(INDIVIDUAL_URI, DP1, "value");
Statement s2 = objectStmt(INDIVIDUAL_URI, OP1, I1);
rawRdf = model(s1, s2);
expectedLod = includeDocInfo(model(s1, s2));
policyUnrestricted();
filterAndCompare("getOutgoingStatements");
}
@Test
public void filterOutgoingStatements() {
Statement s1 = dataStmt(INDIVIDUAL_URI, DP1, "value");
Statement s2 = objectStmt(INDIVIDUAL_URI, OP1, I1);
rawRdf = model(s1, s2);
expectedLod = includeDocInfo(model());
policyRestrictByPredicate(DP1, OP1);
filterAndCompare("filterOutgoingStatements");
}
@Test
public void getIncomingStatements() {
Statement s1 = objectStmt(I1, OP1, INDIVIDUAL_URI);
rawRdf = model(s1);
expectedLod = includeDocInfo(model(s1));
policyUnrestricted();
filterAndCompare("getIncomingStatements");
}
@Test
public void filterIncomingStatements() {
Statement s1 = objectStmt(I1, OP1, INDIVIDUAL_URI);
rawRdf = model(s1);
expectedLod = includeDocInfo(model());
policyRestrictByPredicate(OP1);
filterAndCompare("filterIncomingStatements");
}
@Test
public void getLabelAndTypeOfOutgoingObjects() {
Statement s1 = objectStmt(INDIVIDUAL_URI, OP1, I1);
Statement s2 = dataStmt(I1, LABEL, "silly label");
Statement s3 = objectStmt(I1, RDF_TYPE, C1);
rawRdf = model(s1, s2, s3);
expectedLod = includeDocInfo(model(s1, s2, s3));
policyUnrestricted();
filterAndCompare("getLabelAndTypeOfOutgoingObjects");
}
@Test
public void filterOrphanStatementsOfOutgoingObjects() {
Statement s1 = objectStmt(INDIVIDUAL_URI, OP1, I1);
Statement s2 = dataStmt(I1, LABEL, "silly label");
Statement s3 = objectStmt(I1, RDF_TYPE, C1);
rawRdf = model(s1, s2, s3);
expectedLod = includeDocInfo(model());
policyRestrictByPredicate(OP1);
filterAndCompare("filterOrphanStatementsOfOutgoingObjects");
}
@Test
public void getLabelAndTypeOfIncomingObjects() {
Statement s1 = objectStmt(I1, OP1, INDIVIDUAL_URI);
Statement s2 = dataStmt(I1, LABEL, "silly label");
Statement s3 = objectStmt(I1, RDF_TYPE, C1);
rawRdf = model(s1, s2, s3);
expectedLod = includeDocInfo(model(s1, s2, s3));
policyUnrestricted();
filterAndCompare("getLabelAndTypeOfIncomingObjects");
}
@Test
public void filterOrphanStatementsOfIncomingObjects() {
Statement s1 = objectStmt(I1, OP1, INDIVIDUAL_URI);
Statement s2 = dataStmt(I1, LABEL, "silly label");
Statement s3 = objectStmt(I1, RDF_TYPE, C1);
rawRdf = model(s1, s2, s3);
expectedLod = includeDocInfo(model());
policyRestrictByPredicate(OP1);
filterAndCompare("filterOrphanStatementsOfIncomingObjects");
}
@Test
public void getTypeStatements() {
Statement s1 = objectStmt(INDIVIDUAL_URI, RDF_TYPE, C1);
rawRdf = model(s1);
expectedLod = includeDocInfo(model(s1));
policyUnrestricted();
filterAndCompare("getTypeStatements");
}
@Test
public void filterTypeStatements() {
Statement s1 = objectStmt(INDIVIDUAL_URI, RDF_TYPE, C1);
rawRdf = model(s1);
expectedLod = includeDocInfo(model());
policyRestrictByClass(C1);
filterAndCompare("filterTypeStatements");
}
@Test
public void getTypeAndLabelOfType() {
Statement s1 = objectStmt(INDIVIDUAL_URI, RDF_TYPE, C1);
Statement s2 = dataStmt(C1, LABEL, "silly label");
Statement s3 = objectStmt(C1, RDF_TYPE, C2);
rawRdf = model(s1, s2, s3);
expectedLod = includeDocInfo(model(s1, s2, s3));
policyUnrestricted();
filterAndCompare("getTypeAndLabelOfType");
}
@Test
public void filterOrphanTypeAndLabelOfType() {
Statement s1 = objectStmt(INDIVIDUAL_URI, RDF_TYPE, C1);
Statement s2 = dataStmt(I1, LABEL, "silly label");
Statement s3 = objectStmt(I1, RDF_TYPE, C2);
rawRdf = model(s1, s2, s3);
expectedLod = includeDocInfo(model());
policyRestrictByClass(C1);
filterAndCompare("filterOrphanTypeAndLabelOfType");
}
@Test
public void dontGetOtherStatementsFromOutgoingObjects() {
Statement s1 = objectStmt(INDIVIDUAL_URI, OP1, I1);
Statement s2 = dataStmt(I1, DP1, "silly data property");
rawRdf = model(s1, s2);
expectedLod = includeDocInfo(model(s1));
policyUnrestricted();
filterAndCompare("dontGetOtherStatementsFromOutgoingObjects");
}
@Test
public void dontGetOtherStatementsFromIncomingObjects() {
Statement s1 = objectStmt(I1, OP1, INDIVIDUAL_URI);
Statement s2 = dataStmt(I1, DP1, "silly data property");
rawRdf = model(s1, s2);
expectedLod = includeDocInfo(model(s1));
policyUnrestricted();
filterAndCompare("dontGetOtherStatementsFromIncomingObjects");
}
@Test
public void dontGetUnrelatedStatements() {
Statement s1 = dataStmt(I1, DP1, "silly data property");
rawRdf = model(s1);
expectedLod = includeDocInfo(model());
policyUnrestricted();
filterAndCompare("dontGetUnrelatedStatements");
}
@Test
public void realWorldTestRoot() throws IOException {
rawRdf = readModelFromFile(RAW_RDF_FILENAME, "N3");
expectedLod = readModelFromFile(UNFILTERED_RDF_FILENAME, "N3");
policyUnrestricted();
filterAndCompare("real world test - root");
}
@Test
public void realWorldTestPublic() throws IOException {
rawRdf = readModelFromFile(RAW_RDF_FILENAME, "N3");
expectedLod = readModelFromFile(FILTERED_RDF_FILENAME, "N3");
policyRestrictByPredicate(REAL_WORLD_PROPERTIES);
filterAndCompare("real world test - public");
}
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
private Statement dataStmt(String subjectUri, String predicateUri,
String value) {
Resource subject = ResourceFactory.createResource(subjectUri);
Property predicate = ResourceFactory.createProperty(predicateUri);
Literal object = ResourceFactory.createPlainLiteral(value);
return ResourceFactory.createStatement(subject, predicate, object);
}
private Statement objectStmt(String subjectUri, String predicateUri,
String objectUri) {
Resource subject = ResourceFactory.createResource(subjectUri);
Property predicate = ResourceFactory.createProperty(predicateUri);
Resource object = ResourceFactory.createResource(objectUri);
return ResourceFactory.createStatement(subject, predicate, object);
}
private OntModel model(Statement... stmts) {
OntModel m = ModelFactory.createOntologyModel(OWL_MEM);
m.add(Arrays.asList(stmts));
return m;
}
private OntModel includeDocInfo(OntModel m) {
List<Statement> list = new ArrayList<>();
list.add(dataStmt(DOCUMENT_URI, LABEL, "RDF description of "
+ INDIVIDUAL_URI));
list.add(dataStmt(DOCUMENT_URI, DATE_DATA_PROPERTY, "bogusTimeStamp"));
list.add(objectStmt(DOCUMENT_URI, RDF_TYPE,
"http://xmlns.com/foaf/0.1/Document"));
list.add(objectStmt(DOCUMENT_URI,
"http://purl.org/dc/elements/1.1/publisher",
"http://vivo.mydomain.edu"));
list.add(objectStmt(DOCUMENT_URI,
"http://purl.org/dc/elements/1.1/rights",
"http://vivo.mydomain.edu/termsOfUse"));
m.add(list);
return m;
}
private void policyUnrestricted() {
ServletPolicyList.addPolicy(ctx, new UnrestrictedPolicy());
}
private void policyRestrictByPredicate(String... predicateUris) {
ServletPolicyList.addPolicy(ctx, new RestrictionsPolicy(predicateUris,
new String[0]));
}
private void policyRestrictByClass(String... classUris) {
ServletPolicyList.addPolicy(ctx, new RestrictionsPolicy(new String[0],
classUris));
}
private void filterAndCompare(String message) {
setupIndividualRdfAssembler();
actualLod = runGetRdf();
List<Statement> missing = modelDifference(expectedLod, actualLod);
List<Statement> extra = modelDifference(actualLod, expectedLod);
removeMatchingDateStatements(missing, extra);
if (missing.isEmpty() && extra.isEmpty()) {
return;
}
failComparison(message, missing, extra);
}
private void setupIndividualRdfAssembler() {
rdfService = new RDFServiceModel(rawRdf);
req.setAttribute("rdfService", rdfService);
req.setAttribute("unfilteredRDFService", rdfService);
vreq = new VitroRequest(req);
ira = new IndividualRdfAssembler(vreq, INDIVIDUAL_URI, ContentType.N3);
}
private OntModel runGetRdf() {
try {
Method m = IndividualRdfAssembler.class.getDeclaredMethod("getRdf");
m.setAccessible(true);
return (OntModel) m.invoke(ira);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private void failComparison(String message, List<Statement> missing,
List<Statement> extra) {
StringWriter sw = new StringWriter();
PrintWriter w = new PrintWriter(sw);
w.println(message);
writeStatementList("Missing statements:", missing, w);
writeStatementList("Extra statements:", extra, w);
System.err.print(sw.toString());
fail(sw.toString());
}
private void writeStatementList(String label, List<Statement> list,
PrintWriter w) {
if (list.isEmpty()) {
return;
}
w.println(label);
for (Statement s : list) {
w.println(" " + s);
}
}
private List<Statement> modelDifference(OntModel first, OntModel second) {
OntModel temp = ModelFactory.createOntologyModel(OWL_MEM);
temp.add(first);
temp.remove(statementList(second));
return statementList(temp);
}
@SuppressWarnings("unchecked")
private List<Statement> statementList(OntModel m) {
return IteratorUtils.toList(m.listStatements());
}
/**
* If two date statements have the same subject, then lets assume that their
* dates are the same. In fact, the actual date statement will have the
* current date/time.
*/
private void removeMatchingDateStatements(List<Statement> list1,
List<Statement> list2) {
for (Iterator<Statement> it1 = list1.iterator(); it1.hasNext();) {
Statement stmt1 = it1.next();
String subject1 = stmt1.getSubject().getURI();
String predicate1 = stmt1.getPredicate().getURI();
if (DATE_DATA_PROPERTY.equals(predicate1)) {
for (Iterator<Statement> it2 = list2.iterator(); it2.hasNext();) {
Statement stmt2 = it2.next();
String subject2 = stmt2.getSubject().getURI();
String predicate2 = stmt2.getPredicate().getURI();
if (predicate1.equals(predicate2)
&& subject1.equals(subject2)) {
it1.remove();
it2.remove();
}
}
}
}
}
// ----------------------------------------------------------------------
// Helper class
// ----------------------------------------------------------------------
private abstract static class AbstractTestPolicy implements PolicyIface {
@Override
public PolicyDecision isAuthorized(IdentifierBundle whoToAuth,
RequestedAction whatToAuth) {
if (whatToAuth instanceof PublishDataPropertyStatement) {
return filterDataProperty((PublishDataPropertyStatement) whatToAuth);
} else if (whatToAuth instanceof PublishObjectPropertyStatement) {
return filterObjectProperty((PublishObjectPropertyStatement) whatToAuth);
} else {
return inconclusive("Bogus");
}
}
private PolicyDecision filterDataProperty(
PublishDataPropertyStatement pdps) {
return filter(pdps.getPredicateUri(), null);
}
private PolicyDecision filterObjectProperty(
PublishObjectPropertyStatement pops) {
String propertyUri = pops.getPredicateUri();
if (VitroVocabulary.RDF_TYPE.equals(propertyUri)) {
return filter(propertyUri, pops.getObjectUri());
} else {
return filter(propertyUri, null);
}
}
protected abstract PolicyDecision filter(String propertyUri,
String classUri);
protected BasicPolicyDecision authorized(String message) {
return new BasicPolicyDecision(Authorization.AUTHORIZED, message);
}
protected BasicPolicyDecision inconclusive(String message) {
return new BasicPolicyDecision(Authorization.INCONCLUSIVE, message);
}
}
private static class UnrestrictedPolicy extends AbstractTestPolicy {
@Override
protected PolicyDecision filter(String propertyUri, String classUri) {
return authorized("Totally unrestricted");
}
}
private static class RestrictionsPolicy extends AbstractTestPolicy {
private final List<String> filteredPropertyUris;
private final List<String> filteredClassUris;
public RestrictionsPolicy(String[] filteredPropertyUris,
String[] filteredClassUris) {
this.filteredPropertyUris = Arrays.asList(filteredPropertyUris);
this.filteredClassUris = Arrays.asList(filteredClassUris);
}
@Override
protected PolicyDecision filter(String propertyUri, String classUri) {
if ((propertyUri != null)
&& filteredPropertyUris.contains(propertyUri)) {
return inconclusive("Filtered property: " + propertyUri);
}
if ((classUri != null) && filteredClassUris.contains(classUri)) {
return inconclusive("Filtered class: " + classUri);
}
return authorized("Passed the filters: " + propertyUri + ","
+ classUri);
}
}
}

View file

@ -0,0 +1,163 @@
@prefix ocresd: <http://purl.org/net/OCRe/study_design.owl#> .
@prefix geo: <http://aims.fao.org/aos/geopolitical.owl#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix scires: <http://vivoweb.org/ontology/scientific-research#> .
@prefix cito: <http://purl.org/spar/cito/> .
@prefix fabio: <http://purl.org/spar/fabio/> .
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .
@prefix obo: <http://purl.obolibrary.org/obo/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ocrer: <http://purl.org/net/OCRe/research.owl#> .
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
@prefix event: <http://purl.org/NET/c4dm/event.owl#> .
@prefix bibo: <http://purl.org/ontology/bibo/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix c4o: <http://purl.org/spar/c4o/> .
@prefix vitro-public: <http://vitro.mannlib.cornell.edu/ns/vitro/public#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix vivo: <http://vivoweb.org/ontology/core#> .
<http://vivo.mydomain.edu/individual/n3639>
a vivo:FacultyMember ,
foaf:Person ,
owl:Thing ,
foaf:Agent ,
obo:BFO_0000002 ,
obo:BFO_0000001 ,
obo:BFO_0000004 ;
rdfs:label "Baker, Able "^^xsd:string ;
obo:ARG_2000028 <http://vivo.mydomain.edu/individual/n3972> ;
obo:RO_0000053 <http://vivo.mydomain.edu/individual/n475> ,
<http://vivo.mydomain.edu/individual/n7850> ;
vitro:mostSpecificType
vivo:FacultyMember ;
vivo:freetextKeyword
"Potrezebie, Chattanooga" ;
vivo:hasCollaborator
<http://vivo.mydomain.edu/individual/n7429> ;
vivo:hasResearchArea
<http://www.eionet.europa.eu/gemet/concept/971> ,
<http://vivo.mydomain.edu/individual/n2158> ;
vivo:overview "Just an ordinary chap of simple means and simple desires." ;
vivo:relatedBy <http://vivo.mydomain.edu/individual/n3401> ,
<http://vivo.mydomain.edu/individual/n5855> ,
<http://vivo.mydomain.edu/individual/n2421> ;
vivo:researchOverview
"Whatever strikes my fancy." ;
vivo:scopusId "abaker" .
<http://vivo.mydomain.edu/individual/n3972>
a vcard:Kind ,
obo:BFO_0000031 ,
owl:Thing ,
obo:ARG_2000379 ,
obo:IAO_0000030 ,
obo:BFO_0000002 ,
obo:BFO_0000001 ,
vcard:Individual ;
obo:ARG_2000029 <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n475>
a owl:Thing ,
obo:BFO_0000023 ,
vivo:InvestigatorRole ,
obo:BFO_0000002 ,
obo:BFO_0000017 ,
vivo:PrincipalInvestigatorRole ,
obo:BFO_0000020 ,
obo:BFO_0000001 ,
vivo:ResearcherRole ;
obo:RO_0000052 <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n7850>
a owl:Thing ,
obo:BFO_0000023 ,
obo:BFO_0000017 ,
obo:BFO_0000002 ,
obo:BFO_0000020 ,
obo:BFO_0000001 ,
vivo:LeaderRole ;
rdfs:label "Lead Guitarist"^^xsd:string ;
obo:RO_0000052 <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n7429>
a foaf:Person ,
vivo:FacultyMember ,
foaf:Agent ,
owl:Thing ,
obo:BFO_0000002 ,
obo:BFO_0000001 ,
obo:BFO_0000004 ;
rdfs:label "Yum, Yum " .
<http://www.eionet.europa.eu/gemet/concept/971>
a owl:Thing ,
<http://vivo.mydomain.edu/individual/n7793> ,
skos:Concept ;
rdfs:label "botany"^^xsd:string ;
vivo:researchAreaOf <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n2158>
a owl:Thing ,
skos:Concept ;
rdfs:label "What a concept!"^^xsd:string ;
vivo:researchAreaOf <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n3401>
a owl:Thing ,
vivo:Relationship ,
obo:BFO_0000002 ,
obo:BFO_0000020 ,
obo:BFO_0000001 ,
vivo:Authorship ;
vivo:relates <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n5855>
a vivo:FacultyPosition ,
owl:Thing ,
vivo:Relationship ,
obo:BFO_0000002 ,
obo:BFO_0000020 ,
obo:BFO_0000001 ,
vivo:Position ;
rdfs:label "Functionary"^^xsd:string ;
vivo:relates <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n2421>
a owl:Thing ,
vivo:Relationship ,
obo:BFO_0000002 ,
obo:BFO_0000020 ,
obo:BFO_0000001 ,
vivo:Grant ;
rdfs:label "Cosmogenic Lassitude in Plegmatic Axolotls" ;
vivo:relates <http://vivo.mydomain.edu/individual/n3639> .
obo:BFO_0000001
a owl:Class ;
rdfs:label "Entity" .
obo:BFO_0000002
a owl:Class ;
rdfs:label "Continuant" .
obo:BFO_0000004
a owl:Class ;
rdfs:label "Independent Continuant"@en-US .
vivo:FacultyMember
a owl:Class ;
rdfs:label "Faculty Member"@en-US .
foaf:Person
a owl:Class ;
rdfs:label "Person"@en-US .
foaf:Agent
a owl:Class ;
rdfs:label "Agent"@en-US .
owl:Thing
a owl:Class .

View file

@ -0,0 +1,171 @@
@prefix ocresd: <http://purl.org/net/OCRe/study_design.owl#> .
@prefix geo: <http://aims.fao.org/aos/geopolitical.owl#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix scires: <http://vivoweb.org/ontology/scientific-research#> .
@prefix cito: <http://purl.org/spar/cito/> .
@prefix fabio: <http://purl.org/spar/fabio/> .
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .
@prefix obo: <http://purl.obolibrary.org/obo/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ocrer: <http://purl.org/net/OCRe/research.owl#> .
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
@prefix event: <http://purl.org/NET/c4dm/event.owl#> .
@prefix bibo: <http://purl.org/ontology/bibo/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix c4o: <http://purl.org/spar/c4o/> .
@prefix vitro-public: <http://vitro.mannlib.cornell.edu/ns/vitro/public#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix vivo: <http://vivoweb.org/ontology/core#> .
<http://vivo.mydomain.edu/individual/n3639>
a vivo:FacultyMember ,
foaf:Person ,
owl:Thing ,
foaf:Agent ,
obo:BFO_0000002 ,
obo:BFO_0000001 ,
obo:BFO_0000004 ;
rdfs:label "Baker, Able "^^xsd:string ;
obo:ARG_2000028 <http://vivo.mydomain.edu/individual/n3972> ;
obo:RO_0000053 <http://vivo.mydomain.edu/individual/n475> ,
<http://vivo.mydomain.edu/individual/n7850> ;
vitro:mostSpecificType
vivo:FacultyMember ;
vivo:freetextKeyword
"Potrezebie, Chattanooga" ;
vivo:hasCollaborator
<http://vivo.mydomain.edu/individual/n7429> ;
vivo:hasResearchArea
<http://www.eionet.europa.eu/gemet/concept/971> ,
<http://vivo.mydomain.edu/individual/n2158> ;
vivo:overview "Just an ordinary chap of simple means and simple desires." ;
vivo:relatedBy <http://vivo.mydomain.edu/individual/n3401> ,
<http://vivo.mydomain.edu/individual/n5855> ,
<http://vivo.mydomain.edu/individual/n2421> ;
vivo:researchOverview
"Whatever strikes my fancy." ;
vivo:scopusId "abaker" .
<http://vivo.mydomain.edu/individual/n3972>
a vcard:Kind ,
obo:BFO_0000031 ,
owl:Thing ,
obo:ARG_2000379 ,
obo:IAO_0000030 ,
obo:BFO_0000002 ,
obo:BFO_0000001 ,
vcard:Individual ;
obo:ARG_2000029 <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n475>
a owl:Thing ,
obo:BFO_0000023 ,
vivo:InvestigatorRole ,
obo:BFO_0000002 ,
obo:BFO_0000017 ,
vivo:PrincipalInvestigatorRole ,
obo:BFO_0000020 ,
obo:BFO_0000001 ,
vivo:ResearcherRole ;
obo:RO_0000052 <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n7850>
a owl:Thing ,
obo:BFO_0000023 ,
obo:BFO_0000017 ,
obo:BFO_0000002 ,
obo:BFO_0000020 ,
obo:BFO_0000001 ,
vivo:LeaderRole ;
rdfs:label "Lead Guitarist"^^xsd:string ;
obo:RO_0000052 <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n7429>
a foaf:Person ,
vivo:FacultyMember ,
foaf:Agent ,
owl:Thing ,
obo:BFO_0000002 ,
obo:BFO_0000001 ,
obo:BFO_0000004 ;
rdfs:label "Yum, Yum " .
<http://www.eionet.europa.eu/gemet/concept/971>
a owl:Thing ,
<http://vivo.mydomain.edu/individual/n7793> ,
skos:Concept ;
rdfs:label "botany"^^xsd:string ;
vivo:researchAreaOf <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n2158>
a owl:Thing ,
skos:Concept ;
rdfs:label "What a concept!"^^xsd:string ;
vivo:researchAreaOf <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n3401>
a owl:Thing ,
vivo:Relationship ,
obo:BFO_0000002 ,
obo:BFO_0000020 ,
obo:BFO_0000001 ,
vivo:Authorship ;
vivo:relates <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n5855>
a vivo:FacultyPosition ,
owl:Thing ,
vivo:Relationship ,
obo:BFO_0000002 ,
obo:BFO_0000020 ,
obo:BFO_0000001 ,
vivo:Position ;
rdfs:label "Functionary"^^xsd:string ;
vivo:relates <http://vivo.mydomain.edu/individual/n3639> .
<http://vivo.mydomain.edu/individual/n2421>
a owl:Thing ,
vivo:Relationship ,
obo:BFO_0000002 ,
obo:BFO_0000020 ,
obo:BFO_0000001 ,
vivo:Grant ;
rdfs:label "Cosmogenic Lassitude in Plegmatic Axolotls" ;
vivo:relates <http://vivo.mydomain.edu/individual/n3639> .
obo:BFO_0000001
a owl:Class ;
rdfs:label "Entity" .
obo:BFO_0000002
a owl:Class ;
rdfs:label "Continuant" .
obo:BFO_0000004
a owl:Class ;
rdfs:label "Independent Continuant"@en-US .
vivo:FacultyMember
a owl:Class ;
rdfs:label "Faculty Member"@en-US .
foaf:Person
a owl:Class ;
rdfs:label "Person"@en-US .
foaf:Agent
a owl:Class ;
rdfs:label "Agent"@en-US .
owl:Thing
a owl:Class .
<http://vivo.mydomain.edu/individual/n3639/n3639.n3>
a foaf:Document ;
rdfs:label "RDF description of Baker, Able - http://vivo.mydomain.edu/individual/n3639" ;
<http://purl.org/dc/elements/1.1/date> "2014-03-10T11:08:39"^^xsd:dateTime ;
<http://purl.org/dc/elements/1.1/publisher> <http://vivo.mydomain.edu> ;
<http://purl.org/dc/elements/1.1/rights> <http://vivo.mydomain.edu/termsOfUse> .

View file

@ -2,7 +2,9 @@
package edu.cornell.mannlib.vitro.webapp.dao.filtering;
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_URI;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.*;
import static org.junit.Assert.fail;
import java.util.ArrayList;
@ -82,12 +84,22 @@ public class IndividualFilteringByStatementTest extends AbstractTestClass {
private static final String URI_VISIBLE_OBJECT_ORDINARY = "object://visible_on_ordinary";
private static final String URI_MAYBE_OBJECT_ORDINARY = "object://maybe_on_ordinary";
private static final String FAUX_DOMAIN_VISIBLE = "faux://visibleDomain";
private static final String FAUX_RANGE_VISIBLE = "faux://visibleRange";
private static final String FAUX_DOMAIN_HIDDEN = "faux://hiddenDomain";
private static final String FAUX_RANGE_HIDDEN = "faux://hiddenRange";
private static final String URI_FAUX_VISIBLE_ORDINARY = "object://faux_visible_on_ordinary";
private static final String URI_FAUX_HIDDEN_ORDINARY = "object://faux_hidden_on_ordinary";
private IndividualStub indSpecial;
private IndividualStub indOrdinary;
private Individual filteredSpecial;
private Individual filteredOrdinary;
@Before
public void createIndividuals() {
IndividualStub indSpecial = new IndividualStub(URI_INDIVIDUAL_SPECIAL);
indSpecial = new IndividualStub(URI_INDIVIDUAL_SPECIAL);
indSpecial.addDataPropertyStatement(PROPERTY_DATA_HIDDEN,
VALUE_HIDDEN_DATA_SPECIAL);
@ -96,17 +108,17 @@ public class IndividualFilteringByStatementTest extends AbstractTestClass {
indSpecial.addDataPropertyStatement(PROPERTY_DATA_MAYBE,
VALUE_MAYBE_DATA_SPECIAL);
indSpecial.addObjectPropertyStatement(PROPERTY_OBJECT_HIDDEN,
indSpecial.addObjectPropertyStatement(property(PROPERTY_OBJECT_HIDDEN),
URI_HIDDEN_OBJECT_SPECIAL);
indSpecial.addObjectPropertyStatement(PROPERTY_OBJECT_VISIBLE,
URI_VISIBLE_OBJECT_SPECIAL);
indSpecial.addObjectPropertyStatement(PROPERTY_OBJECT_MAYBE,
indSpecial.addObjectPropertyStatement(
property(PROPERTY_OBJECT_VISIBLE), URI_VISIBLE_OBJECT_SPECIAL);
indSpecial.addObjectPropertyStatement(property(PROPERTY_OBJECT_MAYBE),
URI_MAYBE_OBJECT_SPECIAL);
filteredSpecial = new IndividualFiltering(indSpecial,
new IndividualBasedFilter());
IndividualStub indOrdinary = new IndividualStub("someOtherUri");
indOrdinary = new IndividualStub("someOtherUri");
indOrdinary.addDataPropertyStatement(PROPERTY_DATA_HIDDEN,
VALUE_HIDDEN_DATA_ORDINARY);
@ -115,17 +127,30 @@ public class IndividualFilteringByStatementTest extends AbstractTestClass {
indOrdinary.addDataPropertyStatement(PROPERTY_DATA_MAYBE,
VALUE_MAYBE_DATA_ORDINARY);
indOrdinary.addObjectPropertyStatement(PROPERTY_OBJECT_HIDDEN,
URI_HIDDEN_OBJECT_ORDINARY);
indOrdinary.addObjectPropertyStatement(PROPERTY_OBJECT_VISIBLE,
URI_VISIBLE_OBJECT_ORDINARY);
indOrdinary.addObjectPropertyStatement(PROPERTY_OBJECT_MAYBE,
indOrdinary.addObjectPropertyStatement(
property(PROPERTY_OBJECT_HIDDEN), URI_HIDDEN_OBJECT_ORDINARY);
indOrdinary.addObjectPropertyStatement(
property(PROPERTY_OBJECT_VISIBLE), URI_VISIBLE_OBJECT_ORDINARY);
indOrdinary.addObjectPropertyStatement(property(PROPERTY_OBJECT_MAYBE),
URI_MAYBE_OBJECT_ORDINARY);
filteredOrdinary = new IndividualFiltering(indOrdinary,
new IndividualBasedFilter());
}
private ObjectProperty property(String propertyUri) {
return property(propertyUri, SOME_URI, SOME_URI);
}
private ObjectProperty property(String propertyUri, String domainUri,
String rangeUri) {
ObjectProperty op = new ObjectProperty();
op.setURI(propertyUri);
op.setDomainVClassURI(domainUri);
op.setRangeVClassURI(rangeUri);
return op;
}
// ----------------------------------------------------------------------
// Tests on data properties
// ----------------------------------------------------------------------
@ -363,6 +388,41 @@ public class IndividualFilteringByStatementTest extends AbstractTestClass {
fail("onOrdinary_getPopulatedObjectPropertyList not implemented");
}
// ----------------------------------------------------------------------
// Tests on Faux object properties
// ----------------------------------------------------------------------
@Test
public void hiddenFauxWithVisibleBase() {
indOrdinary.addObjectPropertyStatement(
property(PROPERTY_OBJECT_VISIBLE, FAUX_DOMAIN_HIDDEN,
FAUX_RANGE_HIDDEN), URI_FAUX_HIDDEN_ORDINARY);
filteredOrdinary = new IndividualFiltering(indOrdinary,
new IndividualBasedFilter());
List<ObjectPropertyStatement> expected = opsList(filteredOrdinary,
ops(PROPERTY_OBJECT_VISIBLE, URI_VISIBLE_OBJECT_ORDINARY));
List<ObjectPropertyStatement> actual = filteredOrdinary
.getObjectPropertyStatements();
assertEquivalentOpsList("hidden faux is not visible", expected, actual);
}
@Test
public void visibleFauxWithHiddenBase() {
indOrdinary.addObjectPropertyStatement(
property(PROPERTY_OBJECT_HIDDEN, FAUX_DOMAIN_VISIBLE,
FAUX_RANGE_VISIBLE), URI_FAUX_VISIBLE_ORDINARY);
filteredOrdinary = new IndividualFiltering(indOrdinary,
new IndividualBasedFilter());
List<ObjectPropertyStatement> expected = opsList(filteredOrdinary,
ops(PROPERTY_OBJECT_VISIBLE, URI_VISIBLE_OBJECT_ORDINARY),
ops(PROPERTY_OBJECT_HIDDEN, URI_FAUX_VISIBLE_ORDINARY));
List<ObjectPropertyStatement> actual = filteredOrdinary
.getObjectPropertyStatements();
assertEquivalentOpsList("visible faux even if base is hidden",
expected, actual);
}
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
@ -726,14 +786,33 @@ public class IndividualFilteringByStatementTest extends AbstractTestClass {
@Override
public Boolean fn(ObjectPropertyStatement ops) {
if (PROPERTY_OBJECT_VISIBLE.equals(ops.getPropertyURI())) {
return true;
if (isFauxHidden(ops)) {
return false;
} else {
return true;
}
}
if (PROPERTY_OBJECT_MAYBE.equals(ops.getPropertyURI())
&& URI_INDIVIDUAL_SPECIAL.equals(ops.getSubjectURI())) {
return true;
}
if (isFauxVisible(ops)) {
return true;
}
return false;
}
private boolean isFauxHidden(ObjectPropertyStatement ops) {
ObjectProperty prop = ops.getProperty();
return FAUX_DOMAIN_HIDDEN.equals(prop.getDomainVClassURI())
&& FAUX_RANGE_HIDDEN.equals(prop.getRangeVClassURI());
}
private boolean isFauxVisible(ObjectPropertyStatement ops) {
ObjectProperty prop = ops.getProperty();
return FAUX_DOMAIN_VISIBLE.equals(prop.getDomainVClassURI())
&& FAUX_RANGE_VISIBLE.equals(prop.getRangeVClassURI());
}
}
// ----------------------------------------------------------------------

View file

@ -75,6 +75,7 @@ public class DataPropertyDaoJenaTest extends AbstractTestClass {
property1.setPropertyValue(subModel.createProperty(VitroVocabulary.DISPLAY_LIMIT), subModel.createTypedLiteral(5));
property1.setPropertyValue(subModel.createProperty(VitroVocabulary.HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT), subModel.createResource("http://vitro.mannlib.cornell.edu/ns/vitro/role#curator"));
property1.setPropertyValue(subModel.createProperty(VitroVocabulary.PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT), subModel.createResource("http://vitro.mannlib.cornell.edu/ns/vitro/role#selfEditor"));
property1.setPropertyValue(subModel.createProperty(VitroVocabulary.HIDDEN_FROM_PUBLISH_BELOW_ROLE_LEVEL_ANNOT), subModel.createResource("http://vitro.mannlib.cornell.edu/ns/vitro/role#editor"));
property1.setPropertyValue(subModel.createProperty(VitroVocabulary.PROPERTY_INPROPERTYGROUPANNOT), subModel.createResource("http://thisIsTheInPropertyGroupURI"));
property1.setPropertyValue(subModel.createProperty(VitroVocabulary.PROPERTY_CUSTOMENTRYFORMANNOT), subModel.createResource("http://thisIsTheCustomFormEntryURI"));

View file

@ -149,6 +149,7 @@ public class ObjectPropertyDaoJenaTest extends AbstractTestClass {
property1.setPropertyValue(subModel.createProperty(VitroVocabulary.PROPERTY_OBJECTINDIVIDUALSORTPROPERTY), subModel.createResource("http://thisIsTheObjectIndividualSortProperty"));
property1.setPropertyValue(subModel.createProperty(VitroVocabulary.HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT), subModel.createResource("http://vitro.mannlib.cornell.edu/ns/vitro/role#curator"));
property1.setPropertyValue(subModel.createProperty(VitroVocabulary.PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT), subModel.createResource("http://vitro.mannlib.cornell.edu/ns/vitro/role#selfEditor"));
property1.setPropertyValue(subModel.createProperty(VitroVocabulary.HIDDEN_FROM_PUBLISH_BELOW_ROLE_LEVEL_ANNOT), subModel.createResource("http://vitro.mannlib.cornell.edu/ns/vitro/role#editor"));
property1.setPropertyValue(subModel.createProperty(VitroVocabulary.PROPERTY_INPROPERTYGROUPANNOT), subModel.createResource("http://thisIsTheInPropertyGroupURI"));
property1.setPropertyValue(subModel.createProperty(VitroVocabulary.PROPERTY_CUSTOMENTRYFORMANNOT), subModel.createResource("http://thisIsTheCustomFormEntryURI"));
property1.setPropertyValue(subModel.createProperty(VitroVocabulary.PROPERTY_SELECTFROMEXISTINGANNOT), subModel.createTypedLiteral(true));

View file

@ -70,6 +70,7 @@ public class VClassDaoTest {
class1.setPropertyValue(subModel.createProperty(VitroVocabulary.SEARCH_BOOST_ANNOT), subModel.createTypedLiteral(2.4f));
class1.setPropertyValue(subModel.createProperty(VitroVocabulary.HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT), subModel.createResource("http://vitro.mannlib.cornell.edu/ns/vitro/role#curator"));
class1.setPropertyValue(subModel.createProperty(VitroVocabulary.PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT), subModel.createResource("http://vitro.mannlib.cornell.edu/ns/vitro/role#selfEditor"));
class1.setPropertyValue(subModel.createProperty(VitroVocabulary.HIDDEN_FROM_PUBLISH_BELOW_ROLE_LEVEL_ANNOT), subModel.createResource("http://vitro.mannlib.cornell.edu/ns/vitro/role#editor"));
class1.setPropertyValue(subModel.createProperty(VitroVocabulary.PROPERTY_CUSTOMENTRYFORMANNOT), subModel.createTypedLiteral("this is the custom entry form annotation"));
class1.setPropertyValue(subModel.createProperty(VitroVocabulary.PROPERTY_CUSTOMDISPLAYVIEWANNOT), subModel.createTypedLiteral("this is the custom display view annotation"));
class1.setPropertyValue(subModel.createProperty(VitroVocabulary.PROPERTY_CUSTOMSHORTVIEWANNOT), subModel.createTypedLiteral("this is the custom short view annotation"));

View file

@ -92,6 +92,7 @@ public class VClassJenaTest {
class1.setPropertyValue(ontModel.createProperty(VitroVocabulary.SEARCH_BOOST_ANNOT), ontModel.createTypedLiteral(2.4f));
class1.setPropertyValue(ontModel.createProperty(VitroVocabulary.HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT), ontModel.createResource("http://vitro.mannlib.cornell.edu/ns/vitro/role#curator"));
class1.setPropertyValue(ontModel.createProperty(VitroVocabulary.PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT), ontModel.createResource("http://vitro.mannlib.cornell.edu/ns/vitro/role#selfEditor"));
class1.setPropertyValue(ontModel.createProperty(VitroVocabulary.HIDDEN_FROM_PUBLISH_BELOW_ROLE_LEVEL_ANNOT), ontModel.createResource("http://vitro.mannlib.cornell.edu/ns/vitro/role#editor"));
class1.setPropertyValue(ontModel.createProperty(VitroVocabulary.PROPERTY_CUSTOMENTRYFORMANNOT), ontModel.createTypedLiteral("this is the custom entry form annotation"));
class1.setPropertyValue(ontModel.createProperty(VitroVocabulary.PROPERTY_CUSTOMDISPLAYVIEWANNOT), ontModel.createTypedLiteral("this is the custom display view annotation"));
class1.setPropertyValue(ontModel.createProperty(VitroVocabulary.PROPERTY_CUSTOMSHORTVIEWANNOT), ontModel.createTypedLiteral("this is the custom short view annotation"));
@ -126,6 +127,7 @@ public class VClassJenaTest {
Assert.assertEquals(vClassJena.getSearchBoost(), vClass.getSearchBoost());
Assert.assertEquals(vClassJena.getHiddenFromDisplayBelowRoleLevel(), vClass.getHiddenFromDisplayBelowRoleLevel());
Assert.assertEquals(vClassJena.getProhibitedFromUpdateBelowRoleLevel(), vClass.getProhibitedFromUpdateBelowRoleLevel());
Assert.assertEquals(vClassJena.getHiddenFromPublishBelowRoleLevel(), vClass.getHiddenFromPublishBelowRoleLevel());
}
@ -156,6 +158,7 @@ public class VClassJenaTest {
protected AnnotationProperty LOCAL_PROPERTY_CUSTOMSEARCHVIEWANNOT = _constModel.createAnnotationProperty(VitroVocabulary.PROPERTY_CUSTOMSEARCHVIEWANNOT);
protected AnnotationProperty LOCAL_HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT = _constModel.createAnnotationProperty(VitroVocabulary.HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT);
protected AnnotationProperty LOCAL_PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT = _constModel.createAnnotationProperty(VitroVocabulary.PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT);
protected AnnotationProperty LOCAL_HIDDEN_FROM_PUBLISH_BELOW_ROLE_LEVEL_ANNOT = _constModel.createAnnotationProperty(VitroVocabulary.HIDDEN_FROM_PUBLISH_BELOW_ROLE_LEVEL_ANNOT);
protected AnnotationProperty LOCAL_IN_CLASSGROUP = _constModel.createAnnotationProperty(VitroVocabulary.IN_CLASSGROUP);
@ -234,6 +237,25 @@ public class VClassJenaTest {
}
vcw.setProhibitedFromUpdateBelowRoleLevel(prohibitedRoleLevel);//this might get set to null
//There might be multiple LOCAL_HIDDEN_FROM_PUBLISH_BELOW_ROLE_LEVEL_ANNOT properties, only use the highest
it = cls.listProperties(LOCAL_HIDDEN_FROM_PUBLISH_BELOW_ROLE_LEVEL_ANNOT);
BaseResourceBean.RoleLevel publishRoleLevel = null;
while( it.hasNext() ){
Statement stmt = it.nextStatement();
RDFNode obj;
if( stmt != null && (obj = stmt.getObject()) != null && obj.isURIResource() ){
Resource res = (Resource)obj.as(Resource.class);
if( res != null && res.getURI() != null ){
BaseResourceBean.RoleLevel roleFromModel = BaseResourceBean.RoleLevel.getRoleByUri(res.getURI());
if( roleFromModel != null &&
(publishRoleLevel == null || roleFromModel.compareTo(publishRoleLevel) > 0 )){
publishRoleLevel = roleFromModel;
}
}
}
}
vcw.setHiddenFromPublishBelowRoleLevel(publishRoleLevel);//this might get set to null
} finally {
cls.getModel().leaveCriticalSection();
}

View file

@ -8,8 +8,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.sdb.util.Pair;
import com.hp.hpl.jena.vocabulary.OWL;
@ -27,7 +25,6 @@ public class PropertyRestrictionPolicyHelperStub extends
return getInstance(null, null);
}
/** Prohibit some namespaces. */
public static PropertyRestrictionPolicyHelperStub getInstance(
String[] restrictedNamespaces) {
@ -44,30 +41,28 @@ public class PropertyRestrictionPolicyHelperStub extends
if (restrictedNamespaces != null) {
namespaceSet.addAll(Arrays.asList(restrictedNamespaces));
}
Map<Pair<String, Pair<String,String>>, RoleLevel> thresholdMap = new HashMap<
Pair<String, Pair<String,String>>, RoleLevel>();
Map<Pair<String, Pair<String, String>>, RoleLevel> thresholdMap = new HashMap<>();
if (restrictedProperties != null) {
for (String prop : restrictedProperties) {
thresholdMap.put(
new Pair<String, Pair<String, String>>(
OWL.Thing.getURI(), new Pair<String, String>(
prop, OWL.Thing.getURI())),
RoleLevel.NOBODY);
thresholdMap.put(new Pair<String, Pair<String, String>>(
OWL.Thing.getURI(), new Pair<String, String>(prop,
OWL.Thing.getURI())), RoleLevel.NOBODY);
}
}
return new PropertyRestrictionPolicyHelperStub(namespaceSet, null,
null, thresholdMap);
null, thresholdMap, null);
}
private PropertyRestrictionPolicyHelperStub(
Set<String> modifyRestrictedNamespaces,
Set<String> modifyPermittedExceptions,
Map<Pair<String, Pair<String,String>>, RoleLevel> displayThresholds,
Map<Pair<String, Pair<String,String>>, RoleLevel> modifyThresholds) {
Map<Pair<String, Pair<String, String>>, RoleLevel> displayThresholds,
Map<Pair<String, Pair<String, String>>, RoleLevel> modifyThresholds,
Map<Pair<String, Pair<String, String>>, RoleLevel> publishThresholds) {
super(modifyRestrictedNamespaces, modifyPermittedExceptions,
displayThresholds, modifyThresholds, ModelFactory.createDefaultModel());
displayThresholds, modifyThresholds, publishThresholds);
}
}

View file

@ -12,6 +12,9 @@ import java.util.Set;
import org.json.JSONException;
import org.json.JSONObject;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
@ -21,6 +24,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
/**
* Mock the basic functions of Individual for unit tests.
@ -31,6 +35,8 @@ public class IndividualStub implements Individual {
// ----------------------------------------------------------------------
private final String uri;
private final String namespace;
private final String localName;
private final Set<DataPropertyStatement> dpsSet = new HashSet<DataPropertyStatement>();
private final Set<ObjectPropertyStatement> opsSet = new HashSet<ObjectPropertyStatement>();
@ -40,27 +46,25 @@ public class IndividualStub implements Individual {
public IndividualStub(String uri) {
this.uri = uri;
Resource r = ResourceFactory.createResource(uri);
this.namespace = r.getNameSpace();
this.localName = r.getLocalName();
}
public void addDataPropertyStatement(String predicateUri, String object) {
dpsSet.add(new DataPropertyStatementImpl(this.uri, predicateUri, object));
}
public void addObjectPropertyStatement(String predicateUri, String objectUri) {
opsSet.add(new ObjectPropertyStatementImpl(this.uri, predicateUri,
objectUri));
public void addObjectPropertyStatement(ObjectProperty property, String objectUri) {
ObjectPropertyStatementImpl ops = new ObjectPropertyStatementImpl();
ops.setSubject(this);
ops.setProperty(property);
ops.setObjectURI(objectUri);
opsSet.add(ops);
}
public void addPopulatedObjectPropertyStatement(String predicateUri,
String objectUri, Individual object) {
ObjectPropertyStatementImpl stmt = new ObjectPropertyStatementImpl(
this.uri, predicateUri, objectUri);
stmt.setObject(object);
opsSet.add(stmt);
}
public void addVclass(String namespace, String localname, String vClassName) {
vClasses.add(new VClass(namespace, localname, vClassName));
public void addVclass(String ns, String localname, String vClassName) {
vClasses.add(new VClass(ns, localname, vClassName));
}
// ----------------------------------------------------------------------
@ -72,6 +76,22 @@ public class IndividualStub implements Individual {
return uri;
}
@Override
public boolean isAnonymous() {
return (this.uri == null || VitroVocabulary.PSEUDO_BNODE_NS.equals(this
.getNamespace()));
}
@Override
public String getLocalName() {
return this.localName;
}
@Override
public String getNamespace() {
return this.namespace;
}
@Override
public void setName(String name) {
this.name = name;
@ -81,17 +101,17 @@ public class IndividualStub implements Individual {
public String getName() {
return name;
}
@Override
@Override
public String getLabel() {
return getName();
return getName();
}
@Override
public String getPickListName() {
return getName();
return getName();
}
@Override
public List<DataPropertyStatement> getDataPropertyStatements() {
return new ArrayList<DataPropertyStatement>(dpsSet);
@ -146,7 +166,6 @@ public class IndividualStub implements Individual {
return null;
}
@Override
public boolean isVClass(String vclassUri) {
for (VClass vc : vClasses) {
@ -167,12 +186,6 @@ public class IndividualStub implements Individual {
// does nothing.
}
@Override
public String getLocalName() {
// Useless for now.
return "BOGUS Local Name";
}
@Override
public VClass getVClass() {
for (VClass vc : vClasses) {
@ -198,69 +211,75 @@ public class IndividualStub implements Individual {
// Un-implemented methods
// ----------------------------------------------------------------------
@Override
public boolean isAnonymous() {
throw new RuntimeException(
"ResourceBean.isAnonymous() not implemented.");
}
@Override
public void setURI(String URI) {
throw new RuntimeException("ResourceBean.setURI() not implemented.");
}
@Override
public String getNamespace() {
throw new RuntimeException(
"ResourceBean.getNamespace() not implemented.");
throw new RuntimeException("IndividualStub.setURI() not implemented.");
}
@Override
public void setNamespace(String namespace) {
throw new RuntimeException(
"ResourceBean.setNamespace() not implemented.");
"IndividualStub.setNamespace() not implemented.");
}
@Override
public void setLocalName(String localName) {
throw new RuntimeException(
"ResourceBean.setLocalName() not implemented.");
"IndividualStub.setLocalName() not implemented.");
}
@Override
public RoleLevel getHiddenFromDisplayBelowRoleLevel() {
throw new RuntimeException(
"ResourceBean.getHiddenFromDisplayBelowRoleLevel() not implemented.");
"IndividualStub.getHiddenFromDisplayBelowRoleLevel() not implemented.");
}
@Override
public void setHiddenFromDisplayBelowRoleLevel(RoleLevel eR) {
throw new RuntimeException(
"ResourceBean.setHiddenFromDisplayBelowRoleLevel() not implemented.");
"IndividualStub.setHiddenFromDisplayBelowRoleLevel() not implemented.");
}
@Override
public void setHiddenFromDisplayBelowRoleLevelUsingRoleUri(String roleUri) {
throw new RuntimeException(
"ResourceBean.setHiddenFromDisplayBelowRoleLevelUsingRoleUri() not implemented.");
"IndividualStub.setHiddenFromDisplayBelowRoleLevelUsingRoleUri() not implemented.");
}
@Override
public RoleLevel getProhibitedFromUpdateBelowRoleLevel() {
throw new RuntimeException(
"ResourceBean.getProhibitedFromUpdateBelowRoleLevel() not implemented.");
"IndividualStub.getProhibitedFromUpdateBelowRoleLevel() not implemented.");
}
@Override
public void setProhibitedFromUpdateBelowRoleLevel(RoleLevel eR) {
throw new RuntimeException(
"ResourceBean.setProhibitedFromUpdateBelowRoleLevel() not implemented.");
"IndividualStub.setProhibitedFromUpdateBelowRoleLevel() not implemented.");
}
@Override
public void setProhibitedFromUpdateBelowRoleLevelUsingRoleUri(String roleUri) {
throw new RuntimeException(
"ResourceBean.setProhibitedFromUpdateBelowRoleLevelUsingRoleUri() not implemented.");
"IndividualStub.setProhibitedFromUpdateBelowRoleLevelUsingRoleUri() not implemented.");
}
@Override
public RoleLevel getHiddenFromPublishBelowRoleLevel() {
throw new RuntimeException(
"IndividualStub.getHiddenFromPublishBelowRoleLevel() not implemented.");
}
@Override
public void setHiddenFromPublishBelowRoleLevel(RoleLevel eR) {
throw new RuntimeException(
"IndividualStub.setHiddenFromPublishBelowRoleLevel() not implemented.");
}
@Override
public void setHiddenFromPublishBelowRoleLevelUsingRoleUri(String roleUri) {
throw new RuntimeException(
"IndividualStub.setHiddenFromPublishBelowRoleLevelUsingRoleUri() not implemented.");
}
@Override
@ -271,9 +290,10 @@ public class IndividualStub implements Individual {
@Override
public List<String> getMostSpecificTypeURIs() {
throw new RuntimeException("Individual.getMostSpecificTypeURIs() not implemented.");
throw new RuntimeException(
"Individual.getMostSpecificTypeURIs() not implemented.");
}
@Override
public String getRdfsLabel() {
throw new RuntimeException("Individual.getRdfsLabel() not implemented.");