Search in sources :

Example 1 with ReportExecExportFormat

use of org.apache.syncope.common.lib.types.ReportExecExportFormat in project syncope by apache.

the class ReportSyncopeOperations method exportExecutionResult.

public String exportExecutionResult(final String executionKey, final String reportExecExportFormat) throws Exception {
    ReportExecExportFormat format = ReportExecExportFormat.valueOf(reportExecExportFormat);
    SequenceInputStream report = (SequenceInputStream) reportService.exportExecutionResult(executionKey, format).getEntity();
    String fileName = "export_" + executionKey;
    OutputStream os = null;
    switch(format) {
        case XML:
            fileName += ".xml";
            XMLUtils.createXMLFile(report, fileName);
            break;
        case CSV:
            fileName += ".csv";
            os = Files.newOutputStream(Paths.get(fileName));
            IOUtils.copyAndCloseInput(report, os);
            break;
        case PDF:
            fileName += ".pdf";
            os = Files.newOutputStream(Paths.get(fileName));
            IOUtils.copyAndCloseInput(report, os);
            break;
        case HTML:
            fileName += ".html";
            os = Files.newOutputStream(Paths.get(fileName));
            IOUtils.copyAndCloseInput(report, os);
            break;
        case RTF:
            fileName += ".rtf";
            os = Files.newOutputStream(Paths.get(fileName));
            IOUtils.copyAndCloseInput(report, os);
            break;
        default:
            return format + " not supported";
    }
    if (os != null) {
        os.close();
    }
    return fileName;
}
Also used : ReportExecExportFormat(org.apache.syncope.common.lib.types.ReportExecExportFormat) SequenceInputStream(java.io.SequenceInputStream) OutputStream(java.io.OutputStream)

Example 2 with ReportExecExportFormat

use of org.apache.syncope.common.lib.types.ReportExecExportFormat in project syncope by apache.

the class ReportServiceImpl method exportExecutionResult.

@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();
}
Also used : ReportExecExportFormat(org.apache.syncope.common.lib.types.ReportExecExportFormat) ReportLogic(org.apache.syncope.core.logic.ReportLogic) Autowired(org.springframework.beans.factory.annotation.Autowired) StreamingOutput(javax.ws.rs.core.StreamingOutput) ReportService(org.apache.syncope.common.rest.api.service.ReportService) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) Service(org.springframework.stereotype.Service) ReportExec(org.apache.syncope.core.persistence.api.entity.ReportExec) URI(java.net.URI) ReportTO(org.apache.syncope.common.lib.to.ReportTO) RESTHeaders(org.apache.syncope.common.rest.api.RESTHeaders) AbstractExecutableLogic(org.apache.syncope.core.logic.AbstractExecutableLogic) ReportExecExportFormat(org.apache.syncope.common.lib.types.ReportExecExportFormat) StreamingOutput(javax.ws.rs.core.StreamingOutput) ReportExec(org.apache.syncope.core.persistence.api.entity.ReportExec)

Aggregations

ReportExecExportFormat (org.apache.syncope.common.lib.types.ReportExecExportFormat)2 OutputStream (java.io.OutputStream)1 SequenceInputStream (java.io.SequenceInputStream)1 URI (java.net.URI)1 List (java.util.List)1 HttpHeaders (javax.ws.rs.core.HttpHeaders)1 Response (javax.ws.rs.core.Response)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 ReportTO (org.apache.syncope.common.lib.to.ReportTO)1 RESTHeaders (org.apache.syncope.common.rest.api.RESTHeaders)1 ReportService (org.apache.syncope.common.rest.api.service.ReportService)1 AbstractExecutableLogic (org.apache.syncope.core.logic.AbstractExecutableLogic)1 ReportLogic (org.apache.syncope.core.logic.ReportLogic)1 ReportExec (org.apache.syncope.core.persistence.api.entity.ReportExec)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1