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)
Accessing Dataset at runtime
cwfranklin
Hello,
I have been trying to figure out a way to see if my dataset has returned any results from the java code before the render task.
Here is the issue that I want to resolve:
Our reports are stored in the database along with the status (Processing, Success, Faliure, etc.). I want to be able to determine whether the dataset returned no records and set the status to "No Records". In another system we were able to check to see if the report byte array was null and if so set the status accordingly, but this report also has report parameters displayed so it will never be null. I'm trying to get the row count after the run task and before the render task in order to set the status to accordingly.
Is there a way to do this?
Find more posts tagged with
Comments
mwilliams
You just want to be able to find out if the dataSet has returned any values or not? If this is the case, you can initialize a variable in your initialize script to "false" or to 0, and then in your onFetch of the dataSet in question, you could either set the variable to "true" or increment the variable, depending on what you did in the initialize event. Then you'd know based on that whether the dataSet returned any data.
Hope this helps.
cwfranklin
Thanks for the quick reply.
How would I access this field in my Java code? In my case the java code just sets the parameters and calls the run and render tasks. I am doing all the event handling inside the javascript of the report.
I have tried setting a global variable in the beforeClose event, but I'm not sure how to access it from my java class.
Thanks again
cwfranklin
Anyone have any insight on this issue?
I need to deploy for testing today and this feature is expected to be in it.
I just need a way to find out if the dataset of a report has returned any records on the java side. I set the No Records flag from my java code.
Or is there a way to set a java class variable from inside the javascript of the report.
Or maybe even a way to set the IRunTask cancel flag from inside birt.
Please help. Thanks!
mwilliams
I talked with a colleague and he suggested using the data extraction task on the report document to check the result count. Here is an example of using the data extraction task:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
//import org.eclipse.birt.data.engine.api.IResultMetaData;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderContext;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.data.engine.api.IFilterDefinition;
import org.eclipse.birt.data.engine.api.IConditionalExpression;
import org.eclipse.birt.data.engine.api.querydefn.FilterDefinition;
import org.eclipse.birt.data.engine.api.querydefn.ConditionalExpression;
import org.eclipse.birt.report.engine.api.IReportDocument;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.TOCNode;
import org.eclipse.birt.report.engine.api.IDataIterator;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IRunTask;
import org.eclipse.birt.report.engine.api.ReportEngine;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.IDataExtractionTask;
import org.eclipse.birt.report.engine.api.IExtractionResults;
import org.eclipse.birt.report.engine.api.IResultMetaData;
//import org.eclipse.birt.report.engine.api.IDataIterator;
import org.eclipse.birt.report.engine.api.IResultSetItem;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.data.engine.core.DataException;
public class DataExtract {
static void readReport() throws EngineException
{
IReportEngine engine=null;
EngineConfig config = null;
try{
config = new EngineConfig( );
config.setBIRTHome("C:\\birt\\birt-runtime-2_5_1\\birt-runtime-2_5_1\\ReportEngine");
config.setLogConfig(null, Level.OFF);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
}catch( Exception ex){
ex.printStackTrace();
}
IReportDocument iReportDocument = engine.openReportDocument("output/resample/xtab.rptdocument");
//Setup data extraction task
IDataExtractionTask task = engine.createDataExtractionTask(iReportDocument);
//task.getReportRunnable().getDesignHandle().getModuleHandle().getMessage("resourceKey");
/**
* returns the metadata corresponding to the data stored in the report
* document. Could specify a component.
*/
ArrayList resultSetList = (ArrayList)task.getResultSetList( );
IResultSetItem resultItem = null;
Iterator it = resultSetList.iterator();
while (it.hasNext()) {
resultItem = (IResultSetItem)it.next();
System.out.println("ResultSetName ====> " + resultItem.getResultSetName( ));
}
resultItem = (IResultSetItem)resultSetList.get( 0 );
String dispName = resultItem.getResultSetName( );
//Name Tables for ease
task.selectResultSet( dispName );
//Return Only customers between 201-300
IFilterDefinition[] FilterExpression = new IFilterDefinition[2];
FilterExpression[0] = new FilterDefinition( new ConditionalExpression( "row[\"CUSTOMERNUMBER\"]",
IConditionalExpression.OP_GE, "201", null ) );
FilterExpression[1] = new FilterDefinition( new ConditionalExpression( "row[\"CUSTOMERNUMBER\"]",
IConditionalExpression.OP_LT, "300", null ) );
task.setFilters( FilterExpression );
IExtractionResults iExtractResults = task.extract();
IDataIterator iData = null;
try{
if ( iExtractResults != null )
{
iData = iExtractResults.nextResultIterator( );
//Get metadata on retrieved results
IResultMetaData irmd = iData.getResultMetaData();
if ( iData != null ){
int colCount = irmd.getColumnCount();
System.out.println("Cloumn Count =" + colCount );
for( int j=0; j< colCount; j++){
System.out.println("Cloumn Name =" + irmd.getColumnName(j) );
System.out.println("Cloumn Type =" + irmd.getColumnTypeName(j) );
}
while ( iData.next( ) )
{
//Just disply the first two columns
Object objColumn1;
Object objColumn2;
try{
objColumn1 = iData.getValue(4);
}catch(DataException e){
objColumn1 = new String("");
}
try{
objColumn2 = iData.getValue(14);
}catch(DataException e){
objColumn2 = new String("");
}
System.out.println( objColumn1 + " , " + objColumn2 );
}
iData.close();
}
}
}
catch( Exception e){
e.printStackTrace();
}
task.close();
engine.destroy();
Platform.shutdown();
System.out.println("Finished");
}
/**
*
@param
args
*/
public static void main(String[] args) {
try
{
readReport( );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
</pre>
cwfranklin
Thanks for the help. I will try this out.
I tried it before, but it returned some data when there wasn't any. I guess its because I display the parameter values on the report but its not within the table element. Therefore it says that it has data.
I wonder if there is a way to connect to a particular dataset using the data extraction task.
Anyway, I'll try it out... thanks again.
cwfranklin
I have the DataExtraction task working. The problem is that it not only extracts the table data but also all of the other data items that I have on the report. I resolved this by naming my tables beginning with "_DS", however, if another developer comes along and creates a report this information won't be apparent.<br />
<br />
I noticed in debugging that each IResultSetItem has a handle and for tables it is called a TableHandle. So, I tried this:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
ArrayList resultList = (ArrayList) task.getResultSetList();
IResultSetItem resultItem = null;
Iterator it = resultList.iterator();
while (it.hasNext()) {
resultItem = (IResultSetItem) it.next();
if (resultItem instanceof TableHandle
&& !resultItem.getResultSetName().contains("DNE")) {
resultSetName = resultItem.getResultSetName();
}
}
</pre>
<br />
This didn't work because the resultItem is an instance of IResultSetItem. Is there a way to see what the handle is programmatically?
mwilliams
The handle is private, so I don't know that you'll be able to do anything with that.