Below is the java code which will show you the current task and next task for a given process id .
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
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.project.SequenceFlowImpl; | |
import oracle.bpm.project.model.ProjectObject; | |
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{ | |
//The process id in EM will be like bpmn:240469 | |
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); | |
// // work out which activities have not finished | |
List<IAuditInstance> started = new ArrayList<IAuditInstance>(); | |
System.out.println(auditInstances.size()); | |
for (IAuditInstance a1 : auditInstances) { | |
if (a1.getAuditInstanceType().compareTo("START") == 0) { | |
// ingore the process instance itself, we only care | |
// about tasks in the process | |
if (a1.getActivityName().compareTo("PROCESS") != 0) { | |
started.add(a1); | |
} | |
} | |
} | |
next: | |
for (IAuditInstance a2 : auditInstances) { | |
if (a2.getAuditInstanceType().compareTo("END") == 0) { | |
for (int i = 0; i < started.size(); i++) { | |
// IAuditInstance temp=(IAuditInstance)started.get(i); | |
if (a2.getActivityId().compareTo(started.get(i).getActivityId())== 0) { | |
started.remove(i); | |
continue next; | |
} | |
} | |
} | |
} | |
System.out.println("\n\nLooks like the following have started but not ended:"); | |
for (IAuditInstance s : started) { | |
System.out.println(s.getActivityId() + "\nwhich is a " | |
+ s.getActivityName() + "\ncalled " | |
+ s.getLabel() + "\n"); | |
} | |
// now we need to find what is after these activities... | |
// WARNING WARNING WARNING | |
// The ProcessModel, ProcessObject, etc. are UNDOCUMENTED APIs - | |
// this means that they could (and probably will) change | |
// in some future release - you SHOULD NOT build any code | |
// that relies on them, unless you understand and | |
// accept the risks of using undocumented APIs. | |
List<ProjectObject> nextActivities = new ArrayList<ProjectObject>(); | |
next2: | |
for (ProjectObject po : processModelPackage.getProcessModel().getChildren()) { | |
if (po instanceof SequenceFlowImpl) { | |
for (IAuditInstance s2 : started) { | |
if (((SequenceFlowImpl)po).getSource() | |
.getId().compareTo(s2.getActivityId()) == 0) { | |
nextActivities.add(po); | |
continue next2; | |
} | |
} | |
} | |
} | |
System.out.println("\n\nLooks like the next activities are:"); | |
for (ProjectObject po2 : nextActivities) { | |
System.out.println(((SequenceFlowImpl)po2).getTarget().getId() | |
+ "\nwhich is a " | |
+ ((SequenceFlowImpl)po2).getTarget().getBpmnType() | |
+ "\ncalled " | |
+ ((SequenceFlowImpl)po2).getTarget().getDefaultLabel() | |
+ "\n"); | |
} | |
}else{ | |
System.out.println("Could not find instance, aborting"); | |
} | |
} | |
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, | |
"xxx"); | |
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL, | |
"xxx"); | |
bpmscf = BPMServiceClientFactory.getInstance(properties, null, null); | |
} | |
return bpmscf; | |
} | |
} |
Libraries and jar files required are as shown in the below screen shot
No comments:
Post a Comment