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++;
}
}
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;
}
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;
}
Aggregations