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);
}
}
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));
}
}
}
}
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();
}
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);
}
}
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);
}
}
Aggregations