Search in sources :

Example 41 with Report

use of io.jmix.reports.entity.Report in project jmix by jmix-framework.

the class ReportExecutionHistoryRecorderImpl method handleNewReportEntity.

private void handleNewReportEntity(ReportExecution entity) {
    Report report = entity.getReport();
    // handle case when user runs report that isn't saved yet from Report Editor
    if (entityStates.isNew(report)) {
        Report reloaded = dataManager.load(Id.of(report)).fetchPlan(FetchPlan.INSTANCE_NAME).optional().orElse(null);
        entity.setReport(reloaded);
    }
}
Also used : Report(io.jmix.reports.entity.Report)

Example 42 with Report

use of io.jmix.reports.entity.Report in project jmix by jmix-framework.

the class ReportImportExportImpl method withReportOptions.

protected void withReportOptions(Report report, @Nullable EnumSet<ReportImportOption> importOptions) {
    if (importOptions != null) {
        for (ReportImportOption option : importOptions) {
            if (ReportImportOption.DO_NOT_IMPORT_ROLES == option) {
                Report dbReport = null;
                try {
                    dbReport = reloadReport(report);
                } catch (EntityAccessException e) {
                // Do nothing
                }
                if (dbReport != null) {
                    report.setReportRoles(dbReport.getReportRoles());
                } else {
                    report.setReportRoles(Collections.emptySet());
                }
                report.setXml(reportsSerialization.convertToString(report));
            }
        }
    }
}
Also used : Report(io.jmix.reports.entity.Report) ReportImportOption(io.jmix.reports.entity.ReportImportOption)

Example 43 with Report

use of io.jmix.reports.entity.Report in project jmix by jmix-framework.

the class ReportImportExportImpl method exportReports.

@Override
public byte[] exportReports(Collection<Report> reports) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream);
    try {
        zipOutputStream.setMethod(ZipArchiveOutputStream.STORED);
        zipOutputStream.setEncoding(ENCODING);
        for (Report report : reports) {
            try {
                byte[] reportBytes = exportReport(report);
                ArchiveEntry singleReportEntry = newStoredEntry(replaceForbiddenCharacters(report.getName()) + ".zip", reportBytes);
                zipOutputStream.putArchiveEntry(singleReportEntry);
                zipOutputStream.write(reportBytes);
                zipOutputStream.closeArchiveEntry();
            } catch (IOException e) {
                throw new ReportingException(String.format("Exception occurred while exporting report [%s]", report.getName()), e);
            }
        }
    } finally {
        IOUtils.closeQuietly(zipOutputStream);
    }
    return byteArrayOutputStream.toByteArray();
}
Also used : ReportingException(io.jmix.reports.exception.ReportingException) Report(io.jmix.reports.entity.Report) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) ArchiveEntry(org.apache.commons.compress.archivers.ArchiveEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 44 with Report

use of io.jmix.reports.entity.Report in project jmix by jmix-framework.

the class ReportImportExportImpl method importReport.

protected void importReport(byte[] zipBytes, @Nullable EnumSet<ReportImportOption> importOptions, ReportImportResult importResult) throws IOException {
    Report report = fromByteArray(zipBytes);
    if (report == null) {
        importResult.addException(new ReportingException("Unable to convert data from archive to report"));
        return;
    }
    updateReportTemplate(report, zipBytes);
    withReportOptions(report, importOptions);
    Optional<Report> existingReport = dataManager.load(Report.class).id(report.getId()).fetchPlan(FetchPlan.INSTANCE_NAME).optional();
    report = reportsPersistence.save(report);
    importResult.addImportedReport(report);
    if (existingReport.isPresent()) {
        importResult.addUpdatedReport(report);
        log.info("Existing report {} updated", report);
    } else {
        importResult.addCreatedReport(report);
        log.info("New report {} imported", report);
    }
}
Also used : ReportingException(io.jmix.reports.exception.ReportingException) Report(io.jmix.reports.entity.Report)

Example 45 with Report

use of io.jmix.reports.entity.Report in project jmix by jmix-framework.

the class ReportRunnerImpl method prepareContext.

protected void prepareContext(ReportRunContext context) {
    Report report = context.getReport();
    context.setReport(reportsUtils.reloadReportIfNeeded(report, "report.edit"));
    ReportTemplate template = context.getReportTemplate();
    if (template == null) {
        template = getDefaultTemplate(report);
        context.setReportTemplate(template);
    }
    if (!entityStates.isLoadedWithFetchPlan(template, "template.edit")) {
        template = dataManager.load(Id.of(template)).fetchPlan("template.edit").one();
        context.setReportTemplate(template);
    }
}
Also used : Report(io.jmix.reports.entity.Report) ReportTemplate(io.jmix.reports.entity.ReportTemplate)

Aggregations

Report (io.jmix.reports.entity.Report)45 ReportTemplate (io.jmix.reports.entity.ReportTemplate)13 Subscribe (io.jmix.ui.screen.Subscribe)8 ReportOutputDocument (com.haulmont.yarg.reporting.ReportOutputDocument)7 TemplateReport (io.jmix.emailtemplates.entity.TemplateReport)7 MetaClass (io.jmix.core.metamodel.model.MetaClass)6 FluentUiReportRunner (io.jmix.reportsui.runner.FluentUiReportRunner)5 ReportWithParams (io.jmix.emailtemplates.dto.ReportWithParams)4 ReportInputParameter (io.jmix.reports.entity.ReportInputParameter)4 UiReportRunContext (io.jmix.reportsui.runner.UiReportRunContext)4 List (java.util.List)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 DataManager (io.jmix.core.DataManager)3 ParameterPrototype (io.jmix.reports.app.ParameterPrototype)3 ReportingException (io.jmix.reports.exception.ReportingException)3 ReportRunContext (io.jmix.reports.runner.ReportRunContext)3 LiteratureType (reports.ex2.entity.LiteratureType)3 Id (io.jmix.core.Id)2 CurrentUserSubstitution (io.jmix.core.usersubstitution.CurrentUserSubstitution)2 ParameterValue (io.jmix.emailtemplates.entity.ParameterValue)2