activiti工作流常用组件

activiti工作流常用组件
1.事件
1.1 timer事件定义
定时事件定义

<timerEventDefinition>
    <timeDate>2011-03-11T12:13:14</timeDate>
</timerEventDefinition>

时间段定义

<timerEventDefinition>
    <timeDuration>P10D</timeDuration>
</timerEventDefinition>

循环定义

<timerEventDefinition>
    <timeCycle activiti:endDate="2015-02-25T16:42:11+00:00">R3/PT10H</timeCycle>
</timerEventDefinition>

1.2 error事件定义

<endEvent id="myErrorEndEvent">
  <errorEventDefinition errorRef="myError" />
</endEvent>

1.3 信号时间定义
//信号定义

<signal id="alertSignal" name="alert" />

<process id="catchSignal">
    抛出信号事件
	<intermediateThrowEvent id="throwSignalEvent" name="Alert">
		信号事件定义
		<signalEventDefinition signalRef="alertSignal" />
	</intermediateThrowEvent>
	
	捕获信号事件
	<intermediateCatchEvent id="catchSignalEvent" name="On Alert">
		<signalEventDefinition signalRef="alertSignal" />
	</intermediateCatchEvent>
</process>

运行期通知收到信号

RuntimeService.signalEventReceived(String signalName);//全局通知
RuntimeService.signalEventReceived(String signalName, String executionId);//单实例通知

1.4 message事件定义

  <message id="newInvoice" name="newInvoiceMessage" />
  <message id="payment" name="paymentMessage" />

  <process id="invoiceProcess">

    <startEvent id="messageStart" >
    	<messageEventDefinition messageRef="newInvoice" />
    </startEvent>
    ...
    <intermediateCatchEvent id="paymentEvt" >
    	<messageEventDefinition messageRef="payment" />
    </intermediateCatchEvent>
    ...
  </process>
  
  启动流程时指定消息
  ProcessInstance startProcessInstanceByMessage(String messageName);
ProcessInstance startProcessInstanceByMessage(String messageName, Map<String, Object> processVariables);
ProcessInstance startProcessInstanceByMessage(String messageName, String businessKey, Map<String, Object> processVariables);

运行时收到消息
void messageEventReceived(String messageName, String executionId);
void messageEventReceived(String messageName, String executionId, HashMap<String, Object> processVariables);

1.5 事件
startEvent 开始事件
endEvent 结束事件
boundaryEvent 附着在其他组件上的事件
intermediateCatchEvent 中间流程事件
intermediateThrowEvent 抛出事件
以上事件都可以内部嵌套不同的事件定义形成更广泛的事件

2.sequenceFlow 连线
用来连接不同的组件,可以配置过渡监听,条件等

<sequenceFlow id="flow" sourceRef="theStart" targetRef="theTask">
  <conditionExpression xsi:type="tFormalExpression">
    <![CDATA[${order.price > 100 && order.price < 250}]]>
  </conditionExpression>
</sequenceFlow>

3.Gateways网关
3.1 Exclusive Gateway排他网关
该网关只会选择一条出口,如果有多个出口满足条件,选择定义靠前的
3.2 Parallel Gateway 并行网关
多个出口同时执行,运行时产生子执行实例,
在join时,等待所有流入连线到来,才会执行出口操作
3.3Inclusive Gateway兼容性网关
具有排他网关和并行网关特性,在出口时所有满足条件的出口都会产生子运行实例,
在join时所有上一步运行的子实例都到达时,执行出口操作

4.任务
4.1 User Task

<userTask id="theTask" name="Important task" />
List<Task> tasks = taskService.createTaskQuery().taskAssignee("kermit").list();
List<Task> tasks = taskService.createTaskQuery().taskCandidateUser("kermit");
<userTask id="theTask" name="my task" activiti:candidateUsers="kermit, gonzo" />
<userTask id="theTask" name="my task" activiti:candidateGroups="management, accountancy" />

4.2Java Service Task

<serviceTask id="javaService"
             name="My Java Service Task"
             activiti:class="org.activiti.MyJavaDelegate" />
委托给java类执行
public class ToUppercase implements JavaDelegate {

  public void execute(DelegateExecution execution) throws Exception {
    String var = (String) execution.getVariable("input");
    var = var.toUpperCase();
    execution.setVariable("input", var);
  }

}

字段注入,以及解析表达式:

<serviceTask id="javaService" name="Java service invocation"
  activiti:class="org.activiti.examples.bpmn.servicetask.ReverseStringsFieldInjected">

  <extensionElements>
    <activiti:field name="text1">
      <activiti:expression>${genderBean.getGenderString(gender)}</activiti:expression>
    </activiti:field>
    <activiti:field name="text2">
       <activiti:expression>Hello ${gender == 'male' ? 'Mr.' : 'Mrs.'} ${name}</activiti:expression>
    </activiti:field>
  </ extensionElements>
</ serviceTask>
上一篇:Activiti7官方博客翻译第一篇——介绍


下一篇:Activiti 开发案例之动态指派任务