From Eclipsepedia

< Stardust
Revision as of 07:17, 16 May 2012 by (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This article will show how to run default or custom reports in Stardust and add them as process attachments. This article assumes that reader is already familiar with basics of Stardust, Stardust Bert report and DMS components.

Following sections explain how to run and attach reports with the help of an example process model and simple java application. All artifacts source code discussed here can be downloaded from Model and Source Code section at the end.

Demo Model

We will use the following example process definition. It is very simple process having only three steps. First step will read the Bert Report URL and its parameters from the user.

Second step is a simple java application, see source code below, which simply takes in report URL (from step 1) and runs the report. The returned report content (PDF in this case), is added into the document repository and then associated as a document in the current process attachments.

The third step is a plan manually activity where user can stop and view/verify if the run is attached to the process attachments. If everything goes well, you will see the report document in the process attachments list.

Process 1:


Report Runner Java App

package com.sungard.infinity.reports;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.eclipse.stardust.common.log.LogManager;
import org.eclipse.stardust.common.log.Logger;
import org.eclipse.stardust.engine.api.runtime.DmsUtils;
import org.eclipse.stardust.engine.api.runtime.Document;
import org.eclipse.stardust.engine.api.runtime.DocumentInfo;
import org.eclipse.stardust.engine.api.runtime.DocumentManagementService;
import org.eclipse.stardust.engine.api.runtime.WorkflowService;
import org.eclipse.stardust.engine.api.spring.SpringUtils;
import org.eclipse.stardust.ui.web.processportal.view.ActivityDetailsBean;
public class ReportAttachmentAPI {
	private static final Logger log = LogManager
	private ActivityDetailsBean activityDetails;
	public ReportAttachmentAPI() {
		log.debug("Instanciating ReportAttachmentAPI");
		activityDetails = (ActivityDetailsBean) SpringUtils
	 * @param reportRunURL
	 *            URL of the report to be run and attach
	public void runAndAttachReport(String reportRunURL) {
		log.debug("Got in val as : " + reportRunURL);
		DocumentManagementService dmsService = ContextPortalServices
		WorkflowService workflowService = ContextPortalServices
		String targetFolder = activityDetails.getProcessAttachmentsFolderId();
		// Create an instance of HttpClient.
		HttpClient client = new HttpClient();
		// Create a method instance.
		GetMethod method = new GetMethod(reportRunURL);
		// Provide custom retry handler is necessary
				new DefaultHttpMethodRetryHandler(3, false));
		try {
			// Execute the method.
			int statusCode = client.executeMethod(method);
			if (statusCode != HttpStatus.SC_OK) {
				System.err.println("Method failed: " + method.getStatusLine());
			// Read the response body.
			byte[] responseBody = method.getResponseBody();
			// Deal with the response.
			// Use caution: ensure correct character encoding and is not binary
			// data
			log.debug(new String(responseBody));
			DocumentInfo docInfo = DmsUtils
							+ (new Date()).getTime());
			// docInfo.setContentType("text/html");
			docInfo.setDescription("TestReportName1 desc");
			// docInfo.setOwner(wfService.getUser().getAccount());
			byte[] docContent = responseBody;
			DmsUtils.ensureFolderHierarchyExists(targetFolder, dmsService);
			Document doc = dmsService.createDocument(targetFolder, docInfo,
					docContent, null);
			List<Document> docList = new ArrayList<Document>();
					.getOID(), DmsConstants.PATH_ID_ATTACHMENTS, docList);
		} catch (HttpException e) {
			System.err.println("Fatal protocol violation: " + e.getMessage());
		} catch (IOException e) {
			System.err.println("Fatal transport error: " + e.getMessage());
		} finally {
			// Release the connection.

Model and Source Code

Download the model and source code here