Monthly report based on dynamic XML data source
#1
Posted 08 May 2012 - 04:55 AM
I am pretty new to BIRT, but already facing complicated (to me) requirements - and I could not find obvious answer. Could you please direct me how should I approach this?
The task is to create monthly report (so a table with 28 to 31 rows) based on XML data source where each row requires separate call to XML data server. In addition, user should be able to define start/end dated for the report via report parameters.
I have XML server that gives me details for each single day only, so I need to call it for each day of the month to fetch requested information. Then I call URL like http://localhost/dai...ails/{date}.xml where {date} formatted is as yyyy-mm-dd (single day), and I need to build monthly report out of that.
Is there a way of creating data source based on above? Even if I tried to specify 31 different data sources like this:
http://localhost/dai.../2012-05-01.xml
http://localhost/dai.../2012-05-02.xml
http://localhost/dai.../2012-05-03.xml
http://localhost/dai.../2012-05-04.xml
...
this will not correspond to start/end dates a user might define.
I was also looking at onFetch method - but this is executed after fetching the row, not before...
Thank you in advance!
#2
Posted 08 May 2012 - 04:28 PM
#3
Posted 09 May 2012 - 03:21 PM
Very similar option that came to my mind - to create virtual XML data source that upon startup would be populated by sequential calls to XML server. Since I am not a developer - I spent a while on that, but following beforeOpen code seems to work:
importPackage( Packages.java.io );
var s_date = "";
var date_from = params["Date_from"];
var date_to = params["Date_to"];
var cdate = date_from;
mystr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
mystr = mystr + "<schedules type=\"array\">";
while ( BirtDateTime.diffDay(cdate,date_to) >= 0 ) {
s_date = BirtDateTime.year(cdate) + "-" + BirtDateTime.month(cdate,1) + "-" + BirtDateTime.day(cdate);
var url_str = params["report_server_url"] + "/daily_details/"+ s_date + ".xml";
rurl = new Packages.java.net.URL(url_str);
input_stream = rurl.openStream();
data_input_stream = new Packages.java.io.DataInputStream( new Packages.java.io.BufferedInputStream( input_stream ));
while ( (rline = data_input_stream.readLine()) != null ){
rline = rline.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>","");
rline = rline.replace("<schedules type=\"array\">","");
rline = rline.replace("</schedules>","");
mystr = mystr + rline;
}
data_input_stream = null ;
input_stream = null;
rurl = null;
cdate = BirtDateTime.addDay(cdate,1);
}
mystr = mystr + "<\/schedules>";
JavaStr = new java.lang.String( mystr );
bais = new ByteArrayInputStream( JavaStr.getBytes());
appcon = reportContext.getAppContext();
appcon.put("org.eclipse.datatools.enablement.oda.xml.inputStream", bais);
It's probably not perfect, so any improvements are welcome.





MultiQuote





