Pages

Sunday, July 1, 2012

BIRT 3.7 - Dynamic connection profiles

The other day I used BIRT 3.7 Report Engine Runtime for generating reports over the web.  The reports creation and access will occur from different clients using technologies like .Net, JAVA, etc...  And the report design will use web services as the data source for populating the report information (data, images, etc..).

Something I had a little trouble when making the dynamic report was how to specify the data source connections dynamically?  In my case the solution is self-configure through having an environment variable which identifies the system as DEV, QAT, UAT, PROD.  All the different projects could be built one time and deploy to different environment without any configuration change.  I wanted the same for the reporting solution.

The ideas I read for making dynamic connections required to:
  1. Define the connection profiles pointing to the data sources
  2. Pass the connection profile name in the URL
This solves most of my problems, except when I found out that refreshing the web service WSDL schema will failed due to not knowing the connection profile to use.  For this I made a simple scripts which always defaults to the development connection and overrides when the connection profile parameter is passed in.
var profName = "DEV-Localhost.conn";

try { 
    profName = params["connProfileName"]; 
} 
catch (err) 
{  /* continue... */ }

reportContext.getAppContext().get("birt.viewer.resource.path") 
    + "/report/config/" + profName;


Putting it all together...

  1. Create the dynamic web project to host the BIRT report engine runtime.  In my setup I have "birt.viewer.resource.path" pointing to the WebContent folder.  So I just need to point the report designers in <path>/report/design/ and the connection profiles in  <path>/report/config/
  2. Define a connection profile for the data source.
  3. Define a report parameter for the connection profile name.
  4. Duplicate the profile connection file and edit the URI address to the data source.
  5. Dev-Localhost.conn
    
        
        
            
        
        
    
    

  6. Go back to the data source and add  in the property binding section the connection profile store script from above.
  7. Test the report by passing as an argument the different connection profiles in the report generation URL.
http://localhost:8080/WR/frameset?connProfileName=DEV-Localhost.conn&__report=report/design/MyReport.rptdesign
http://localhost:8080/WR/frameset?connProfileName=QAT-Server.conn&__report=report/design/MyReport.rptdesign
http://localhost:8080/WR/frameset?connProfileName=ETC-Server.conn&__report=report/design/MyReport.rptdesign

No comments:

Post a Comment