Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Schedule a task to Ftp a BIRT report using iServer
meehanmartin
Hi,
Is it possible to Schedule a task to sFtp a BIRT report using iServer?
Thanks,
Martin
Find more posts tagged with
Comments
rmurphy
Yes, this is possible, but is not an out of the box function. There are several possibilities, including making a call from the afterFactory method of a BIRT report that signals a process to perform download and FTP the file. You will use the web service layer of the iServer, known as the Information Delivery API (IDAPI), to download the file from the iServer.
meehanmartin
<blockquote class='ipsBlockquote' data-author="'rmurphy'" data-cid="108570" data-time="1345138186" data-date="16 August 2012 - 10:29 AM"><p>
Yes, this is possible, but is not an out of the box function. There are several possibilities, including making a call from the afterFactory method of a BIRT report that signals a process to perform download and FTP the file. You will use the web service layer of the iServer, known as the Information Delivery API (IDAPI), to download the file from the iServer.<br /></p></blockquote>
<br />
<br />
Thanks,<br />
<br />
Can you point me towards the java class that the afterMethod is in? I tried: <br />
<br />
import org.eclipse.birt.report.engine.script.internal.element.ReportDesign;<br />
import org.eclipse.birt.report.engine.ir.Report;<br />
import org.eclipse.birt.report.engine.api.ReportEngine;<br />
<br />
Or is this a section that can be added to a .rptdesign file? I tried the "scripts" section in the palette toolsbox of BIRT integrated into eclipse but can only see methods/event handlers.<br />
<br />
beforeOpen<br />
afterOpen<br />
onFetch<br />
beforeClose<br />
afterClose<br />
<br />
<br />
Martin
johnw
It would get added to the BIRT Report itself. The BIRT scripting environment is a Javascript wrapper around the native JVM (using Rhino as the wrapper), so anything in the JVM is accessible to BIRT reports. So what you can do is either write a Java class and deploy it to the iServer instance, or write it in Javascript. You can directly use the java.net.* packages using the Javascript importPackage() method. What is good about this approach is the report can report on the success or failure of the file transfer. You can also use Java in this same manner to trigger a shell script to kick off the FTP transfer.
meehanmartin
<blockquote class='ipsBlockquote' data-author="'johnw'" data-cid="108721" data-time="1345591880" data-date="21 August 2012 - 04:31 PM"><p>
It would get added to the BIRT Report itself. The BIRT scripting environment is a Javascript wrapper around the native JVM (using Rhino as the wrapper), so anything in the JVM is accessible to BIRT reports. So what you can do is either write a Java class and deploy it to the iServer instance, or write it in Javascript. You can directly use the java.net.* packages using the Javascript importPackage() method. What is good about this approach is the report can report on the success or failure of the file transfer. You can also use Java in this same manner to trigger a shell script to kick off the FTP transfer.<br /></p></blockquote>
<br />
Thanks,<br />
<br />
I'm new to BIRT but it looks like a great reporting tool.<br />
<br />
My plan is to schedule reports (passing date range and email parameters).<br />
<br />
The report is run by the scheduler and:<br />
<br />
1) Converts into CSV format using the CSV emitter<br />
<br />
CSVRenderOption() options = new CSVRenderOption();<br />
String fileName = reportName + ".csv";<br />
options.setOutputFileName(fileName);<br />
options.setOutputFormat(CSVRenderOption.CSV);<br />
task.setRenderOption(options);<br />
<br />
//run the report<br />
try<br />
{<br />
task.run();<br />
}<br />
catch (Exception e)<br />
{<br />
System.err.println("An error occured while running the report!");<br />
e.printStackTrace();<br />
System.exit(-1);<br />
}<br />
<br />
I'm not sure which script method this code would to call from, maybe beforeRender in the Generation phase?<br />
Not sure since this is inside a .rptdesign file whether we would need to call task.run(); from the java code? <br />
<br />
2) Triggers either an email or sftps the CSV file. (both need to be supported)<br />
<br />
Run this in the afterFactory method. How do I get a handle to the report from inside the .rptdesign? I basically want to pass the report into the java sftp or email code.<br />
Is it by using "this"?<br />
<br />
In the docs <a class='bbc_url' href='
http://www.eclipse.org/birt/phoenix/deploy/reportScripting.php'>http://www.eclipse.org/birt/phoenix/deploy/reportScripting.php</a>
; separate event orders are shown for generation and presentation phases.<br />
<br />
Does this mean that the generation phase comes before the presentation phase. Therefore, not sure I can do what I need to do as I can't call a beforeRender before an afterFactory?<br />
<br />
Thanks,<br />
Martin
johnw
Yes, Generation events (beforeFactory, afterFactory, onPrepare, onCreate) are done before the presentation phase (onRender, beforeREnder, etc). There are lots of things you can do. You can in the afterFactory event, get the instance of the report document that gets generated, then manually render by creating a Render Task to render to CSV, then FTP. So the code from #1 would reside in your afterFactory event. It would look something like...
var reportDocument = reportContext.getReportDocument();
var options = new CSVRenderOption();
var fileName = reportName + ".csv";
options.setOutputFileName(fileName);
options.setOutputFormat(CSVRenderOption.CSV);
task.setRenderOption(options);
task.run();
var ftp = new FTPClient(); //or whatever Java FTP client you are using
ftpClient.connect("ftp.foo.com", "user01", "pass1234");
ftpClient.upload("C:\\Temp\\", fileName);
ftpClient.disconnect();
There is a little more to it, but that should be the basic idea. Then you just schedule a Run Task for the report, and skip the render task since the rendering is being handled in the afterFactory.
meehanmartin
Thanks!
Question, how do you pass a parameter programmitically in java to BIRT report?
I'm using quartz and I would like to schedule say daily, weekly, monthly etc
and require the report to pick up this parameter and say
if paramter="daily" set dayFrom = today-1 dayTo=today.
if paramter="weekly" set dayFrom = today-7 dayTo=today etc.
I also would like to use the same report in an unscheduled way so I can just manually enter the parameters ad-hoc when a report is needed.
<parameters>
<scalar-parameter name="DayFrom" id="109">
<text-property name="helpText">Day From</text-property>
<text-property name="promptText">Day From</text-property>
<property name="valueType">static</property>
<property name="isRequired">true</property>
<property name="dataType">date</property>
<property name="distinct">true</property>
<simple-property-list name="defaultValue">
<value type="javascript">BirtDateTime.addDay( BirtDateTime.today(), -1 )</value>
</simple-property-list>
<property name="paramType">simple</property>
<property name="controlType">text-box</property>
<structure name="format">
<property name="category">Custom</property>
<property name="pattern">yyyy-MM-dd</property>
</structure>
</scalar-parameter>
Thanks,
Martin
Latif M P
hi,
Have you solve ur seduling issue.
Can you please send me ur rptdesign file..
Thanks