BIRT Exchange Forum: Monthly report based on dynamic XML data source - BIRT Exchange Forum

Jump to content


 

No Latest Open Poll.

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Monthly report based on dynamic XML data source Rate Topic: -----

#1 User is offline   mlb Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 20-April 12


Posted 08 May 2012 - 04:55 AM

Hello,

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!
0

#2 User is offline   mwilliams Icon

  • BIRT Guru
  • Icon
  • View blog
  • Group: Administrators
  • Posts: 13105
  • Joined: 16-May 08


Posted 08 May 2012 - 04:28 PM

I've tried a few things to make it work with no success. The file name is set in the dataSource and that only connects once. You could download the source and edit the ODA to set the file in the dataSet and you could probably use a single source. Without being able to change the file name in the dataSet, you'll probably have to dynamically create dataSources and dataSets in the beforeFactory based on your input parameters. That's my guess. If I find anything else, I'll let you know.
Regards,

Michael

Twitter
Facebook
Blog
Yahoo: mwilliams_actuate@yahoo.com
Google: mwilliams.actuate@gmail.com
1

#3 User is offline   mlb Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 20-April 12


Posted 09 May 2012 - 03:21 PM

Thanks Michael,

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.
1

#4 User is offline   mwilliams Icon

  • BIRT Guru
  • Icon
  • View blog
  • Group: Administrators
  • Posts: 13105
  • Joined: 16-May 08


Posted 11 May 2012 - 07:28 AM

Awesome! Glad you got something working! :) Let us know if you run into any more issues!
Regards,

Michael

Twitter
Facebook
Blog
Yahoo: mwilliams_actuate@yahoo.com
Google: mwilliams.actuate@gmail.com
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users