Creating Report Datasources#
The built-in reporting engine of Allegra is based on JasperSoft. Reports are created from a datasource and are then processed and formatted by the report engine. The datasource has to provide the data to be reported in a suitable format.
There are a number of report datasources coming with Allegra. However, they will not cover all needs and it may be necessary to create a new custom datasource.
You can create custom (Java) code, bundle it in a plug-in archive, and drop the plugin archive in the Allegra plug-in directory.
The custom datasource can include a user interface, for example to select parameters such as a reporting period or grouping.
The Java class to be used for the datasource needs to be declared in a file named description.xml
.
Just include the datasource name in a tag named datasourcePlugin
, like this:
<datasourcePlugin>com.yourCompany.YourReportClass</datasourcePlugin/>
Development Process Outline#
To develop a custom datasource, follow these steps:
Using one of the existing templates or starting from scratch design your new report template as described above. This template should make use of your new, not yet existing datasource. In the first step you do not have data to fill it, this you will do later on. Upload this template to your local Allegra installation.
Starting with the Report datasource Development Kit and following the procedure described above write the Java code and optionally JavaScript code for your new datasource.
Execute (“Run As Ant Build”) the
build.xml
file in your project.Restart your Tomcat from within Eclipse in Debug mode.
You can now debug your code.
Repeat 2 to 5 as necessary. When you are done you will find the deployable
tpx
file in thedist
directory.
Step 1: Install Allegra on your Development Computer#
To develop datasource plug-ins you have to properly set up your development environment. I n the first step you install Allegra on your development computer and get it to run properly. This way you have an Apache Tomcat and a database installed.
Follow the instructions for a manual install as described in the installation guide. In the following we assume you have configured
TRACKPLUS\_HOME
to/opt/trackplus
. On Windows computers it is typicallyC:\\Program Files\\Trackplus
. Start your system and make sure that everything works. Save yourTorque.properties
fileCreate a directory
/opt/trackplus/webapps
.Place the Allegra WAR file (
track-5xxx.war
) intoopt/trackplus/webapps
and call ittrack.war
.
Step 2: Configure your Eclipse IDE#
Follow the instructions in section ref{sec:tools} to configure your development environment.
Configuring the Datasource Project#
In Eclipse go to File > New > Project and create a new standard Java project to develop your datasource in.
You need to adjust the Java build path of the project to compile. Add the
/opt/trackplus/webapps/track/WEB-INF/classes
directory to the build path and all libraries (*.jar
files) in/opt/trackplus/webapps/track/WEB-INF/lib
.
Edit the entries in file
build.properties
. Note in particular that the datasource jar name in this file needs to match the JavaScript package name you use for your user interface classes! If inbuild.properties
your datasource jar name ismyPackage
, and you need JavaScript classAccounting
, you must useExt.define("myPackage.Accounting", {... }
for your JavaScript class.Right click on
build.xml
and select “Run As” “Ant Build”.Select the Tomcat server project. Configure the Debug configuration as shown below.
Start the Tomcat server from within Eclipse in Debug mode and debug your datasource.
Jasper Report datasource Elements#
A report datasource serves to deliver an XML data structure to a JasperReport template. It consists of
an optional JavaScript user interface to configure datasource parameters, like selecting a project or users or accounts.
an optional application logic to handle the parameter setting process via the JavaScript code.
the business logic that generates the XML data structure that can be used by the associated JasperReport templates
A single datasource may be used by any number of JasperReport templates.