74
© 2008 by Scott Rosenbaum; made available under the EPL v1.0 | 3/11/2008 Integrating Reporting into your Application The BIRT Programming Interfaces Scott Rosenbaum – Innovent Solutions, BIRT PMC [email protected]

Integrating Reporting into your Application

Embed Size (px)

DESCRIPTION

Integrating Reporting into your Application. The BIRT Programming Interfaces Scott Rosenbaum – Innovent Solutions, BIRT PMC [email protected]. Getting The Examples. Subversion Repository http://longlake.minnovent.com/repos/birt_example. How was your spring vacation?. Agenda. - PowerPoint PPT Presentation

Citation preview

Page 1: Integrating Reporting into your Application

© 2008 by Scott Rosenbaum; made available under the EPL v1.0 | 3/11/2008

Integrating Reporting into your Application

The BIRT Programming Interfaces

Scott Rosenbaum – Innovent Solutions, BIRT [email protected]

Page 2: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Getting The Examples

• Subversion Repository

http://longlake.minnovent.com/repos/birt_example

Page 3: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

How was your spring vacation?

Page 4: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Agenda

• Overview• BIRT Home• Running Reports• Deployment Scenarios• Develop Designs in Code• Modify Designs using BIRT Event Handlers • Extending BIRT

Page 5: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.05

Report Designer

Report Design Engine

XMLReportDesign

HTMLPDFDOCXLSPrintPSCSV

Report Engine

PresentationServices

GenerationServices

DataTransformServices

4

ReportDocumentData

Data

1

ChartingEngine 5

Eclipse DTPODA

2

Eclipse WTP

3

ChartDesigner

5

Eclipse ReportDesigner

High Level BIRT Architecture

Page 6: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Chart Builder

RptDocumentReport

Document

JavaScript Events

Optional Java Events

RptDesignXML

Design FileGeneration Phase Presentation Phase

Paginated HTML

PDF

CSV

WORD

XLS

PostScript

PPT

ReportDesigner

DesignEngine

Report Engine

optional

Report EngineReport EngineChart

Engine

Example Web Viewer ContainsExample Web Viewer Contains

BIRT Pipeline with respect to the APIs

Page 7: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

BIRT API Summary

• DEAPI - Design Engine Builds a Report Creates XML ‘rptdesign’ Validates correct XML format Requires knowledge of the Report Object Model (ROM)

More Difficult to Use

• REAPI - Report Engine Runs the Report Provides a relatively simple set of ‘Tasks’ Run reports Render Reports Manipulate Parameters Extract Report Data

Page 8: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

BIRT API Summary

• CEAPI - Chart Engine API Chart Engine

Stand-Alone Charting

Chart Designer Eclipse UI Chart Building Components

Covered in Depth on Wednesday

• BIRT Extension Customize and Extend Standard BIRT Behavior

Data Aggregates Report Items Emitters

Page 9: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

BIRT Runtime Home – What Is It?

• Bare Bones Eclipse Environment OSGi framework Platform Startup No UI Components

• Key BIRT Components Report Engine Design Engine (no UI) Chart Engine Data Tools Connectivity iText, Rhino, Batik

Page 10: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

BIRT Runtime Home – Layout• Lib

Eclipse Platform Startup code BIRT Interfaces

• Plugins Loaded through OSGi Implementation Code (REAPI, DEAPI, CEAPI…) ODA (add your drivers)

• Configuration config.ini

• Custom – need to add Extensions – add to plugins POJOs - add to class-path

Page 11: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

BIRT API OSGi Startup

• Platform Class Starts up required BIRT plug-ins Uses OSGi Used by DE and RE PlatformConfig class configures startup DesignConfig & EngineConfig extend PlatformConfig PlatformContext Class Sets Location of plug-ins Factory creates DesignEngine or ReportEngine

Page 12: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

EngineConfigConfigure BIRT

setLogConfig( location, level )Set logging variables (null location means no file)

setAppContext( HashMap )Adds Java Objects for scripting

Extends

