Activiti5第十一弹,流程监听器与任务监听器

首先创建流程监听器和任务监听器的实体类,个人比较喜欢使用Delegate Expression方式,其他两种方式也可以


流程监听器

package org.mpc.final_activiti;import java.io.Serializable;import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.Expression;/*** * 可以使用 CLASS ,EXPRESSION,DELEGATE EXPRESSSION三种方式来创建监听器,这里使用第三种方式,其他两种方式和* 在servicetask中的使用方式相同* * */
public class ExectuionListenerDemo implements Serializable, ExecutionListener {/*** @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)*/private static final long serialVersionUID = 8513750196548027535L;private Expression message;public Expression getMessage() {return message;}public void setMessage(Expression message) {this.message = message;}@Overridepublic void notify(DelegateExecution execution) throws Exception {System.out.println("流程监听器" + message.getValue(execution));}}

任务监听器

package org.mpc.final_activiti;import java.io.Serializable;import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.Expression;
import org.activiti.engine.delegate.TaskListener;/*** * 任务监听器,实现TaskListener接口* * */
public class TaskListenerDemo implements Serializable, TaskListener {private Expression arg;public Expression getArg() {return arg;}public void setArg(Expression arg) {this.arg = arg;}@Overridepublic void notify(DelegateTask delegateTask) {System.out.println("任务监听器:" + arg.getValue(delegateTask));}}

这两个监听器只是简单的表明了自己的身份,并打印出在流程中注入给他们的值


接着是流程定义图




从左到右依次是  空开始事件--排他网关--用户任务--空中间抛出事件--空结束事件

首先在空白处点击鼠标,接着在properties选项卡中做如下操作:



然后在排他网关、空中间抛出事件、以及节点之间的箭头上点击鼠标同样可以做如上的操作,这些都流程监听事件的配置



在usertask上我们特别配置usertask才有的任务监听器,配置过程如下图所示



和流程监听器的配置大同小异呢


展示一下配置结果的xml文件,特别注意一下加注释的地方

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test"><process id="myProcess" name="My process" isExecutable="true"><extensionElements><activiti:executionListener event="start" delegateExpression="${myprocessListener}"><activiti:field name="message"><activiti:string><![CDATA[流程启动]]></activiti:string></activiti:field></activiti:executionListener><activiti:executionListener event="end" delegateExpression="${myprocessListener}"><activiti:field name="message"><activiti:string><![CDATA[流程结束]]></activiti:string></activiti:field></activiti:executionListener></extensionElements><startEvent id="startevent1" name="Start"></startEvent><exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"><extensionElements><activiti:executionListener event="start" delegateExpression="${myprocessListener}"><activiti:field name="message"><activiti:string><![CDATA[排他网关开始]]></activiti:string></activiti:field></activiti:executionListener><activiti:executionListener event="end" delegateExpression="${myprocessListener}"><activiti:field name="message"><activiti:string><![CDATA[排他网关结束]]></activiti:string></activiti:field></activiti:executionListener></extensionElements></exclusiveGateway><sequenceFlow id="flow3" sourceRef="startevent1" targetRef="exclusivegateway1"></sequenceFlow><userTask id="usertask2" name="User Task" activiti:assignee="${user}"><extensionElements><activiti:taskListener event="create" delegateExpression="${mytaskListener}"><activiti:field name="arg"><activiti:string><![CDATA[任务启动]]></activiti:string></activiti:field></activiti:taskListener><activiti:taskListener event="assignment" delegateExpression="${mytaskListener}"><activiti:field name="arg"><activiti:string><![CDATA[分配人员]]></activiti:string></activiti:field></activiti:taskListener><activiti:taskListener event="complete" delegateExpression="${mytaskListener}"><activiti:field name="arg"><activiti:string><![CDATA[任务完成]]></activiti:string></activiti:field></activiti:taskListener><!-- 在可视化工具中无法给usertask加上流程监听器,但是,我们在xml中可以自己敲进去· --><activiti:executionListener event="start" delegateExpression="${myprocessListener}"><activiti:field name="message"><activiti:string><![CDATA[流程启动任务]]></activiti:string></activiti:field></activiti:executionListener><activiti:executionListener event="end" delegateExpression="${myprocessListener}"><activiti:field name="message"><activiti:string><![CDATA[流程关闭任务]]></activiti:string></activiti:field></activiti:executionListener><!-- ........................................................................................................................................ --></extensionElements></userTask><sequenceFlow id="flow4" sourceRef="exclusivegateway1" targetRef="usertask2"><extensionElements><activiti:executionListener event="take" delegateExpression="${myprocessListener}"><activiti:field name="message"><activiti:string><![CDATA[从排他网关到用户任务,好长的一段路]]></activiti:string></activiti:field></activiti:executionListener></extensionElements></sequenceFlow><intermediateThrowEvent id="noneintermediatethrowevent1" name="NoneThrowEvent"><extensionElements><activiti:executionListener event="start" delegateExpression="${myprocessListener}"><activiti:field name="message"><activiti:string><![CDATA[中间事件开始]]></activiti:string></activiti:field></activiti:executionListener><activiti:executionListener event="end" delegateExpression="${myprocessListener}"><activiti:field name="message"><activiti:string><![CDATA[中间事件结束]]></activiti:string></activiti:field></activiti:executionListener></extensionElements></intermediateThrowEvent><sequenceFlow id="flow5" sourceRef="usertask2" targetRef="noneintermediatethrowevent1"></sequenceFlow><endEvent id="endevent1" name="End"></endEvent><sequenceFlow id="flow6" sourceRef="noneintermediatethrowevent1" targetRef="endevent1"></sequenceFlow></process><bpmndi:BPMNDiagram id="BPMNDiagram_myProcess"><bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess"><bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1"><omgdc:Bounds height="35.0" width="35.0" x="160.0" y="180.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1"><omgdc:Bounds height="40.0" width="40.0" x="240.0" y="130.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2"><omgdc:Bounds height="55.0" width="105.0" x="325.0" y="123.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="noneintermediatethrowevent1" id="BPMNShape_noneintermediatethrowevent1"><omgdc:Bounds height="35.0" width="35.0" x="475.0" y="133.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1"><omgdc:Bounds height="35.0" width="35.0" x="555.0" y="133.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3"><omgdi:waypoint x="195.0" y="197.0"></omgdi:waypoint><omgdi:waypoint x="260.0" y="170.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4"><omgdi:waypoint x="280.0" y="150.0"></omgdi:waypoint><omgdi:waypoint x="325.0" y="150.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5"><omgdi:waypoint x="430.0" y="150.0"></omgdi:waypoint><omgdi:waypoint x="475.0" y="150.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6"><omgdi:waypoint x="510.0" y="150.0"></omgdi:waypoint><omgdi:waypoint x="555.0" y="150.0"></omgdi:waypoint></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram>
</definitions>


