Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Retrieving Column Mapping From Report
Anshul
Hi
I'm integrating BIRT in my application where I'm generating a Report using JDBC Queries.
I want to fetch, maximum possible information from BIRT intermediate RPTDocument.
Now, the Report Engine APIs only allow fetching data that is present in the data sets inside report.
Is there a way to get additional Data such as Styling and Mapping Details?
Mainly, I'm concerned about -
Logical Column Names Specified in Table Headers
Getting out mapped information in case a map list is associated with a column
Can DE APIs can also be employed for this purpose, if yes please specify how?
Thanks,
Find more posts tagged with
Comments
JasonW
Try something like the code below. Remember starting and stopping the platform is expensive so if the app continues to run do not shut it down.
import java.io.IOException;
import java.util.Iterator;
import java.util.logging.Level;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.IReportDocument;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.model.api.ComputedColumnHandle;
import org.eclipse.birt.report.model.api.TableHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException;
/**
* Simple BIRT Design Engine API (DEAPI) demo.
*/
public class ReportDocumentDetails
{
public static void main( String[] args )
{
try
{
getDetails( );
}
catch ( IOException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch ( SemanticException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static void getDetails( ) throws IOException, SemanticException
{
// Create a session handle. This is used to manage all open designs.
// Your app need create the session only once.
EngineConfig config = new EngineConfig( );
config.setBIRTHome("C:/birt/birt-runtime-2_6_1/birt-runtime-2_6_1/ReportEngine");
IReportEngine engine=null;
try{
config = new EngineConfig( );
config.setBIRTHome("C:\\birt\\birt-runtime-2_6_1\\birt-runtime-2_6_1\\ReportEngine");
config.setLogConfig(null, Level.FINE);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
IReportDocument document = null;
//Open the report design
document = engine.openReportDocument("Reports/mytabletest.rptdocument");
TableHandle th = (TableHandle)document.getReportDesign().findElement("mytable");
for( Iterator itr = th.getColumnBindings().iterator(); itr.hasNext(); ){
ComputedColumnHandle cch = (ComputedColumnHandle) itr.next();
System.out.println(cch.getName() + " Expression " + cch.getExpression());
}
document.close();
Platform.shutdown();
}catch(Exception e){
e.printStackTrace();
}
System.out.println("Finished");
// We're done!
}
}
Jason
Anshul
@Jason
Thanks for your reply... The code helped in understanding BIRT more.
However I'm looking for acquiring column Mapping:
e.g. My Data query result gives me a column.
A, B, C.
But my report column displays
Alpha, Bravo, Charlie
through map rules.
This information I need to gather from report design.
I'm assuming MapRuleHandle is the way out.
If yes, please tell me how to get it.
Thanks
JasonW
This will depend on where the map rule is, but if it is on the column you could use code like:
document = engine.openReportDocument("Reports/mytabletest.rptdocument");
TableHandle th = (TableHandle)document.getReportDesign().findElement("mytable");
for( Iterator itr = th.getColumnBindings().iterator(); itr.hasNext(); ){
ComputedColumnHandle cch = (ComputedColumnHandle) itr.next();
System.out.println(cch.getName() + " tExpression " + cch.getExpression());
}
ColumnHandle ch = (ColumnHandle)th.getColumns().get(0);
PropertyHandle mapRules = ch.getPropertyHandle( StyleHandle.MAP_RULES_PROP );
for ( Iterator itr = mapRules.iterator( ); itr.hasNext( ); )
{
MapRuleHandle mr = (MapRuleHandle) itr.next( );
System.out.println( "Expression " +mr.getTestExpression() + " operator " + mr.getOperator() + " Value "+ mr.getValue1());
}
Jason
Anshul
Thanks Again Jason.
Will try it soon.
Is it possible to reach you through some other channel?
JasonW
My email address is jasonweathersby at windstream dot net.