Archiving Audit Diagrams as Images in Oracle SOA Suite BPM Processes2

本文介绍如何在Oracle SOA Suite 11g中保存业务流程的审计实例图作为图片,并通过Java代码实现流程图的获取与存档,同时突出显示流程实例的流转路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

July 26, 2011

Archiving Audit Diagrams as Images in Oracle SOA Suite BPM Processes

Filed under:   BPEL,   BPM,   Java,   Oracle Service Bus,   SOA  — Tags:   Audit Trail Image,   Oracle BPM 11g,   Oracle BPM 11g API,   Oracle SOA Suite 11g,   PAPI,   Process Audit Image in Oracle BPM 11g  — Arun Pareek @ 4:10 pm

In my previous post I had described how we can create a custom Java Class to save custom business indicators in a formatted PDF file. It might be useful in cases where businesses wants process data be presented in a meaningful way.

Another practical case that i had encountered in the past while designing business processes is to save the Audit diagram of the process once it is complete. The audit instance diagram can be viewed in the EM console by clicking on Flow Trace for any process instance.

In the good all Oracle BPM 10g days (prior to Oracle SOA/BPM Suite 11g) we had a fully documented API’s for interacting with process instances. PAPI interfaces were available both as web service and java API’s to connect to a in-flight or completed instance and retrieve all audit data from it.

Getting an audit image from a business process instance using PAPI was a cake walk. The below code sample shows its ease

ProcessService processService = null;
ProcessServiceSession session = null;
try {
processService = ProcessService.create(configuration);
session = processService.createSession(USERNAME, PASSWORD, HOSTNAME);
for (String processId : session.processesGetIds())
{
 fuego.papi.Process process = session.processGet(processId);
 ProcessDiagram diagram = session.processGetDiagram(processId);
 diagram.setTheme(ProcessDiagram.THEME_COLOR_BPMN);
 diagram.setDrawFlowOnly(true);
 Image image = diagram.getImage();
 File pngImage = new File(createPngFilename("image"));
 image.write(pngImage, ImageExtension.PNG);
}
catch (Exception e)
{
 e.printStackTrace();
}
finally
{
 session.close();
 processService.close();
}

Whoa! Pretty Simple and elegant.

However if we want to achieve something similar in Oracle SOA Suite 11g it is a lot more challenging.

Oracle BPM Suite 11g doesn’t have any published API’s that developers can refer. This makes it an even bigger nightmare.

The process instance data in Oracle SOA suite 11g is stored in the dehydration store in the SOA_INFRA schema. In all practical scenarios this store will be subjected to purging and maintenance. So many a people/project might need to archive the flow trace of a process instance as an image. As we all know how significant is historical data for business process improvements and reengineering.

In this blog post I will show how the same functionality of getting an instance image from a process can be achieved using Oracle SOA Suite 11g and explain the code in steps.

Assuming we are using Oracle SOA Suite 11g PS3 that has a running domain and a BPM process deployed with a couple of running/completed instances.

Create a Generic Java project in JDeveloper say ArchiveInstanceImage. Create a Java class of the same name inside it. Right click on the project and add the following JAR’s to the project’s classpath.

Oracle.bpm.bpm-services.client.jar
Oracle.bpm.bpm-services.interface.jar
Oracle.bpm.client.jar
Bpm-infra.jar
Bpm-services.jar
Oracle.bpm.project.model.jar
Oracle.bpm.project.draw.jar
Oracle.bpm.project.catalog.jar
Wlfullclient.jar
Wsclient_extended.jar
Oracle.bpm.core.jar
Oracle.bpm.lib.jar
Oracle.bpm.papi.jar
Oracle.bpm.xml.jar
Oracle.bpm.diagram.draw.jar
Oracle-bpm.jar
Oracle.bpm.bpm-services.implementation.jar
Oracle.bpm.bpm-services.internal.jar
Oracle.bpm.bpmobject.jar
Oracle.bpm.runtime.jar
Oracle.bpm.ui.jar

All these above JAR’s can be found at the following directories

<JDevHome>\soa\modules\oracle.bpm.client_11.1.1
<JDevHome>\soa\modules\oracle.soa.fabric_11.1.1
<JDevHome>\soa\modules\oracle.soa.workflow_11.1.1
<JDevHome>\soa\modules\oracle.bpm.project_11.1.1
<MiddlewareHome>\wlserver_10.3\server\lib
<MiddlewareHome>\oracle_common\webservices
<JDevHome>\soa\modules\oracle.bpm.runtime_11.1.1
<JDevHome>\soa\modules\oracle.bpm.workspace_11.1.1

You can created Wlfullclient.jar as under

Change directories to the server/lib directory.

cd <MiddlewareHome>wlserver_10.3/server/lib

Use the following command to create wlfullclient.jar in the server/lib directory:

java -jar wljarbuilder.jar

You can now copy and bundle the wlfullclient.jar with client applications.

Add the wlfullclient.jar to the client application’s classpath.

See here for more information

http://download.oracle.com/docs/cd/E12840_01/wls/docs103/client/jarbuilder.html

First and foremost like any remote client we need to get an instance of the SOA server runtime to be able to gain access to any running processes inside it. This is pretty simple. The following lines of code demonstrates how we can use BPMServiceClientFactory class to get an instance of the server runtime.

Next initialize an IBPMContext from BPMServiceClientFactory.

// URL of the SOA Server and PORT on which the application is deployed
private static String soaURL = "t3://localhost:4003";

public static BPMServiceClientFactory getBPMServiceClientFactory()
{
Map<IWorkflowServiceClientConstants.CONNECTION_PROPERTY,String> properties = new HashMap<IWorkflowServiceClientConstants.CONNECTION_PROPERTY,String>();
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,WorkflowServiceClientFactory.REMOTE_CLIENT);
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,soaURL);
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,"weblogic");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,"welcome123");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
return BPMServiceClientFactory.getInstance(properties, null, null);
}

