Search in sources :

Example 1 with DocumentVisibility

use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.

the class DisjunctiveNormalFormConverterTest method testConvertToDnf.

/**
 * Test ability to convert expressions into Disjunctive Normal Form.
 */
@Test
public void testConvertToDnf() {
    for (final Pair<String, String> pair : INPUT_AND_EXPECTED_BOOLEAN_EXPRESSIONS) {
        final String input = pair.getLeft();
        final String expected = pair.getRight();
        final DocumentVisibility inputDv = new DocumentVisibility(input);
        final DocumentVisibility resultDv = DisjunctiveNormalFormConverter.convertToDisjunctiveNormalForm(inputDv);
        assertEquals(expected, new String(resultDv.flatten()));
    }
}
Also used : DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility) Test(org.junit.Test)

Example 2 with DocumentVisibility

use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.

the class DisjunctiveNormalFormConverterTest method testTruthTableSize3FromNode.

/**
 * Test truth table with 3 inputs from a node.
 */
@Test
public void testTruthTableSize3FromNode() {
    final DocumentVisibility dv = new DocumentVisibility("(A&B)|(A&C)");
    final byte[][] truthTable = DisjunctiveNormalFormConverter.createTruthTableInputs(dv.getParseTree(), dv.getExpression());
    final byte[][] expected = { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 1, 0 }, { 0, 1, 1 }, { 1, 0, 0 }, { 1, 0, 1 }, { 1, 1, 0 }, { 1, 1, 1 } };
    assertArrayEquals(expected, truthTable);
}
Also used : DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility) Test(org.junit.Test)

Example 3 with DocumentVisibility

use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.

the class DisjunctiveNormalFormConverterTest method testTruthTableNullExpression.

/**
 * Test truth table with a {@code null} expression.
 */
@Test(expected = NullPointerException.class)
public void testTruthTableNullExpression() {
    final Node node = new DocumentVisibility("A").getParseTree();
    final byte[] expression = null;
    DisjunctiveNormalFormConverter.createTruthTableInputs(node, expression);
}
Also used : Node(org.apache.accumulo.core.security.ColumnVisibility.Node) DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility) Test(org.junit.Test)

Example 4 with DocumentVisibility

use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.

the class DocumentVisibilityUtil method multidimensionalArrayToBooleanString.

/**
 * Converts a multidimensional array object representation of the document
 * visibility boolean expression into a string.
 * @param object the multidimensional array object representing the
 * document visibility boolean expression.
 * @return the boolean string expression.
 */
public static String multidimensionalArrayToBooleanString(final Object[] object) {
    final String booleanString = multidimensionalArrayToBooleanStringInternal(object);
    // Simplify and clean up the formatting.
    final DocumentVisibility dv = DisjunctiveNormalFormConverter.createDnfDocumentVisibility(booleanString);
    final byte[] bytes = dv.flatten();
    final String result = new String(bytes, Charsets.UTF_8);
    return result;
}
Also used : DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility)

Example 5 with DocumentVisibility

use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.

the class MongoDBRyaDAOIT method testReconstructDao.

@Test
public void testReconstructDao() throws RyaDAOException, IOException {
    MongoDBRyaDAO dao = new MongoDBRyaDAO();
    try {
        dao.setConf(conf);
        dao.init();
        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.setColumnVisibility(new DocumentVisibility("B").flatten());
        final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
        final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());
        dao.add(builder.build());
        assertEquals(coll.count(), 1);
        final Document dbo = coll.find().first();
        assertTrue(dbo.containsKey(DOCUMENT_VISIBILITY));
        assertTrue(dbo.containsKey(TIMESTAMP));
    } finally {
        dao.destroy();
    }
    // Test reinitializing the same instance
    try {
        dao.init();
    } finally {
        dao.destroy();
    }
    // Reconstruct new DAO and try again
    dao = new MongoDBRyaDAO();
    try {
        dao.setConf(conf);
        dao.init();
        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.setColumnVisibility(new DocumentVisibility("B").flatten());
        final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
        final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());
        dao.add(builder.build());
        assertEquals(coll.count(), 1);
        final Document dbo = coll.find().first();
        assertTrue(dbo.containsKey(DOCUMENT_VISIBILITY));
        assertTrue(dbo.containsKey(TIMESTAMP));
    } finally {
        dao.destroy();
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatementBuilder(org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder) DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility) Document(org.bson.Document) MongoDatabase(com.mongodb.client.MongoDatabase) Test(org.junit.Test)

Aggregations

DocumentVisibility (org.apache.rya.mongodb.document.visibility.DocumentVisibility)18 Test (org.junit.Test)12 RyaURI (org.apache.rya.api.domain.RyaURI)7 RyaStatementBuilder (org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder)6 MongoDatabase (com.mongodb.client.MongoDatabase)5 Document (org.bson.Document)5 RyaStatement (org.apache.rya.api.domain.RyaStatement)3 ArrayList (java.util.ArrayList)2 Node (org.apache.accumulo.core.security.ColumnVisibility.Node)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 List (java.util.List)1 Authorizations (org.apache.accumulo.core.security.Authorizations)1 RyaType (org.apache.rya.api.domain.RyaType)1 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)1 MalformedDocumentVisibilityException (org.apache.rya.mongodb.document.visibility.DocumentVisibilityAdapter.MalformedDocumentVisibilityException)1