Search in sources :

Example 1 with QueryReportExecutor

use of com.adobe.acs.commons.reports.models.QueryReportExecutor in project acs-aem-commons by Adobe-Consulting-Services.

the class ReportCSVExportServlet method updateCSV.

private void updateCSV(Resource config, SlingHttpServletRequest request, List<ReportCellCSVExporter> exporters, Csv csv, Writer writer) throws ReportException {
    QueryReportExecutor executor = request.adaptTo(QueryReportExecutor.class);
    executor.setConfiguration(config);
    log.debug("Retrieved executor {}", executor);
    ResultsPage queryResult = executor.getAllResults();
    List<? extends Object> results = queryResult.getResults();
    log.debug("Retrieved {} results", results.size());
    for (Object result : results) {
        List<String> row = new ArrayList<String>();
        try {
            for (ReportCellCSVExporter exporter : exporters) {
                row.add(exporter.getValue(result));
            }
            csv.writeRow(row.toArray(new String[row.size()]));
            writer.flush();
        } catch (Exception e) {
            log.warn("Exception writing row: " + row, e);
        }
    }
    log.debug("Results written successfully");
}
Also used : QueryReportExecutor(com.adobe.acs.commons.reports.models.QueryReportExecutor) ArrayList(java.util.ArrayList) ResultsPage(com.adobe.acs.commons.reports.api.ResultsPage) ReportCellCSVExporter(com.adobe.acs.commons.reports.api.ReportCellCSVExporter) ReportException(com.adobe.acs.commons.reports.api.ReportException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

ReportCellCSVExporter (com.adobe.acs.commons.reports.api.ReportCellCSVExporter)1 ReportException (com.adobe.acs.commons.reports.api.ReportException)1 ResultsPage (com.adobe.acs.commons.reports.api.ResultsPage)1 QueryReportExecutor (com.adobe.acs.commons.reports.models.QueryReportExecutor)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ServletException (javax.servlet.ServletException)1