public static IBPMServiceClient getBPMServiceClient(){
return getBPMServiceClientFactory().getBPMServiceClient();
}
public static IBPMContext getIBPMContextForAuthenticatedUser() throws Exception{
return getBPMServiceClientFactory().getBPMUserAuthenticationService().getBPMContextForAuthenticatedUser();
}

We also have to get a handle to the IBPMServiceClient interface. Create a self initializing constructor for our main class to get a hook to this interface.

// Get a handle to the IBPMServiceClient interface in the ArchiveInstanceImage class
public ArchiveInstanceImage(IBPMServiceClient bpmServiceClient)
{
this.bpmServiceClient = bpmServiceClient;
}

Using the IBPMContext and a searchable instance id from the process we can get process data using the IProcessInstance interface.

See the code snippet below that shows how we can retrieve the audit diagram for a process instance

public InputStream getProcessAuditImage(IBPMContext bpmContext, String instanceId)
throws BPMException
{
IInstanceQueryService instanceQueryService = this.bpmServiceClient.getInstanceQueryService();
IProcessInstance processInstance = instanceQueryService.getProcessInstance(bpmContext, instanceId);

if (processInstance == null) {
return null;
}
IProcessModelPackage processModelPackage = this.bpmServiceClient.getProcessModelService().getProcessModel(bpmContext, processInstance.getSca().getCompositeDN(), processInstance.getSca().getComponentName());

AuditProcessDiagrammer auditProcessImage  = new AuditProcessDiagrammer(processModelPackage.getProcessModel());
return getProcessImage(auditProcessImage);
}

private InputStream getProcessImage(AuditProcessDiagrammer processImage)
throws BPMException
{
InputStream processImageStream  = null;
ByteArrayOutputStream auditImageOutputStream = new ByteArrayOutputStream();
try {
// Get base64 encoded image String from processImage
String base64Image = processImage.getImage();
Image image = Image.createFromBase64(base64Image);
BufferedImage bufferedImage = (BufferedImage)image.asAwtImage();
// Use the Image Extension that suites you from .PNG, .JPG and .GIF
ImageIOFacade.writeImage(bufferedImage, ImageExtension.PNG, auditImageOutputStream);
processImageStream  = new ByteArrayInputStream(auditImageOutputStream.toByteArray());
// Archives the Process Image at any suitable location
archiveDiagramToFile(processImageStream);
}
catch (Exception e)
{
throw new BPMException(e);
}
finally {
}
return processImageStream;
}