为了让usertak产生一个指定人员的事件,我们给这个usertask弄一个指定人员



然后就是测试代码

package final_activiti.progress;import java.util.HashMap;
import java.util.Map;import org.activiti.engine.impl.test.PluggableActivitiTestCase;
import org.activiti.engine.test.Deployment;
import org.junit.Test;
import org.mpc.final_activiti.ExectuionListenerDemo;
import org.mpc.final_activiti.TaskListenerDemo;public class ListenersTest extends PluggableActivitiTestCase {@Test@Deployment(resources = "final_activiti/progress/listeners.bpmn")public void test() {Map<String, Object> map = new HashMap<String, Object>();map.put("myprocessListener", new ExectuionListenerDemo());map.put("mytaskListener", new TaskListenerDemo());map.put("user", "mpc");runtimeService.startProcessInstanceByKey("myProcess", map);taskService.complete(taskService.createTaskQuery().singleResult().getId());;}}

测试结果:


分析:

1.我们给usertask定义的流程监听实现了

2.usertask中先执行流程监听的start、然后是分配人员、任务启动、任务完成、流程关闭任务;任务是包含在流程中的

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/569325.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

06_go语言基础

// 07枚举 package main import ( "fmt" ) func main() { // 1.iota常量自动生成器&#xff0c;每个一行&#xff0c;自动累加1 // 2.iota给常量赋值使用 const ( a iota // 0 b iota // 1 c iota // 2 ) fmt.Printf("a %d,b %d,c %d\n", a, b, c) /…

通过继承来实现注解方式的属性注入

要使用注解来注入属性&#xff0c;首先就要定义一个注解&#xff0c;注解的定义如下&#xff1a; package everyworkdayprogramming._2015_1_23;import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; im…

ASCII码对照表

1、字母转换成ASCII码 1 string str "hello";2 byte[] array new byte[1]; 3 array System.Text.Encoding.ASCII.GetBytes(str); //把str的每个字符转换成ascii码4 5 int asciicode1 (short)(array[0]);//h 的…

2015-2月的小程序们

马上就要过年了&#xff0c;今天是二月最后一天上班了&#xff0c;心情有些激动&#xff0c;恨不得立马就到家去。再来公司的时候就是3.1号了&#xff0c;所以在离开之前把2月份的小程序们储存起来。虽然很多都是参考了网上的小程序练习&#xff0c;但是自己有自己的风格&#…

SHOI2009 会场预约

题目传送门 嗯&#xff0c;这道题的标签是STL&#xff0c;因为这个STL用的确实太妙了 这道题目要求维护一堆区间&#xff0c;而一个重要的操作是要删除所有与新区间冲突的区间 虽然可以用\(Splay\)来操作&#xff0c;但用STL里的set也绝对不虚 其中最精妙的当属这个重载运算符 …

创建者模式 builder

