oracle BPEL 学习

 

package  test.bpel;

import  java.util.ArrayList;
import  java.util.List;

import  oracle.bpel.services.workflow.WorkflowException;
import  oracle.bpel.services.workflow.client.IWorkflowServiceClient;
import  oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import  oracle.bpel.services.workflow.query.ITaskQueryService;
import  oracle.bpel.services.workflow.repos.Predicate;
import  oracle.bpel.services.workflow.repos.TableConstants;
import  oracle.bpel.services.workflow.task.model.SystemAttributesType;
import  oracle.bpel.services.workflow.task.model.Task;
import  oracle.bpel.services.workflow.task.model.TaskImpl;
import  oracle.bpel.services.workflow.verification.IWorkflowContext;

import  oracle.jbo.JboException;

import  org.apache.commons.logging.Log;
import  org.apache.commons.logging.LogFactory;


/**
 * Class to be used to work with the BPEL API for Human Workflow.
 * 
 * NOTE: Expects a wf_client_config.xml in the classpath with correct server information!
 * 
 * 
@author pascal alma
 * 
 * $Log: HumanWorkflowServices.java,v $
 
*/

public   class  HumanWorkflowServices 
{
      
private static final Log __log = LogFactory.getLog(HumanWorkflowServices.class);

      
/**
       * Authenticates agianst the BPEL instance.
       * 
@param name Username
       * 
@param password password of user
       * 
@param domain domain to authenticate against
       * 
@param onBehalfOfUser If 
       * 
@return
       
*/

      
public static IWorkflowContext authenticate(String name, String password, String domain, String onBehalfOfUser)
      
{
        
final String method = "authenticate(...)";
        __log.debug(method);

        IWorkflowContext ctx 
= null;

        
try
        
{
          IWorkflowServiceClient client 
= WorkflowServiceClientFactory.getWorkflowServiceClient(WorkflowServiceClientFactory.REMOTE_CLIENT);

          ITaskQueryService taskQueryService 
= client.getTaskQueryService();

          ctx 
= taskQueryService.authenticate(name, password, domain, onBehalfOfUser);
        }

        
catch (WorkflowException wfe)
        
{
          __log.error(
"Error occured while authenticating", wfe);
          
throw new JboException(wfe);
        }

        
return ctx;
      }


      
private static ITaskQueryService getTaskQueryService()
      
{
        IWorkflowServiceClient client 
= 
          WorkflowServiceClientFactory.getWorkflowServiceClient(WorkflowServiceClientFactory.REMOTE_CLIENT);

        ITaskQueryService taskQueryService 
= client.getTaskQueryService();

        
return taskQueryService;
      }


      
/**
       * Queries the BPEL enigine and gets a list of assigned tasks for the
       * user in the WorkflowContext
       * 
@param ctx
       * 
@return
       
*/

      
public static List<Task> getTaskList(IWorkflowContext ctx)
      
{
        
final String method = "getTaskList(...)";
        __log.debug(method);

        List
<TaskImpl> resultSet = null;
        
try
        
{
          
//Set up list of columns to query
          List queryColumns = new ArrayList();
          queryColumns.add(TableConstants.WFTASK_TITLE_COLUMN.getName());
          queryColumns.add(TableConstants.WFTASK_PRIORITY_COLUMN.getName());
          queryColumns.add(TableConstants.WFTASK_STATE_COLUMN.getName());
          queryColumns.add(TableConstants.WFTASK_SUBSTATE_COLUMN.getName());
          queryColumns.add(TableConstants.WFTASK_ACQUIREDBY_COLUMN.getName());
          queryColumns.add(TableConstants.WFTASK_TASKID_COLUMN.getName());
          queryColumns.add(TableConstants.WFTASK_TASKNUMBER_COLUMN.getName());

          Predicate filter 
= null//getFilter(ctx);

          
// Do not query addtional info
          
// No keywords
          
// No custom predicate
          
// No special ordering
          
// Do not page the query result
          resultSet = getTaskQueryService().queryTasks(ctx, queryColumns, null, ITaskQueryService.ASSIGNMENT_FILTER_ALL , null, filter, null00);
          
//MY_AND_GROUP
          __log.info("resultSet = " + resultSet.size());
        }

        
catch (WorkflowException wfe)
        
{
          __log.error(
"Error occured while getting tasklist", wfe);
          
throw new JboException(wfe);
        }


        
// Get the detailed tasks and put them in the list.
         List<Task> tasks = new ArrayList<Task>();
        
for (TaskImpl taskImpl: resultSet)
        
{
          tasks.add(getTaskDetail(ctx, taskImpl));
        }

        __log.info(
"#tasks = " + tasks.size());
        
return tasks;
      }


      
/**
       * Gets the taskDetails for a given TaskImpl (is kind of summary in TaskList)
       * 
@param ctx
       * 
@param taskImpl
       * 
@return
       
*/

      
private static Task getTaskDetail(IWorkflowContext ctx, TaskImpl taskImpl)
      
{
        
final String method = "getTaskDetail(...)";
        __log.debug(method);

        SystemAttributesType strAttrType 
= taskImpl.getSystemAttributes();

        Task task 
= null;
        
try
        
{
          task 
= getTaskQueryService().getTaskDetailsById(ctx, strAttrType.getTaskId());
          
          __log.debug(
"Tasknumber = " + task.getSystemAttributes().getTaskNumber());
        }

        
catch (WorkflowException wfe)
        
{
          __log.error(
"Error occurred while getting task detail", wfe);
          
throw new JboException(wfe);
        }

        
return task;
      }


      
/**
       * Creates the filter used when getting tasks from BPEL workflow
       * 
       * 
@return
       
*/

      
private static Predicate getFilter(IWorkflowContext ctx)
      
{
        
final String method = "getFilter(...)";
        __log.debug(method);

        Predicate mainFilter 
= null;
        
try
        
{
          Predicate subFilter1 
= new Predicate(TableConstants.WFTASK_STATE_COLUMN, Predicate.OP_EQ, "ASSIGNED");
          Predicate acquireSubFilter1 
= new Predicate(TableConstants.WFTASK_ACQUIREDBY_COLUMN, Predicate.OP_EQ, (Object)null);
          Predicate acquireSubFilter2 
= new Predicate(TableConstants.WFTASK_ACQUIREDBY_COLUMN, Predicate.OP_EQ, ctx.getUser());
          Predicate acquireFilter 
= new Predicate(acquireSubFilter1, Predicate.OR, acquireSubFilter2);
          mainFilter 
= new Predicate(subFilter1, Predicate.AND, acquireFilter);
        }

        
catch (WorkflowException wfe)
        
{
          __log.error(
"Error occurred while getting task detail", wfe);
          
throw new JboException(wfe);
        }

        
        __log.debug( 
"Filter takslist: " + mainFilter!=null ? mainFilter.getString(): "<<leeg>>");
        
return mainFilter;
      }

       
      
public static void main(String[] args) 
      
{
         __log.debug(
"main(String[] args)");
         
        IWorkflowContext ctx 
=  authenticate("oc4jadmin","ias_admin1","jazn.com"null);
        
        __log.debug(
"ctx = " + ctx);
        
         List tasks 
=  getTaskList(ctx);        
        
      }

    }


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值