// Utility method to Archive the InputStream into a PNG File
private void archiveDiagramToFile(InputStream istream) throws IOException {
File outputFile = new File("C:\\Arrun\\ProcessAuditImage\\ProcessImage.png");
OutputStream out = new FileOutputStream(outputFile);

// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = istream.read(buf)) > 0) {
out.write(buf, 0, len);
}
istream.close();
out.close();
}

Finally to test the code that we had written add a main method to invoke getProcessAuditImage(iBPMContext, instanceId) to see the process audit image created.

public static void main (String args[]) throws BPMException, Exception
{
ArchiveInstanceImage instImage = new ArchiveInstanceImage(getBPMServiceClient());
// Use any instanceId that is existing for the process in the server
InputStream istream= instImage.getProcessAuditImage(getIBPMContextForAuthenticatedUser(),"840001");
}

Running the standalone Java program from inside JDeveloper creates the following process image in the target archive directory.

image

A quick look at the image and we will realize what it is lacking. Off course we have been quite able to get the image for the process (similar to what we used to get using PAPI in OBPM 10g). However we don’t see the flow trace i.e the sequence of activities that the instance traversed in its flow.

To get that we have get a List of DiagramEvent and highlight the process image by passing this list to it.

Create another private function to get a list of all Events that the instance encountered in its flow as below.

