#1 2015-12-03 06:49:17

ralex
Member
Registered: 2015-04-20

How to generate a birt report in background and then sending via email

Hi,
we need to run an heavy birt report ,called via URL as link in a web page,(it takes several minutes to make it and we don't want to time the http session out) in background and once generated that by sending it to an email address on demand not a certain time like scheduling.
Is it possible?
If so, how can I do it?
Please

Thanks,

Ale


PS: are there any API reportserver that we can use for that? Or better, I saw the "send to" function via console management, could we use it via API by scripting in asynchronous mode? That's to say the user clicks on the link and instead of waiting for downloading it he can close the web page and once the report has been made , he wil receive by email.

Last edited by ralex (2015-12-03 11:52:14)

Offline

#2 2015-12-04 07:10:02

ralex
Member
Registered: 2015-04-20

Re: How to generate a birt report in background and then sending via email

Hi,
I don't know if I've explained well what I'd like to do...I try again...
we have a java application , fundamentally is a web page, that has some links. Anytime a user clicks on it triggers our servlet generate/open the correct reportserver url ,for example http\://reportserverhost\:8080/reportserver/reportserver/httpauthexport?key\=myreport&user\=myuser&password\=dummy&format\=pdf&p_param1\=abc&p_param2\=njh , and we get the download of file.
Now, for certain kind of reports,we would like to have the same situation but as soon as we click the link we would like to generate the report in background(asynchronous mode) and get it via email. In other words we would like to integrate the same behaviour of "send to" function that we have by console in our web page. So, is there any API or method who can activate this behaviour via URL call?
Thanks,

Alex

Last edited by ralex (2015-12-04 07:12:52)

Offline

#3 2015-12-04 09:09:55

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: How to generate a birt report in background and then sending via email

Hi Alex,

the short answer is: yes, this can be done with a little scripting. Scripting usually goes a bit beyond the free support that we can manage here, but let me see if I can find some time to explain the basics later today.

Cheers
-Arno

Offline

#4 2015-12-04 09:26:16

ralex
Member
Registered: 2015-04-20

Re: How to generate a birt report in background and then sending via email

OK, I will be waiting for you basics input.
In the meantime, could you , please, tell me , if I purchase the scripting guide, I can alone to write down the script that I need ? Or better is this guide complete to accomplish this task?
Thanks again.

Alex

Arno Mittelbach wrote:

Hi Alex,

the short answer is: yes, this can be done with a little scripting. Scripting usually goes a bit beyond the free support that we can manage here, but let me see if I can find some time to explain the basics later today.

Cheers
-Arno

Offline

#5 2015-12-04 10:00:57

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: How to generate a birt report in background and then sending via email

Hi Alex,

let me answer this way: a book on programming explains the basic concepts, contains some more advanced topics and some examples. It gets you started to program your own programs but it probably will not contain sample code for exactly the problem that you wanted to solve when looking into programming. Similarly, the script guide gets you started with ReportServer scripting and should enable you to concoct your own scripts but it does not contain an explicit example of how to do program the "send to".

Cheers
-Arno

Offline

#6 2015-12-05 15:13:45

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: How to generate a birt report in background and then sending via email

Hi Alex,

so here it goes. The following should provide the basic outline. It executes a report (with id 42; note the l at the end to indicate its a long) and then sends the result via mail.

import net.datenwerke.rs.core.service.mail.MailService
import net.datenwerke.rs.core.service.reportmanager.ReportService
import net.datenwerke.rs.core.service.reportmanager.ReportExecutorService
import net.datenwerke.rs.core.service.mail.SimpleAttachement

// load services
def reportService = GLOBALS.getInstance(ReportService.class)
def reportExec = GLOBALS.getInstance(ReportExecutorService.class)
def mailService = GLOBALS.getInstance(MailService.class)

// the report's id
def reportId = 42l

// get the report object
def report = reportService.getReportById(reportId)

// execute report
def pdf = reportExec.execute(report, "PDF")

// prepare for sending mail
def mail = mailService.newSimpleMail()
mail.setSubject("The Report")
mail.setToRecipients("to@reportserver.net")
mail.setFrom("from@reportserver.net")

def attachement = new SimpleAttachement(pdf.getReport(), pdf.getMimeType(), "filename.pdf")
mail.setContent("Some Message", attachement)

// send mail
mailService.sendMail(mail)

If you want to make it accessible via URL, you need to call it via the scriptAccess servlet, for example,

http://SERVER:PORT/reportserverbasedir/reportserver/scriptAccess?id=ScriptID

Within the script you can access the request object via the predefined httpRequest variable to for example obtain a report ID via a URL parameter.

Hope this gets you started.

Cheers
-Arno

Offline

#7 2015-12-06 13:36:36

karolina
Member
Registered: 2014-08-09

Re: How to generate a birt report in background and then sending via email

Hi Arno,

Thanks - that was sth I was looking for, too.

Would you mind putting this on the support portal HOW-TO as well?

Cheers,
Karolina

Offline

#8 2015-12-10 07:29:09

ralex
Member
Registered: 2015-04-20

Re: How to generate a birt report in background and then sending via email

Arno Mittelbach wrote:

Hi Alex,

so here it goes. The following should provide the basic outline. It executes a report (with id 42; note the l at the end to indicate its a long) and then sends the result via mail.

import net.datenwerke.rs.core.service.mail.MailService
import net.datenwerke.rs.core.service.reportmanager.ReportService
import net.datenwerke.rs.core.service.reportmanager.ReportExecutorService
import net.datenwerke.rs.core.service.mail.SimpleAttachement

// load services
def reportService = GLOBALS.getInstance(ReportService.class)
def reportExec = GLOBALS.getInstance(ReportExecutorService.class)
def mailService = GLOBALS.getInstance(MailService.class)

// the report's id
def reportId = 42l

// get the report object
def report = reportService.getReportById(reportId)

// execute report
def pdf = reportExec.execute(report, "PDF")

// prepare for sending mail
def mail = mailService.newSimpleMail()
mail.setSubject("The Report")
mail.setToRecipients("to@reportserver.net")
mail.setFrom("from@reportserver.net")

def attachement = new SimpleAttachement(pdf.getReport(), pdf.getMimeType(), "filename.pdf")
mail.setContent("Some Message", attachement)

// send mail
mailService.sendMail(mail)

If you want to make it accessible via URL, you need to call it via the scriptAccess servlet, for example,

http://SERVER:PORT/reportserverbasedir/reportserver/scriptAccess?id=ScriptID

Within the script you can access the request object via the predefined httpRequest variable to for example obtain a report ID via a URL parameter.

Hope this gets you started.

Cheers
-Arno

Many thanks for your support and sorry for my delay smile

I defined the script under report manager and linked to your script(modifying it with my reportid...). Then I called http://SERVER:PORT/reportserverbasedir/reportserver/scriptAccess?id=ScriptID via URL and it works well .(I get the report via email..)
Now, my question is.. if I want to call a report  that gets parameters on runtime via script , how can I use the request object and this httpRequest variable inside the script,you mentioned ?

Last edited by ralex (2015-12-10 09:20:51)

Offline

#9 2015-12-10 15:17:09

ralex
Member
Registered: 2015-04-20

Re: How to generate a birt report in background and then sending via email

I maybe partially understood how to modify the script to retrieve all dynamic informations such as reportId, parameter values and then execute the report by using the reportExec of the ReportExecutorService  class :
1) Adding at the beginning of the script
   

 import javax.servlet.http.HttpServletRequest  

