Search in sources :

Example 6 with ReportException

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);
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ArrayList(java.util.ArrayList) QueryManager(javax.jcr.query.QueryManager) ReportException(com.adobe.acs.commons.reports.api.ReportException) RepositoryException(javax.jcr.RepositoryException) ResultsPage(com.adobe.acs.commons.reports.api.ResultsPage) Session(javax.jcr.Session)

Aggregations

ReportException (com.adobe.acs.commons.reports.api.ReportException)6 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ReportCellCSVExporter (com.adobe.acs.commons.reports.api.ReportCellCSVExporter)2 ResultsPage (com.adobe.acs.commons.reports.api.ResultsPage)2 LinkedHashMap (java.util.LinkedHashMap)2 RepositoryException (javax.jcr.RepositoryException)2 Query (javax.jcr.query.Query)2 QueryManager (javax.jcr.query.QueryManager)2 QueryResult (javax.jcr.query.QueryResult)2 ServletException (javax.servlet.ServletException)2 QueryReportExecutor (com.adobe.acs.commons.reports.models.QueryReportExecutor)1 Csv (com.day.text.csv.Csv)1 Handlebars (com.github.jknack.handlebars.Handlebars)1 Template (com.github.jknack.handlebars.Template)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Writer (java.io.Writer)1 HashMap (java.util.HashMap)1 NodeIterator (javax.jcr.NodeIterator)1 Session (javax.jcr.Session)1