Querying Oracle BPM Process Instances

THURSDAY, JULY 14, 2011

Querying Oracle BPM Process Instances

This is the first in a series of posts related to the BPM 11g Java API. As far as I know, as of this writing, there is no official Oracle BPM 11g Java API documentation that is being release yet, but the corresponding jars are already present on a standard JDeveloper installation (probably after installing BPM Extension).
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:  

Cheers!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值