exchanging information between report-context and java wrapper
<p>Hello,</p>
<p> </p>
<p>I've created a report with scripted data-source and data-set.</p>
<p>Since the query is very complex ( with dynamically created table name) - I decided to use script and open/fetch event to mine the data and bind it to the report's controls.</p>
<p> </p>
<p>For the sake of example I will show a simple report.</p>
<p>My report script in the open event looks like:</p>
<pre class="_prettyXprint _lang-js _linenums:1">
birtProxyClass = new Packages.com.org.birtproxy.BirtProxyClass();
var connectionString = "jdbc:postgresql://somemachine:5432/db";
var driverString = "org.postgresql.Driver";
function Alert (p_memname,p_application,p_group_name,p_handled,p_data_center) {
this.memname = p_memname;
this.group_name = p_group_name;
this.application = p_application;
this.handled = p_handled;
this.data_center = p_data_center;
}
function ReportDelegate () {
var alerts = [];
this.addAlert = function (p_alert) {
alerts.push(p_alert);
}
this.getAlerts = function() {
return alerts;
}
this.executeReport = function() {
var alertsSql = "select name,application,group_name,handled,data_center from alarm-150812";
alerts_temp = birtProxyClass.executeQuery(alertsSql, connectionString, "user", "pass", 5, driverString);
if(alerts_temp.size() == 0 ) return;
for (var i = 0; i < alerts_temp.size(); i++) {
var alert_temp = alerts_temp.get(i);
var alert = new Alert(alert_temp[0], alert_temp[1], alert_temp[2], alert_temp[3],alert_temp[4]);
alerts.push(alert);
}
}
}
// self executed function - main
var reportDelegate = new ReportDelegate();
reportDelegate.executeReport();
alerts_report = reportDelegate;
current_row = 0;
total_rows = reportDelegate.getAlerts().length;
</pre>
<p> And my fetch event looks like:</p>
<pre class="_prettyXprint _lang-js _linenums:1">
if(current_row >= total_rows) {
return ( false );
}
var alerts = alerts_report.getAlerts();
var alert = alerts[current_row];
var memname = alert.memname;
var group_name = alert.group_name;
var handled = alert.handled;
var application = alert.application;
var data_center = alert.data_center;
row["memname"] = memname;
row["group_name"] = group_name;
row["application"] = application;
row["handled"] = handled;
row["data_center"] = data_center;
current_row = current_row + 1;
return (true);
</pre>
<p>I execute this report using BIRT Runtime API</p>
<pre class="_prettyXprint _lang-js _linenums:1">
IReportRunnable design = engine.openReportDesign(is);
//Create task to run and render the report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
HTMLRenderOption options = new HTMLRenderOption();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
options.setOutputStream(bout);
options.setOutputFormat("html");
//Setting this to true removes html and body tags
options.setEmbeddable(true);
options.setEnableInlineStyle(true);
options.setEnableCompactMode(true);
task.setRenderOption(options);
//run and render report
task.run();
task.close();
String reportOutput = bout.toString("UTF-8");
return reportOutput;
</pre>
<p>Now to the question,</p>
<p>In general I want to modify the script in the open event before executing the report.</p>
<p>In specific, I would like to dynamically build where part of the queryString that is defined in the script :</p>
<pre class="_prettyXprint _lang-js _linenums:1">
var alertsSql = "select name,application,group_name,handled,data_center from alarm-150812"; // + "some dynamically where part that was send from the JAVA wrapper.
</pre>
<p>I thought I could use IReportContext and its setPersistentGlobalVariable method to define and inject variable into the design of the report.</p>
<p>Then, I would read those vars by calling getPersistentGlobalVariable from the open event javascript.</p>
<p>This way I would be able to build the wherepart dynamically.</p>
<p>Sadly, I cannot find how to access the IReportContext in my JAVA application.</p>
<p> </p>
<p>Any idea how to get to that object?</p>
<p>Maybe there are other ways of injecting variables into the report design from BIRT Runtime?</p>
<p> </p>
<p>Really appreciate any help - 10x;</p>