2) Get an istance of HttpServletRequest
   

 def requestProvider = GLOBALS.getProvider(HttpServletRequest.class) 
            HttpRequest req = requestProvider.get()   //maybe I might write shorter by using the httpRequest variable, as you mentioned
   

3) Instead of a static reportId, I should get it by the req object ,but I don't know which  methods this req object has...I suppose something like
   def reportId = req.getReportId() //Does it exist ???
4) Once that I get the reportId (long value); can I get and execute the report as you did? Or Do I need to pass the parameter by using some method of ReportParameterService?? 
(reportService.getReportById(reportId) and then reportExec.execute(report, "PDF") )

Thanks ,
Cheers,

Alex

Offline

#10 2015-12-10 15:23:32

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: How to generate a birt report in background and then sending via email

Hi Alex,

I am afraid you are somewhat off track here. First, for your script there is no need for a script report, it can safely be on its own in the fileserver and executed via the scriptAccess URL. Then to get to the current request object, there is no need to try to obtain this via the predefined variable httpRequest. So no need to use GLOBALS or anything extra.

Cheers,
Arno

Offline

#11 2015-12-10 16:01:15

ralex
Member
Registered: 2015-04-20

Re: How to generate a birt report in background and then sending via email

I understand that I don't need to define a script report (under report manager) linked through a script,as I did so far,but when you say "your script executed via the scriptAccess URL " what do you exactly mean?
My intention is call the script via the scriptAccess servlet, then the script has to be able to call/execute and send by email the report.
Statically it works, but I wonder instead of static values such as def reportId = 42l I would like to retrieve these values (report id , parameters) from the request object. That's why I think I should call/define the request object....
So how can I dynamically get these values ?
Thanks,
Cheers,
Alex

