Mark Lorenz on Technology

Wednesday, February 22, 2006

BIRT Tips for Java Developers


As I've used BIRT (Business Intelligence and Reporting Tools) over the last few months, I've collected some lessons learned. I'm hoping these can save some future newbies the pain of learning the hard way.

Background
BIRT is an open source (free) framework for designing and generating HTML and PDF reports from the Java Eclipse platform. BIRT 2.0 was released in January 2006.

Highlights:
  1. WYSIWYG drag and drop design layout tools and templates
  2. Control of attributes such as font, alignment, and color via settings as well as JavaScript
  3. Sorting, grouping, subtotals
  4. POJO (via scripting), XML, JDBC, JDO, and Hibernate data sources, also with DnD
  5. Bar, pie, line, scatter charts in 2D and 3D
  6. Multi-page PDF and HTML output with headers and footers
  7. Fully integrated with Eclipse
  8. Very active development community
Prerequisites:
  1. Eclipse 3.1+
  2. Open source Eclipse plugins:
  • Graphic Editor Framework (GEF)
  • Eclipse Modeling Framework (EMF)
  • iText (PDF framework built on top of FOP)
  • Apache Axis (SOAP support)
Strengths:
  1. Easy to use, fast report development (approx. 20 common LOC + 10-15 LOC per report type + design file for each report)
  2. Powerful components with wide range of settings and customization via scripting
  3. Free while still offering paid support for those that want it
  4. Virtually any input is supported, including business object state data and DB query results
  5. Good, responsive support (bugzilla, newsgroup, tutorials, example code, online help)
  • Actuate offers a commercial version with service level agreements for those projects that need better support
Weaknesses:
  1. Installation is not automated (will be resolved in the 2.1 release in summer of 2006)
Tips

Logging
  • BIRT is using the 1.4 logging package. To change the logging level, you need to edit the logging.properties file in the /lib directory that you are running off of.
     Change the line:
    .level= INFO
    to something else, like:
    .level= WARNING
     
Dates
  • To output the current date, you can use a text element (specified as HTML/Dynamic type) and type the following expression:
     <value-of format="MM/dd/yyyy hh:mm:ss">new Date()</value-of>
     
Threads
  • BIRT supports multi-threaded application. ReportEngine is the primary entry point for most applications to integrate with BIRT. It is designed to be thread-safe. When you work with BIRT engine, there are a few key concepts needed to be aware of:

    1. engineConfig, which holds the engine configurations for the current report engine instance. It is not thread safe. So the application should have the engineConfig set for the report engine object before launching any worker threads to execute engine tasks.

    2. engineTask, which represents the report generation/rendering operation. In a standalone application, each engine task should be assigned to a worker thread to execute. In case of BIRT viewer, the viewer servlet thread is the worker thread. So there is no thread safety issue for engineTask itself.

    3. IReportRunnable, represents the report design. It's thread safe. You should be able reuse a cached report design for different engine tasks.

    BIRT report viewer itself is multi-threaded application. You can look to BIRT viewer code for details on how to use BIRT engine API.
Master Page footer
  • You can insert only one top-level element in the header or footer. Because
    there's already a date element in the footer, you can't insert the page
    element.

    If you want only the page element, delete the date element first, then
    insert the page element.

    If you want to insert multiple elements, delete the date element first,
    insert a grid, then insert as many elements as you want in the grid
    No data set fields on the master page.
Here's how to put a page number on all pages: have the following line as the only script on the Master Page footer:
                       - <value-of>pageNumber</value-of> -
Browser
  • If you are using Firefox, artwork files should be referenced with relative paths - absolute paths will work in IE but not in Firefox:
               E.g.: "./images/filename.jpg"

Conditional Coloring on Charts
  • Here's the script I associated with my chart to conditionally color a bar based on a marker value:
    function beforeDrawDataPoint(
    dataPointHints, fill, scriptContext ){

    val = dataPointHints.getOrthogonalValue();
    chart = scriptContext.getChartInstance();
    marker = chart.getAxes().get(0).getAssociatedAxes().get(0).getMarkerLines().get(0).getValue().getValue();
    if (val > marker) //crosses marker?
    fill.set(255, 0, 0); //yes - display in red
    else
    fill.set(0, 0, 255); //no - display in blue

    }
More tips coming soon...

Resources


| 8 comments links to this post