IEngineConfigImplements

setResourcePath( ResourceLocation )Retrieves resources – Libs, Images, etc

setResourceLocator( IResourceLocator )Builds your own resource locator

setTempDir( location )birt.data.engine.memcachesize (default 10M)

setMaxRowsPerQuery( location )Maximum Rows to Retrieve

setBIRTHome( location )Set location of BIRT plug-ins

setOSGiArguments( String[] )Configures OSGi

setPlatformContext( IPlatformContext )Locates OSGi plug-ins

PlatformConfig

DesignConfigConfigure BIRT

Extends

IDesignConfigImplements

setResourceLocator( IResourceLocator )Builds your own resource locator

Page 13: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

IPlatformContextLocation=getPlatform()

PlatformStarts up startup OSGi and create Factory Objects. Static methods.

StartupStart Platform

ShutdownStop Platform

createFactoryObjectLaunch a plugin: implements FactoryService Extension

ReportEngineFactoryReport Engine API

DesignEngineFactoryDesign Engine API

DataEngineFactoryData Engine API

DataAdapterFactoryData Apater API

Model to DataOSGILauncher

Startup

PlatformServletContext

•Looks for javax.servlet.context.tempdir•Creates platform directory in tempdir•Uses getResourcePaths for /WEB-INF/platform to locate plug-ins•Copies plug-ins and configuration to tempdir/platform directory

PlatformFileContext

•Default PlatformContext•Looks for plug-ins in BIRT_HOME

PlaformConfig: EngineConfig/DesignConfig

Optionally implement your

own IPlatformContext

Page 14: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Report Engine Platform Startup Code

IReportEngine engine=null;EngineConfig config = new EngineConfig;config.setBIRTHome(“../ReportEngineProject");try{ Platform.startup( config ); IReportEngineFactory factory = (IReportEngineFactory)

Platform.createFactoryObject(

IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);

engine = factory.createReportEngine( config );

} catch ( Exception ex){ ex.printStackTrace();}

Page 15: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Design Engine Platform Startup Code

IDesignEngine engine = null;

DesignConfig config = new DesignConfig( );

