Search in sources :

Example 1 with RyaQuery

use of org.apache.rya.api.persist.query.RyaQuery in project incubator-rya by apache.

the class AccumuloRyaQueryEngine method query.

@Override
public CloseableIteration<RyaStatement, RyaDAOException> query(RyaStatement stmt, AccumuloRdfConfiguration conf) throws RyaDAOException {
    if (conf == null) {
        conf = configuration;
    }
    RyaQuery ryaQuery = RyaQuery.builder(stmt).load(conf).build();
    CloseableIterable<RyaStatement> results = query(ryaQuery);
    return new CloseableIterableIteration<RyaStatement, RyaDAOException>(results);
}
Also used : CloseableIterableIteration(org.apache.rya.api.utils.CloseableIterableIteration) RyaStatement(org.apache.rya.api.domain.RyaStatement) BatchRyaQuery(org.apache.rya.api.persist.query.BatchRyaQuery) RyaQuery(org.apache.rya.api.persist.query.RyaQuery)

Example 2 with RyaQuery

use of org.apache.rya.api.persist.query.RyaQuery in project incubator-rya by apache.

the class MongoDBRyaDAOIT method testVisibilityStatement.

/**
 * Generates a test statement with the provided document visibility to
 * determine if the specified user authorization can view the statement.
 *
 * @param dao - The DAO that will be used by the test.
 * @param documentVisibility - The document visibility boolean expression
 * string.
 * @param userAuthorizations - The user authorization strings.
 * @return {@code true} if provided authorization could access the document
 * in the collection. {@code false} otherwise.
 * @throws RyaDAOException
 */
private boolean testVisibilityStatement(final MongoDBRyaDAO dao, final String documentVisibility, final Authorizations userAuthorizations) throws RyaDAOException {
    final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
    final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());
    final RyaStatement statement = buildVisibilityTestRyaStatement(documentVisibility);
    dao.getConf().setAuths(AuthorizationsUtil.getAuthorizationsStringArray(Authorizations.EMPTY));
    dao.add(statement);
    dao.getConf().setAuths(AuthorizationsUtil.getAuthorizationsStringArray(userAuthorizations != null ? userAuthorizations : Authorizations.EMPTY));
    assertEquals(1, coll.count());
    final MongoDBQueryEngine queryEngine = (MongoDBQueryEngine) dao.getQueryEngine();
    queryEngine.setConf(conf);
    final CloseableIterable<RyaStatement> iter = queryEngine.query(new RyaQuery(statement));
    // Check if user has authorization to view document based on its visibility
    final boolean hasNext = iter.iterator().hasNext();
    // Reset
    dao.delete(statement, conf);
    assertEquals(0, coll.count());
    dao.getConf().setAuths(AuthorizationsUtil.getAuthorizationsStringArray(Authorizations.EMPTY));
    return hasNext;
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaQuery(org.apache.rya.api.persist.query.RyaQuery) Document(org.bson.Document) MongoDatabase(com.mongodb.client.MongoDatabase)

Aggregations

RyaStatement (org.apache.rya.api.domain.RyaStatement)2 RyaQuery (org.apache.rya.api.persist.query.RyaQuery)2 MongoDatabase (com.mongodb.client.MongoDatabase)1 BatchRyaQuery (org.apache.rya.api.persist.query.BatchRyaQuery)1 CloseableIterableIteration (org.apache.rya.api.utils.CloseableIterableIteration)1 Document (org.bson.Document)1