private List<DiagramEvent> getHighlightEvents(Process processModel, IAuditInstance auditInstance)
{
List events = new ArrayList();

String activityId = auditInstance.getActivityId();
Date eventDate = auditInstance.getCreateTime().getTime();
DiagramEvent nodeEvent = DiagramEvent.create(DiagramEvent.DiagramEventType.FLOW_NODE_IN, activityId, eventDate);

events.add(nodeEvent);
String sourceActivity;
String targetActivity;
if (auditInstance.getAuditInstanceType().equalsIgnoreCase("START")) {
FlowNode flowNode = (FlowNode)processModel.findDescendant(FlowNode.class, auditInstance.getActivityId());

if (flowNode != null) {
sourceActivity = auditInstance.getSourceActivity();
Sequence<SequenceFlow> incommingSequenceFlows = flowNode.getIncomingSequenceFlows();
if ((incommingSequenceFlows != null) && (!incommingSequenceFlows.isEmpty()) && (sourceActivity != null)) {
Iterator<SequenceFlow> seqIterator  = incommingSequenceFlows.iterator();
while(seqIterator.hasNext())
{
SequenceFlow sequenceFlow= seqIterator.next();
if (sequenceFlow.getSource().getId().equalsIgnoreCase(sourceActivity)) {
DiagramEvent sequenceEvent = DiagramEvent.create(DiagramEvent.DiagramEventType.SEQUENCE_FLOW, sequenceFlow.getId(), eventDate);
events.add(sequenceEvent);
}}
}}
}
else if (auditInstance.getAuditInstanceType().equalsIgnoreCase("END")) {
FlowNode flowNode = (FlowNode)processModel.findDescendant(FlowNode.class, auditInstance.getActivityId());

if (flowNode != null) {
targetActivity = auditInstance.getTargetActivity();
Sequence<SequenceFlow> outgoingSequenceFlows = flowNode.getOutgoingSequenceFlows();

if ((outgoingSequenceFlows != null) && (!outgoingSequenceFlows.isEmpty()) &&
(targetActivity != null)) {
Iterator<SequenceFlow> seqIterator  = outgoingSequenceFlows.iterator();
while(seqIterator.hasNext())
{
SequenceFlow sequenceFlow= seqIterator.next();
if (sequenceFlow.getTarget().getId().equalsIgnoreCase(targetActivity))
{
DiagramEvent sequenceEvent = DiagramEvent.create(DiagramEvent.DiagramEventType.SEQUENCE_FLOW, sequenceFlow.getId(), eventDate);
events.add(sequenceEvent);
}}
}}
}

Add these following line to the getProcessAuditImage(IBPMContext bpmContext, String instanceId) method before the return statement to highlight the image

List auditInstances = this.bpmServiceClient.getInstanceQueryService().queryAuditInstanceByProcessId(bpmContext, instanceId);
List diagramEvents = new ArrayList();

for (int IAuditInstance=0; IAuditInstance< auditInstances.size(); IAuditInstance++)
{
diagramEvents.addAll(getHighlightEvents(process, (IAuditInstance)auditInstances.get(IAuditInstance)));
}
auditProcessImage.highlight(diagramEvents);

Run the Java program once again and view the image created this time.

image

This time you can see that the activities and transitions that the instance took are highlighted in the image.

The complete Java Class can be found below

package blog.beatechnologies.soasuiteutil;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import oracle.bpel.services.bpm.common.IBPMContext;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;

import oracle.bpm.client.BPMServiceClientFactory;
import oracle.bpm.collections.Sequence;
import oracle.bpm.draw.diagram.AuditProcessDiagrammer;
import oracle.bpm.draw.diagram.DiagramEvent;
import oracle.bpm.project.model.processes.FlowNode;
import oracle.bpm.project.model.processes.Process;
import oracle.bpm.project.model.processes.SequenceFlow;
import oracle.bpm.services.client.IBPMServiceClient;
import oracle.bpm.services.common.exception.BPMException;
import oracle.bpm.services.instancemanagement.model.IProcessInstance;
import oracle.bpm.services.instancequery.IAuditInstance;
import oracle.bpm.services.instancequery.IInstanceQueryService;
import oracle.bpm.services.internal.processmodel.model.IProcessModelPackage;
import oracle.bpm.ui.Image;
import oracle.bpm.ui.utils.ImageExtension;
import oracle.bpm.ui.utils.ImageIOFacade;

public class ArchiveInstanceImage
{
private IBPMServiceClient bpmServiceClient;
// URL of the SOA Server and PORT on which the application is deployed
private static String soaURL = "t3://soasitapp03.us.dell.com:5411";

public ArchiveInstanceImage(IBPMServiceClient bpmServiceClient)
{
this.bpmServiceClient = bpmServiceClient;
}

public InputStream getProcessAuditImage(IBPMContext bpmContext, String instanceId)
throws BPMException
{
IInstanceQueryService instanceQueryService = this.bpmServiceClient.getInstanceQueryService();
IProcessInstance processInstance = instanceQueryService.getProcessInstance(bpmContext, instanceId);

if (processInstance == null) {
return null;
}
IProcessModelPackage processModelPackage = this.bpmServiceClient.getProcessModelService().getProcessModel(bpmContext, processInstance.getSca().getCompositeDN(), processInstance.getSca().getComponentName());

AuditProcessDiagrammer auditProcessImage  = new AuditProcessDiagrammer(processModelPackage.getProcessModel());
List auditInstances = this.bpmServiceClient.getInstanceQueryService().queryAuditInstanceByProcessId(bpmContext, instanceId);

List diagramEvents = new ArrayList();

for (int IAuditInstance=0; IAuditInstance< auditInstances.size(); IAuditInstance++)
{
diagramEvents.addAll(getHighlightEvents(processModelPackage.getProcessModel(), (IAuditInstance)auditInstances.get(IAuditInstance)));
}
auditProcessImage.highlight(diagramEvents);
return getProcessImage(auditProcessImage);
}

private InputStream getProcessImage(AuditProcessDiagrammer processImage)
throws BPMException
{
InputStream processImageStream  = null;
ByteArrayOutputStream auditImageOutputStream = new ByteArrayOutputStream();
try {
// Get base64 encoded image String from processImage
String base64Image = processImage.getImage();
Image image = Image.createFromBase64(base64Image);
BufferedImage bufferedImage = (BufferedImage)image.asAwtImage();
// Use the Image Extension that suites you from .PNG, .JPG and .GIF
ImageIOFacade.writeImage(bufferedImage, ImageExtension.PNG, auditImageOutputStream);
processImageStream  = new ByteArrayInputStream(auditImageOutputStream.toByteArray());
// Archives the Process Image at any suitable location
archiveDiagramToFile(processImageStream);
}
catch (Exception e)
{
throw new BPMException(e);
}
finally {
}
return processImageStream;
}

private List<DiagramEvent> getHighlightEvents(Process processModel, IAuditInstance auditInstance)
{
List events = new ArrayList();

String activityId = auditInstance.getActivityId();
Date eventDate = auditInstance.getCreateTime().getTime();
DiagramEvent nodeEvent = DiagramEvent.create(DiagramEvent.DiagramEventType.FLOW_NODE_IN, activityId, eventDate);

events.add(nodeEvent);
String sourceActivity;
String targetActivity;
if (auditInstance.getAuditInstanceType().equalsIgnoreCase("START")) {
FlowNode flowNode = (FlowNode)processModel.findDescendant(FlowNode.class, auditInstance.getActivityId());

if (flowNode != null) {
sourceActivity = auditInstance.getSourceActivity();
Sequence<SequenceFlow> incommingSequenceFlows = flowNode.getIncomingSequenceFlows();

if ((incommingSequenceFlows != null) && (!incommingSequenceFlows.isEmpty()) && (sourceActivity != null)) {
Iterator<SequenceFlow> seqIterator  = incommingSequenceFlows.iterator();

while(seqIterator.hasNext())
{
SequenceFlow sequenceFlow= seqIterator.next();
if (sequenceFlow.getSource().getId().equalsIgnoreCase(sourceActivity)) {
DiagramEvent sequenceEvent = DiagramEvent.create(DiagramEvent.DiagramEventType.SEQUENCE_FLOW, sequenceFlow.getId(), eventDate);
events.add(sequenceEvent);
}}
}}
}
else if (auditInstance.getAuditInstanceType().equalsIgnoreCase("END")) {
FlowNode flowNode = (FlowNode)processModel.findDescendant(FlowNode.class, auditInstance.getActivityId());

if (flowNode != null) {
targetActivity = auditInstance.getTargetActivity();
Sequence<SequenceFlow> outgoingSequenceFlows = flowNode.getOutgoingSequenceFlows();

if ((outgoingSequenceFlows != null) && (!outgoingSequenceFlows.isEmpty()) && (targetActivity != null)) {
Iterator<SequenceFlow> seqIterator  = outgoingSequenceFlows.iterator();
while(seqIterator.hasNext())
{
SequenceFlow sequenceFlow= seqIterator.next();
if (sequenceFlow.getTarget().getId().equalsIgnoreCase(targetActivity)) {
DiagramEvent sequenceEvent = DiagramEvent.create(DiagramEvent.DiagramEventType.SEQUENCE_FLOW, sequenceFlow.getId(), eventDate);
events.add(sequenceEvent);
}}
}}
}
return events;
}
public static BPMServiceClientFactory getBPMServiceClientFactory() {
Map<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, String> properties = new HashMap<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, String>();
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,WorkflowServiceClientFactory.REMOTE_CLIENT);
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,soaURL);
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,"arun_pareek");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,"#Jannu12");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
return BPMServiceClientFactory.getInstance(properties, null, null);
}
public static IBPMServiceClient getBPMServiceClient(){
return getBPMServiceClientFactory().getBPMServiceClient();
}
public static IBPMContext getIBPMContextForAuthenticatedUser() throws Exception{
return getBPMServiceClientFactory().getBPMUserAuthenticationService().getBPMContextForAuthenticatedUser();
}

