flowable6.5自定义条件解析器

本文介绍了一种在Flowable6.5中避免表单字段污染流程变量,实现自定义条件解析的方法。通过自定义逻辑,从processEngineConfiguration获取ExpressionManager,并在XML配置中使用该解析器进行条件判断。读者可以留言交流使用中遇到的问题。

需求背景:项目里开发了自己的表单服务,在网关分支条件里需要使用表单的字段做条件比较。

解决思路:第一想到的就是把表单的字段全部放到流程变量里,使用流程变量做条件分支判断,可是这样有个弊端,就是表单数据直接污染了流程变量,还有重名的变量被覆盖值的风险。能不能不放流程变量还能认识表单的字段呢,找了好久,终于找到这样的方法了,直接上代码:

@Component
public class ConditionParser implements Serializable {

    @Autowired
    private FormDataService formDataService;

    @Autowired
    private ManagementService managementService;

    @Autowired
    private ProcessEngineConfigurationImpl processEngineConfiguration;

    /**
     * @param expression 表达式
     * @param execution 内置变量
     * @return
     */
    public Boolean parser(String expression,DelegateExecution execution){
        log.info("expression:"+expression+"processInstanceId:"+execution.getProcessInstanceId());
        Map<String,Object> data = this.formDataService.findByProcessInstanceId(execution.getProcessInstanceId());
        data.putAll(execution.getVariables());
        Object value = processEngineConfiguration.getExpressionManager().cr
Flowable中,每个FlowElement(例如Task、Gateway、Event等)都有一个与之相关联的Listener。你可以通过实现Flowable的Java接口来创建自定义的Listener,并将其添加到流程中。 要自定义所有FlowElement的leave事件,请执行以下步骤: 1. 创建一个Java类,并实现Flowable的`ExecutionListener`接口。例如: ```java public class CustomExecutionListener implements ExecutionListener { @Override public void notify(DelegateExecution execution) { String eventName = execution.getEventName(); String elementId = execution.getCurrentActivityId(); System.out.println("Element " + elementId + " left with event " + eventName); } } ``` 2. 在BPMN 2.0文件中,将该Listener添加到流程中的所有FlowElement。例如: ```xml <process id="myProcess" name="My process"> <startEvent id="startEvent"> <extensionElements> <flowable:executionListener event="end" class="com.example.CustomExecutionListener" /> </extensionElements> </startEvent> <userTask id="userTask"> <extensionElements> <flowable:executionListener event="start" class="com.example.CustomExecutionListener" /> <flowable:executionListener event="end" class="com.example.CustomExecutionListener" /> </extensionElements> </userTask> ... </process> ``` 在这个示例中,我们将`CustomExecutionListener`添加到了`startEvent`和`userTask`中的所有事件(start和end)中。执行流程时,每次离开一个FlowElement时,都会触发这个Listener,并打印一条消息。 注意,要在BPMN 2.0文件中使用Flowable的扩展元素,你需要在文件的开头添加命名空间声明: ```xml <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:flowable="http://flowable.org/bpmn" targetNamespace="http://activiti.org/bpmn"> ... </definitions> ```
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值