use of com.adobe.acs.commons.reports.api.ReportException in project acs-aem-commons by Adobe-Consulting-Services.
the class QueryReportExecutor method fetchResults.
private ResultsPage fetchResults(int limit, int offset) throws ReportException {
prepareStatement();
ResourceResolver resolver = request.getResourceResolver();
Session session = resolver.adaptTo(Session.class);
List<Object> results = new ArrayList<>();
try {
QueryManager queryMgr = session.getWorkspace().getQueryManager();
Query query = queryMgr.createQuery(statement, config.getQueryLanguage());
if (page != -1) {
log.debug("Fetching results with limit {} and offset {}", new Object[] { limit, offset });
query.setLimit(limit);
query.setOffset(offset);
} else {
log.debug("Fetching all results");
}
QueryResult result = query.execute();
NodeIterator nodes = result.getNodes();
while (nodes.hasNext()) {
results.add(resolver.getResource(nodes.nextNode().getPath()));
}
} catch (RepositoryException re) {
log.error("Exception executing search results", re);
throw new ReportException("Exception executing search results", re);
}
return new ResultsPage(results, config.getPageSize(), page);
}
Aggregations