mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 04:02:09 +08:00
ELBus中增加bind方法,并扩充data的使用范围
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.yomahub.liteflow.builder.el;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 捕获异常表达式
|
||||
* Catch(a).do(b)
|
||||
@@ -35,6 +37,30 @@ public class CatchELWrapper extends ELWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CatchELWrapper data(String dataName, Object object) {
|
||||
super.data(dataName, object);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CatchELWrapper data(String dataName, String jsonString) {
|
||||
super.data(dataName, jsonString);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CatchELWrapper data(String dataName, Map<String, Object> jsonMap) {
|
||||
super.data(dataName, jsonMap);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CatchELWrapper bind(String key, String value) {
|
||||
super.bind(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CatchELWrapper maxWaitSeconds(Integer maxWaitSeconds){
|
||||
setMaxWaitSeconds(maxWaitSeconds);
|
||||
|
||||
@@ -58,22 +58,25 @@ public class CommonNodeELWrapper extends ELWrapper {
|
||||
|
||||
@Override
|
||||
public CommonNodeELWrapper data(String dataName, Object object) {
|
||||
setData("'" + JsonUtil.toJsonString(object) + "'");
|
||||
setDataName(dataName);
|
||||
super.data(dataName, object);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonNodeELWrapper data(String dataName, String jsonString) {
|
||||
setData("'" + jsonString + "'");
|
||||
setDataName(dataName);
|
||||
super.data(dataName, jsonString);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonNodeELWrapper data(String dataName, Map<String, Object> jsonMap) {
|
||||
setData("'" + JsonUtil.toJsonString(jsonMap) + "'");
|
||||
setDataName(dataName);
|
||||
super.data(dataName, jsonMap);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ELWrapper bind(String key, String value) {
|
||||
super.bind(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -102,28 +105,4 @@ public class CommonNodeELWrapper extends ELWrapper {
|
||||
processWrapperProperty(sb, paramContext);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Node的公共属性不包括id,对父类方法重载。
|
||||
*
|
||||
* @param elContext EL 上下文
|
||||
* @param paramContext 参数上下文
|
||||
*/
|
||||
@Override
|
||||
protected void processWrapperProperty(StringBuilder elContext, StringBuilder paramContext){
|
||||
if(this.getTag() != null){
|
||||
elContext.append(StrUtil.format(".tag(\"{}\")", this.getTag()));
|
||||
}
|
||||
if(this.getData() != null){
|
||||
elContext.append(StrUtil.format(".data({})", this.getDataName()));
|
||||
paramContext.append(StrUtil.format("{} = {}", this.getDataName(), this.getData())).append(";\n");
|
||||
}
|
||||
if(this.getMaxWaitSeconds() != null){
|
||||
elContext.append(StrUtil.format(".maxWaitSeconds({})", String.valueOf(this.getMaxWaitSeconds())));
|
||||
}
|
||||
if (this.getRetry() != null){
|
||||
elContext.append(StrUtil.format(".retry({})", this.getRetry().toString()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.yomahub.liteflow.builder.el;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.builder.el.vo.RetryELVo;
|
||||
import com.yomahub.liteflow.util.JsonUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* ELWrapper是所有组件的抽象父类
|
||||
@@ -25,6 +24,7 @@ public abstract class ELWrapper {
|
||||
private String id;
|
||||
private String dataName;
|
||||
private String data;
|
||||
private final Map<String, String> bindData = new HashMap<>();
|
||||
private Integer maxWaitSeconds;
|
||||
private RetryELVo retry;
|
||||
|
||||
@@ -84,6 +84,18 @@ public abstract class ELWrapper {
|
||||
return this.dataName;
|
||||
}
|
||||
|
||||
protected String getBindData(String key) {
|
||||
return bindData.get(key);
|
||||
}
|
||||
|
||||
protected void putBindData(String key, String value) {
|
||||
this.bindData.put(key, value);
|
||||
}
|
||||
|
||||
protected Map<String, String> getBindData() {
|
||||
return bindData;
|
||||
}
|
||||
|
||||
protected void setMaxWaitSeconds(Integer maxWaitSeconds){
|
||||
this.maxWaitSeconds = maxWaitSeconds;
|
||||
}
|
||||
@@ -161,6 +173,11 @@ public abstract class ELWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected ELWrapper bind(String key, String value){
|
||||
putBindData(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
protected ELWrapper maxWaitSeconds(Integer maxWaitSeconds){
|
||||
setMaxWaitSeconds(maxWaitSeconds);
|
||||
@@ -227,6 +244,13 @@ public abstract class ELWrapper {
|
||||
if(this.getTag() != null){
|
||||
elContext.append(StrUtil.format(".tag(\"{}\")", this.getTag()));
|
||||
}
|
||||
if(this.getData() != null){
|
||||
elContext.append(StrUtil.format(".data({})", this.getDataName()));
|
||||
paramContext.append(StrUtil.format("{} = {}", this.getDataName(), this.getData())).append(";\n");
|
||||
}
|
||||
if(MapUtil.isNotEmpty(this.getBindData())){
|
||||
this.getBindData().forEach((key, value) -> elContext.append(StrUtil.format(".bind(\"{}\", \"{}\")", key, value)));
|
||||
}
|
||||
if(this.getMaxWaitSeconds() != null){
|
||||
elContext.append(StrUtil.format(".maxWaitSeconds({})", String.valueOf(this.getMaxWaitSeconds())));
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.yomahub.liteflow.builder.el;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 后置表达式
|
||||
* 只能在THEN组件中调用
|
||||
@@ -28,6 +30,30 @@ public class FinallyELWrapper extends ELWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FinallyELWrapper data(String dataName, Object object) {
|
||||
super.data(dataName, object);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FinallyELWrapper data(String dataName, String jsonString) {
|
||||
super.data(dataName, jsonString);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FinallyELWrapper data(String dataName, Map<String, Object> jsonMap) {
|
||||
super.data(dataName, jsonMap);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FinallyELWrapper bind(String key, String value) {
|
||||
super.bind(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后置组件无法设置maxWaitSeconds属性,重载用protected修饰
|
||||
*
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.yomahub.liteflow.builder.el;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -211,6 +212,30 @@ public class IfELWrapper extends ELWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IfELWrapper data(String dataName, Object object) {
|
||||
super.data(dataName, object);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IfELWrapper data(String dataName, String jsonString) {
|
||||
super.data(dataName, jsonString);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IfELWrapper data(String dataName, Map<String, Object> jsonMap) {
|
||||
super.data(dataName, jsonMap);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IfELWrapper bind(String key, String value) {
|
||||
super.bind(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IfELWrapper maxWaitSeconds(Integer maxWaitSeconds){
|
||||
setMaxWaitSeconds(maxWaitSeconds);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.yomahub.liteflow.builder.el;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* FOR、WHILE、ITERATOR循环表达式的公共抽象父类
|
||||
*
|
||||
@@ -68,6 +70,30 @@ public class LoopELWrapper extends ELWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoopELWrapper data(String dataName, Object object) {
|
||||
super.data(dataName, object);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoopELWrapper data(String dataName, String jsonString) {
|
||||
super.data(dataName, jsonString);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoopELWrapper data(String dataName, Map<String, Object> jsonMap) {
|
||||
super.data(dataName, jsonMap);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoopELWrapper bind(String key, String value) {
|
||||
super.bind(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoopELWrapper maxWaitSeconds(Integer maxWaitSeconds){
|
||||
setMaxWaitSeconds(maxWaitSeconds);
|
||||
|
||||
@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 并行组件
|
||||
@@ -70,6 +71,30 @@ public class ParELWrapper extends ELWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParELWrapper data(String dataName, Object object) {
|
||||
super.data(dataName, object);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParELWrapper data(String dataName, String jsonString) {
|
||||
super.data(dataName, jsonString);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParELWrapper data(String dataName, Map<String, Object> jsonMap) {
|
||||
super.data(dataName, jsonMap);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParELWrapper bind(String key, String value) {
|
||||
super.bind(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParELWrapper maxWaitSeconds(Integer maxWaitSeconds){
|
||||
setMaxWaitSeconds(maxWaitSeconds);
|
||||
|
||||
@@ -30,6 +30,30 @@ public class PreELWrapper extends ELWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreELWrapper data(String dataName, Object object) {
|
||||
super.data(dataName, object);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreELWrapper data(String dataName, String jsonString) {
|
||||
super.data(dataName, jsonString);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreELWrapper data(String dataName, Map<String, Object> jsonMap) {
|
||||
super.data(dataName, jsonMap);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreELWrapper bind(String key, String value) {
|
||||
super.bind(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreELWrapper maxWaitSeconds(Integer maxWaitSeconds){
|
||||
setMaxWaitSeconds(maxWaitSeconds);
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 串行组件
|
||||
@@ -74,6 +75,30 @@ public class SerELWrapper extends ELWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SerELWrapper data(String dataName, Object object) {
|
||||
super.data(dataName, object);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SerELWrapper data(String dataName, String jsonString) {
|
||||
super.data(dataName, jsonString);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SerELWrapper data(String dataName, Map<String, Object> jsonMap) {
|
||||
super.data(dataName, jsonMap);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SerELWrapper bind(String key, String value) {
|
||||
super.bind(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SerELWrapper maxWaitSeconds(Integer maxWaitSeconds){
|
||||
setMaxWaitSeconds(maxWaitSeconds);
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.yomahub.liteflow.builder.el;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 选择组件
|
||||
* SWITCH(a).TO(b,c,d...).default(x)
|
||||
@@ -47,6 +49,30 @@ public class SwitchELWrapper extends ELWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SwitchELWrapper data(String dataName, Object object) {
|
||||
super.data(dataName, object);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SwitchELWrapper data(String dataName, String jsonString) {
|
||||
super.data(dataName, jsonString);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SwitchELWrapper data(String dataName, Map<String, Object> jsonMap) {
|
||||
super.data(dataName, jsonMap);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SwitchELWrapper bind(String key, String value) {
|
||||
super.bind(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SwitchELWrapper maxWaitSeconds(Integer maxWaitSeconds){
|
||||
setMaxWaitSeconds(maxWaitSeconds);
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 串行组件
|
||||
@@ -74,6 +75,30 @@ public class ThenELWrapper extends ELWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThenELWrapper data(String dataName, Object object) {
|
||||
super.data(dataName, object);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThenELWrapper data(String dataName, String jsonString) {
|
||||
super.data(dataName, jsonString);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThenELWrapper data(String dataName, Map<String, Object> jsonMap) {
|
||||
super.data(dataName, jsonMap);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThenELWrapper bind(String key, String value) {
|
||||
super.bind(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThenELWrapper maxWaitSeconds(Integer maxWaitSeconds){
|
||||
setMaxWaitSeconds(maxWaitSeconds);
|
||||
|
||||
@@ -68,6 +68,30 @@ public class WhenELWrapper extends ELWrapper {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WhenELWrapper data(String dataName, Object object) {
|
||||
super.data(dataName, object);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WhenELWrapper data(String dataName, String jsonString) {
|
||||
super.data(dataName, jsonString);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WhenELWrapper data(String dataName, Map<String, Object> jsonMap) {
|
||||
super.data(dataName, jsonMap);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WhenELWrapper bind(String key, String value) {
|
||||
super.bind(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WhenELWrapper maxWaitSeconds(Integer maxWaitSeconds){
|
||||
setMaxWaitSeconds(maxWaitSeconds);
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.yomahub.liteflow.test.builder;
|
||||
|
||||
import com.yomahub.liteflow.builder.el.ELBus;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SpringBootTest(classes = BindELBuilderTest.class)
|
||||
@EnableAutoConfiguration
|
||||
public class BindELBuilderTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
public void testBind1(){
|
||||
String actualEl = ELBus.then("a", ELBus.element("b").bind("k1", "v1")).toEL();
|
||||
String expected = "THEN(a,b.bind(\"k1\", \"v1\"));";
|
||||
System.out.println(actualEl);
|
||||
Assertions.assertEquals(expected, actualEl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBind2(){
|
||||
String actualEl = ELBus.then("a", "b").bind("k1","v1").toEL();
|
||||
String expected = "THEN(a,b).bind(\"k1\", \"v1\");";
|
||||
System.out.println(actualEl);
|
||||
Assertions.assertEquals(expected, actualEl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBind3(){
|
||||
String actualEl = ELBus.then("a", ELBus.node("b").bind("k1", "v1")).toEL();
|
||||
String expected = "THEN(a,node(\"b\").bind(\"k1\", \"v1\"));";
|
||||
System.out.println(actualEl);
|
||||
Assertions.assertEquals(expected, actualEl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBind4(){
|
||||
String actualEl = ELBus.then("a", ELBus.when("b","c").bind("k1", "v1")).bind("k2","v2").toEL();
|
||||
String expected = "THEN(a,WHEN(b,c).bind(\"k1\", \"v1\")).bind(\"k2\", \"v2\");";
|
||||
System.out.println(actualEl);
|
||||
Assertions.assertEquals(expected, actualEl);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user