use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.
the class DisjunctiveNormalFormConverterTest method testTruthTableNullNode.
/**
* Test truth table with a {@code null} {@link Node}.
*/
@Test(expected = NullPointerException.class)
public void testTruthTableNullNode() {
final Node node = null;
final byte[] expression = new DocumentVisibility("A").getExpression();
DisjunctiveNormalFormConverter.createTruthTableInputs(node, expression);
}
use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.
the class MongoDBRyaDAO2IT 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();
}
}
use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.
the class DocumentVisibilityUtil method doesUserHaveDocumentAccess.
/**
* Checks if the user's authorizations allows them to have access to the
* provided document based on its document visibility.
* @param authorizations the {@link Authorizations}.
* @param documentVisibility the document visibility byte expression.
* @return {@code true} if the user has access to the document.
* {@code false} otherwise.
*/
public static boolean doesUserHaveDocumentAccess(final Authorizations authorizations, final byte[] documentVisibilityExpression) {
final byte[] expression = documentVisibilityExpression != null ? documentVisibilityExpression : MongoDbRdfConstants.EMPTY_DV.getExpression();
final DocumentVisibility documentVisibility = new DocumentVisibility(expression);
return doesUserHaveDocumentAccess(authorizations, documentVisibility);
}
use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.
the class DocumentVisibilityUtil method toMultidimensionalArray.
/**
* Converts a {@link DocumentVisibility} object into a multidimensional
* array representation of the boolean expression.
* @param dv the {@link DocumentVisibility}. (not {@code null})
* @return the multidimensional array representation of the boolean
* expression.
* @throws DocumentVisibilityConversionException
*/
public static Object[] toMultidimensionalArray(final DocumentVisibility dv) throws DocumentVisibilityConversionException {
checkNotNull(dv);
final byte[] expression = dv.flatten();
final DocumentVisibility flattenedDv = DisjunctiveNormalFormConverter.createDnfDocumentVisibility(expression);
final Object[] result = toMultidimensionalArray(flattenedDv.getParseTree(), flattenedDv.getExpression());
// (i.e. "A" should be ["A"])
if (result.length > 0 && result[0] instanceof String) {
final List<Object[]> formattedResult = new ArrayList<>();
formattedResult.add(result);
return formattedResult.toArray(new Object[0]);
}
return result;
}
use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.
the class MongoDBRyaDAOIT method testDeleteWildcard.
@Test
public void testDeleteWildcard() throws RyaDAOException {
final MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
final RyaStatementBuilder builder = new RyaStatementBuilder();
builder.setPredicate(new RyaURI("http://temp.com"));
builder.setColumnVisibility(new DocumentVisibility("A").flatten());
dao.delete(builder.build(), conf);
} finally {
dao.destroy();
}
}
Aggregations