Run a dataset rather than the report itself [message #551120] |
Thu, 05 August 2010 10:28 |
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 #551958 is a reply to message #551380] |
Tue, 10 August 2010 10:03 |
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03837 seconds