Wednesday, February 4, 2015

Oracle BPM ; Get Process text audit trail using BPM api's

Using the below code you can get text audit trail details of a process instance using process id.

import java.util.HashMap;
import java.util.List;
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.instancemanagement.model.IProcessInstance;
import oracle.bpm.services.instancequery.IAuditInstance;
import oracle.bpm.services.instancequery.IInstanceQueryService;
import oracle.bpm.services.internal.processmodel.model.IProcessModelPackage;
public class Class2 {
private static BPMServiceClientFactory bpmscf;
public Class2() {
super();
}
public static void main(String[] args) throws Exception {
// process id will be like bpmn:240481 in EM console
String instanceIdS = "240481";
// 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();
IProcessInstance processInstance =
instanceQueryService.getProcessInstance(bpmContext, instanceIdS);
if (processInstance != null) {
// get details of the process (not a specific instance of it,
// but the actual process definition itself)
// WARNING WARNING WARNING
// The ProcessModelService is an UNDOCUMENTED API - this means
// that it could (and probably will) change in some future
// release - you SHOULD NOT build any code that relies on it,
// unless you understand and accept the risks of using an
// undocumented API.
IProcessModelPackage processModelPackage =
bpmServiceClient.getProcessModelService().getProcessModel(bpmContext,
processInstance.getSca().getCompositeDN(),
processInstance.getSca().getComponentName());
// get a list of the audit events that have occurred in this instance
List<IAuditInstance> auditInstances =
bpmServiceClient.getInstanceQueryService().queryAuditInstanceByProcessId(bpmContext,
instanceIdS);
for (IAuditInstance a1 : auditInstances) {
System.out.println(a1.getActivityName());
System.out.println(a1.getCompositeInstanceId());
System.out.println(a1.getLabel());
System.out.println(a1.getCreateTime().getTime());
System.out.println("---------------------------");
}
} else {
System.out.println("Could not find instance");
}
}
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:xxx");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,
"xxxx");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,
"xxx");
bpmscf =
BPMServiceClientFactory.getInstance(properties, null, null);
}
return bpmscf;
}
}


Libraries used : 




Audit trail : 




No comments:

Post a Comment