html5-img
1 / 74

Integrating Reporting into your Application

Integrating Reporting into your Application. The BIRT Programming Interfaces Scott Rosenbaum – Innovent Solutions, BIRT PMC scottr@innoventsolutions.com. Getting The Examples . Subversion Repository http://longlake.minnovent.com/repos/birt_example. How was your spring vacation?. Agenda.

Télécharger la présentation

Integrating Reporting into your Application

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Integrating Reporting into your Application The BIRT Programming Interfaces Scott Rosenbaum – Innovent Solutions, BIRT PMC scottr@innoventsolutions.com

  2. Getting The Examples • Subversion Repository http://longlake.minnovent.com/repos/birt_example

  3. How was your spring vacation?

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

  5. Report Engine Chart Designer Data Transform Services Charting Engine Eclipse DTP ODA Eclipse WTP 5 2 5 3 HTML PDF DOC XLS Print PS CSV Presentation Services Generation Services 4 Data XMLReportDesign ReportDocument Data High Level BIRT Architecture 1 Report Designer Eclipse Report Designer Report Design Engine 5

  6. BIRT Pipeline with respect to the APIs Report Designer Chart Builder Report Engine Optional Java Events Design Engine Chart Engine Paginated HTML PDF CSV WORD XLS PostScript PPT JavaScript Events RptDesign XML Design File Generation Phase Presentation Phase Report Engine RptDocument Report Document optional Example Web Viewer Contains

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

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

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

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

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

  12. setPlatformContext( IPlatformContext ) Locates OSGi plug-ins PlatformConfig setBIRTHome( location ) Set location of BIRT plug-ins setOSGiArguments( String[] ) Configures OSGi Extends Extends EngineConfig Configure BIRT DesignConfig Configure BIRT Implements IEngineConfig Implements IDesignConfig setLogConfig( location, level ) Set logging variables (null location means no file) setResourceLocator( IResourceLocator ) Builds your own resource locator setAppContext( HashMap ) Adds Java Objects for scripting 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

  13. Platform Starts up startup OSGi and create Factory Objects. Static methods. Startup Start Platform Shutdown Stop Platform createFactoryObject Launch a plugin: implements FactoryService Extension DesignEngineFactory Design Engine API ReportEngineFactory Report Engine API Optionally implement your own IPlatformContext DataEngineFactory Data Engine API DataAdapterFactory Data Apater API Model to Data OSGILauncher Startup IPlatformContext Location=getPlatform() PlaformConfig: EngineConfig/DesignConfig PlatformFileContext PlatformServletContext • Default PlatformContext • Looks for plug-ins in BIRT_HOME • 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

  14. 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(); }

  15. 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(); }

  16. Platform Start Up - Logging • BIRT core uses java.util.logging • command line options • jre/lib/logging.properties • engineConfig.setLogConfig(fileName, Level)

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

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

  19. Platform Startup/Shutdown • Relatively Expensive Process • IReportEngine • IDesignEngine • Thread-safe • Save for re-use • Shutdown • Call reportEngine.destroy() • Platform.shutdown()

  20. Platform Startup • Demo

  21. 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…)

  22. RptDesign XML Design File RptDocument Report Document RptDesign XML Design File RptDocument Report Document RptDesign XML Design File RptDocument Report Document Set configuration variables such as Engine Home and Log configuration EngineConfig Open Report Design and Documents Create Engine Task ReportEngine Generate one or more tasks Retrieve Parameters and their properties GetParameterDefinitionTask RunAndRenderTask Does not support Pagination, TOC, Bookmarks DataExtractionTask Extract Data from Report Document Generate Paginated HTML, XLS, PDF Document, Postscript, XLS RunTask RenderTask Retrieve TOC and Bookmarks

  23. BIRT Runtime Demos • Two Eclipse Projects • Runtime Lib Project • Runtime Example • Demos • RunAndRender • Run Then Render • Data Extraction • Parameters • Automated Report Testing

  24. Deployment - Scenarios APIs (DE API, CE API, RE API) BIRT Tag Libs Custom Servlet Web Viewer Web Viewer Plugin Chart Tag Libs J2EE AS RCP Application Google Web Toolkit Standalone Application Paginated HTML, PDF, XLS, WORD, PPT, PostScript, TOC, Bookmarks, CSV

  25. Deployment - BIRT and Web Tools Project

  26. Web Viewer Servlet Mappings Web Viewer Servlet Mappings 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. frameset 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. run 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. preview

  27. BIRT Web Viewer Example WebViewerExample The default location for BIRT logs. logs Location for class files used in a Scripted Data Source. scriptlib Default location of Report Designs report webcontent birt JavaScript files used with the Viewer ajax The Viewer example uses a PlatformServletContext. So by default the plug-ins are searched for in WEB-INF/platform. JSP Fragments used to build the Viewer pages Images used by the Viewer images CSS files used by the Viewer styles WEB-INF lib Location for BIRT required Jars. platform BIRT required runtime plug-ins. plug-ins Location for OSGi configuration files. configuration

  28. WebViewer Tag Libraries Birt.tld Use this tag to display the complete Viewer inside an IFRAME. This tag allows you to use /frameset and /run mappings. viewer 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. report 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. param 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. parameterPage 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. paramDef

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

  30. Deployment – From a Servlet Use Singleton to launch Design or Report Engine. Start Platform on Servlet Startup and shutdown Platform on Servlet destroy. YourServletExample The default location for BIRT logs. logs Default location of Report Designs report Use PlatformServletContext images Default location for report images WEB-INF lib Location for BIRT required Jars. Copy from Runtime. platform BIRT required runtime plug-ins. Copy from runtime. plug-ins Location for OSGi configuration files. Copy from runtime. configuration

  31. Deployment - Servlet Demo • Example Servlet using the Report Engine

  32. Deployment – RCP Application • Using the BIRT plug-ins in Eclipse based applications

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

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

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

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

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

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

  39. DEAPI – Basic Report Elements • Page Layout • Data Source • Data Sets • Body • Grids • Tables • Rows, Columns, Cells • Data, Labels, Text, Charts • Parameters • Styles

  40. DEAPI – Getting Started • Create a SessionHandle Instance (platform startup) • Get the ReportDesignHandle ReportDesignHandle reportDesignHandle = session.createDesign() • Get the ElementFactory ElementFactory 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

  41. 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 slot reportDesignHandle.getMasterPages().add(simpleMasterPage) reportDesignHandle.getDataSources().add(dsHandle) reportDesignHandle.getBody().add(tableHandle) • Multi-Element Slots use lists tableHandle.getDetail().getContents().add(rowHandle)

  42. DEAPI – Master Page Slot • Create the simpleMasterPage DesignElementHandle simpleMasterPage = elementFactory().newSimpleMasterPage("Master Page"); • Customize the simpleMasterPage simpleMasterPage.setProperty(“topMargin”, “0.5in”) simpleMasterPage.setProperty(“orientation”, “portrait”) • Add the element to the designHandle reportDesignHandle.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>

  43. DEAPI – Data Sources • Create the Data Source OdaDataSourceHandle dsHandle = eFactory.newOdaDataSource ("srcClassicModels",“org.eclipse.birt.report.data.oda.jdbc") • Set Data Source Properties dsHandle.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 handle reportDesignHandle.getDataSources().add(dsHandle);

  44. DEAPI – DataSets • Create the DataSet OdaDataSetHandle dataSetHandle = eFactory.newOdaDataSet ("setOrderDetails", "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet"); • Set the Data Source dataSetHandle.setDataSource("srcClassicModels"); • Set the query dataSetHandle.setQueryText("Select * from ORDERDETAILS"); • Add columns (next page) • Add to the reportHandle reportDesignHandle.getDataSets().add(dataSetHandle);

  45. DEAPI – Add ResultSet Columns • ResultSet Columns PropertyHandle 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);

  46. 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);

  47. 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");

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

More Related