Executing a report
An ExecuteReport operation generates a synchronous report from an executable file. The executable file can be an Actuate BIRT file type or an external executable file type.
An ExecuteReport request identifies the input file. To save the output, you indicate the output file’s destination by including a full path in the Name parameter for RequestedOutputFile.
An ExecuteReportResponse returns an Encyclopedia volume-generated ObjectId and the status of the report. For a persistent report, the ObjectId is valid until a user deletes the report. For a transient report, the ObjectId is a temporary identifier that lasts for a configurable period of time.
ExecuteReportResponse also returns a ConnectionHandle for a persistent report. Subsequent requests for the same report must use this ConnectionHandle. The ConnectionHandle remains valid throughout the session.
Understanding the structure of an ExecuteReport application
An ExecuteReport application typically uses a mix of developer and com.actuate.schemas classes to implement an ExecuteReport operation in an Encyclopedia volume. The following application derives from the code in the BIRT iHub Integration Technology example applications for the Apache Axis 2 client. In the example application, AcExecuteReport, performs these tasks:
*Instantiates the Arguments class, gets the input file (.rptdesign) and output file (.rptdocument) names as command line arguments, and passes these command line arguments to the constructor
*Instantiates the ActuateController class, getting a server URL from Arguments, if specified, at the command line
*Uses methods defined in the controller class to send a request to execute a report using the com.actuate.schemas.ExecuteReport and ExecuteReportResponse classes
The AcExecuteReport class looks like the following example:
public class AcExecuteReport {
public static ActuateControl actuateControl;
public static void main(String[ ] args) {
// download settings
String inputFileName;
String outputFileName;
Arguments arguments = new Arguments(args);
inputFileName = arguments.getArgument( );
outputFileName = arguments.getArgument( );
try {
actuateControl =
new ActuateControl(arguments.getURL( ));
actuateControl.setInputFileName(inputFileName);
actuateControl.setOutputFileName(outputFileName);
actuateControl.executeReport( );
}
catch (Exception e) {
e.printStackTrace( );
}
}
}
ActuateControl.executeReport( ) performs the following tasks:
*Sets up an ExecuteReport object, specifying the job name, input file name, and output file flag
*Sets up a NewFile object to receive the requested output file
*Calls the proxy to submit the request and receives the response
*Outputs a status message
ActuateControl.executeReport( ) looks like the following example:
public void executeReport( ) throws RemoteException {
com.actuate.schemas.ExecuteReport executeReport =
new com.actuate.schemas.ExecuteReport( );
executeReport.setJobName(jobName);
executeReport.setInputFileName(inputFileName);
boolean bSaveOutputFile = (!outputFileName.equals(""));
executeReport.setSaveOutputFile(
new Boolean(bSaveOutputFile));
if (bSaveOutputFile) {
com.actuate.schemas.NewFile requestedOutputFile =
new com.actuate.schemas.NewFile( );
requestedOutputFile.setName(outputFileName);
executeReport.setRequestedOutputFile(requestedOutputFile);
}
com.actuate.schemas.ExecuteReportResponse executeReportResponse
= proxy.executeReport(executeReport);
System.out.println("Status " + executeReportResponse.getStatus( ));
}
Using SelectJavaReportPage
SelectJavaReportPage retrieves a specific page from an Actuate BIRT report specifying a page number, a page range, a component, or other search criteria. The following sample application, AcSelectJavaReportPage, selects a single page and saves the result in the specified directory by performing the following tasks:
*Instantiates the Arguments class, passing any command line arguments to the constructor
*Instantiates the ActuateController class, getting a server URL from Arguments, if specified in the command line
*Uses methods defined in the controller class to send a request to select a page using com.actuate.schemas.SelectJavaReportPage, SelectJavaReportPageResponse, ViewParameter, ObjectIdentifier, PageIdentifier, NameValuePair, and ArrayOfNameValuePair classes
*Instantiates the SelectJavaReportPage class and specifies the SelectJavaReportPage operation by performing the following tasks:
*Sets up an ObjectIdentifier object, specifying the name and type of the file to view
*Sets up a PageIdentifier object, specifying the page number to view and the page view mode
*Sets up the references to the ObjectIdentifier and PageIdentifier objects in the SelectJavaReportPage object
*Sets up the view properties used by the BIRT viewer using NameValuePair and ArrayOfNameValuePair classes
The view properties include the following settings:
*SVGFlag
Specifies whether to use Scalable Vector Graphics (SVG), an XML language used to describe two-dimensional graphics, such as vector graphics shapes, images, and text. This flag is used by the chart engine to determine if SVG chart output is supported.
*ContextPath
Specifies a context path relative to the root directory of the web server.
*MasterPage
Determines whether to use the master page, which defines the layout for the pages of a report.
*enableMetaData
Enables the client to retrieve metadata required to communicate with the service.
*displayGroupIcon
Enables the display of group icons for viewing related items.
*displayFilterIcon
Enables the display of filter icons for viewing items using options a user selects.
*viewMode
Specifies whether the report displays in HTML or PDF.
*Makes the remote call to the Actuate SOAP port using proxy.selectJavaReportPage( ), returning a reference to the com.actuate.schemas.SelectJavaReportPageResponse object
*Sets up the download directory using mkdir( )
*Saves the result in the download directory
*To obtain an image on a page in the document, the application performs the following tasks:
*Gets the page reference
*Calls Attachment.getContentData( ) to obtain the page content and sets up a ByteArrayInputStream
*Calls getEmbed( ), passing in the references to ByteArrayInputStream and ActuateControl objects
getEmbed( ) performs the following tasks:
*Sets up an InputStreamReader to iteratively read pattern chunks, line by line, to decode the input stream
*Compiles the generic image file name, specified in a regular expression, into a pattern instance, which allows the application to use a Matcher object to identify an embedded image
*Uses Matcher.find( ) to scan a chunk to locate a sequence matching the specified pattern
*Calls returnId( ) to get the image ID
*Sets up a GetJavaReportEmbededComponent object, specifying the file name, file type, and a name-value pair indicating the image component ID
*Sets the response connection handle, the session ID of the object
*Calls ActuateControl.GetJavaReportEmbededComponent ( ) to get the embedded object
*Saves the Attachment to the download directory
AcSelectJavaReportPage class looks like the following example:
public class AcSelectJavaReportPage {
public static ActuateControl actuateControl;
// download settings
static String filename;
static String downloadDirectory = "download";
static String format = "Reportlet";
static int pageNumber = 1;
static com.actuate.schemas.SelectJavaReportPageResponse
resp=null;
public static void main(String[ ] args)
{
// get command line arguments
Arguments arguments = new Arguments(args);
filename = arguments.getArgument( );
pageNumber = Integer.parseInt(arguments.getOptionalArgument("1"));
downloadDirectory = arguments.getOptionalArgument(downloadDirectory);
 
actuateControl.selectPage(
filename,format,pageNumber,downloadDirectory);
com.actuate.schemas.SelectJavaReportPage
acselectjavarptpage = new
com.actuate.schemas.SelectJavaReportPage( );
com.actuate.schemas.ObjectIdentifier objId =
new ObjectIdentifier( );
objId.setName(filename);
objId.setType("rptdocument");
acselectjavarptpage.setObject(objId);
PageIdentifier pgId = new PageIdentifier( );
pgId.setPageNum(new Long(pageNumber));
pgId.setViewMode(new Integer(1));
acselectjavarptpage.setPage(pgId); acselectjavarptpage.setOutputFormat(format);
acselectjavarptpage.setDownloadEmbedded(
new Boolean(true));
com.actuate.schemas.NameValuePair nvpair =
new com.actuate.schemas.NameValuePair( );
nvpair0.setName("SVGFlag");
nvpair0.setValue("false");
com.actuate.schemas.NameValuePair nvpair1 =
new com.actuate.schemas.NameValuePair( );
nvpair1.setName("ContextPath");
nvpair1.setValue("/");
com.actuate.schemas.NameValuePair nvpair2 =
new com.actuate.schemas.NameValuePair( );
nvpair2.setName("MasterPage");
nvpair2.setValue("true");
com.actuate.schemas.NameValuePair nvpair3 =
new com.actuate.schemas.NameValuePair( );
nvpair3.setName("enableMetaData");
nvpair3.setValue("false");
com.actuate.schemas.NameValuePair nvpair4 =
new com.actuate.schemas.NameValuePair( );
nvpair4.setName("displayGroupIcon");
nvpair4.setValue("false");
com.actuate.schemas.NameValuePair nvpair5 =
new com.actuate.schemas.NameValuePair( );
nvpair5.setName("displayFilterIcon");
nvpair5.setValue("false");
com.actuate.schemas.NameValuePair nvpair6 =
new com.actuate.schemas.NameValuePair();
nvpair6.setName("viewMode");
nvpair6.setValue("1");
com.actuate.schemas.NameValuePair npair[ ] =
{nvpair,nvpair1,nvpair2,nvpair3,
nvpair4,nvpair5,nvpair6};
ArrayOfNameValuePair arr = new ArrayOfNameValuePair( );
arr.setNameValuePair(npair);
acselectjavarptpage.setViewProperties(arr);
resp = actuateControl.proxy.selectJavaReportPage(
acselectjavarptpage);
// Save the result in download directory
new java.io.File(downloadDirectory).mkdir( );
 
String firstAttachmentName =
actuateControl.saveAttachment(resp.getPageRef( ),
downloadDirectory);
com.actuate.schemas.Attachment att = resp.getPageRef( );
 
byte[ ] content = att.getContentData( );
java.io.ByteArrayInputStream ba =
new java.io.ByteArrayInputStream(content);
getembed(ba,actuateControl);
}
catch (Exception e)
{
e.printStackTrace( );
}
 
public static void getembed(
java.io.ByteArrayInputStream ba,
ActuateControl actuateControl) throws Exception {
Charset cs = Charset.forName("UTF-8");
java.io.InputStreamReader isr =
new java.io.InputStreamReader(ba,cs);
Pattern p = Pattern.compile("__imageID=(\\S+\\.jpg)");
java.io.BufferedReader br =
new java.io.BufferedReader(isr);
String chunk = null;
while ((chunk = br.readLine( )) != null) {
Matcher m = p.matcher(chunk);
String image_id = null;
if(m.find( ) ) {
System.out.println("String read :" + chunk);
String tmp = m.group();
image_id = returnId(tmp);
String decoded_image_id =
java.net.URLDecoder.decode(image_id, "UTF-8");
GetJavaReportEmbededComponent jrptComp =
new GetJavaReportEmbededComponent( );
jrptComp.setDownloadEmbedded(new Boolean(true));
ObjectIdentifier jobj = new ObjectIdentifier( );
jobj.setName(filename);
jobj.setType("rptdocument");
jrptComp.setObject(jobj);
com.actuate.schemas.NameValuePair jpair =
new com.actuate.schemas.NameValuePair( );
jpair.setName("compId");
 
jpair.setValue(decoded_image_id);
com.actuate.schemas.NameValuePair njpair[ ] =
{jpair};
ArrayOfNameValuePair jarr =
new ArrayOfNameValuePair( );
jarr.setNameValuePair(njpair);
jrptComp.setComponent(jarr);
actuateControl.setConnectionHandle(
resp.getConnectionHandle( ));
GetJavaReportEmbededComponentResponse jresp =
actuateControl.proxy.getJavaReportEmbededComponent(
jrptComp);
String imageName =
actuateControl.saveAttachment(
jresp.getEmbeddedRef( ), downloadDirectory);
System.out.println( imageName);
}
}
}
public static String returnId (String str){
int startPos;
startPos = str.indexOf("=");
String id = str.substring(startPos + 1);
return id;
}
}