public static void main (String args[]) throws BPMException, Exception
{
ArchiveInstanceImage instImage = new ArchiveInstanceImage(getBPMServiceClient());
InputStream istream= instImage.getProcessAuditImage(getIBPMContextForAuthenticatedUser(),"10002");
}
void archiveDiagramToFile(InputStream istream) throws IOException {
File outputFile = new File("C:\\Arrun\\process.png");
OutputStream out = new FileOutputStream(outputFile);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = istream.read(buf)) > 0) {
out.write(buf, 0, len);
}
istream.close();
out.close();
}
}

This was all about getting this Java API’s to work with SOA Suite 11g PS3. I also tried to test the same with a  PS2 domain and with PS2 libraries.

Everything was almost same except for a few things.

There is no class called IProcessModelPackage that I could find in PS2 BPM jar’s

So the process image was obtained using IProcessModelService class like below

IProcessModelService processModelService =  this.bpmServiceClient.getProcessModelService();
Process process = processModelService.getProcessModel(bpmContext, processInstance.getSca().getCompositeDN(), processInstance.getSca().getComponentName());
AuditProcessDiagrammer auditProcessImage = new AuditProcessDiagrammer(process);

The additional libraries that we need to put in the project’s classspath are

Oracle.bpm.project.io.jar                    <JDevHome>\soa\modules\oracle.bpm.project_11.1.1
Oracle.bpm.project.jar                         <JDevHome>\soa\modules\oracle.bpm.project_11.1.1
Oracle.bpm.project.compile.jar        <JDevHome>\soa\modules\oracle.bpm.project_11.1.1
Oracle.bpm.vfilesystem.jar                 <JDevHome>\soa\modules\oracle.bpm.runtime_11.1.1

