Search in sources :

Example 1 with ReportOutputDocument

use of com.haulmont.yarg.reporting.ReportOutputDocument in project jmix-docs by Haulmont.

the class RunReportScreen method onRrcBtn1Click.

@Subscribe("rrcBtn1")
protected void onRrcBtn1Click(Button.ClickEvent event) {
    Report report = getReportByCode("BOOKS");
    LiteratureType type = dataManager.load(LiteratureType.class).query("select c from jmxrpr_LiteratureType c where c.name = :name").parameter("name", "Art").one();
    // tag::report-run-context-v1[]
    ReportRunContext context = new ReportRunContext(report).addParam("type", type).setOutputNamePattern("Books");
    // end::report-run-context-v1[]
    ReportOutputDocument document = reportRunner.run(context);
    List<ReportOutputDocument> documents = new ArrayList<>();
    documents.add(document);
    // tag::report-zip-utils[]
    byte[] zipArchiveContent = reportZipUtils.createZipArchive(documents);
    downloader.download(zipArchiveContent, "Reports.zip", DownloadFormat.ZIP);
// end::report-zip-utils[]
}
Also used : UiReportRunContext(io.jmix.reportsui.runner.UiReportRunContext) ReportRunContext(io.jmix.reports.runner.ReportRunContext) ReportOutputDocument(com.haulmont.yarg.reporting.ReportOutputDocument) Report(io.jmix.reports.entity.Report) ArrayList(java.util.ArrayList) LiteratureType(reports.ex2.entity.LiteratureType) Subscribe(io.jmix.ui.screen.Subscribe)

Example 2 with ReportOutputDocument

use of com.haulmont.yarg.reporting.ReportOutputDocument in project jmix-docs by Haulmont.

the class RunReportScreen method onRrBtn2Click.

// end::rr-btn1-end[]
// tag::rr-btn2-start[]
@Subscribe("rrBtn2")
protected void onRrBtn2Click(Button.ClickEvent event) {
    // end::rr-btn2-start[]
    Report report = getReportByCode("BOOKS");
    LiteratureType type = dataManager.load(LiteratureType.class).query("select c from jmxrpr_LiteratureType c where c.name = :name").parameter("name", "Art").one();
    // tag::report-runner-v3[]
    ReportOutputDocument document = reportRunner.byReportEntity(report).addParam("type", type).withOutputType(// <1>
    ReportOutputType.PDF).withOutputNamePattern(// <2>
    "Books").run();
    // end::report-runner-v3[]
    // tag::get-content[]
    String documentName = document.getDocumentName();
    byte[] content = document.getContent();
// end::get-content[]
// tag::rr-btn2-end[]
}
Also used : ReportOutputDocument(com.haulmont.yarg.reporting.ReportOutputDocument) Report(io.jmix.reports.entity.Report) LiteratureType(reports.ex2.entity.LiteratureType) Subscribe(io.jmix.ui.screen.Subscribe)

Example 3 with ReportOutputDocument

use of com.haulmont.yarg.reporting.ReportOutputDocument in project jmix-docs by Haulmont.

the class RunReportScreen method onRrcBtn2Click.

// tag::rrc-btn2-start[]
@Subscribe("rrcBtn2")
protected void onRrcBtn2Click(Button.ClickEvent event) {
    // end::rrc-btn2-start[]
    Report report = getReportByCode("BOOKS");
    LiteratureType type = dataManager.load(LiteratureType.class).query("select c from jmxrpr_LiteratureType c where c.name = :name").parameter("name", "Art").one();
    Map<String, Object> paramsMap = new HashMap<>();
    paramsMap.put("type", type);
    ReportTemplate template = dataManager.load(ReportTemplate.class).query("select c from report_ReportTemplate c where c.code = :code and c.report = :report").parameter("code", "DEFAULT").parameter("report", report).one();
    // tag::report-run-context-v2[]
    ReportRunContext context = new ReportRunContext(report).setReportTemplate(template).setOutputType(ReportOutputType.PDF).setParams(paramsMap);
    // end::report-run-context-v2[]
    // tag::report-runner-v1[]
    ReportOutputDocument document = reportRunner.run(// <1>
    new ReportRunContext(report).setParams(paramsMap));
// end::report-runner-v1[]
// ReportOutputDocument document = reportRunner.run(context);
// tag::rrc-btn2-end[]
}
Also used : UiReportRunContext(io.jmix.reportsui.runner.UiReportRunContext) ReportRunContext(io.jmix.reports.runner.ReportRunContext) ReportOutputDocument(com.haulmont.yarg.reporting.ReportOutputDocument) Report(io.jmix.reports.entity.Report) HashMap(java.util.HashMap) ReportTemplate(io.jmix.reports.entity.ReportTemplate) LiteratureType(reports.ex2.entity.LiteratureType) Subscribe(io.jmix.ui.screen.Subscribe)

