WSO2 SP allows you to generate reports with visualizations of processed data as explained in Generating Reports. You can also schedule these reports to be generated and sent to the required stakeholders when required. WSO2 SP integrates with the Jasper Reports technology in order to provide this feature.
To create a Siddhi application that generates reports and sends them as email attachments to the required addresses in a scheduled manner, follow the steps below.
Before you begin:
- Download the following from here.
- Jasper Reports ® Server
- Jasper Reports ® Library
Setup a database of your choice. In this example, a MySQL database is configured.Click here for instructions to configure a MySQL database.
Download and install MySQL Server.
Download the MySQL JDBC driver.
Unzip the downloaded MySQL driver zipped archive, and copy the MySQL JDBC driver JAR (
mysql-connector-java-x.x.xx-bin.jar) into the
- Enter the following command in a terminal/command window, where
usernameis the username you want to use to access the databases.
mysql -u username -p
- When prompted, specify the password you are using to access the databases with the username you specified.
Add the following configuration under the Data Sources Configuration section of the
You need to change the values for the
passwordparameters to the username and password that you are using to access the MySQL database.
- To create a database table named
SweetFactoryDB, issue the following commands from the terminal.
mysql> create database SweetFactoryDB; mysql> use SweetFactoryDB; mysql> source <SP_HOME>/wso2/editor/dbscripts/metrics/mysql.sql; mysql> grant all on SweetFactoryDB.* TO username@localhost identified by "password";
- Start WSO2 Stream Processor in the editor mode my issuing one of the following commands from the
- For Windows:
- For Linux:
Then access the Stream Processor Studio via the URL displayed in the start up logs.
The default URL is
- For Windows:
- Click New to start creating a new Siddhi application.
- In the new Siddhi file that opens, enter a name and a description for the application as shown in the example below.
Enter the following data to create a basic Siddhi application
In the above Siddhi application, basic production data (i.e., the name of the product and the amount produced) is captured via the
ProductionStreaminput stream. Then the total production for each product is calculated via the
sum()function, and the results are inserted into the
To publish the information you processed and saved in the
ProductionDatatable in a report, you need an output stream to which the sink via which the information is published can be connected. Define the output stream as follows.
To publish the information to be included in the report, connect a sink to the output stream as follows.
Here, the sink connected needs to be of the
reporttype. The parameters and annotations configured for this sink are as follows.
The title of the report. In this example, it is
The path to the directory in your macxhine where the generated report needs to be saved.
The format in which the report needs to be published.
In this scenario, you need to generated a report based on a chunk of events. To enable this, the map type needs to be
JSON. If not, a report is generated per event.
For information about all the possible parameters and annotations that can be configured for the report sink type, see documentation for the siddhi-io-report extension.
To trigger the periodical generation of reports, define a trigger as follows.
This trigger polls the
ProductionDatatable at midnight every Saturday to get the latest production data available at that time.
To schedule the generation of reports, add another query to the Siddhi application as follows.
SetupTriggertrigger you previously defined is applied to the
ProductionDatatable. An RDBMS query gets all the data in this table and inserts that into the
ProductionTotalStreamoutput stream. This is the stream to which the sink of the
reporttype is connected. Therefore, when the Siddhi application is executed, this information extracted from the table and then inserted into the output stream are published in a report.
The complete Siddhi application looks as follows:
Using an external JRXML file to generate reports
If you want to use to use an external JRXML file to generate reports, you must include the following in the sink definition.
- The path to the required JRXML file.
- The dataset parameter that is defined in the JRXML file.
e.g., In this example, the path to the JRMXL file is defined as
template='/home/../scheduled-reporting/template.jrxml'. The dataset parameter is included as
Including multiple charts in a report
To enable multiple query support, the sink definition should include the following parameters:
query.modeparameter needs to be set to
datasource.nameparameter needs to be included. The value should be the same as the datasource you defined under datasource configurations in the
<SP_HOME>/conf/editor/deployment.yamlfile when seeting up the database for your scheduled report generation scenario.
Then the queries can be defined as a JSON string as shown in the example below.
The queries should be provided in the JSON format where the query, chart type the query data should represent, the series and category column names, the chart title.