Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Run a dataset rather than the report itself
Run a dataset rather than the report itself [message #551120] Thu, 05 August 2010 10:28 Go to next message
Ricky Ru is currently offline Ricky Ru
Messages: 14
Registered: February 2010
Junior Member
Hi friends,

Here is the background. I have two birt reports as two jobsteps in my job, one of which is producer and the other one is the consumer. The second report(consumer) will run repeatly with the parameter coming from the producer.

So, I do not need to run the producer report but only run the data set(get the results as xml) which is configured to be the producer dataset. But I got an issue if the producer is defined as below;

1.The SQL for the DataSet is
select dbo.States.stateCode,dbo.States.stateName,dbo.States.cat
from dbo.States
where dbo.States.cat IN ('MS:getCategory')
2.I define a parameter getCategory, give it some static valus, mark the Required and Allow Mulitple Values checkboxes. Before Running the job, I will set the value to the parameter.
3.The below is the script of the beforeopen trigger for the dataset.
var sqlText = this.queryText;

var result = sqlText.match(/MS:([A-Za-z0-9]+)/g);
if (result) {
for (var i = 0; i < result.length; ++i) {
parmname = RegExp.$1;
this.queryText = this.queryText.replace(result[i], params[parmname].value.join("','" ));
}
}

Below is the code segment to get the data set results. If I run other simple data set, it works ok.
public IQueryResults runDataSet()
throws BirtException
{
// Create a couple contexts that are needed
ScriptableObject scriptScope = (ScriptableObject)i_engine.getRootScope();
ScriptContext scriptContext = new ScriptContext(scriptScope);
Context scontext = scriptContext.getContext();

Map<String,ReportingParameterAttribute> rptParams = getReportParms();

initializeScriptContext(scriptContext, scontext, scriptContext.getRootScope());

ReportingScriptableParameters p = new ReportingScriptableParameters(rptParams, scriptContext.getScope());
Object sObj = scriptContext.javaToJs(p);
scriptScope.put(JS_PARAMS, scriptScope, sObj);

DataSessionContext dContext = new DataSessionContext(
DataSessionContext.MODE_DIRECT_PRESENTATION,
null, scriptScope );
DataEngineContext context = dContext.getDataEngineContext();

// Now we can get adapter that converts handles to designs
DataRequestSession dataSession = DataRequestSession.newSession(dContext);
IModelAdapter adapter = dataSession.getModelAdaptor();

// get the data source and data set elements ready
ReportDesignHandle report = (ReportDesignHandle)i_report.getDesignHandle();
DataSetHandle dataSetHandle = report.findDataSet( i_dataSet );
DataSourceHandle sourceHandle = dataSetHandle.getDataSource();
BaseDataSourceDesign dataSource = adapter.adaptDataSource( sourceHandle );
BaseDataSetDesign dataDesign = adapter.adaptDataSet(dataSetHandle);

// Define the data set AFTER the source is defined (avoid BIRT exception)
DataEngine dataEngine = DataEngine.newDataEngine(context);
dataEngine.defineDataSource( dataSource );
dataEngine.defineDataSet(dataDesign);

// Now build the query parameters
QueryDefinition queryDefn = new QueryDefinition( );
queryDefn.setDataSetName( i_dataSet );

// add parameters if have any
Iterator<?> paramIter = dataSetHandle.parametersIterator(); //The paramIter does not have any element.
while ( paramIter.hasNext( ) )
{
DataSetParameterHandle paramDefn = (DataSetParameterHandle)paramIter.next();

// for input parameters, we must specify a binding
if(paramDefn.isInput())
{
String paramExpr = null;

// For Oda, we can get the values from Prompt variables
if ( paramDefn instanceof OdaDataSetParameterHandle )
{
String paramName = ((OdaDataSetParameterHandle)paramDefn).getParamName();
Object param = getParameterValue(paramName);

paramExpr = objectToString(param, true);
}

// If parameter to found, we need to get default
if( paramExpr == null)
{
paramExpr = paramDefn.getDefaultValue();
}

//If variable not set, BIRT will give error. Not great, but OK.
if ( paramExpr != null )
{
String dataSetParamName = paramDefn.getName();
ScriptExpression scriptExp = new ScriptExpression( paramExpr );
queryDefn.addInputParamBinding(
new InputParameterBinding( dataSetParamName,
scriptExp ) );
}
}
}

scriptContext.exit();
queryDefn.setAutoBinding( true );

// Prepare and execute the query
IPreparedQuery query = dataEngine.prepare( queryDefn, i_appContext );
IQueryResults results = query.execute( scriptScope);//This call will throw exception.

return results;
}

2010-08-05 17:37:33,024 ERROR [com.rky.reporting.ws.ReportingImpl]
org.eclipse.birt.data.engine.core.DataException: A BIRT exception occurred: There are errors evaluating script "__bm_beforeOpen()":
TypeError: Cannot find function join. (<inline>#9).. See next exception for more information.
There are errors evaluating script "__bm_beforeOpen()":
TypeError: Cannot find function join. (<inline>#9).
at org.eclipse.birt.data.engine.core.DataException.wrap(DataExc eption.java:118)
at org.eclipse.birt.data.engine.script.ScriptEvalUtil.evaluateJ SAsExpr(ScriptEvalUtil.java:717)
at org.eclipse.birt.data.engine.script.JSMethodRunner.runScript (JSMethodRunner.java:76)
at org.eclipse.birt.data.engine.script.DataSetJSEventHandler.ha ndleBeforeOpen(DataSetJSEventHandler.java:62)
at org.eclipse.birt.data.engine.impl.DataSetRuntime.beforeOpen( DataSetRuntime.java:523)
at org.eclipse.birt.data.engine.impl.QueryExecutor.dataSetBefor eOpen(QueryExecutor.java:198)
at org.eclipse.birt.data.engine.impl.QueryExecutor.prepareExecu tion(QueryExecutor.java:309)
at org.eclipse.birt.data.engine.impl.PreparedQuery.doPrepare(Pr eparedQuery.java:498)
at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.pr oduceQueryResults(PreparedDataSourceQuery.java:189)
at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.ex ecute(PreparedDataSourceQuery.java:177)
at org.eclipse.birt.data.engine.impl.PreparedOdaDSQuery.execute (PreparedOdaDSQuery.java:143)
at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.ex ecute(PreparedDataSourceQuery.java:158)
at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.ex ecute(PreparedDataSourceQuery.java:141)
at com.rky.reporting.ws.reportengine.GetDataSetResultsTask.runD ataSet(GetDataSetResultsTask.java:154)
at com.rky.reporting.ws.reportengine.BirtReportEngine.renderDat aSetXML(BirtReportEngine.java:772)
at com.rky.reporting.ws.reportengine.BirtReportEngine.renderDat aSet(BirtReportEngine.java:610)
at com.rky.reporting.ws.reportengine.BirtReportEngine.renderRep ort(BirtReportEngine.java:431)
at com.rky.reporting.ws.reportengine.ReportEngineBase.renderRep ort(ReportEngineBase.java:120)
at com.rky.reporting.ws.ReportingImpl.renderSync(ReportingImpl. java:649)
at com.rky.reporting.ws.ReportingSOAPImpl.renderSync(ReportingS OAPImpl.java:186)
at com.rky.reporting.ws.ReportingSOAPSkeleton.renderSync(Report ingSOAPSkeleton.java:210)

Could any one give me some suggestion on it?
Any feedback is welcome.

Thanks,
-Ricky
Re: Run a dataset rather than the report itself [message #551143 is a reply to message #551120] Thu, 05 August 2010 12:27 Go to previous messageGo to next message
Steve Schafer is currently offline Steve Schafer
Messages: 22
Registered: December 2009
Junior Member
Is this what it's choking on? params[parmname].value.join("','" )

If so I think it's because value is a java String, not a javascript String. Or it may even be an Object. You can find out what it is with this:

var value = params[parmname].value;
Packages.java.lang.System.out.println(value == null ? "null" : value.getClass().getName());

And then run eclipsec.exe. I'm not sure, off the top of my head, how to convert a java string to a javascript string. You could try

var jsstring = new String(value);

Just a guess.
Re: Run a dataset rather than the report itself [message #551380 is a reply to message #551143] Fri, 06 August 2010 08:35 Go to previous messageGo to next message
Ricky Ru is currently offline Ricky Ru
Messages: 14
Registered: February 2010
Junior Member
Hi Steve,

Thanks for your information which is very useful for me to fix this issue.

params[parmname].value is the hash code of a java string array like [Ljava.lang.Object;@414c8f. It's not the value I am expecting. I need to find out where the wrong conversion takes place.

Thanks again.

-Ricky
Re: Run a dataset rather than the report itself [message #551958 is a reply to message #551380] Tue, 10 August 2010 10:03 Go to previous messageGo to next message
Ricky Ru is currently offline Ricky Ru
Messages: 14
Registered: February 2010
Junior Member
I finally found the issue.
The parameter getCategory is set to allow multiple values. The selected values(assuming a, b and c with string type) will be stored in an Object array first and then converted to a string. Finally, the string representing the values will be converted into javascript array by birt engine. The issue happens in setp 2

//the java object array to store the selected values.
Object[] valueArray = new String[]{"a", "b", "c"};
//We use the wrong way to convert the object array to a string representing the value.
String value = valueArray.toSring();//value is a hash code
The two thing are done in method getReportParams() call.

The call getReportParms() will return a map(assuming size is one. because I just have 1 parameter-getCategory) whose key is parameter name, and values is a string(vaues). so the ReportingParameterAttribute object holds the wrong value. and the call javaToJs will also returns the wrong values.

Seems the solution is to modify getReportParms and set the correct string to ReportingParameterAttribute.

My question is what format I need to set. a string like "a,b,c" or "[a, b, c]" and other? I did not found the document saying this. Does anyone know it? Any suggestion is welcome!

import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.WrapFactory;
public IQueryResults runDataSet()
throws BirtException
{
// Create a couple contexts that are needed
ScriptableObject scriptScope = (ScriptableObject)i_engine.getRootScope();
ScriptContext scriptContext = new ScriptContext(scriptScope);
Context scontext = scriptContext.getContext();

Map<String,ReportingParameterAttribute> rptParams = getReportParms();

initializeScriptContext(scriptContext, scontext, scriptContext.getRootScope());

ReportingScriptableParameters p = new ReportingScriptableParameters(rptParams, scriptContext.getScope());
Object sObj = scriptContext.javaToJs(p);

Thanks,
-Ricky
Re: Run a dataset rather than the report itself [message #553325 is a reply to message #551958] Tue, 17 August 2010 07:50 Go to previous message
Ricky  is currently offline Ricky
Messages: 9
Registered: June 2010
Junior Member
If the value of the parameter is allowed to be multiple.

You do not need to convert the array to a string value.

/the java object array to store the selected values.
Object[] valueArray = new String[]{"a", "b", "c"};
//We use the wrong way to convert the object array to a string representing the value.
String value = valueArray.toSring();//value is a hash code

The java array will later be converted into a javascript array. And the join method will be executed sucessfully.
Previous Topic:BirtViewer and the Jazz Data Source
Next Topic:BIRT for beginners
Goto Forum:
  


Current Time: Mon Oct 20 23:04:31 GMT 2014

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

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