[
https://issues.apache.org/jira/browse/RYA-119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15703545#comment-15703545
]
ASF GitHub Bot commented on RYA-119:
------------------------------------
Github user isper3at commented on a diff in the pull request:
https://github.com/apache/incubator-rya/pull/124#discussion_r89909627
--- Diff:
dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBRyaDAOTest.java ---
@@ -28,102 +30,279 @@
import org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder;
import org.apache.rya.api.domain.RyaURI;
import org.apache.rya.api.persist.RyaDAOException;
+import org.apache.rya.api.persist.query.RyaQuery;
+import org.apache.rya.mongodb.document.visibility.Authorizations;
+import org.bson.Document;
+import org.calrissian.mango.collect.CloseableIterable;
import org.junit.Before;
import org.junit.Test;
-import com.mongodb.DB;
-import com.mongodb.DBCollection;
import com.mongodb.MongoException;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoDatabase;
public class MongoDBRyaDAOTest extends MongoRyaTestBase {
- private MongoDBRyaDAO dao;
- private MongoDBRdfConfiguration configuration;
+ private MongoDBRyaDAO dao;
+ private MongoDBRdfConfiguration configuration;
- @Before
- public void setUp() throws IOException, RyaDAOException{
- final Configuration conf = new Configuration();
+ @Before
+ public void setUp() throws IOException, RyaDAOException{
+ final Configuration conf = new Configuration();
conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, "test");
conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya_");
conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, "rya_");
configuration = new MongoDBRdfConfiguration(conf);
final int port =
mongoClient.getServerAddressList().get(0).getPort();
configuration.set(MongoDBRdfConfiguration.MONGO_INSTANCE_PORT,
""+port);
- dao = new MongoDBRyaDAO(configuration, mongoClient);
- }
+ dao = new MongoDBRyaDAO(configuration, mongoClient);
+ }
- @Test
- public void testDeleteWildcard() throws RyaDAOException {
- final RyaStatementBuilder builder = new RyaStatementBuilder();
- builder.setPredicate(new RyaURI("http://temp.com"));
- dao.delete(builder.build(), configuration);
- }
+ @Test
+ public void testDeleteWildcard() throws RyaDAOException {
+ final RyaStatementBuilder builder = new RyaStatementBuilder();
+ builder.setPredicate(new RyaURI("http://temp.com"));
+ dao.delete(builder.build(), configuration);
+ }
- @Test
- public void testAdd() throws RyaDAOException, MongoException,
IOException {
- final RyaStatementBuilder builder = new RyaStatementBuilder();
- builder.setPredicate(new RyaURI("http://temp.com"));
- builder.setSubject(new RyaURI("http://subject.com"));
- builder.setObject(new RyaURI("http://object.com"));
+ @Test
+ public void testAdd() throws RyaDAOException, MongoException,
IOException {
+ final RyaStatementBuilder builder = new RyaStatementBuilder();
+ builder.setPredicate(new RyaURI("http://temp.com"));
+ builder.setSubject(new RyaURI("http://subject.com"));
+ builder.setObject(new RyaURI("http://object.com"));
- final DB db =
mongoClient.getDB(configuration.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
- final DBCollection coll =
db.getCollection(configuration.getTriplesCollectionName());
+ final MongoDatabase db =
mongoClient.getDatabase(configuration.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
+ final MongoCollection<Document> coll =
db.getCollection(configuration.getTriplesCollectionName());
- dao.add(builder.build());
+ dao.add(builder.build());
assertEquals(coll.count(),1);
- }
+ }
- @Test
- public void testDelete() throws RyaDAOException, MongoException,
IOException {
- final RyaStatementBuilder builder = new RyaStatementBuilder();
- builder.setPredicate(new RyaURI("http://temp.com"));
- builder.setSubject(new RyaURI("http://subject.com"));
- builder.setObject(new RyaURI("http://object.com"));
- final RyaStatement statement = builder.build();
+ @Test
+ public void testDelete() throws RyaDAOException, MongoException,
IOException {
+ final RyaStatementBuilder builder = new RyaStatementBuilder();
+ builder.setPredicate(new RyaURI("http://temp.com"));
+ builder.setSubject(new RyaURI("http://subject.com"));
+ builder.setObject(new RyaURI("http://object.com"));
+ final RyaStatement statement = builder.build();
- final DB db =
mongoClient.getDB(configuration.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
- final DBCollection coll =
db.getCollection(configuration.getTriplesCollectionName());
+ final MongoDatabase db =
mongoClient.getDatabase(configuration.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
+ final MongoCollection<Document> coll =
db.getCollection(configuration.getTriplesCollectionName());
- dao.add(statement);
+ dao.add(statement);
assertEquals(coll.count(),1);
dao.delete(statement, configuration);
assertEquals(coll.count(),0);
- }
+ }
- @Test
- public void testDeleteWildcardSubjectWithContext() throws
RyaDAOException, MongoException, IOException {
- final RyaStatementBuilder builder = new RyaStatementBuilder();
- builder.setPredicate(new RyaURI("http://temp.com"));
- builder.setSubject(new RyaURI("http://subject.com"));
- builder.setObject(new RyaURI("http://object.com"));
- builder.setContext(new RyaURI("http://context.com"));
- final RyaStatement statement = builder.build();
+ @Test
+ public void testDeleteWildcardSubjectWithContext() throws
RyaDAOException, MongoException, IOException {
+ final RyaStatementBuilder builder = new RyaStatementBuilder();
+ builder.setPredicate(new RyaURI("http://temp.com"));
+ builder.setSubject(new RyaURI("http://subject.com"));
+ builder.setObject(new RyaURI("http://object.com"));
+ builder.setContext(new RyaURI("http://context.com"));
+ final RyaStatement statement = builder.build();
- final DB db =
mongoClient.getDB(configuration.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
- final DBCollection coll =
db.getCollection(configuration.getTriplesCollectionName());
+ final MongoDatabase db =
mongoClient.getDatabase(configuration.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
+ final MongoCollection<Document> coll =
db.getCollection(configuration.getTriplesCollectionName());
- dao.add(statement);
+ dao.add(statement);
assertEquals(coll.count(),1);
- final RyaStatementBuilder builder2 = new RyaStatementBuilder();
- builder2.setPredicate(new RyaURI("http://temp.com"));
- builder2.setObject(new RyaURI("http://object.com"));
- builder2.setContext(new RyaURI("http://context3.com"));
- final RyaStatement query = builder2.build();
+ final RyaStatementBuilder builder2 = new RyaStatementBuilder();
+ builder2.setPredicate(new RyaURI("http://temp.com"));
+ builder2.setObject(new RyaURI("http://object.com"));
+ builder2.setContext(new RyaURI("http://context3.com"));
+ final RyaStatement query = builder2.build();
dao.delete(query, configuration);
assertEquals(coll.count(),1);
- }
+ }
+ @Test
+ public void testVisibility() throws RyaDAOException, MongoException,
IOException {
+ // Doc requires "A" and user has "B" = User CANNOT view
+ assertFalse(testVisibilityStatement("A", new Authorizations("B")));
+
+ // Doc requires "A" and user has "A" = User can view
+ assertTrue(testVisibilityStatement("A", new Authorizations("A")));
+
+ // Doc requires "A" and "B" and user has "A" and "B" = User can
view
+ assertTrue(testVisibilityStatement("A&B", new Authorizations("A",
"B")));
+
+ // Doc requires "A" or "B" and user has "A" and "B" = User can view
+ assertTrue(testVisibilityStatement("A|B", new Authorizations("A",
"B")));
+
+ // Doc requires "A" and user has "A" and "B" = User can view
+ assertTrue(testVisibilityStatement("A", new Authorizations("A",
"B")));
+
+ // Doc requires "A" and user has "A" and "B" and "C" = User can
view
+ assertTrue(testVisibilityStatement("A", new Authorizations("A",
"B", "C")));
+
+ // Doc requires "A" and "B" and user has "A" = User CANNOT view
+ assertFalse(testVisibilityStatement("A&B", new
Authorizations("A")));
+
+ // Doc requires "A" and "B" and "C" and user has "A" and "B" and
"C" = User can view
+ assertTrue(testVisibilityStatement("A&B&C", new
Authorizations("A", "B", "C")));
+
+ // Doc requires "A" and "B" and "C" and user has "A" and "B" =
User CANNOT view
+ assertFalse(testVisibilityStatement("A&B&C", new
Authorizations("A", "B")));
+
+ // Doc requires "A" and "B" and user has "A" and "B" and "C" =
User can view
+ assertTrue(testVisibilityStatement("A&B", new Authorizations("A",
"B", "C")));
+
+ // Doc requires "A" or "B" and user has "A" = User can view
+ assertTrue(testVisibilityStatement("A|B", new
Authorizations("A")));
+
+ // Doc requires "A" or "B" or "C" and user has "A" and "B" and "C"
= User can view
+ assertTrue(testVisibilityStatement("A|B|C", new
Authorizations("A", "B", "C")));
+
+ // Doc requires "A" or "B" or "C" and user has "A" and "B" = User
can view
+ assertTrue(testVisibilityStatement("A|B|C", new
Authorizations("A", "B")));
+
+ // Doc requires "A" or "B" or "C" and user has "A" = User can view
+ assertTrue(testVisibilityStatement("A|B|C", new
Authorizations("A")));
+
+ // Doc requires "A" or "B" and user has "A" and "B" and "C" = User
can view
+ assertTrue(testVisibilityStatement("A|B", new Authorizations("A",
"B", "C")));
+
+ // Doc requires "A" and user has "" = User can view
+ assertTrue(testVisibilityStatement("A", Authorizations.EMPTY));
+
+ // Doc requires "A" and "B" and user has "" = User can view
+ assertTrue(testVisibilityStatement("A&B", Authorizations.EMPTY));
+
+ // Doc requires "A" or "B" and user has "" = User can view
+ assertTrue(testVisibilityStatement("A|B", Authorizations.EMPTY));
--- End diff --
this seems wrong....if Doc requries A or B, shouldn't this be false?
> Add visibility support to MongoDB
> ---------------------------------
>
> Key: RYA-119
> URL: https://issues.apache.org/jira/browse/RYA-119
> Project: Rya
> Issue Type: Improvement
> Components: dao
> Affects Versions: 3.2.10
> Reporter: Andrew Smith
> Assignee: Eric White
>
> Currently, when querying mongo, visibility is ignored. Need to add support
> for visibility when querying mongo.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)