@Override public ExecTO getExecTO(final ReportExec execution) { ExecTO execTO = new ExecTO(); execTO.setKey(execution.getKey()); execTO.setJobType(JobType.REPORT); execTO.setRefKey(execution.getReport().getKey()); execTO.setRefDesc(buildRefDesc(execution.getReport())); execTO.setStatus(execution.getStatus()); execTO.setMessage(execution.getMessage()); execTO.setStart(execution.getStart()); execTO.setEnd(execution.getEnd()); return execTO; } }
@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_READ + "')") public ReportExec getReportExec(final String executionKey) { ReportExec reportExec = reportExecDAO.find(executionKey); if (reportExec == null) { throw new NotFoundException("Report execution " + executionKey); } if (!ReportExecStatus.SUCCESS.name().equals(reportExec.getStatus()) || reportExec.getExecResult() == null) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidReportExec); sce.getElements().add(reportExec.getExecResult() == null ? "No report data produced" : "Report did not run successfully"); throw sce; } return reportExec; }
try (ByteArrayInputStream bais = new ByteArrayInputStream(reportExec.getExecResult()); ZipInputStream zis = new ZipInputStream(bais)) { parameters.put("status", reportExec.getStatus()); parameters.put("message", reportExec.getMessage()); parameters.put("start", reportExec.getStart()); parameters.put("end", reportExec.getEnd()); IOUtils.toInputStream(reportExec.getReport().getTemplate().getHTMLTemplate(), StandardCharsets.UTF_8))); xsl2html.setParameters(parameters); IOUtils.toInputStream(reportExec.getReport().getTemplate().getFOTemplate(), StandardCharsets.UTF_8))); xsl2pdf.setParameters(parameters); IOUtils.toInputStream(reportExec.getReport().getTemplate().getFOTemplate(), StandardCharsets.UTF_8))); xsl2rtf.setParameters(parameters); IOUtils.toInputStream(reportExec.getReport().getTemplate().getCSVTemplate(), StandardCharsets.UTF_8))); xsl2csv.setParameters(parameters);
execution.setStatus(ReportExecStatus.STARTED); execution.setStart(new Date()); execution.setReport(report); execution = reportExecDAO.save(execution); execution.setStatus(ReportExecStatus.RUNNING); execution = reportExecDAO.save(execution); LOG.error("While executing reportlet {} for report {}", reportlet, reportKey, t); execution.setStatus(ReportExecStatus.FAILURE); handler.endDocument(); if (!ReportExecStatus.FAILURE.name().equals(execution.getStatus())) { execution.setStatus(ReportExecStatus.SUCCESS); execution.setStatus(ReportExecStatus.FAILURE); reportExecutionMessage.append(ExceptionUtils2.getFullStackTrace(e)); execution.setExecResult(baos.toByteArray()); execution.setMessage(reportExecutionMessage.toString()); execution.setEnd(new Date()); reportExecDAO.save(execution);
@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_DELETE + "')") @Override public List<BatchResponseItem> deleteExecutions( final String key, final Date startedBefore, final Date startedAfter, final Date endedBefore, final Date endedAfter) { Report report = reportDAO.find(key); if (report == null) { throw new NotFoundException("Report " + key); } List<BatchResponseItem> batchResponseItems = new ArrayList<>(); reportExecDAO.findAll(report, startedBefore, startedAfter, endedBefore, endedAfter).forEach(exec -> { BatchResponseItem item = new BatchResponseItem(); item.getHeaders().put(RESTHeaders.RESOURCE_KEY, Arrays.asList(exec.getKey())); batchResponseItems.add(item); try { reportExecDAO.delete(exec); item.setStatus(Response.Status.OK.getStatusCode()); } catch (Exception e) { LOG.error("Error deleting execution {} of report {}", exec.getKey(), key, e); item.setStatus(Response.Status.BAD_REQUEST.getStatusCode()); item.setContent(ExceptionUtils2.getFullStackTrace(e)); } }); return batchResponseItems; }
@Override public Response exportExecutionResult(final String executionKey, final ReportExecExportFormat fmt) { ReportExecExportFormat format = (fmt == null) ? ReportExecExportFormat.XML : fmt; ReportExec reportExec = logic.getReportExec(executionKey); StreamingOutput sout = (os) -> logic.exportExecutionResult(os, reportExec, format); return Response.ok(sout). header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + reportExec.getReport().getName() + "." + format.name().toLowerCase()). build(); }