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)
MyScriptedDataSet Example
JDH
Hi-
I am new to BIRT. I am having trouble running the fetch() method from tutorial 2 in the 2nd Edition of Integrating and Enhancing BIRT. I want to be able to supply a Java class to return the data from my query as I need to do some manipulation of the data beyond the query.
I typed in the code from Listing 12-30 exactly as it is listed in the book.
When I tried to compile I had an error related to catching the Exception. I found a post somewhere that said you should change it to use the ScriptException. I did but that gave me a compile error as well. I read in your forum that you need an additional jar that is not called out in the imports of the java file (coreapi.jar). That fixed the compile problem. To save anyone reading this post some effort it can be found in org.eclipse.birt.core_2.6.1.v20100819.jar which I found in birt-runtime-2.6.1/ReportEngine/plugins. You also need org.eclipse.birt.report.engine_2.6.1.v20100915.jar which I found in BIRT 2.6.1 under birt-runtime-2.6.1/ReportEngine/plugins. I also needed scriptapi.jar which I found in BIRT 2.6.1 in the birt.war under WEB_INF\lib.
When I first tried to run it I had trouble figuring out where to put the .jar containing the MyScriptedDataSet class. I finally got that to work by creating a MyScriptedDataSet.jar in the root of my Java project directory in the workspace.
In the same workspace I have a second project that is a BIRT report project. In there I discovered from the forum that you need to put the classpath in Windows->ReportDesign->Preferences->Classpath. I used Add Jars to include the MyScriptedDataSetJava.jar from my java project mentioned above. I also modified the Event handler class property in the Script Data Set so that it included the entire path for my class. This is , in my case, com.oce.asd.scripted.dataset.MyScriptedDataSet.
After all of the above I finally was able to get the report to run in Eclipse using the Preview. Here is the code with slight modifications from the book that eventually worked.
For those beginners like me, these are things that would make a nice addition to the next version of the book. They can be figured out with some effort but calling them out in the book would make it sooo much easier.
package com.oce.asd.scripted.dataset;
import org.eclipse.birt.report.engine.api.script.eventadapter.ScriptedDataSetEventAdapter;
import org.eclipse.birt.report.engine.api.script.IUpdatableDataSetRow;
import org.eclipse.birt.report.engine.api.script.instance.IDataSetInstance;
import org.eclipse.birt.report.engine.api.script.ScriptException;
public class MyScriptedDataSet extends ScriptedDataSetEventAdapter {
public int recordCount = 0;
public boolean result = false;
public boolean fetch(IDataSetInstance dataSet, IUpdatableDataSetRow row) {
System.out.println("Inside fetch");
try {
if (recordCount < 20) {
recordCount++;
row.setColumnValue("col1", recordCount);
row.setColumnValue("col2", "Count =" + recordCount);
row.setColumnValue("col3", recordCount * .05);
result = true;
}
} catch (ScriptException e) {
e.printStackTrace();
}
return result;
}
public void open(IDataSetInstance dataSet) {
recordCount = 0;
}
}
Thanks,
JDH
Find more posts tagged with
Comments
JasonW
JDH,
Thanks for the comments. You should also be able to set the BIRT project to use a Java project in the same workspace as the classpath.
You should have been able to just add the jars from the reportenginedownload/reportengine/lib directory.
Jason