package mode.bulider;/*** * 首先是汽车&#xff0c;组成零件有&#xff1a;玻璃、轮胎、发动机&#xff1b;他们都是抽象的概念&#xff0c;所以用抽象类来创建* * */ public class Car {Glass glass;Wheel wheel;Engine engine; } package mode.bulider; /*** * 抽象的玻璃*…

平行四边形的特殊性质

定义平行四边形内角平分线围城的四边形为$\lambda$四边形$\lambda$四边形是矩形 $\lambda$四边形的中线为平行四边形中心$\lambda$四边形的对角线和平行四边形的边平行转载于:https://www.cnblogs.com/guoshaoyang/p/11011612.html

静态方法工厂模式

工厂模式有三种方法来实现&#xff0c;一种是通过传入参数的名称来决定创建哪一个产品&#xff0c;这种方法有很大的缺点&#xff0c;就是如果传入的产品名称如果不小心错误的话&#xff0c;就是无法来创建我们想得到的产品的。另一种是方法工厂模式&#xff0c;这种工厂模式中…

Elasticsearch 入门到高手的成长阶梯-索引的基本操作(1)

1. 创建索引 Elasticsearch中索引的名称&#xff0c;必须符合以下要求&#xff1a; 字母只能够是小写字母不能够包含特殊字符&#xff0c;如\, /, *, ?, ", <, >, |, , ,, #等名称不能够以英文的中划线“-”、下划线“_”以及加号“”开头名称不可以是“.”或“.…

对象的深度复制

首先什么是深度复制&#xff1f;什么又是浅复制&#xff1f; 百度告诉我---------------> 浅复制&#xff1a;将一个对象复制后&#xff0c;基本类型都会重新创建&#xff0c;而引用类型指向的还是原对象所指的引用&#xff1b; 深复制&#xff1a;讲一个对象复制后&…

java 判断int类型为空

int id 10; if("0".equals(String.valueOf(id)) || "null".equals(String.valueOf(id)) || id < 0) return false;比如&#xff1a; "0".equals(String.valueOf(定义的int类型参数)) 判断int类型不能为空或不能小于等于0 也可以转换为String…

P1-0:项目框架搭建

后台java&#xff0c;前端用html,js &#xff0c;数据库用mysql,云数据库 构建BS结构项目 转载于:https://www.cnblogs.com/superisland/p/11016113.html

2.MySQL中的索引

索引就像树的目录&#xff0c;是为了更快的找到所要找的内容&#xff08;数据&#xff09;。MySQL中&#xff0c;索引是在存储引擎层实现的&#xff0c;不同的存储引擎有不同的索引模型&#xff0c;如innodb是采用的是B树的索引模型&#xff0c;本篇主要以innodb存储引擎的索引…

python学习-10 运算符1

1.加&#xff0c;减-&#xff0c;乘*&#xff0c;除/ 例如&#xff1a; a 1 b 2 c a b print(c) 运算结果&#xff1a; 3Process finished with exit code 0 a 1 b 2 c a - b print(c) 运算结果&#xff1a; -1Process finished with exit code 0 a 1 b 2 c a * b pr…

如何在idea中使用Mybatis-generator插件快速生成代码

代码下载地址&#xff1a;https://download.csdn.net/download/hua_faded/10671547 一、配置Maven pom.xml 文件 在pom.xml增加以下插件&#xff1a; <build><finalName>zsxt</finalName> <plugins> <plugin> <groupId>org.mybatis.genera…

游戏开发-cocos creator技巧-cc.Component.EventHandler自定义click事件

cocos creator有两种给按钮注册click事件的方式&#xff0c; EventHandler的方式虽然有点麻烦&#xff0c;但是比较灵活&#xff0c;使用时候注意每个参数必须填写正确&#xff0c;否则click时候会报null的错误第一种 node_level.on(cc.Node.EventType.TOUCH_START, this.on_pa…

Java 泛型(1):基本原理

1.1 擦除 15.7例子 Java的泛型是同伙擦除来实现的&#xff0c;在泛型代码内部&#xff0c;无法获得任何有关泛型参数类型的信息(这一点有别于C等实现)&#xff0c;这意味着你在使用泛型时&#xff0c;无法知道任何类型信息&#xff0c;只知道你在使用一个对象&#xff0c;…

21-MySQL-Ubuntu-快速回到SQL语句的行首和行末

行首: Ctrl A 行末:Ctrl E转载于:https://www.cnblogs.com/summer1019/p/11043692.html

django CBV装饰器 自定义django中间件 csrf跨站请求伪造 auth认证模块

CBV加装饰器 第一种  method_decorator(装饰器&#xff09;  加在get上 第二种  method_decorator(login_auth,nameget)  加在类上 第三种  method_decorator(login_auth)  加在dispatch上  3.7的要return super().dispatch def login(request):if request.metho…

Dubbo理论知识

本文是作者根据官方文档以及自己平时的使用情况&#xff0c;对 Dubbo 所做的一个总结。如果不懂 Dubbo 的使用的话&#xff0c;可以参考我的这篇文章《超详细&#xff0c;新手都能看懂 &#xff01;使用SpringBootDubbo 搭建一个简单的分布式服务》 Dubbo 官网&#xff1a;http…