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:

  1. 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.

  2. 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.

  3. Execute (“Run As Ant Build”) the build.xml file in your project.

  4. Restart your Tomcat from within Eclipse in Debug mode.

  5. You can now debug your code.

  6. Repeat 2 to 5 as necessary. When you are done you will find the deployable tpx file in the dist 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.

  1. 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 typically C:\\Program Files\\Trackplus. Start your system and make sure that everything works. Save your Torque.properties file

  2. Create a directory /opt/trackplus/webapps.

  3. Place the Allegra WAR file (track-5xxx.war) into opt/trackplus/webapps and call it track.war.

Step 2: Configure your Eclipse IDE#

Follow the instructions in section ref{sec:tools} to configure your development environment.

Configuring the Datasource Project#

  1. In Eclipse go to File > New > Project and create a new standard Java project to develop your datasource in.

_images/chapter4-23.png
  1. 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.

_images/chapter4-24.png
  1. 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 in build.properties your datasource jar name is myPackage, and you need JavaScript class Accounting , you must use Ext.define("myPackage.Accounting", {... } for your JavaScript class.

  2. Right click on build.xml and select “Run As” “Ant Build”.

  3. Select the Tomcat server project. Configure the Debug configuration as shown below.

_images/chapter4-25.png _images/chapter4-26.png
  1. 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.