Reports
Introduction
The REQUEA platform integrates the JasperReports reporting engine.
This engine allows you to create reports as lists, graphics or detail sheets. These reports can be generated as PDF, stored in the database or sent by email.
These JasperReports reports are defined as .jrxml file. They are typically created with iReport reports design tool.
NOTE: iReport documentation is available as a book we recommend reading:
'' 'Requea provides no support, or assistance with the design of reports iReport / JasperReports' ''.
Please see the iReport documentation, purchase books published by JasperSoft, or buy service or training iReport / JasperSoft if you need it.
iReport is an open source tool developed by JasperSoft offers a number of services around its tool. Requea does not provide services around iReport paying nor free.
Installation
NOTE: Versions of iReport / JaspertReports
iReport is a tool that evolves pretty quickly. Requea actually provides integration with iReport version 4.0.1.
Integration is done as a netbeans plugin offering the following features :
- Dynapage connexion to use HQL queries (DynapageQL) on top of Dynapage model.
- HTTP / HTTPS connexion allowing the use of a remote serveur.
To install the Dyanapage plugin:
- Download Dynapage pglugin here: Dynapage IReport plugin
- Download iReport 4.0.1 from JasperReports website.
- in the Tools / Plugins menu, in the"Downloaded" tab, click on "Add Plugins..." button, select the .nbm file
- Then select the plugin and click "Install".
HQL vs SQL
You can choose between 2 query langages for your reports
SQL
'''Pros''':
- more powerful, more flexible
'''Cons''':
- no portability between database engines (Oracle / mySQL / MSSQL)
- SQL expressions more complicated
- Dynapage Option labels not managed
- You need to look into the database to discover table and columns names
HQL (Hibernate Query Language)
Pros :
- Works with any database engine
- Simpler expressions (specially for joins)
Cons :
- Need of the knowledge: documentation available on : Documentation Hibernate Query Language on JBoss website
- Data model must include all the relations between objects, you cannot build joins "on the fly". You can only use relations defined by Reference/Component properties
Conclusion
- Use SQL if it is a single project and you are a SQL expert
- Use HQL if you build a product that can be used in various environment
Building a connection
Click on the Datasource button in the iReport toolbar
Click "New" to create your datasource: JDBC for a SQL connection, or "Dynapage Instance" for a HQL based connection
Dynapage Query
When you are in the report editor(Hit "New" menu to create one), you can enter the query that will populate the report
Query language selection
For Requea Dynapage based HQL, select"Dynapage QL", not "Hibernate Query Language (HQL)"
Query
Here is a simple query example On the right, a tree view shows the available properties. Note: you need sometimes to modify the query (add / remove a character) for the list to be refreshed
Field selection
References / components / extensions
Double click on a cardinality 1 reference and you can pickup properties from the referenced object.
List of values
For property defined with a "List of values", the returned value by default is the value stored in the database. You can "double click" on the field to access on the "title" field. You will then get the corresponding title instead of the value stored in the database.
Using fields
Once you have selected the fields and added them with the "Add selected fields" button, you can use them in your report.
Subreports
In Jasperreports, sub lists and graphics must be managed as subreports .
Please read the iReport documentation (JasperSoft) for further help.
Important things to know are:
- You need to use the "SUBREPORT_DIR" parameter to manage the subreport directory in order to be ready for the deployment on the Requea server
- The connection
Here are the steps to create a subreport.
SUBREPORT_DIR
This parameter is mandatory for the reporting engine to find the subreports when running in the Requea platform.
We advise you to always define this parameter
Put your local directory where you put your reports in order to test the report in iReport. The value will be automatically overridden when the report will be processed with the Requea platform:
NOTE: SUBREPORT_DIR is also used for static images ("Image Expression" property):
Deployment on the target Requea plateform
Go to the "Design" tab and click on the "Reports and graphs" menu using the "RequeaDev" login
Fill the mandatory fields:
- The bundle in which the report will be saved
- The format (PDF by default)
- Upload in "File" the jrxml file of the main report
- Upload in "Support files" subreports jrxml files and static images files
- Parameters. Fill the parameters according to your report definition (SUBREPORT_DIR parameter does not need to be defined here). in order to have dynamic values for parameters use the ${xxx} syntax.
Report processing
Reports can be generated in an action or by an operation script, in order to attach the result to an instance of an entity or to send it using a notification
Within an action
Within an action, the report can be generated by using a step of type "Print".
Create an action named "print", click "Instance" and add a step of type "Print" (the PDF icon in the toolbar)
Select the "Printing Type" to "Report" and select your report in the "Report" property.
Using an Operation script
Add a "Script" step to your operation :
// retrieve the report
var report = sysReport.Get("402881ff1cbdc5aa011cbde9dfc915ac");
// retrieve the PDF result
var result = report.PrintReport(data);
// set the report as an attachement
data.custFile = result.sysData;
In the example the report in attached to the custFile property defined as a "File Attachment" type.
Passing parameters to the report
Parameters value can be passed in 2 ways:
- Using an entity instance. ${xxxx} expressions refer to entity properties
var result = report.PrintReport(data); // the params are calculated based on 'data'
- Using a JSON object
var params = {
param1:"test",
param2:"test2"
}
var result = JasperReports.Print(report, null, report.rqFormat, params); // the params are in params'