In case you would need the entire class here is what you should use in case you are on Oracle SOA Suite 11g PS2

package blog.beatechnologies.soautil;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import oracle.bpel.services.bpm.common.IBPMContext;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;

import oracle.bpm.client.BPMServiceClientFactory;
import oracle.bpm.collections.Sequence;
import oracle.bpm.draw.diagram.AuditProcessDiagrammer;
import oracle.bpm.draw.diagram.DiagramEvent;
import oracle.bpm.project.model.processes.FlowNode;
import oracle.bpm.project.model.processes.Process;
import oracle.bpm.project.model.processes.SequenceFlow;
import oracle.bpm.services.client.IBPMServiceClient;
import oracle.bpm.services.common.exception.BPMException;
import oracle.bpm.services.instancemanagement.model.IProcessInstance;
import oracle.bpm.services.instancequery.IAuditInstance;
import oracle.bpm.services.instancequery.IInstanceQueryService;
import oracle.bpm.services.internal.processmodel.IProcessModelService;
import oracle.bpm.services.util.AuditTrail;
import oracle.bpm.ui.Image;
import oracle.bpm.ui.utils.ImageExtension;
import oracle.bpm.ui.utils.ImageIOFacade;

public class ArchiveInstanceImage
{
private IBPMServiceClient bpmServiceClient;
// URL of the SOA Server and PORT on which the application is deployed
private static String soaURL = "t3://wxp-fxhp7bs.blr.amer.dell.com:4003";

// Get a handle of IBPMServiceClient through the class constructor
public ArchiveInstanceImage(IBPMServiceClient bpmServiceClient)
{
this.bpmServiceClient = bpmServiceClient;
}

public InputStream getProcessAuditImage(IBPMContext bpmContext, String instanceId)
throws BPMException
{
IInstanceQueryService instanceQueryService = this.bpmServiceClient.getInstanceQueryService();
IProcessInstance processInstance = instanceQueryService.getProcessInstance(bpmContext, instanceId);

System.out.println("Composite DN " + processInstance.getSca().getCompositeDN());
System.out.println("Composite DN " + processInstance.getSca().getComponentName());

if (processInstance == null) {
return null;
}

IProcessModelService processModelService =  this.bpmServiceClient.getProcessModelService();
Process process = processModelService.getProcessModel(bpmContext, processInstance.getSca().getCompositeDN(), processInstance.getSca().getComponentName());
AuditProcessDiagrammer auditProcessImage = new AuditProcessDiagrammer(process);
List auditInstances = this.bpmServiceClient.getInstanceQueryService().queryAuditInstanceByProcessId(bpmContext, instanceId);

List diagramEvents = new ArrayList();

for (int IAuditInstance=0; IAuditInstance< auditInstances.size(); IAuditInstance++)
{
diagramEvents.addAll(getHighlightEvents(process, (IAuditInstance)auditInstances.get(IAuditInstance)));
}
auditProcessImage.highlight(diagramEvents);
//auditProcessImage.getImage()
return getProcessImage(auditProcessImage);
}

private InputStream getProcessImage(AuditProcessDiagrammer processImage)
throws BPMException
{
InputStream processImageStream = null;
ByteArrayOutputStream auditImageOutputStream = new ByteArrayOutputStream();
try {
// Get base64 encoded image String from processImage
String base64Image = processImage.getImage();
Image image = Image.createFromBase64(base64Image);
BufferedImage bufferedImage = (BufferedImage)image.asAwtImage();
// Use the Image Extension that suites you from .PNG, .JPG and .GIF
ImageIOFacade.writeImage(bufferedImage, ImageExtension.PNG, auditImageOutputStream);
processImageStream = new ByteArrayInputStream(auditImageOutputStream.toByteArray());
// Archives the Process Image at any suitable location
archiveDiagramToFile(processImageStream);
}
catch (Exception e)
{
throw new BPMException(e);
}
finally {
}
return processImageStream;
}

private List<DiagramEvent> getHighlightEvents(Process processModel, IAuditInstance auditInstance)
{
List events = new ArrayList();
String activityId = auditInstance.getActivityId();
Date eventDate = auditInstance.getCreateTime().getTime();
DiagramEvent nodeEvent = DiagramEvent.create(DiagramEvent.DiagramEventType.FLOW_NODE_IN, activityId, eventDate);
events.add(nodeEvent);
String sourceActivity;
String targetActivity;
if (auditInstance.getAuditInstanceType().equalsIgnoreCase("START")) {
FlowNode flowNode = (FlowNode)processModel.findDescendant(FlowNode.class, auditInstance.getActivityId());

if (flowNode != null) {
sourceActivity = auditInstance.getSourceActivity();
Sequence<SequenceFlow> incommingSequenceFlows = flowNode.getIncomingSequenceFlows();

if ((incommingSequenceFlows != null) && (!incommingSequenceFlows.isEmpty()) && (sourceActivity != null)) {
Iterator<SequenceFlow> seqIterator  = incommingSequenceFlows.iterator();
while(seqIterator.hasNext())
{
SequenceFlow sequenceFlow= seqIterator.next();
if (sequenceFlow.getSource().getId().equalsIgnoreCase(sourceActivity)) {
DiagramEvent sequenceEvent = DiagramEvent.create(DiagramEvent.DiagramEventType.SEQUENCE_FLOW, sequenceFlow.getId(), eventDate);
events.add(sequenceEvent);
}}
}}
}
else if (auditInstance.getAuditInstanceType().equalsIgnoreCase("END")) {
FlowNode flowNode = (FlowNode)processModel.findDescendant(FlowNode.class, auditInstance.getActivityId());

if (flowNode != null) {
targetActivity = auditInstance.getTargetActivity();
Sequence<SequenceFlow> outgoingSequenceFlows = flowNode.getOutgoingSequenceFlows();

if ((outgoingSequenceFlows != null) && (!outgoingSequenceFlows.isEmpty()) &&
(targetActivity != null)) {
Iterator<SequenceFlow> seqIterator  = outgoingSequenceFlows.iterator();
while(seqIterator.hasNext())
{
SequenceFlow sequenceFlow= seqIterator.next();
if (sequenceFlow.getTarget().getId().equalsIgnoreCase(targetActivity))
{
DiagramEvent sequenceEvent = DiagramEvent.create(DiagramEvent.DiagramEventType.SEQUENCE_FLOW, sequenceFlow.getId(), eventDate);
events.add(sequenceEvent);
}}
}}
}
return events;
}
public static BPMServiceClientFactory getBPMServiceClientFactory() {
Map<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, String> properties = new HashMap<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, String>();
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,WorkflowServiceClientFactory.REMOTE_CLIENT);
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,soaURL);
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,"weblogic");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,"welcome123");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
return BPMServiceClientFactory.getInstance(properties, null, null);
}
public static IBPMServiceClient getBPMServiceClient(){
return getBPMServiceClientFactory().getBPMServiceClient();
}
public static IBPMContext getIBPMContextForAuthenticatedUser() throws Exception{
return getBPMServiceClientFactory().getBPMUserAuthenticationService().getBPMContextForAuthenticatedUser();
}
public static void main (String args[]) throws BPMException, Exception {

ArchiveInstanceImage instImage = new ArchiveInstanceImage(getBPMServiceClient());
InputStream istream= instImage.getProcessAuditImage(getIBPMContextForAuthenticatedUser(),"840001");
}
// Utility method to Archive the InputStream into a PNG File
private void archiveDiagramToFile(InputStream istream) throws IOException {
File outputFile = new File("C:\\Arrun\\ProcessAuditImage\\ProcessImage.png");
OutputStream out = new FileOutputStream(outputFile);

// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = istream.read(buf)) > 0) {
out.write(buf, 0, len);
}
istream.close();
out.close();
}
}