Example 4 with ReportOutputDocument

use of com.haulmont.yarg.reporting.ReportOutputDocument in project jmix by jmix-framework.

the class EmailTemplatesImpl method createEmailAttachment.

protected EmailAttachment createEmailAttachment(String templateName, ReportWithParams reportWithParams) {
    ReportOutputDocument outputDocument = reportRunner.run(new ReportRunContext(reportWithParams.getReport()).setParams(reportWithParams.getParams()));
    String fileName = outputDocument.getDocumentName();
    if (StringUtils.isNotBlank(templateName)) {
        String extension = Files.getFileExtension(templateName);
        String docExtension = Files.getFileExtension(fileName);
        if (StringUtils.isNotBlank(extension)) {
            fileName = templateName;
        } else if (StringUtils.isNotBlank(docExtension)) {
            fileName = templateName + "." + docExtension;
        } else {
            fileName = templateName;
        }
    }
    return new EmailAttachment(outputDocument.getContent(), fileName);
}
Also used : ReportOutputDocument(com.haulmont.yarg.reporting.ReportOutputDocument) ReportRunContext(io.jmix.reports.runner.ReportRunContext) EmailAttachment(io.jmix.email.EmailAttachment)

Example 5 with ReportOutputDocument

use of com.haulmont.yarg.reporting.ReportOutputDocument in project jmix by jmix-framework.

the class ReportRunnerImpl method run.

@Override
public ReportOutputDocument run(ReportRunContext context) {
    prepareContext(context);
    if (!reportsProperties.isHistoryRecordingEnabled()) {
        return createReportDocumentInternal(context);
    }
    ReportExecution reportExecution = executionHistoryRecorder.startExecution(context.getReport(), context.getParams());
    try {
        ReportOutputDocument document = createReportDocumentInternal(context);
        executionHistoryRecorder.markAsSuccess(reportExecution, document);
        return document;
    } catch (ReportCanceledException e) {
        executionHistoryRecorder.markAsCancelled(reportExecution);
        throw e;
    } catch (Exception e) {
        executionHistoryRecorder.markAsError(reportExecution, e);
        throw e;
    }
}
Also used : ReportOutputDocument(com.haulmont.yarg.reporting.ReportOutputDocument) ReportExecution(io.jmix.reports.entity.ReportExecution) ReportingInterruptedException(com.haulmont.yarg.exception.ReportingInterruptedException) NoFreePortsException(com.haulmont.yarg.formatters.impl.doc.connector.NoFreePortsException) OpenOfficeException(com.haulmont.yarg.exception.OpenOfficeException)

Aggregations

ReportOutputDocument (com.haulmont.yarg.reporting.ReportOutputDocument)18 Report (io.jmix.reports.entity.Report)7 ReportRunContext (io.jmix.reports.runner.ReportRunContext)7 ReportTemplate (io.jmix.reports.entity.ReportTemplate)4 Subscribe (io.jmix.ui.screen.Subscribe)4 LiteratureType (reports.ex2.entity.LiteratureType)4 ShowChartScreen (io.jmix.reportsui.screen.report.run.ShowChartScreen)3 ShowPivotTableScreen (io.jmix.reportsui.screen.report.run.ShowPivotTableScreen)3 ShowReportTableScreen (io.jmix.reportsui.screen.report.run.ShowReportTableScreen)3 HashMap (java.util.HashMap)3 OpenOfficeException (com.haulmont.yarg.exception.OpenOfficeException)2 ReportingInterruptedException (com.haulmont.yarg.exception.ReportingInterruptedException)2 NoFreePortsException (com.haulmont.yarg.formatters.impl.doc.connector.NoFreePortsException)2 ReportExecution (io.jmix.reports.entity.ReportExecution)2 FailedToConnectToOpenOfficeException (io.jmix.reports.exception.FailedToConnectToOpenOfficeException)2 NoOpenOfficeFreePortsException (io.jmix.reports.exception.NoOpenOfficeFreePortsException)2 ReportingException (io.jmix.reports.exception.ReportingException)2 UiReportRunContext (io.jmix.reportsui.runner.UiReportRunContext)2 BackgroundTask (io.jmix.ui.executor.BackgroundTask)2 TaskLifeCycle (io.jmix.ui.executor.TaskLifeCycle)2