Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Design ideas, using BIRT only as viewer ?(Use BIRT on top of a query function only for report-viewing and pdf-rendering, not dw-access, authoring etc)
Design ideas, using BIRT only as viewer ? [message #560090] Tue, 21 September 2010 07:49 Go to next message
jerome k is currently offline jerome k
Messages: 5
Registered: September 2010
Junior Member
Hi,
We have built a quite successful query function to a production system that primarily returns fully drillable tables, almost like pivottables.

Select page/row/value-fields, prompts, subtotals, getting the dw-data by SQL, authority issues per user etc works real fine, but we want to add a report version för nicer formatting, PDF's, emailing/printing/scheduling (or just on the fly switching to "report mode"). This mode should expand drillable fields.

Our query table classes are easy to convert to XML-data. Is it a good idea to use BIRT to read the XML-data and process a report with the viewer ? Since there are unlimited different queries (and the dw-model are different for all customers and concurrently changing ! ) that can be changed anytime the XML-data as well as the report XML including the data sets must be built and passed on the fly.

So: Is it possible AND a good idea to temporary pass XML-data and a matching XML report descriptions to BIRT viewer for rendering ?

Or should we build our own formatting/style sheets and PDF rendering etc ?

/J

Re: Design ideas, using BIRT only as viewer ? [message #560221 is a reply to message #560090] Tue, 21 September 2010 15:20 Go to previous message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

This definitely possible. You have a couple of choices. You can use the de api to create the report on the fly from a custom jsp/servlet and then forward to the viewer or use the re api in a servlet and call the de api from the re api to create the report on the fly all in the same servlet. Another option is to call the de api in the beforeFactory script of a blank report to create the entire report on the fly in the viewer. I am attaching some simple de api code to show you how to create the report. Note that the birt platform should only be started once for the life of the app. The example just starts and stops it everytime.

Jason

package DEAPI;

import java.io.File;
import java.io.IOException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.DataItemHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.DesignEngine;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.LabelHandle;
import org.eclipse.birt.report.model.api.PropertyHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.RowHandle;
import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.TableHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException ;
import org.eclipse.birt.report.model.api.command.ContentException;
import org.eclipse.birt.report.model.api.command.NameException;
import org.eclipse.birt.report.model.api.elements.DesignChoiceConst ants;
import org.eclipse.birt.report.model.api.elements.structures.Comput edColumn;
import org.eclipse.birt.report.model.api.metadata.IMetaDataDictiona ry;
import org.eclipse.birt.report.model.elements.interfaces.IReportIte mModel;
import org.eclipse.birt.report.model.elements.interfaces.IStyleMode l;

import com.ibm.icu.util.ULocale;

public class XMLReport
{

ReportDesignHandle reportDesignHandle = null;

ElementFactory elementFactory = null;

IMetaDataDictionary dict = null;

ComputedColumn cs1, cs2, cs3 = null;

public static void main( String[] args ) throws SemanticException,
IOException
{
new XMLReport( ).createReport( );
}

void createReport( ) throws SemanticException, IOException
{
//Configure the Engine and start the Platform
DesignConfig config = new DesignConfig( );

config.setBIRTHome("C:/birt/birt-runtime-2_5_1/birt-runtime-2_5_1/ReportEngine ");
IDesignEngine engine = null;
try{


Platform.startup( config );
IDesignEngineFactory factory = (IDesignEngineFactory) Platform
.createFactoryObject(
IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
engine = factory.createDesignEngine( config );

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


SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;


// Create a new report
reportDesignHandle = session.createDesign( );

// Element factory is used to create instances of BIRT elements.
elementFactory = reportDesignHandle.getElementFactory( );

dict = new DesignEngine( null ).getMetaData( );

createMasterPages( );
createDataSources( );
createDataSets( );
createBody( );

//OdaDataSourceHandle dataSourceHandle = (OdaDataSourceHandle)reportDesignHandle.findDataSource("myxmldatasource ");


String outputPath = "output";//$NON-NLS-1$
File outputFolder = new File( outputPath );
if ( !outputFolder.exists( ) && !outputFolder.mkdir( ) )
{
throw new IOException( "Can not create the output folder" );//$NON-NLS-1$
}
reportDesignHandle.saveAs( "output/desample/XMLReport.rptdesign" );//$NON-NLS-1$//$NON-NLS-2$
System.out.println("finished");
}





private void createDataSources( ) throws SemanticException
{
OdaDataSourceHandle dataSourceHandle =
elementFactory.newOdaDataSource("Data Source",
"org.eclipse.birt.report.data.oda.xml");
dataSourceHandle.setProperty("FILELIST", "C:/temp/xmltest2.xml");
reportDesignHandle.getDataSources( ).add( dataSourceHandle );
}

private void createDataSets( ) throws SemanticException
{
// Data Set

OdaDataSetHandle dsHandle = elementFactory.newOdaDataSet( "Data Set",
"org.eclipse.birt.report.data.oda.xml.dataSet" );
dsHandle.setDataSource( "Data Source" );
dsHandle.setQueryText(
" table0#-TNAME-#table0#:#[/people/person/name]#:#{name;String ;} " );

reportDesignHandle.getDataSets( ).add( dsHandle );


}

private void createMasterPages( ) throws ContentException, NameException
{
DesignElementHandle simpleMasterPage =
elementFactory.newSimpleMasterPage( "Master Page" );//$NON-NLS-1$
reportDesignHandle.getMasterPages( ).add( simpleMasterPage );
}



private void createBody( ) throws SemanticException
{



TableHandle table = elementFactory.newTableItem( null, 3, 1, 1, 1 );
table.setProperty( IStyleModel.TEXT_ALIGN_PROP,
DesignChoiceConstants.TEXT_ALIGN_CENTER );
table.setWidth( "80%" );//$NON-NLS-1$
table.setProperty( IReportItemModel.DATA_SET_PROP, "Data Set" );//$NON-NLS-1$

PropertyHandle computedSet = table.getColumnBindings( );
cs1 = StructureFactory.createComputedColumn( );

cs1.setName("Name");
cs1.setExpression( "dataSetRow[\"name\"]" );//$NON-NLS-1$
computedSet.addItem( cs1 );



// Header
RowHandle header = (RowHandle) table.getHeader( ).get( 0 );

CellHandle tcell = (CellHandle) header.getCells( ).get( 0 );
LabelHandle label = elementFactory.newLabel( null );
label.setText( "Name" );//$NON-NLS-1$
tcell.getContent( ).add( label );



DataItemHandle data = null;
// Detail
RowHandle detail = (RowHandle) table.getDetail( ).get( 0 );
tcell = (CellHandle) detail.getCells( ).get( 0 );
data = elementFactory.newDataItem( null );
data.setResultSetColumn( cs1.getName( ) );
tcell.getContent( ).add( data );


reportDesignHandle.getBody( ).add( table );


}


}
Previous Topic:Help with external css
Next Topic:Page number always 1 in the masterpage of the report generated by program
Goto Forum:
  


Current Time: Wed Sep 17 13:48:13 GMT 2014

Powered by FUDForum. Page generated in 0.17092 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software