Now there are a couple of ways to use this Java Code in real practical cases

  1. Use it from any Custom UI/ Workflow UI to access the process image if need be.
  2. Create a Web service wrapper over the Java Class and use it as a WS API that can be invoked from any BPM process and hence it can be reused across multiple BPM processes.
  3. In case you would want to limit the use inside a composite then create a Spring SCA component for this custom Java class and then invoke it from inside a BPM process

In my future blogs I will try to come up with more interesting utilities with these BPM API’s. This will probably be of great use to folks who have worked with the PAPI API’s and find it a great miss in Oracle SOA Suite 11g.

Meanwhile also wondering what is stopping Oracle to publish a well document API for these interfaces. :-)

.

1. 用户与身体信息管理模块 用户信息管理: 注册登录:支持手机号 / 邮箱注册,密码加密存储,提供第三方快捷登录(模拟) 个人资料:记录基本信息(姓名、年龄、性别、身高、体重、职业) 健康目标:用户设置目标(如 “减重 5kg”“增肌”“维持健康”)及期望周期 身体状态跟踪: 体重记录:定期录入体重数据,生成体重变化曲线(折线图) 身体指标:记录 BMI(自动计算)、体脂率(可选)、基础代谢率(根据身高体重估算) 健康状况:用户可填写特殊情况(如糖尿病、过敏食物、素食偏好),系统据此调整推荐 2. 膳食记录与食物数据库模块 食物数据库: 基础信息:包含常见食物(如米饭、鸡蛋、牛肉)的名称、类别(主食 / 肉类 / 蔬菜等)、每份重量 营养成分:记录每 100g 食物的热量(kcal)、蛋白质、脂肪、碳水化合物、维生素、矿物质含量 数据库维护:管理员可添加新食物、更新营养数据,支持按名称 / 类别检索 膳食记录功能: 快速记录:用户选择食物、输入食用量(克 / 份),系统自动计算摄入的营养成分 餐次分类:按早餐 / 午餐 / 晚餐 / 加餐分类记录,支持上传餐食照片(可选) 批量操作:提供常见套餐模板(如 “三明治 + 牛奶”),一键添加到记录 历史记录:按日期查看过往膳食记录,支持编辑 / 删除错误记录 3. 营养分析模块 每日营养摄入分析: 核心指标计算:统计当日摄入的总热量、蛋白质 / 脂肪 / 碳水化合物占比(按每日推荐量对比) 微量营养素分析:检查维生素(如维生素 C、钙、铁)的摄入是否达标 平衡评估:生成 “营养平衡度” 评分(0-100 分),指出摄入过剩或不足的营养素 趋势分析: 周 / 月营养趋势:用折线图展示近 7 天 / 30 天的热量、三大营养素摄入变化 对比分析:将实际摄入与推荐量对比(如 “蛋白质摄入仅达到推荐量的 70%”) 目标达成率:针对健
1. 用户管理模块 用户注册与认证: 注册:用户填写身份信息(姓名、身份证号、手机号)、设置登录密码(需符合复杂度要求),系统生成唯一客户号 登录:支持账号(客户号 / 手机号)+ 密码登录,提供验证码登录、忘记密码(通过手机验证码重置)功能 身份验证:注册后需完成实名认证(模拟上传身份证照片,系统标记认证状态) 个人信息管理: 基本信息:查看 / 修改联系地址、紧急联系人、邮箱等非核心信息(身份证号等关键信息不可修改) 安全设置:修改登录密码、设置交易密码(用于转账等敏感操作)、开启 / 关闭登录提醒 权限控制:普通用户仅能操作本人账户;管理员可管理用户信息、查看系统统计数据 2. 账户与资金管理模块 账户管理: 账户创建:用户可开通储蓄卡账户(默认 1 个主账户,支持最多 3 个子账户,如 “日常消费账户”“储蓄账户”) 账户查询:查看各账户余额、开户日期、状态(正常 / 冻结)、交易限额 账户操作:挂失 / 解挂账户、申请注销账户(需余额为 0) 资金操作: 转账汇款:支持同行转账(输入对方账户号 / 手机号),需验证交易密码,可添加常用收款人 存款 / 取款:模拟存款(输入金额增加余额)、取款(输入金额减少余额,需不超过可用余额) 交易记录:按时间、类型(转入 / 转出 / 存款 / 取款)查询明细,显示交易时间、金额、对方账户(脱敏显示)、交易状态 3. 账单与支付模块 账单管理: 月度账单:自动生成每月收支明细,统计总收入、总支出、余额变动 账单查询:按月份、交易类型筛选账单,支持导出为 Excel 格式 还款提醒:若有贷款(简化版可模拟),系统在还款日 3 天前发送提醒 快捷支付: 绑定支付方式:添加银行卡(系统内账户)作为支付渠道 模拟消费:支持输入商户名称和金额,完成支付(从账户余额扣减) 支付记录:保存所有消费记录,包含商户、时间、金额、支付状态 4.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值