The purpose of this post is to show simple runnable classes so readers can easily have an acquintance with the BPM 11g APIs, without needing to setup a complex web project.
We can manipulate BPM processes through a BPMServiceClient that we can acquire from a BPMServiceClientFactory. Below is a utility class that I set to easily acquire a client instance for my testing. This class need the following jars in the classpath: Oracle.bpm.client.jar, Oracle.bpm.project.model.jar, and Oracle.bpm.runtime.jar which are present inside the BPM folders in "MIDDLEWARE_HOME\jdeveloper\soa\modules" directory.
package soadev.bpmclient;
import java.util.HashMap;
import java.util.Map;
import oracle.bpel.services.bpm.common.IBPMContext;
import oracle.bpel.services.workflow.client.IWorkflowServiceClient;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import oracle.bpm.client.BPMServiceClientFactory;
import oracle.bpm.services.client.IBPMServiceClient;
public class Fixture {
private static String url = "t3://localhost:8001";
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,url);
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY
.EJB_INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
return BPMServiceClientFactory.getInstance(properties, null, null);
}
public static IBPMContext getIBPMContext(String username,
String password) throws Exception{
return getBPMServiceClientFactory().getBPMUserAuthenticationService()
.authenticate(username,
password.toCharArray(),
null);
}
public static IWorkflowServiceClient getIWorkflowServiceClient() {
return getBPMServiceClientFactory().getWorkflowServiceClient();
}
public static IBPMServiceClient getBPMServiceClient(){
return getBPMServiceClientFactory().getBPMServiceClient();
}
}
Below is a sample class that demonstrate querying of BPM process instances. It shows how to compose Predicate, Ordering, and IInstanceQueryInput objects.
package soadev.bpmclient;
import java.util.ArrayList;
import java.util.List;
import oracle.bpel.services.bpm.common.IBPMContext;
import oracle.bpel.services.workflow.repos.Column;
import oracle.bpel.services.workflow.repos.Ordering;
import oracle.bpel.services.workflow.repos.Predicate;
import oracle.bpm.services.instancemanagement.model.IProcessInstance;
import oracle.bpm.services.instancequery.IColumnConstants;
import oracle.bpm.services.instancequery.IInstanceQueryInput;
import oracle.bpm.services.instancequery.IInstanceQueryService;
import oracle.bpm.services.instancequery.impl.InstanceQueryInput;
public class GetProcessInstances {
public static void main(String[] args) {
GetProcessInstances client = new GetProcessInstances();
client.testGetProcessInstances();
}
public void testGetProcessInstances(){
try {
IInstanceQueryService queryService =
Fixture.getBPMServiceClient().getInstanceQueryService();
IBPMContext bpmContext =
Fixture.getIBPMContext("pino", "password1");
List<Column> columns = new ArrayList<Column>();
columns.add(IColumnConstants.PROCESS_ID_COLUMN);
columns.add(IColumnConstants.PROCESS_NUMBER_COLUMN);
columns.add(IColumnConstants.PROCESS_STATE_COLUMN);
columns.add(IColumnConstants.PROCESS_TITLE_COLUMN);
columns.add(IColumnConstants.PROCESS_CREATOR_COLUMN);
columns.add(IColumnConstants.PROCESS_CREATEDDATE_COLUMN);
Ordering ordering = new Ordering(IColumnConstants.PROCESS_NUMBER_COLUMN,
true,true);
Predicate pred = new Predicate(IColumnConstants.PROCESS_STATE_COLUMN,
Predicate.OP_EQ,
"OPEN");
IInstanceQueryInput input = new InstanceQueryInput();
input.setAssignmentFilter(IInstanceQueryInput.AssignmentFilter.MY_AND_GROUP);
List<IProcessInstance> processInstances =
queryService.queryInstances(bpmContext, columns, pred, ordering,
input);
System.out.println("ProcessId\tProcess#\tState\tTitle\t\t\t\t\tCreator\tCreadedDate");
for (IProcessInstance instance : processInstances) {
System.out.println(instance.getSystemAttributes().getProcessInstanceId()
+ "\t" + instance.getSystemAttributes()
.getProcessNumber()
+ "\t" + instance.getSystemAttributes().getState()
+ "\t" + instance.getTitle()
+ "\t" + instance.getCreator()
+ "\t" + instance.getSystemAttributes()
.getCreatedDate().getTime());
}
if (processInstances.isEmpty()){
System.out.println("no result");
}
} catch (Exception e) {
// TODO: Add catch code
e.printStackTrace();
}
}
}
Below is a sample result when I run it on my machine:
You can access the sample application on this link.
Kudus
Kudus to the following blogs and OTN forum posts:- RedStack-Process Instance List and Detail added to Worklist-for showing the right source of Column constants (IColumnConstants instead of the TableConstants constants).
- Matt Wang - Find something interesting today- for I guess starting it up.
Cheers!
本文介绍如何使用Oracle BPM 11g Java API进行流程实例的查询,包括获取客户端实例、设置连接属性并进行授权,通过构建查询参数来获取流程实例信息。
1440

被折叠的 条评论
为什么被折叠?



