JBPM3中文用户手册——第三章:教程(4)

本文介绍了一个基于JBPM工作流引擎的任务分配示例。通过创建一个简单的流程定义,演示了如何使用NappyAssignmentHandler来指定任务参与者。该示例展示了从启动流程到完成任务并结束流程的全过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

3.1    任务分配示例

下一个例子,我们将展示给你如何分配任务给用户。由于jbpm工作流引擎与组织模型是分开的,仅有用于计算用户标识号的表达式语言经常是不够的。因此,你必须指定一个AssignmentHandler接口的实现,其中包含对任务参与者的计算。

 

public void testTaskAssignment() {

  // The process shown below is based on the hello world process.

  // The state node is replaced by a task-node.  The task-node

  // is a node in JPDL that represents a wait state and generates

  // task(s) to be completed before the process can continue to

  // execute. 

  ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(

    "<process-definition name='the baby process'>" +

    "  <start-state>" +

    "    <transition name='baby cries' to='t' />" +

    "  </start-state>" +

    "  <task-node name='t'>" +

    "    <task name='change nappy'>" +

    "      <assignment class='org.jbpm.tutorial.taskmgmt.NappyAssignmentHandler' />" +

    "    </task>" +

    "    <transition to='end' />" +

    "  </task-node>" +

    "  <end-state name='end' />" +

    "</process-definition>"

  );

 

  // Create an execution of the process definition.

  ProcessInstance processInstance =

      new ProcessInstance(processDefinition);

  Token token = processInstance.getRootToken();

 

  // Let's start the process execution, leaving the start-state

  // over its default transition.

  token.signal();

  // The signal method will block until the process execution

  // enters a wait state.   In this case, that is the task-node.

  assertSame(processDefinition.getNode("t"), token.getNode());

 

  // When execution arrived in the task-node, a task 'change nappy'

  // was created and the NappyAssignmentHandler was called to determine

  // to whom the task should be assigned.  The NappyAssignmentHandler

  // returned 'papa'.

 

  // In a real environment, the tasks would be fetched from the

  // database with the methods in the org.jbpm.db.TaskMgmtSession.

  // Since we don't want to include the persistence complexity in

  // this example, we just take the first task-instance of this

  // process instance (we know there is only one in this test

  // scenario).

  TaskInstance taskInstance = (TaskInstance) 

      processInstance

        .getTaskMgmtInstance()

        .getTaskInstances()

        .iterator().next();

 

  // Now, we check if the taskInstance was actually assigned to 'papa'.

  assertEquals("papa", taskInstance.getActorId() );

 

  // Now we suppose that 'papa' has done his duties and mark the task

  // as done.

  taskInstance.end();

  // Since this was the last (only) task to do, the completion of this

  // task triggered the continuation of the process instance execution.

 

  assertSame(processDefinition.getNode("end"), token.getNode());

}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值