Discussions
Categories
Choose a Product
THRUST SERVICES
CORE APPS
CE PRODUCTS
...
Quick Links
POPULAR
HELPFUL TIPS
Groups
My Links
FOR SIGNED IN MEMBERS:
Back to website
Home
Designing Analytics Reports
Use of Design and Report API in scripted dataset open method
Migrateduser
I have an xml data source. I need to insert a chart line in my report and I cannot get all data from single/joint dataset as there are some complex calculation I cannot perform using simple XML.<br />
I need to create a scripted datasaset that reads data from the input xml and performs some calculation in order to define correct values for a chart line.<br />
I created the scripted datasource and scripted dataset in my report, following "Sample BIRT Scripted Data Source Example".<br />
<br />
In the open method of my scripted dataset I have<br />
<br />
<em class='bbc'>testsByDateClass = new Packages.com.customer.birt.ModifyRunningReport();<br />
testsByDateArray = testsByDateClass.getChartLineData();<br />
totalrows = testsByDateArray.size();<br />
currentrow = 0;</em><br />
<br />
When running the report, the factory variables is not creates but solves to null:<br />
<br />
<em class='bbc'>IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );</em><br />
<br />
Questions:<br />
<br />
- May I use report engine and data engine APIs on open method of scripted dataset ?<br />
- May I open the same report (test_report.rptdesign) in the open method ?<br />
- Why the factory is not get created ?<br />
<br />
Following is the method that fails:<br />
<br />
public Vector getChartLineData ()<br />
{<br />
<br />
IReportEngine engine=null;<br />
EngineConfig config = null;<br />
DataEngine de = null; <br />
Vector<Date> vTestsDates = null;<br />
Vector<Test> vTests = null;<br />
Vector<TestChartLineRow> vTestRows = null;<br />
try{<br />
<br />
// Configuration Tasks<br />
config = new EngineConfig( ); <br />
config.setBIRTHome("C:\\birt-runtime-2_6_2\\ReportEngine");<br />
config.setLogConfig(null, Level.FINE);<br />
<br />
// Platform startup<br />
Platform.startup( config );<br />
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );<br />
// This is where I get NPE<br />
engine = factory.createReportEngine( config );<br />
de = DataEngine.newDataEngine( engine.getConfig(), null );<br />
//Open the report design<br />
IReportRunnable design = engine.openReportDesign("reports/test_report.rptdesign");<br />
<br />
<br />
ReportDesignHandle reportDesHandle = (ReportDesignHandle) design.getDesignHandle( );<br />
ElementFactory elementFactory = reportDesHandle.getElementFactory( );<br />
<br />
// Need to get dataset values during design phase<br />
// Get datasource and execute query<br />
SlotHandle dataSources = reportDesHandle.getDataSources();<br />
Iterator it = dataSources.iterator();<br />
DesignElementHandle dataSource = null;<br />
if( it.hasNext() )<br />
{<br />
dataSource = (DesignElementHandle) it.next();<br />
}<br />
// Retrieve datasets defined on report<br />
SlotHandle datasets = reportDesHandle.getDataSets();<br />
it = datasets.iterator();<br />
while( it.hasNext())<br />
{<br />
DesignElementHandle designEl =(DesignElementHandle)it.next();<br />
<br />
if( designEl.getName().equals( "AllTests"))<br />
{ <br />
OdaDataSourceDesign odaDataSource = new OdaDataSourceDesign( "Scripted All Tests Source" );<br />
odaDataSource.setExtensionID( "org.eclipse.datatools.enablement.oda.xml" );<br />
odaDataSource.addPublicProperty( "FILELIST", dataSource.getProperty("FILELIST").toString() ); <br />
<br />
OdaDataSetDesign odaDataSet = new OdaDataSetDesign( "Scripted All Tests Dataset" );<br />
odaDataSet.setDataSource( odaDataSource.getName( ) );<br />
odaDataSet.setExtensionID( "org.eclipse.datatools.enablement.oda.xml.dataSet" );<br />
odaDataSet.setQueryText( designEl.getProperty("queryText").toString() ); <br />
<br />
de.defineDataSource(odaDataSource);<br />
de.defineDataSet(odaDataSet);<br />
<br />
QueryDefinition queryDefinition = new QueryDefinition( );<br />
queryDefinition.setDataSetName( odaDataSet.getName() );<br />
queryDefinition.setAutoBinding(true);<br />
<br />
// Actually execute query<br />
IPreparedQuery pq = de.prepare( queryDefinition ); <br />
IQueryResults qr = pq.execute( null );<br />
<br />
<br />
vTestsDates = new Vector<Date> ();<br />
vTests = new Vector<Test> ();<br />
vTestRows = new Vector<TestChartLineRow> (); <br />
IResultIterator resIt = qr.getResultIterator();<br />
int rowCount = 0; <br />
while ( resIt.next( ) )<br />
{ <br />
Date scheduledFinish = resIt.getDate("ScheduledFinishDate");<br />
if( scheduledFinish != null )<br />
{<br />
if( !vTestsDates.contains(scheduledFinish))<br />
vTestsDates.add( scheduledFinish );<br />
}<br />
Date actualFinish = resIt.getDate("ActualFinishDate");<br />
if( actualFinish != null )<br />
{<br />
if( !vTestsDates.contains(actualFinish))<br />
vTestsDates.add( actualFinish );<br />
}<br />
String revision = resIt.getString("revision");<br />
String id = resIt.getString("ID");<br />
<br />
Test test = new Test(id, revision, scheduledFinish, actualFinish);<br />
vTests.add(test);<br />
rowCount++;<br />
}<br />
Collections.sort(vTestsDates);<br />
<br />
for( Date testDate : vTestsDates)<br />
{<br />
int totalCurrent = 0;<br />
int totalBaseline = 0;<br />
int totalActual = 0;<br />
<br />
for( Test test : vTests )<br />
{<br />
if ( test.getRevision().indexOf(".") == -1 &&<br />
test.getScheduledFinish() != null && test.getScheduledFinish().compareTo(testDate) <= 0 )<br />
{<br />
totalCurrent++;<br />
}<br />
if ( test.getRevision().indexOf(".") != -1 &&<br />
test.getScheduledFinish() != null && test.getScheduledFinish().compareTo(testDate) <= 0 )<br />
{<br />
totalBaseline++;<br />
}<br />
if ( test.getRevision().indexOf(".") == -1 &&<br />
test.getActualFinish() != null && test.getActualFinish().compareTo(testDate) <= 0 )<br />
{<br />
totalActual++;<br />
} <br />
} <br />
<br />
vTestRows.add(new TestChartLineRow(testDate, totalCurrent, totalBaseline, totalActual));<br />
}<br />
<br />
<br />
<br />
System.out.println("Number of dates " + vTestsDates.size());<br />
<br />
System.out.println("Date --- Current --- Baseline ---- Actual");<br />
for( TestChartLineRow row : vTestRows)<br />
{<br />
System.out.println( row.getEventDate() + " --- " + row.getTotalCurrent() + " --- " + row.getTotalBaseline() + " --- " + row.getTotalActual() );<br />
}<br />
<br />
Vector rows = new Vector();<br />
for( TestChartLineRow row : vTestRows)<br />
{<br />
System.out.println( row.getEventDate() + " --- " + row.getTotalCurrent() + " --- " + row.getTotalBaseline() + " --- " + row.getTotalActual() );<br />
rows.add(new Object[]{row.getEventDate(), row.getTotalCurrent(),row.getTotalBaseline(), row.getTotalActual()});<br />
}<br />
System.out.println("done");<br />
return rows;<br />
}<br />
<br />
}<br />
}catch(Exception e)<br />
{<br />
e.printStackTrace();<br />
try{<br />
// Create file <br />
FileWriter fstream = new FileWriter("c:\\temp\\out3.txt");<br />
BufferedWriter out = new BufferedWriter(fstream);<br />
<br />
final Writer result = new StringWriter();<br />
final PrintWriter printWriter = new PrintWriter(result);<br />
e.printStackTrace(printWriter);<br />
<br />
<br />
out.write(result.toString());<br />
//Close the output stream<br />
out.close();<br />
}catch (Exception ex){//Catch exception if any<br />
System.err.println("Error: " + ex.getMessage());<br />
}<br />
<br />
}<br />
<br />
return new Vector();<br />
}
Find more posts tagged with
Comments
There are no comments yet