Hi,
i recently worked on a new CUBA app-component called scheduled-reports
. It is in preview mode currently. Before releasing it “officially” i would like to get your feedback on it. It is open source (Apache 2 license) and you can find it on github:
If you have any thoughts on that, like bug, feature requests etc. I would love to hear from you.
I’ll just copy over the README.md so you get an impression on what it does:
CUBA Platform Application Component - Scheduled Reports
This application component let’s you schedule reports and execute them periodically.
It allows to define a schedule for a report to be executed. The target report file is stored CUBAs File Storage and additionally optionally can be send out via Email.
Installation
-
scheduled-reports
is available in the CUBA marketplace - Select a version of the add-on which is compatible with the platform version used in your project:
Platform Version | Add-on Version |
---|---|
7.0.x | 0.1.x |
Add custom application component to your project:
- Artifact group:
de.diedavids.cuba.scheduledreports
- Artifact name:
scheduledreports-global
- Version: add-on version
dependencies {
appComponent("de.diedavids.cuba.scheduledreports:scheduledreports-global:*addon-version*")
}
CHANGELOG
Information on changes that happen through the different versions of the application component can be found in the CHANGELOG.
The Changelog also contains information about breaking changes and tips on how to resolve them.
Supported DBMS
The following databases are supported by this application component:
- HSQLDB
- PostgreSQL
Example usage
To see this application component in action, check out this example: cuba-example-using-scheduled-reports.
Using the application component
The scheduled-reports
application component enriches the Reports main menu with ability to define Scheduled Reports
.
A Scheduled Report
consists mainly of a reference to the report instance, that should be executed as well as a schedule that defines on how often the report should be executed.
Emailing Report
Besides the file generation itself, it is also possible to send out the report via email. In order to do this, a Email template can be defined, that includes information on the receivers, the Email subject and body etc. The report file is attached to the email.
Programmatic Scheduled Report Extensions
Currently (v. 0.1.0) the ability to define certain parameters of the Report or the Email template are limited to the abilities of the corresponding application components:
Since there is the need to dynamically define certain information, it is possible to extend the functionality of a scheduled report programmatically that is executed at the point when the scheduled report is run.
In order to enhance a scheduled report programmatically, a Spring bean has to be created in the core module of the application, which implements the ScheduledReportExtension
interface.
This interface allows to programmatically define the following options during the execution of a scheduled report:
- define the report parameter
- define the report template
- define the target filename
- veto right to prevent execution
Application Event: ScheduledReportRun
After the scheduled report was executed, the Spring application event ScheduledReportRun
is published. It is possible to register to this application event in order to programmatically use the result of the scheduled report execution.
An example can be found in the example project: BigCustomersListSaver:
@Component(BigCustomersListSaver.NAME)
public class BigCustomersListSaver implements ApplicationListener<ScheduledReportRun> {
public static final String NAME = "ceusr_BigCustomersListSaver";
@Inject
protected DataManager dataManager;
@Override
public void onApplicationEvent(ScheduledReportRun scheduledReportRun) {
ScheduledReportExecution reportExecution = scheduledReportRun.getReportExecution();
String scheduledReportCode = reportExecution.getScheduledReport().getCode();
if (scheduledReportCode.equals("big-customers")) {
BigCustomersList bigCustomersList = dataManager.create(BigCustomersList.class);
bigCustomersList.setFrom(toLocalDate(reportExecution.getExecutedAt()));
bigCustomersList.setBigCustomerListFile(scheduledReportRun.getReportFile());
bigCustomersList.setScheduledReportExecution(reportExecution);
dataManager.commit(bigCustomersList);
};
}
private LocalDate toLocalDate(Date dateToConvert) {
return dateToConvert.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
}
}
Scheduled Report Execution
Every scheduled report execution is logged and can be seen via the menu Reports > Scheduled Reports > Executions
. It contains information about the execution timestamp, the report file and optionally a list of outgoing emails and their sending status.