config.setBIRTHome(“/path2/BIRT/ReportEngine");

try{

Platform.startup( config );

IDesignEngineFactory factory =(IDesignEngineFactory)

Platform.createFactoryObject(

IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );

engine = factory.createDesignEngine( config );

} catch( Exception ex){

ex.printStackTrace();

}

Page 16: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Platform Start Up - Logging

• BIRT core uses java.util.logging command line options jre/lib/logging.properties engineConfig.setLogConfig(fileName, Level)

Page 17: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Platform Startup – ClassPath

• Standard Java Class Loader• Class loader set through appContext

WEBAPP_CLASSPATH_KEY WebViewer sets this through scriptlib parm

PROJECT_CLASSPATH_KEY WORKSPACE_CLASSPATH_KEY

• What do you add – Why? Plug-ins are automatically added through OSGi (so don’t add

them to class path) Any other java classes that your reports call (through

expressions or event handlers) need to be added to the classpath.

Page 18: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Platform Startup – Resource Home

• Designer Defaults to Project Home Configure : Windows => Preferences => Report Design => Resource Need to locate Resources in your deployment

engineConfig.setResourcePath(“path/to/resource/home”)

• Web Viewer BIRT_VIEWER_WORKING_FOLDER ${birt home} BIRT_VIEWER_DOCUMENT_FOLDER ${birt home}/documents BIRT_VIEWER_IMAGE_DIR ${birt home}/report/images BIRT_VIEWER_LOG_DIR ${birt home}/logs BIRT_VIEWER_LOG_LEVEL WARNING BIRT_VIEWER_SCRIPTLIB_DIR ${birt home}/scriptlib BIRT_RESOURCE_PATH ${birt home} BIRT_VIEWER_LOCALE

Page 19: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Platform Startup/Shutdown

• Relatively Expensive Process IReportEngine IDesignEngine Thread-safe Save for re-use

• Shutdown Call reportEngine.destroy() Platform.shutdown()

Page 20: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Platform Startup

• Demo

Page 21: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Report Engine API

• Engine Tasks are used to implement operations RunAndRenderTask RunTask Render Task DataExtraction Task ParameterDetails Task

Retrieves Parameter information Dynamic and Cascading Parameters

• Report Engine Basic Operation Open rptdesign Run Report Generate Report Output (HTML, PDF, Excel…)

Page 22: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

EngineConfig Set configuration variables such as Engine Home and Log configuration

ReportEngineGenerate one or more tasks

Open Report Design and Documents Create Engine Task

RptDesignXML

Design File

RptDesignXML

Design File

RptDesignXML

Design File

RptDocumentReport

Document

RptDocumentReport

Document

RptDocumentReport

Document

DataExtractionTask

GetParameterDefinitionTask

RunTask RenderTask

RunAndRenderTask

Retrieve Parameters and their properties

Does not support Pagination, TOC, Bookmarks

Generate Paginated HTML, XLS, PDF Document, Postscript, XLS

Retrieve TOC and Bookmarks

Extract Data from Report Document

Page 23: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

BIRT Runtime Demos

• Two Eclipse Projects Runtime Lib Project Runtime Example

• Demos RunAndRender Run Then Render Data Extraction Parameters Automated Report Testing

Page 24: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Deployment - ScenariosAPIs (DE API, CE API, RE API)

Web Viewer

J2EE AS

Custom Servlet

BIRT Tag Libs

RCP Application Standalone Application

Web ViewerPlugin

Paginated HTML, PDF, XLS, WORD, PPT, PostScript, TOC, Bookmarks, CSV

Chart Tag Libs

Google Web Toolkit

Page 25: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Deployment - BIRT and Web Tools Project

Page 26: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Web Viewer Servlet Mappings

frameset

run

preview

Use this mapping to launch the complete AJAX based report viewer. Contains toolbar, navbar and table of contents features. Run and Render task are separated. This option will also create a rptdocument file.

Use this mapping to launch the viewer without the navbar, toolbar or table of contents. This mapping uses the RunAndRender task to create the output and does not support pagination and does not create a rptdocument. This mapping does use the AJAX framework to allow cancelling a report.

This mapping is used to RunAndRender a report directly to an output format, or to render an existing rptdocument directly to an output format. It does not use the AJAX framework, but will launch a parameter entry dialog.

Web Viewer Servlet Mappings

Page 27: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

WebViewerExample

plug-ins

logs

scriptlib

WEB-INF

lib

BIRT required runtime plug-ins.

The default location for BIRT logs.

Location for BIRT required Jars.

platform

configuration Location for OSGi configuration files.

report

webcontent

birt

ajax

pages

images

styles

Location for class files used in a Scripted Data Source.

Default location of Report Designs

JavaScript files used with the Viewer

JSP Fragments used to build the Viewer

Images used by the Viewer

CSS files used by the Viewer

The Viewer example uses a PlatformServletContext.

So by default the plug-ins are searched for in WEB-

INF/platform.

BIRT Web Viewer Example

Page 28: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

WebViewer Tag LibrariesBirt.tld

viewer

report

param

parameterPage

paramDef

Use this tag to display the complete Viewer inside an IFRAME. This tag allows you to use /frameset and /run mappings.

Use this tag to display the report inside an IFRAME or DIV tag. This tag allows you to use /preview mapping and does not create a rptdocument. The AJAX Framework is not used.

Use this tag to set parameter values when using the viewer or report tags. This tag must be nested within the viewer or report tag.

Use this tag to launch the BIRT Parameter dialog or to create a customized parameter entry page. This tag can be used with the /frameset, /run, or /preview mappings to launch the viewer after the parameters are entered.

Use this Tag within a parameterPage tag to retrieve pre-generated HTML for specific parameter control types such as radio, checkbox, dynamic or cascaded parameters.

Page 29: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Deployment - BIRT Tag Library• Automatically deployed if using a Web Project or by deploying the Web

Viewer Example• Can Deploy Tag Library in separate context by:

Copy birt.tld to your /WEB-INF/tlds directory. Copy com.ibm.icu_3.6.1v20070417.jar, viewerservlets.jar, modelapi.jar,

coreapi.jar to your web-inf/lib directory. Add the following to the web.xml of your application.

<jsp-config> <taglib> <taglib-uri>/birt.tld</taglib-uri> <taglib-location>/WEB-INF/tlds/birt.tld</taglib-location> </taglib> </jsp-config>

Use baseURL attribute to point to BIRT Context: <birt:report id="1" baseURL="/BirtWTP" isHostPage="false"

reportDesign="test.rptdesign"></birt:report>

Page 30: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

YourServletExample

plug-ins

logs

WEB-INF

lib

BIRT required runtime plug-ins. Copy from runtime.

The default location for BIRT logs.

Location for BIRT required Jars. Copy from Runtime.

platform

configuration Location for OSGi configuration files. Copy from runtime.

report

images

Default location of Report Designs

Default location for report imagesUse PlatformServletContext

Use Singleton to launch Design or Report Engine. Start Platform on Servlet Startup and

shutdown Platform on Servlet destroy.

Deployment – From a Servlet

Page 31: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Deployment - Servlet Demo

• Example Servlet using the Report Engine

Page 32: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Deployment – RCP Application

• Using the BIRT plug-ins in Eclipse based applications

Page 33: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

WebViewer Utility Class (RCPViewer Example)

• WebViewer.display()• See Example for Options.• Used with external browser or SWT Browser Widget.

Page 34: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Using the RE/DE API plug-ins in an RCP application

• Do not set BIRT Home and use engines as normal.• See RCPEngine Example.• Uses SWT Browser Widget.

Page 35: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Deployment – Google Web Toolkit

• Utility Classes Needed due to Asyncronous nature of GWT Client Side

AsyncReportServices ReportItem

Must extend isSerializable

ServerSide BirtTasks RPC Web Services providing actual BIRT calls

Page 36: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Page 37: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Page 38: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Develop Designs in Code

• Design Engine API• Manipulate Report Designs, Templates and Libraries• Build New Designs• Modify Existing Designs• Combine with BIRT Script to modify designs on the fly• Create and delete report elements• Put report elements into slots• Get and set parameter values• Retrieve metadata from report elements, properties and slots• Undo/Redo• Semantic Checks on report designs

Page 39: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

BIRT Elements

• Elements – Report Objects such as Table, Label, Style etc.

• Properties – Modify the Element state and often support inheritance. Discussed in ROM specification. Simple and Complex properties.

• Slots – Describes element - container relationships. For example a Report element contains slots for Data Sources, Data Sets, Report Body, etc. Represented by SlotHandle.

Page 40: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEAPI – Figuring Things Out• Build it with the designer• Explore the Outline view• Explore the XML Source• Property names and values are often static properties

DesignChoiceConstants IStyleModel IReportItemModel

• ElementFactory to build new element• StructureFactory to build new structures• BIRT Source Test Cases

Page 41: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEAPI – Basic Report Elements

• Page Layout• Data Source• Data Sets• Body

Grids Tables Rows, Columns, Cells Data, Labels, Text, Charts

• Parameters• Styles

Page 42: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEAPI – Getting Started

• Create a SessionHandle Instance (platform startup)• Get the ReportDesignHandleReportDesignHandle reportDesignHandle = session.createDesign()

• Get the ElementFactoryElementFactory eFactory = reportDesignHandle.getElementFactory()

• Build elements using ElementFactory• Add new elements to the reportDesignHandle slots

Master Page Slot Data Source Slot Data Set Slot Body Slot

Page 43: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEAPI – Basic Workflow

• Use ElementFactory to build new elements• Populate simple properties

Use static values where possible

• Populate complex properties Use StructureFactory to build new complex properties

• Add the elements to the appropriate parent slotreportDesignHandle.getMasterPages().add(simpleMasterPage)

reportDesignHandle.getDataSources().add(dsHandle)

reportDesignHandle.getBody().add(tableHandle)

• Multi-Element Slots use liststableHandle.getDetail().getContents().add(rowHandle)

Page 44: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEAPI – Master Page Slot

• Create the simpleMasterPageDesignElementHandle simpleMasterPage = elementFactory().newSimpleMasterPage("Master Page");

• Customize the simpleMasterPagesimpleMasterPage.setProperty(“topMargin”, “0.5in”)simpleMasterPage.setProperty(“orientation”, “portrait”)

• Add the element to the designHandlereportDesignHandle.getMasterPages().add(simpleMasterPage)

• Creates the following XML element<simple-master-page name="Simple MasterPage" id="2">

<property name="orientation">portrait</property><property name="topMargin">0.5in</property>

</simple-master-page>

Page 45: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEAPI – Data Sources

• Create the Data SourceOdaDataSourceHandle dsHandle = eFactory.newOdaDataSource

("srcClassicModels",“org.eclipse.birt.report.data.oda.jdbc")

• Set Data Source PropertiesdsHandle.setProperty("odaDriverClass", "org.eclipse.birt.report.data.oda.sampledb.Driver")

dsHandle.setProperty("odaURL", "jdbc:classicmodels:sampledb")

dsHandle.setProperty("odaUser", "ClassicModels")

• Add the Data Source to the report handlereportDesignHandle.getDataSources().add(dsHandle);

Page 46: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEAPI – DataSets

• Create the DataSetOdaDataSetHandle dataSetHandle = eFactory.newOdaDataSet

("setOrderDetails",

"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet");

• Set the Data SourcedataSetHandle.setDataSource("srcClassicModels");

• Set the querydataSetHandle.setQueryText("Select * from ORDERDETAILS");

• Add columns (next page)• Add to the reportHandlereportDesignHandle.getDataSets().add(dataSetHandle);

Page 47: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEAPI – Add ResultSet Columns

• ResultSet ColumnsPropertyHandle resultSet = dataSetHandle.getPropertyHandle

(ScriptDataSetHandle.RESULT_SET_PROP);

OdaResultSetColumn resultColumn = StructureFactory.createOdaResultSetColumn();

resultColumn.setPosition(1);

resultColumn.setColumnName(“column_1”);

resultColumn.setDataType(DesignChoiceConstants.COLUMN_DATA_TYPE_ANY)

resultSet.addItem(resultColumn);

Page 48: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEAPI – Add Computed Columns

PropertyHandle computedSet = dataSetHandle.getPropertyHandle(ScriptDataSetHandle.COMPUTED_COLUMNS_PROP);

ComputedColumn compCol = StructureFactory.createComputedColumn();compCol.setName("TotalAmount");compCol.setExpression

("row[\"PRICEEACH\"] * row[\"ORDERQUANTITY\"]");compCol.setDataType(DesignChoiceConstants.COLUMN_DATA_TYPE_DECIMAL);computedSet.addItem(compCol);

Page 49: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEAPI – Body Element

TableHandle tHandle = elementFactory.newTableItem(“tbl",3,1,1,1);

tableHandle.setProperty(IStyleModel.TEXT_ALIGN_PROP, DesignChoiceConstants.TEXT_ALIGN_CENTER);

tableHandle.setWidth("80%");

tableHandle.setProperty(IReportItemModel.DATA_SET_PROP, "setOrderDetails");

Page 50: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEAPI – Body Element

• Create TableHandle• Build table bindings• Manipulate Slots

Columns (ColumnHandle) tableHandle.getColumns().get(0)

Rows (RowHandle) tableHandle.getHeader().get(0) Cells (CellHandle) rowHandle.getCells().get(0) Labels, TextItems, and DataItems

Use ElementFactory to create and add to Cells

Page 51: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEMO - Design Engine API Examples

• Build a Simple Report• Data Sources and Data Sets• Tables and Data Binding• Slots, Groups, and Styles• Parameters• Modify Existing Design• Access Libraries

Page 52: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEAPI – BIRT Event Handlers

• Dynamically modify your design using the DEAPI• Where to you modify the Design

Better to think When not where BeforeFactory OnPrepare Later events are too late

• DataSets un-available at OnPrepare You can use REAPI and ParameterTask to get name / value

pairs

Page 53: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEAPI – Handles versus Items

• Two types of objects in BIRT Handles = design objects Items = instantiated objects

• Handles in OnPrepare or BeforeFactory Use the DEAPI

• Items are ‘tricky’ Items are wrapped for scripting Script items do not provide full control Access to the ‘real’ item is tricky and discouraged

Page 54: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEAPI – Java vs JavaScript• Java event handlers

(+) Easier to debug(+) Easier to reuse(+) Better code assist(-) Strong type checking - requires frequent casts(-) May introduce deploy issue

• JavaScript event handlers(-) Harder to debug(-) Harder to reuse (cut and paste or libraries)(-) Code assist can be misleading(+) No type checking means no casts(+) Easy to deploy

Page 55: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEAPI – Java vs JavaScript

• Drop a table in JavaIReportRunnable runnable = reportContext.getReportRunnable();

DesignElementHandle designHdl = runnable.getDesignHandle();

ModuleHandle moduleHdl = designHdl.getModuleHandle();

TableHandle tableHdl = (TableHandle)moduleHdl.findElement(“tbl1”);

tableHdl.drop();

• Drop a table in JavaScriptvar runnable = reportContext.getReportRunnable();

var designHandle = runnable.designHandle.getDesignHandle();

designHandle.findElement("table1").drop();

Page 56: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

DEMO – DEAPI BIRT Event Handlers

• JavaScript Drop a Table Add a DataSet Filter

• Java Modify a Table Debug using Runtime Engine Debug using Tester

Page 57: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

BIRT Extensions

• Data Tool Extension Points DriverBridge Open Data Access (ODA) ODA UI

• BIRT Extension Points Aggregates Report Items Emitters Charts

• BIRT Extensions use Eclipse Plug-In Framework

Page 58: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

What Is a Plug-In ?

• Plugins - Reusable component arch.• Eclipse is built using Plug-ins• Core Platform provides Extension Points• BIRT extends the core Eclipse Plug-Ins• You extend BIRT through extension points

Page 59: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Interfaces vs. Adapters

• All BIRT Extensions are defined by an Interface• Most extension interfaces have an adapter class • Implement the Interface

Required to implement all methods Interface changes may break your code

• Extend the Adapter Hides infrequently used interfaces Isolate implementation from an Interface change Recommended procedure

Page 60: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Extension Contribution And Use

org.eclipse.birt.report.data.adapter

Extension Point: aggregation

Exports: - Aggregation - Accumulator - ….

my.new.birt.aggregates

Extensions: aggregation

Classes: - MyAggegator - MyAccumulator

contributes

implements

Runs

Page 61: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

What is a Plug-in (more)

• A new plug-in: Uses dependency to resolve required classes Implements extension points through extensions Optionally – can export packages to clients Optionally – can create extension points

• Eclipse framework is based on OSGi framework R4.0 spec

Eclipse plug-ins ≈ OSGi bundles

Page 62: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Aggregate Extension Point

• Allows you to define your own aggregates Total.yourFunctionHere()

• Relatively easy to implement Create a Plug-in project

Add Dependencies Fill-out Extension interface

Implement Aggregate classes Aggregator extends Aggregation Accumulator extends Accumulator

Test using Runtime Workbench instance

Page 63: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

ODA = Open Data Architecture

• Create new data access components Data Sources

Connect to the data

Data Sets Specify what to get Can re-use same Data Source w/o re-connect

• Access to Non-Standard Data Sources Based on standard DataSource and DataSet UI Filter, Computed Columns, Preview, Joint Data Set are all

built in Report Developers use a Similar Drag and Drop UI

Page 64: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

IQueryprepare

execute

getParameterMetaData

ODA Runtime InterfacesIDriver

create: PlugInIResultSetMetaData

IResultSetGenerates data rows

IParameterMetaDataIf query uses paramsIAdvancedQuery

Supports In/Out, complex paramSupports Blob/Clob TypesSupports multiple resultsets

IParameterRowSet

Supports Complex Parameter Types

IBlob IClob

IDataSetMetaData

Design time only

one per Data Set Type

IConnection

newQuery(dataSetType)

getMetaData

Page 65: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

ODA Runtime Sequence

• Initialize• Prepare Query• Execute Query• Close

Page 66: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

ODA DataSource Wizards

• RunTime Wizard Creates plugin.xml, manifest.mf, and plugin.properties Creates hard code example of ODA interfaces Works, but requires a Designer component

• DesignTime Wizard Creates simple UI for DataSource

Uses Eclipse property editor

Creates simple query based UI for DataSet

Page 67: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

ReportItem Extension

• Add New Items to the Palette Charts are ReportItem extension Crosstab is a ReportItem extension

• Implements multiple extension points Report Object Model – How is persisted in the rptdesign Report Item UI – How does the designer interact Report Item Generation – What happens at run time Report Item Presentation – What happens at view time

• Creating ReportItem extensions is non-trivial Data handling, Presentation, Script handling, Styles UI Issues

Page 68: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Report Object Model (simplified)

Page 69: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Emitters – Interfaces

• IContentEmitter Walks through all of the components in the report Tables, Rows, Cells, Data, Styles, Script … Use ContentEmitterAdapter Stubs out required interfaces, implement as needed

• IEmitterServices Provides required info for emitter E.g. OutputStream, report name, report context, etc.

• IContentVisitor• XMLWriter

Page 70: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Emitters - Difficulty

• Data Dump Emitters Relatively trivial Walk through each component and wrap/write the value

• Full function Emitters Styles, links, actions, etc. Create numerous complex issues for layout and function

mapping

• Report Complexity = Emitter Complexity Complex report designs Require complex emitters

Page 71: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Want More BIRT Talks?

• Introduction to BIRT 2.2Tuesday 11:10 207 Paul Clenahan

• Because Size Matters : Combining CDT and BIRT to Analyze Binary Code Size of Embedded ApplicationsTuesday 14:00 209/210 Philippe Coucaud

• BIRT Chart API'sTuesday 16:30 207 Jason Weathersby

• Using Eclipse BIRT in the real word seriouslyTuesday 16:30 Great America Ballroom JK Justin Miranda

• Getting the most from your BIRT reportsWednesday 10:10 Ballroom E Virgil Dodson

• Introducing DTP Open Data Access FrameworkWednesday 13:30 Great America Room 2 Linda Chan

Page 72: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

We’re not done yet…

• BIRT Short TalksWednesday 15:30 (5 talks in one hour) 203/204

Amazon Web Service Report Virgil Dodson

BIRT and Google Maps Mashup Pierre Tessier

BIRT and Google Web Toolkit John Ward

Charting Everywhere Philippe Coucaud

OpenDocument Format Spread-Sheet Emitter for BIRT Santosh Kumar

• Meeting customer’s reporting reqs by extending BIRTWednesday 4:30 207 Neil Wang, Wei Liu,

Santosh Kumar, Maged Elaasar

Page 73: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Finally

• BIRT BOF - Birts of a FeatherWednesday 8:45pm Grand Ballroom C

Talk to the BIRT tech leads about what you are doing, what you want to do, how we can make the product better, etc.

We’re buying the beer …

• Come by the Actuate Booth at the Exhibitor Hall

Page 74: Integrating Reporting into your Application

Integrating Reporting Into your Application | © 2008 by Scott Rosenbaum; made available under the EPL v1.0

Questions?

• Thank You Very Much• www.eclipse.org/birt• birtworld.blogspot.com• www.birt-exchange.com• longlake.minnovent.com/repos/birt_example

Example Code

[email protected]