流程执行条件节点处理器
流程执行条件节点处理器,用于判断指定参数或KEY的条件下进入到不通分支执行的处理器。
条件节点处理器接口
- 实现流程执行条件节点处理器接口
ConditionNodeHandler
默认实现支持表单参数 + 执行参数
条件KEY
两种模式确认分支。
java
public interface ConditionNodeHandler {
/**
* <p>
* 获取满足条件的条件节点
* </p>
* <p>
* 子类需要实现的方法,来处理具体的操作
* </p>
*
* @param flowLongContext 流程引擎上下文
* @param execution 执行对象
* @param nodeModel 节点模型
* @return true 成功 false 失败
*/
Optional<ConditionNode> getConditionNode(FlowLongContext flowLongContext, Execution execution, NodeModel nodeModel);
/**
* <p>
* 获取满足条件的路由节点
* </p>
* <p>
* 子类需要实现的方法,来处理具体的操作
* </p>
*
* @param flowLongContext 流程引擎上下文
* @param execution 执行对象
* @param nodeModel 节点模型
* @return true 成功 false 失败
*/
Optional<ConditionNode> getRouteNode(FlowLongContext flowLongContext, Execution execution, NodeModel nodeModel);
/**
* <p>
* 获取满足条件的所有包容分支节点
* </p>
* <p>
* 子类需要实现的方法,来处理具体的操作
* </p>
*
* @param flowLongContext 流程引擎上下文
* @param execution 执行对象
* @param nodeModel 节点模型
* @return true 成功 false 失败
*/
Optional<List<ConditionNode>> getInclusiveNodes(FlowLongContext flowLongContext, Execution execution, NodeModel nodeModel);
}
自定义实现
下面自定义实现,继承内置
SimpleConditionNodeHandler
处理器并重写了getArgs
方法,获取参数来源追加表单参数。
java
@Component
public class FlowConditionNodeHandler extends SimpleConditionNodeHandler {
@Override
public Map<String, Object> getArgs(FlowLongContext flowLongContext, Execution execution) {
return FlowForm.flowArgs(execution.getArgs());
}
}
测试用例
测试用例所在源码位置
test.mysql.TestConditionNode
java
public class TestConditionNode extends MysqlTest {
@BeforeEach
public void before() {
processId = this.deployByResource("test/conditionEnd.json", testCreator);
}
@Test
public void testKey() {
// 启动发起
flowLongEngine.startInstanceById(processId, test3Creator).ifPresent(instance -> {
// 指定选择短期条件节点
FlowDataTransfer.specifyConditionNodeKey("k007");
// 人事审批
this.executeActiveTasks(instance.getId(), test2Creator);
FlwHisInstance histInstance = flowLongEngine.queryService().getHistInstance(instance.getId());
Assertions.assertEquals("条件路由", histInstance.getCurrentNodeName());
});
}
@Test
public void testArgs() {
// 启动发起
flowLongEngine.startInstanceById(processId, test3Creator).ifPresent(instance -> {
// 条件参数选择条件节点
Map<String, Object> args = new HashMap<>();
args.put("day", 8);
// 人事审批
this.executeActiveTasks(instance.getId(), test2Creator, args);
// 领导审批
this.executeActiveTasks(instance.getId(), testCreator, args);
FlwHisInstance histInstance = flowLongEngine.queryService().getHistInstance(instance.getId());
Assertions.assertEquals("领导审批结束", histInstance.getCurrentNodeName());
});
}
}