Tuesday, February 3, 2015

Oracle BPM : Generate process audit and process model image

There might be some requirements from the customer to generate BPMN process image or Audit image. This can be achieved by using BPM api's .

import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;
import oracle.bpel.services.bpm.common.IBPMContext;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpm.client.BPMServiceClientFactory;
import oracle.bpm.services.client.IBPMServiceClient;
import oracle.bpm.services.instancequery.IInstanceQueryService;
import oracle.bpm.util.Base64;
public class Class1 {
private static BPMServiceClientFactory bpmscf;
public static void main(String args[]) throws Exception{
//The process id in EM will be like bpmn:240469
String instanceIdS="200479";
// get the BPMServiceClient
IBPMServiceClient bpmServiceClient =
getBPMServiceClientFactory().getBPMServiceClient();
IBPMContext bpmContext =
getBPMServiceClientFactory()
.getBPMUserAuthenticationService()
.authenticate("xxx", "xxx".toCharArray(), null);
// get details of the process instance
IInstanceQueryService instanceQueryService =
bpmServiceClient.getInstanceQueryService();
//Image in PNG format and base64 coded
//String imageSeq=instanceQueryService.getProcessDiagram(bpmContext, instanceIdS,java.util.Locale.ENGLISH );
String imageSeq=instanceQueryService.getProcessAuditDiagram(bpmContext, instanceIdS, java.util.Locale.ENGLISH );
byte[] decode = Base64.decode(imageSeq);
// Write a image byte array into file system
FileOutputStream imageOutFile = new FileOutputStream("C:\\"+instanceIdS+".png");
imageOutFile.write(decode);
imageOutFile.close();
}
protected static BPMServiceClientFactory getBPMServiceClientFactory() {
if (bpmscf == null) {
Map properties = new HashMap();
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,
IWorkflowServiceClientConstants.CLIENT_TYPE_REMOTE);
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,
"t3://xxx:123");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,
"xxx");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,
"xxx");
bpmscf = BPMServiceClientFactory.getInstance(properties, null, null);
}
return bpmscf;
}
}



The libraries need to be added in the classpath of the project is as follows :





No comments:

Post a Comment