Offline

#12 2015-12-10 16:17:46

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: How to generate a birt report in background and then sending via email

Hi Alex,

consider this simple script

httpResponse.getOutputStream().print(
  "the report id is: " + httpRequest.getParameter("reportId")
)

If you now call this via

http://SERVER:PORT/reportserverbasedir/reportserver/scriptAccess?id=ScriptID&reportId=42

it will print

the report id is: 42

Cheers
-Arno

Offline

#13 2015-12-11 09:19:13

ralex
Member
Registered: 2015-04-20

Re: How to generate a birt report in background and then sending via email

Hi Arno,
thanks again....It's clear now how to dynamically pass the reportId to the script. 

def reportId = Long.valueOf(httpRequest.getParameter("reportId"))
def report = reportService.getReportById(reportId)

Now, my question is how to pass/set the value of parameters to the report object before executing

def pdf = reportExec.execute(report, "PDF")

....suppose that my script access url is

 http://SERVER:PORT/reportserverbasedir/reportserver/scriptAccess?id=ScriptID&reportId=42&mypar1=bla

I guess that I need retrieve the parameterSet object, because the report object also has an execute method with this signature "execute(Report report, ParameterSet parameterSet, java.lang.String outputFormat) "

Please highlight  me a bit smile

Offline

#14 2015-12-14 09:34:10

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: How to generate a birt report in background and then sending via email

Hi Alex,

using the httpRequest object you can also read in parameters that you pass on to the report execution. The simplest way would, however be to use the existing hook
ConfigureReportViaHttpRequestHook which is also used by the servlet which allows to execute reports via the URL. The basic idea is the following: You'll need the additional
imports and load the hookhandler.

import net.datenwerke.rs.core.service.reportmanager.hooks.ConfigureReportViaHttpRequestHook
import net.datenwerke.hookhandler.shared.hookhandler.HookHandlerService

def hookService = GLOBALS.getInstance(HookHandlerService.class)

When you load the report object, make sure it is loaded in unmanaged mode (since we are going to change it and don't want the changes to be written back to the database.

def report = reportService.getUnmanagedReportById(reportId)

Then adjust the report before execution

hookService.getHookers(ConfigureReportViaHttpRequestHook.class).each {
	it.adjustReport(report, httpRequest);
}

Then simply execute the report. In order to set the parameters via URL, you can then use the standard URL scheme for parameters. That is, "p_ParameterKey=ParameterValue".

Offline

#15 2015-12-14 13:59:08

ralex
Member
Registered: 2015-04-20

Re: How to generate a birt report in background and then sending via email

Arno Mittelbach wrote:

Hi Alex,

using the httpRequest object you can also read in parameters that you pass on to the report execution. The simplest way would, however be to use the existing hook
ConfigureReportViaHttpRequestHook which is also used by the servlet which allows to execute reports via the URL. The basic idea is the following: You'll need the additional
imports and load the hookhandler.

import net.datenwerke.rs.core.service.reportmanager.hooks.ConfigureReportViaHttpRequestHook
import net.datenwerke.hookhandler.shared.hookhandler.HookHandlerService

def hookService = GLOBALS.getInstance(HookHandlerService.class)

When you load the report object, make sure it is loaded in unmanaged mode (since we are going to change it and don't want the changes to be written back to the database.

def report = reportService.getUnmanagedReportById(reportId)

Then adjust the report before execution

hookService.getHookers(ConfigureReportViaHttpRequestHook.class).each {
	it.adjustReport(report, httpRequest);
}

Then simply execute the report. In order to set the parameters via URL, you can then use the standard URL scheme for parameters. That is, "p_ParameterKey=ParameterValue".

Great! Always thanks! smile
Just for my personal curiosity, but what are these hookers ? (I would have never found them ! smile )
Cheers,
Alex

Offline

#16 2015-12-14 14:21:18

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: How to generate a birt report in background and then sending via email

Hi Alex,

the hook handler is a plugin concept with a somewhat misplaced name .. .:)

Cheers,
-Arno

Offline

Board footer

Powered by FluxBB