[CUBA-component] scheduled reports | preview

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

  1. scheduled-reports is available in the CUBA marketplace
  2. 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

The latest version is: Download

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.

sales-report-scheduled-report

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.

sales-report-email-template

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.

big-customers-execution

sales-report-execution

3 Likes

Hi Mario
This is, indeed, an excellent add-on that you have developed.

Quick questions or comments :slight_smile:

1- if you also add week as time dimension that will be useful.

2- option to update parameters automatically and dynamically e.g. sales report generated on 1st June for the month of May.

Regards

Hi,

thanks, appreciate it :+1:

Regarding your first comment:
Yes, makes sense. Will add that in a later version. It can be configured right now via defining a cron expression: 0 0 9 ? * MON *

Regarding your second comment:
This is already possible. The example provided in the example app: https://github.com/mariodavid/cuba-example-using-scheduled-reports contains the very same example (if I did not misunderstood you).
In this case the scheduled report extension class is MonthlySalesReportScheduledReportExtension which provides the report parameters dynamically in this method: provideParameters.

Is that what you are talking about?

Bye
Mario

Hi Mario
That’s great! looking forward for the next version. I’m going to use your add-on to my project, thank you again.

With regards to the second point, it seems that you have what I am talking about, want to test. How can I use that extension, do I have to program it or can be used in the Scheduler at run-time?

regards

I didn’t find this add-on in the Market Place. Isn’t it supposed to be there?

Hi,

Im not sure what you mean by:

Both are true. It has to be developed and then it can.be used at runtime.

You can find it in the marketplace: https://www.cuba-platform.com/marketplace/scheduled-reports/

Bye

Thanks I know that link but what I don’t see is from CUBA Studio Market Place link:
image

i think in studio there is a filter for your CUBA version. Not sure which version you use. Scheduled records is currently 7.0.x only.

Bye
Mario

I’m using the most recent versions of both Studio and Platform I.e. 7.1

hi,

you can now schedule reports and automatically send them through email with the scheduled-reports addon for @CubaPlatform also for version 7.1. It is now available in version 0.2.0. Check it out here: https://github.com/mariodavid/cuba-component-scheduled-reports

0

Hi Mario
Thanks. I wonder why this is still not visible from the Studio. Most likely the studio is filtering by v.7.1.1 (as you will see in the footnote), do you see it from the latest version of the Studio ?

I have added the dependency to the gradle file manually as follows, it has successfully deployed without any error but I don;t see the add-on menu in my application.

 appComponent('de.diedavids.cuba.scheduledreports:scheduledreports-global:0.2.0')