Search in sources :

Example 16 with DocumentVisibility

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

the class DocumentVisibilityUtilTest method testBadExpressions.

@Test
public void testBadExpressions() {
    int count = 1;
    for (final String booleanExpression : INVALID_BOOLEAN_EXPRESSIONS) {
        log.info("Invalid Test: " + count);
        try {
            log.info("Original: " + booleanExpression);
            // Convert to multidimensional array
            final DocumentVisibility dv = new DocumentVisibility(booleanExpression);
            final Object[] multidimensionalArray = DocumentVisibilityUtil.toMultidimensionalArray(dv);
            log.info("Array   : " + Arrays.deepToString(multidimensionalArray));
            // Convert multidimensional array back to string
            final String booleanString = DocumentVisibilityUtil.multidimensionalArrayToBooleanString(multidimensionalArray);
            log.info("Result  : " + booleanString);
            // Compare results
            final String expected = new String(dv.flatten(), Charsets.UTF_8);
            assertEquals(expected, booleanString);
            fail("Bad expression passed.");
        } catch (final Exception e) {
        // Expected
        }
        log.info("===========================");
        count++;
    }
}
Also used : DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility) Test(org.junit.Test)

Example 17 with DocumentVisibility

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

the class DisjunctiveNormalFormConverter method createDnfDocumentVisibility.

/**
 * Creates a new document visibility based on the boolean expression that is
 * converted into disjunctive normal form.
 * @param expression the boolean expression bytes.
 * @return the {@link DocumentVisibility} in DNF.
 */
public static DocumentVisibility createDnfDocumentVisibility(final byte[] expression) {
    final DocumentVisibility documentVisibility = new DocumentVisibility(expression);
    final DocumentVisibility dnfDv = convertToDisjunctiveNormalForm(documentVisibility);
    return dnfDv;
}
Also used : DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility)

Example 18 with DocumentVisibility

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

the class SimpleMongoDBStorageStrategy method deserializeDBObject.

@Override
public RyaStatement deserializeDBObject(final DBObject queryResult) {
    final Map<?, ?> result = queryResult.toMap();
    final String subject = (String) result.get(SUBJECT);
    final String object = (String) result.get(OBJECT);
    final String objectType = (String) result.get(OBJECT_TYPE);
    final String predicate = (String) result.get(PREDICATE);
    final String context = (String) result.get(CONTEXT);
    DocumentVisibility documentVisibility = null;
    try {
        documentVisibility = DocumentVisibilityAdapter.toDocumentVisibility(queryResult);
    } catch (final MalformedDocumentVisibilityException e) {
        throw new RuntimeException("Unable to convert document visibility", e);
    }
    final Long timestamp = (Long) result.get(TIMESTAMP);
    final String statementMetadata = (String) result.get(STATEMENT_METADATA);
    RyaType objectRya = null;
    if (objectType.equalsIgnoreCase(ANYURI.stringValue())) {
        objectRya = new RyaURI(object);
    } else {
        objectRya = new RyaType(factory.createURI(objectType), object);
    }
    final RyaStatement statement;
    if (!context.isEmpty()) {
        statement = new RyaStatement(new RyaURI(subject), new RyaURI(predicate), objectRya, new RyaURI(context));
    } else {
        statement = new RyaStatement(new RyaURI(subject), new RyaURI(predicate), objectRya);
    }
    statement.setColumnVisibility(documentVisibility.flatten());
    if (timestamp != null) {
        statement.setTimestamp(timestamp);
    }
    if (statementMetadata != null) {
        try {
            final StatementMetadata metadata = new StatementMetadata(statementMetadata);
            statement.setStatementMetadata(metadata);
        } catch (final Exception ex) {
            LOG.debug("Error deserializing metadata for statement", ex);
        }
    }
    return statement;
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) MalformedDocumentVisibilityException(org.apache.rya.mongodb.document.visibility.DocumentVisibilityAdapter.MalformedDocumentVisibilityException) StatementMetadata(org.apache.rya.api.domain.StatementMetadata) RyaStatement(org.apache.rya.api.domain.RyaStatement) DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility) RyaType(org.apache.rya.api.domain.RyaType) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MalformedDocumentVisibilityException(org.apache.rya.mongodb.document.visibility.DocumentVisibilityAdapter.MalformedDocumentVisibilityException)

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