OFBIZ Reports with BIRT Generating Open For Business Reports with the BIRT RCP Designer by Leon Torres and Si Chen The Business Intelligence Reporting Tools (BIRT) is a suite of tools for generating professionallooking reports from a database. BIRT can be integrated into a web application server framework to render reports in HTML or PDF on the fly. Alternatively, BIRT can run standalone using the Rich Client Platform (RCP) Designer application, which is installed on a client machine and connects to an OFBiz database remotely. Overview This tutorial describes in detail how to set up the BIRT RCP Designer application on a Windows machine as a client to an OFBiz database running on another machine. It also presents a brief tutorial on how to generate reports using sample sales orders created in the OFBiz Order Manager application. The database used in this tutorial is PostgreSQL 8.0. However, it is easy to replicate the instructions for any other database. Prerequisites OFBiz running on a database of your choice. In this tutorial, we will cover PostgreSQL 8.0. Standalone BIRT RCP Designer (download the latest onto the Windows client machine). • http://download.eclipse.org/birt/downloads/ Configuration First, you will need to configure the OFBiz database to allow connections from the Windows client machine. In order to do this in PostgreSQL, edit the pg_hba.conf file and enter a line to allow access from the client machine's IP address, or, if desired, from the IP block which the client machine resides in. In this example we will assume that the client machine and the server running OFBiz and PostgreSQL 8.0 are in the same internal network block 192.168.1.0/24. # Enter this line into pg_hba.conf host all all 192.168.1.0/24 md5 Database connectivity can be tested from within the BIRT RCP Designer. © 2006 Open Source Strategies, Inc. All Rights Reserved. OFBIZ Reports with BIRT Next, you will need to download the JDBC driver for your database onto the Windows client machine so that BIRT can connect. You can place the driver anywhere on the client. The PostgreSQL 8.0 JDBC driver is distributed with OFBiz at the following location, ofbiz/framework/entity/lib/jdbc/postgresql-8.0-311.jdbc3.jar Planning a Report Before we begin using BIRT, we should plan what our report is going to be. For this tutorial, we will be determining the total number of products sold and the revenue generated by product ID. This involves summing the quantity of each order item, summing the quantity times unit price of each order item, and grouping the results by order ID. If you're running a demo, create some sales orders using the order manager application. There is no need to complete the orders. BIRT has a data model navigation tool and a handy SQL editor, so it is unnecessary to write down the SQL here. With the report plan in mind, we can now begin writing the report. Running BIRT Unzip the BIRT RCP zip file that you downloaded anywhere on the client machine. Click on the BIRT.exe file to start the program. BIRT should look like the following illustration. © 2006 Open Source Strategies, Inc. All Rights Reserved. Illustration 1: This is how BIRT should look whenever it starts. OFBIZ Reports with BIRT The first step is to create a new report. From the File menu, select New Report and give it a name such as test.newrpt. When you finish, the view will fill up with many options. One of the windows is called Cheat Sheets. Go ahead and close it, you won't be needing it. In the middle is a view window where you will construct the report by dragging and dropping elements from the Palette. The Palette is located in the upper left. Let's begin by constructing a title for the report. Drag a Label object from the Palette onto the view window. You'll be prompted to enter the label text. Type in the name of the first report, “Sales By Product” and press Enter. To change the text again, right click on the Label and select Edit. Underneath the view is a Property Editor which displays options for the Label. You can change the font, colors, and general appearance. Make the Label looks like a title by changing the background color, increasing the font size, centering the text and making it bold. © 2006 Open Source Strategies, Inc. All Rights Reserved. Illustration 3: View with a Label and Text Illustration 2: When a new report is created, the view fills up with many options. Close the Cheat Sheets window. OFBIZ Reports with BIRT Now add a text object underneath the title to describe the first report. To do this, drag a Text from the Palette and a box should pop up prompting for input. Enter a description such as, “This is a report that shows the sales breakdown by product.” The text should appear as the illustration above. Connecting to the database Databases are represented as Data Sources in BIRT. Find the Data Explorer tab next to the Palette and click on it. You should see a Data Sources folder. To create a Data Source, right click on the Data Sources folder and select New Data Source. © 2006 Open Source Strategies, Inc. All Rights Reserved. Illustration 5: Creating a new Data Source Illustration 4: Label and Text objects in the view OFBIZ Reports with BIRT You'll be prompted to select a Data Source type. Select JDBC Data Source and click on Next. The next dialog requests the connection information. First we will need to add our JDBC driver to the list named Driver Class. To do this, select Manage Drivers. © 2006 Open Source Strategies, Inc. All Rights Reserved. OFBIZ Reports with BIRT In the Manage JDBC Drivers dialog, use the Add button to add the JDBC jar file which you copied over to this machine. It will show up in the list of JAR Files. Once the driver is listed, click OK to return to the dialog asking for connection information. Now you can select your driver from the Driver Class list. The remaining connection information should be the same as that described in your OFBiz entityengine.xml configuration file. Enter the information and then click on Test Connection to see if you can connect. Then click OK to return to the main view. © 2006 Open Source Strategies, Inc. All Rights Reserved. Illustration 6: Enter your connection information from entityengine.xml OFBIZ Reports with BIRT Creating Report Queries Assuming the connection was successful, we can proceed to define queries that our report will use. These queries are called Data Sets. They are located in the Data Explorer under the Data Sources. To create a new Data Set, right click on the Data Set folder and select New Data Set from the context menu. This dialog asks for basic information about the Data Set. Give it a name, such as “Sales By Product”. There is only one data source. The Data Set Type is SQL Select Query. The next dialog allows you to construct a SQL query and navigate the database and all of its objects, including tables, sequences, foreign keys, etc. © 2006 Open Source Strategies, Inc. All Rights Reserved. OFBIZ Reports with BIRT You can also narrow down the list of choices with the filter options at the bottom. It is a good idea to show tables only by selecting Tables for Type. This will get rid of the nontable objects from the database item tree. Go ahead and type the query as shown in the illustration above. Alternatively, you can drag the names of the objects from the tree onto the query to save some typing. The query could be more sophisticated, but this is sufficient for the purpose of the tutorial. Note the use of AS to rename the fields. BIRT will use “Quantity” and “Amount” as the column names for the sums. When you're finished, the Data Set should look like the illustration on the right. Notice that the result columns are part of the list. This is important because we can drag these columns onto objects in the view to create an association between a view object and the result column. © 2006 Open Source Strategies, Inc. All Rights Reserved. Illustration 7: Creating a query OFBIZ Reports with BIRT Presenting the Data Set in a Table The next step is to display the results in a table. Go to the palette and drag a Table object onto the view. You will be presented with a dialog requesting the number of columns and details. There are three result columns, so the default of three should be fine. Details is where our data would be displayed. Think of Details as a union of Data Sets. Since there is only one Data Set, the default of one detail is good. The table appears on the view showing three kinds of rows, a Header row for the column title, a Detail row for our data, and a Footer row. In order to link the table columns with the result set columns, all you need to do is drag the desired column from our Data Set in the Data Explorer onto the cell in the Detail row where you want the data to display. © 2006 Open Source Strategies, Inc. All Rights Reserved. Illustration 8: A Table on the view with the the first cell of the Detail row selected. Illustration 9: Table with a Detail Row cell highlighted. OFBIZ Reports with BIRT This is best explained by the following illustration, where the product_id column is dragged onto the first Detail cell. BIRT fills in the Header for you. To format the table, click on each object to be formatted and edit their properties as you did with the Label and Text objects. You can format individual cells or whole rows and columns. Finally, our report is finished. Preview the results by clicking on the Preview tab, which is located along the bottom of the view. Alternatively, you may select a preview option from the File menu. © 2006 Open Source Strategies, Inc. All Rights Reserved. Illustration 10: Linking the product_id result column to the first Detail column by dragging. Illustration 11: Report preview OFBIZ Reports with BIRT Saving the Report To save the report, select Save from the File menu. This preserves all the work you've done up to this point as a .rptdesign file and allows you to resume the report creation at a later time. The .rptdesign file is also used to generate a report to the user dynamically as will be described in the next section. Presenting the Report Dynamically Once you've saved your report as an .rptdesign file, you can use the report as HTML or PDF by using a web browser. In Preview mode, right click on the window and select Create Shortcut from the context menu as shown in the illustration on the right. BIRT will place a URL shortcut on your desktop that contains the .rptdesign file. When you want to view your report, first open the BIRT RCP Designer on your desktop. Then, open the shortcut in a web browser, and you should see the report as HTML. The report will be updated every time the link is refreshed. To serve this page as a PDF instead, look for the URL parameter __format=html. Change it to __format=pdf. As long as the BIRT RCP Designer is running, your .rptdesign report will be rendered. Alternatively, the .rptdesign files that you create can be incorporated into an application such as OFBiz or an application server such as Geronimo and served up over the web. The user would type in a URL that contains the .rptdesign file and be presented with the HTML or PDF result. This will deserve further investigation. Conclusions In this tutorial you learned how to set up BIRT RCP Designer on a client machine, how to connect BIRT to a remote server running OFBiz, how to generate a report, and how to present the report as HTML or PDF dynamically. From this point, you may wish to explore how to integrate BIRT into OFBiz or serve it from Geronimo so that the reports may be run from a web browser. In all cases, the report files (.rptdesign) must be created first, as you did here with the BIRT RCP Designer. © 2006 Open Source Strategies, Inc. All Rights Reserved. Illustration 12: Creating a Shortcut URL OFBIZ Reports with BIRT BIRT is also available as an Eclipse perspective. If the person who will be generating the reports also uses the Eclipse IDE, he or she may wish to install it as a plugin. Instructions for doing this may be found at the Eclipse Project home page. http://www.eclipse.org/birt/phoenix/ © 2006 Open Source Strategies, Inc. All Rights Reserved.