From 96061dd5d395240aca65ee71dd0f8408c54c0628 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Fri, 21 Feb 2025 16:27:23 +0800 Subject: [PATCH] =?UTF-8?q?feature=20#IBL9CK=20=E5=A2=9E=E5=8A=A0bind?= =?UTF-8?q?=E5=85=B3=E9=94=AE=E5=AD=97=EF=BC=8C=E8=83=BD=E5=A4=9F=E5=9C=A8?= =?UTF-8?q?=E4=BB=BB=E4=BD=95=E5=9C=B0=E6=96=B9bind=20key=E5=92=8Cvalue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/common/ChainConstant.java | 2 + .../yomahub/liteflow/core/NodeComponent.java | 37 ++++++- .../core/proxy/DeclComponentProxy.java | 38 +------ .../exception/ObjectConvertException.java | 29 +++++ .../util/LiteflowContextRegexMatcher.java | 57 ++++++++++ .../pom.xml | 6 ++ ...Test.java => BindDataSpringbootTest1.java} | 8 +- .../bindData/BindDataSpringbootTest2.java | 100 ++++++++++++++++++ .../test/bindData/{cmp => cmp1}/ACmp.java | 2 +- .../test/bindData/{cmp => cmp1}/BCmp.java | 2 +- .../test/bindData/{cmp => cmp1}/CCmp.java | 2 +- .../test/bindData/{cmp => cmp1}/DCmp.java | 2 +- .../test/bindData/{cmp => cmp1}/XCmp.java | 2 +- .../test/bindData/{cmp => cmp1}/YCmp.java | 2 +- .../liteflow/test/bindData/cmp2/A1Cmp.java | 27 +++++ .../liteflow/test/bindData/cmp2/A2Cmp.java | 28 +++++ .../liteflow/test/bindData/cmp2/A3Cmp.java | 26 +++++ .../liteflow/test/bindData/cmp2/A4Cmp.java | 26 +++++ .../liteflow/test/bindData/cmp2/A5Cmp.java | 26 +++++ .../test/bindData/context/Member.java | 28 +++++ .../test/bindData/context/MemberContext.java | 24 +++++ .../test/bindData/context/OrderContext.java | 34 ++++++ .../bindData/context/UserInfoContext.java | 17 +++ .../resources/bindData/application.properties | 1 - .../bindData/application2.properties | 1 + .../bindData/{flow.el.xml => flow2.xml} | 16 +-- 26 files changed, 487 insertions(+), 56 deletions(-) create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/exception/ObjectConvertException.java create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteflowContextRegexMatcher.java rename liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/{BindDataSpringbootTest.java => BindDataSpringbootTest1.java} (91%) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/BindDataSpringbootTest2.java rename liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/{cmp => cmp1}/ACmp.java (92%) rename liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/{cmp => cmp1}/BCmp.java (92%) rename liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/{cmp => cmp1}/CCmp.java (92%) rename liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/{cmp => cmp1}/DCmp.java (93%) rename liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/{cmp => cmp1}/XCmp.java (91%) rename liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/{cmp => cmp1}/YCmp.java (90%) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A1Cmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A2Cmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A3Cmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A4Cmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A5Cmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/context/Member.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/context/MemberContext.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/context/OrderContext.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/context/UserInfoContext.java delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/application2.properties rename liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/{flow.el.xml => flow2.xml} (51%) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java b/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java index 8a6a2e924..492c7094f 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java @@ -114,4 +114,6 @@ public interface ChainConstant { String USER_DIR = "user.dir"; String BIND = "bind"; + + String CONTEXT_SEARCH_REGEX = "^\\$\\{(.*?)\\}$"; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java index 3b3aa7f3f..2aad3ac06 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java @@ -9,10 +9,13 @@ package com.yomahub.liteflow.core; import cn.hutool.core.date.StopWatch; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.ReUtil; import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.common.ChainConstant; import com.yomahub.liteflow.core.proxy.LiteFlowProxyUtil; import com.yomahub.liteflow.enums.CmpStepTypeEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.exception.ObjectConvertException; import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.flow.element.Node; import com.yomahub.liteflow.flow.entity.CmpStep; @@ -26,6 +29,7 @@ import com.yomahub.liteflow.slot.DataBus; import com.yomahub.liteflow.slot.Slot; import com.yomahub.liteflow.spi.holder.CmpAroundAspectHolder; import com.yomahub.liteflow.util.JsonUtil; +import com.yomahub.liteflow.util.LiteflowContextRegexMatcher; import java.lang.reflect.Method; import java.util.Date; @@ -446,10 +450,31 @@ public abstract class NodeComponent{ if (StrUtil.isBlank(bindData)) { return null; } - if (clazz.equals(String.class) || clazz.equals(Object.class)) { - return (T) bindData; + + //如果bind的value是一个正则表达式,说明要在上下文中进行搜索 + if (ReUtil.isMatch(ChainConstant.CONTEXT_SEARCH_REGEX, bindData)) { + Object searchResult = LiteflowContextRegexMatcher.searchContext( + this.getSlot().getContextBeanList(), + ReUtil.getGroup1(ChainConstant.CONTEXT_SEARCH_REGEX, bindData) + ); + + if (searchResult == null){ + return null; + } + + //搜索到的对象一定要符合给定的clazz + if (clazz.isAssignableFrom(searchResult.getClass())) { + return (T) searchResult; + }else{ + String errMsg = StrUtil.format("{} cannot convert to {}", searchResult.getClass().getName(), clazz.getName()); + throw new ObjectConvertException(errMsg); + } + }else{ + if (clazz.equals(String.class) || clazz.equals(Object.class)) { + return (T) bindData; + } + return JsonUtil.parseObject(bindData, clazz); } - return JsonUtil.parseObject(bindData, clazz); } public List getBindDataList(Class clazz) { @@ -514,4 +539,10 @@ public abstract class NodeComponent{ Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); return originalClass.getName(); } + + public static void main(String[] args) { + + boolean flag = ReUtil.isMatch(ChainConstant.CONTEXT_SEARCH_REGEX, "${user.name}"); + System.out.println(ReUtil.getGroup1(ChainConstant.CONTEXT_SEARCH_REGEX, "${user.name}")); + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/DeclComponentProxy.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/DeclComponentProxy.java index 713c84700..905d89847 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/DeclComponentProxy.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/DeclComponentProxy.java @@ -20,6 +20,7 @@ import com.yomahub.liteflow.flow.element.Node; import com.yomahub.liteflow.log.LFLog; import com.yomahub.liteflow.log.LFLoggerManager; import com.yomahub.liteflow.slot.DataBus; +import com.yomahub.liteflow.util.LiteflowContextRegexMatcher; import com.yomahub.liteflow.util.SerialsUtil; import net.bytebuddy.ByteBuddy; import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; @@ -157,8 +158,6 @@ public class DeclComponentProxy { } - private final ExpressRunner expressRunner = new ExpressRunner(); - private Object[] loadMethodParameter(Object proxy, MethodWrapBean methodWrapBean, Object[] args){ NodeComponent thisNodeComponent = (NodeComponent) proxy; @@ -181,38 +180,9 @@ public class DeclComponentProxy { return null; } - // 把上下文数据转换成map形式的,key为别名,value为上下文 - Map contextMap = DataBus.getSlot(thisNodeComponent.getSlotIndex()).getContextBeanList().stream().collect( - Collectors.toMap(tuple -> tuple.get(0), tuple -> tuple.get(1)) - ); - - List errorList = new ArrayList<>(); - - Object result = null; - // 根据表达式去上下文里搜索相匹配的数据 - for(Map.Entry entry : contextMap.entrySet()){ - try{ - InstructionSet instructionSet = expressRunner.getInstructionSetFromLocalCache(entry.getKey() + "." + parameterWrapBean.getFact().value()); - DefaultContext context = new DefaultContext<>(); - context.put(entry.getKey(), entry.getValue()); - result = expressRunner.execute(instructionSet, context, errorList, false, false); - if (result != null){ - break; - } - }catch (Exception ignore){} - } - - if (result == null){ - try{ - // 如果没有搜到,那么尝试推断表达式是指定的上下文,按照指定上下文的方式去再获取 - InstructionSet instructionSet = expressRunner.getInstructionSetFromLocalCache("contextMap." + parameterWrapBean.getFact().value()); - DefaultContext context = new DefaultContext<>(); - context.put("contextMap", contextMap); - result = expressRunner.execute(instructionSet, context, errorList, false, false); - }catch (Exception ignore){} - } - - return result; + return LiteflowContextRegexMatcher.searchContext( + DataBus.getSlot(thisNodeComponent.getSlotIndex()).getContextBeanList(), + parameterWrapBean.getFact().value()); }).toArray(); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ObjectConvertException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ObjectConvertException.java new file mode 100644 index 000000000..5ea45f369 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ObjectConvertException.java @@ -0,0 +1,29 @@ +package com.yomahub.liteflow.exception; + +/** + * 对象转型异常 + * + * @author Bryan.Zhang + * @since 2.13.0 + */ +public class ObjectConvertException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** 异常信息 */ + private String message; + + public ObjectConvertException(String message) { + this.message = message; + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteflowContextRegexMatcher.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteflowContextRegexMatcher.java new file mode 100644 index 000000000..61b8e83db --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteflowContextRegexMatcher.java @@ -0,0 +1,57 @@ +package com.yomahub.liteflow.util; + +import cn.hutool.core.lang.Tuple; +import com.ql.util.express.DefaultContext; +import com.ql.util.express.ExpressRunner; +import com.ql.util.express.InstructionSet; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * LiteFlow上下文正则表达式匹配器 + * 用来根据正则表达式去寻找上下文中符合的对象 + * @author Bryan.Zhang + * @since 2.13.0 + */ +public class LiteflowContextRegexMatcher { + + private static final ExpressRunner expressRunner = new ExpressRunner(); + + public static Object searchContext(List contextList, String regPattern){ + // 把上下文数据转换成map形式的,key为别名,value为上下文 + Map contextMap = contextList.stream().collect( + Collectors.toMap(tuple -> tuple.get(0), tuple -> tuple.get(1)) + ); + + List errorList = new ArrayList<>(); + + Object result = null; + // 根据表达式去上下文里搜索相匹配的数据 + for(Map.Entry entry : contextMap.entrySet()){ + try{ + InstructionSet instructionSet = expressRunner.getInstructionSetFromLocalCache(entry.getKey() + "." + regPattern); + DefaultContext context = new DefaultContext<>(); + context.put(entry.getKey(), entry.getValue()); + result = expressRunner.execute(instructionSet, context, errorList, false, false); + if (result != null){ + break; + } + }catch (Exception ignore){} + } + + if (result == null){ + try{ + // 如果没有搜到,那么尝试推断表达式是指定的上下文,按照指定上下文的方式去再获取 + InstructionSet instructionSet = expressRunner.getInstructionSetFromLocalCache("contextMap." + regPattern); + DefaultContext context = new DefaultContext<>(); + context.put("contextMap", contextMap); + result = expressRunner.execute(instructionSet, context, errorList, false, false); + }catch (Exception ignore){} + } + + return result; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javax-springboot/pom.xml b/liteflow-testcase-el/liteflow-testcase-el-script-javax-springboot/pom.xml index 4636f0fd2..01239774a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javax-springboot/pom.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javax-springboot/pom.xml @@ -24,6 +24,12 @@ ${revision} test + + com.yomahub + liteflow-script-javax + ${revision} + test + org.springframework.boot spring-boot-starter-test diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/BindDataSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/BindDataSpringbootTest1.java similarity index 91% rename from liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/BindDataSpringbootTest.java rename to liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/BindDataSpringbootTest1.java index fb22daec7..106da8382 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/BindDataSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/BindDataSpringbootTest1.java @@ -18,11 +18,11 @@ import javax.annotation.Resource; * * @author Bryan.Zhang */ -@TestPropertySource(value = "classpath:/bindData/application.properties") -@SpringBootTest(classes = BindDataSpringbootTest.class) +@TestPropertySource(value = "classpath:/bindData/application1.properties") +@SpringBootTest(classes = BindDataSpringbootTest1.class) @EnableAutoConfiguration -@ComponentScan({ "com.yomahub.liteflow.test.bindData.cmp" }) -public class BindDataSpringbootTest extends BaseTest { +@ComponentScan({ "com.yomahub.liteflow.test.bindData.cmp1" }) +public class BindDataSpringbootTest1 extends BaseTest { @Resource private FlowExecutor flowExecutor; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/BindDataSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/BindDataSpringbootTest2.java new file mode 100644 index 000000000..0533b4cbf --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/BindDataSpringbootTest2.java @@ -0,0 +1,100 @@ +package com.yomahub.liteflow.test.bindData; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.exception.ObjectConvertException; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.bindData.context.Member; +import com.yomahub.liteflow.test.bindData.context.MemberContext; +import com.yomahub.liteflow.test.bindData.context.OrderContext; +import com.yomahub.liteflow.test.bindData.context.UserInfoContext; +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 org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; + +import javax.annotation.Resource; + +/** + * springboot环境EL常规的例子测试 + * + * @author Bryan.Zhang + */ +@TestPropertySource(value = "classpath:/bindData/application2.properties") +@SpringBootTest(classes = BindDataSpringbootTest2.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.bindData.cmp2"}) +public class BindDataSpringbootTest2 extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // 测试动态bind,最简单的情况,2个上下文中搜索 + @Test + public void testBindDynamic1() throws Exception { + MemberContext memberContext = new MemberContext(); + memberContext.setId(31); + memberContext.setName("jack"); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", memberContext, new DefaultContext()); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getContextBean(DefaultContext.class); + Assertions.assertEquals("jack", context.getData("a1")); + } + + // 测试动态bind,多级取数据,2个上下文中搜索 + @Test + public void testBindDynamic2() throws Exception { + OrderContext orderContext = new OrderContext(); + orderContext.setOrderCode("SO1234"); + orderContext.setMember(new Member("M0001","jack")); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg", orderContext, new DefaultContext()); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getContextBean(DefaultContext.class); + Assertions.assertEquals("M0001", context.getData("a2")); + } + + // 测试动态bind,多个上下文,拥有相同的变量,指定上下文 + @Test + public void testBindDynamic3() throws Exception { + OrderContext orderContext = new OrderContext(); + orderContext.setId(1000); + orderContext.setOrderCode("SO1234"); + orderContext.setMember(new Member("M0001","jack")); + + MemberContext memberContext = new MemberContext(); + memberContext.setId(2000); + memberContext.setName("jack"); + + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg", orderContext, memberContext, new DefaultContext()); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getContextBean(DefaultContext.class); + Assertions.assertEquals(2000, (Integer) context.getData("a3")); + } + + // 测试动态bind,多个上下文,结合@ContextBean测试 + @Test + public void testBindDynamic4() throws Exception { + UserInfoContext userInfoContext = new UserInfoContext(); + userInfoContext.setInfo("test info"); + + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg", userInfoContext, new DefaultContext()); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getContextBean(DefaultContext.class); + Assertions.assertEquals("test info", context.getData("a4")); + } + + // 测试动态bind,getBindData中的class给错,报错 + @Test + public void testBindDynamic5() throws Exception { + MemberContext memberContext = new MemberContext(); + memberContext.setId(31); + memberContext.setName("jack"); + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg", memberContext, new DefaultContext()); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals(ObjectConvertException.class, response.getCause().getClass()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/ACmp.java similarity index 92% rename from liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/ACmp.java rename to liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/ACmp.java index 57e07216f..7730a1cd8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/ACmp.java @@ -5,7 +5,7 @@ * @email weenyc31@163.com * @Date 2020/4/1 */ -package com.yomahub.liteflow.test.bindData.cmp; +package com.yomahub.liteflow.test.bindData.cmp1; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.core.NodeComponent; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/BCmp.java similarity index 92% rename from liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/BCmp.java rename to liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/BCmp.java index a67876e1c..689c6f4c2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/BCmp.java @@ -5,7 +5,7 @@ * @email weenyc31@163.com * @Date 2020/4/1 */ -package com.yomahub.liteflow.test.bindData.cmp; +package com.yomahub.liteflow.test.bindData.cmp1; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.core.NodeComponent; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/CCmp.java similarity index 92% rename from liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/CCmp.java rename to liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/CCmp.java index 8488ecad2..7223469ab 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/CCmp.java @@ -5,7 +5,7 @@ * @email weenyc31@163.com * @Date 2020/4/1 */ -package com.yomahub.liteflow.test.bindData.cmp; +package com.yomahub.liteflow.test.bindData.cmp1; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.core.NodeComponent; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/DCmp.java similarity index 93% rename from liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/DCmp.java rename to liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/DCmp.java index b169cea40..ce5ec2ede 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/DCmp.java @@ -5,7 +5,7 @@ * @email weenyc31@163.com * @Date 2020/4/1 */ -package com.yomahub.liteflow.test.bindData.cmp; +package com.yomahub.liteflow.test.bindData.cmp1; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.core.NodeComponent; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/XCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/XCmp.java similarity index 91% rename from liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/XCmp.java rename to liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/XCmp.java index 4398afc14..43b960907 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/XCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/XCmp.java @@ -1,4 +1,4 @@ -package com.yomahub.liteflow.test.bindData.cmp; +package com.yomahub.liteflow.test.bindData.cmp1; import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.slot.DefaultContext; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/YCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/YCmp.java similarity index 90% rename from liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/YCmp.java rename to liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/YCmp.java index 6d0ba089f..9f050b019 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp/YCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp1/YCmp.java @@ -1,4 +1,4 @@ -package com.yomahub.liteflow.test.bindData.cmp; +package com.yomahub.liteflow.test.bindData.cmp1; import com.yomahub.liteflow.core.NodeSwitchComponent; import com.yomahub.liteflow.slot.DefaultContext; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A1Cmp.java new file mode 100644 index 000000000..d91ea1c54 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A1Cmp.java @@ -0,0 +1,27 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.bindData.cmp2; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.bindData.context.Member; +import org.springframework.stereotype.Component; + +@Component("a1") +public class A1Cmp extends NodeComponent { + + @Override + public void process() { + DefaultContext defaultContext = this.getContextBean(DefaultContext.class); + String bindValue = this.getBindData("k1", String.class); + if (bindValue != null) { + defaultContext.setData(this.getNodeId(), bindValue); + } + + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A2Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A2Cmp.java new file mode 100644 index 000000000..481e4af55 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A2Cmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.bindData.cmp2; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.bindData.context.Member; +import org.springframework.stereotype.Component; + +@Component("a2") +public class A2Cmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getContextBean(DefaultContext.class); + String bindValue = this.getBindData("k1", String.class); + if (bindValue != null) { + context.setData(this.getNodeId(), bindValue); + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A3Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A3Cmp.java new file mode 100644 index 000000000..a3bc634aa --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A3Cmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.bindData.cmp2; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("a3") +public class A3Cmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getContextBean(DefaultContext.class); + Integer bindValue = this.getBindData("k1", Integer.class); + if (bindValue != null) { + context.setData(this.getNodeId(), bindValue); + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A4Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A4Cmp.java new file mode 100644 index 000000000..aeaf8383f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A4Cmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.bindData.cmp2; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("a4") +public class A4Cmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getContextBean(DefaultContext.class); + String bindValue = this.getBindData("k1", String.class); + if (bindValue != null) { + context.setData(this.getNodeId(), bindValue); + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A5Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A5Cmp.java new file mode 100644 index 000000000..a651d7578 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/cmp2/A5Cmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.bindData.cmp2; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("a5") +public class A5Cmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getContextBean(DefaultContext.class); + String bindValue = this.getBindData("k1", String.class); + if (bindValue != null) { + context.setData(this.getNodeId(), bindValue); + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/context/Member.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/context/Member.java new file mode 100644 index 000000000..c1b2fe026 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/context/Member.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.bindData.context; + +public class Member { + private String memberCode; + + private String memberName; + + public Member(String memberCode, String memberName) { + this.memberCode = memberCode; + this.memberName = memberName; + } + + public String getMemberCode() { + return memberCode; + } + + public void setMemberCode(String memberCode) { + this.memberCode = memberCode; + } + + public String getMemberName() { + return memberName; + } + + public void setMemberName(String memberName) { + this.memberName = memberName; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/context/MemberContext.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/context/MemberContext.java new file mode 100644 index 000000000..75b3285ed --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/context/MemberContext.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.bindData.context; + +public class MemberContext { + + private Integer id; + + private String name; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/context/OrderContext.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/context/OrderContext.java new file mode 100644 index 000000000..967b069c1 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/context/OrderContext.java @@ -0,0 +1,34 @@ +package com.yomahub.liteflow.test.bindData.context; + +public class OrderContext { + + private Integer id; + + private String orderCode; + + private Member member; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getOrderCode() { + return orderCode; + } + + public void setOrderCode(String orderCode) { + this.orderCode = orderCode; + } + + public Member getMember() { + return member; + } + + public void setMember(Member member) { + this.member = member; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/context/UserInfoContext.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/context/UserInfoContext.java new file mode 100644 index 000000000..22a79fd70 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/bindData/context/UserInfoContext.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.bindData.context; + +import com.yomahub.liteflow.context.ContextBean; + +@ContextBean("userCx") +public class UserInfoContext { + + private String info; + + public String getInfo() { + return info; + } + + public void setInfo(String info) { + this.info = info; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/application.properties b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/application.properties deleted file mode 100644 index fca905fff..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/application.properties +++ /dev/null @@ -1 +0,0 @@ -liteflow.rule-source=bindData/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/application2.properties b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/application2.properties new file mode 100644 index 000000000..d0fce85e2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/application2.properties @@ -0,0 +1 @@ +liteflow.rule-source=bindData/flow2.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/flow2.xml similarity index 51% rename from liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/flow.el.xml rename to liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/flow2.xml index 0aeacf067..41139afd7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/flow.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/bindData/flow2.xml @@ -2,22 +2,22 @@ - THEN(a.bind("k1", "test"), b); + THEN(a1.bind("k1", "${name}")); - THEN(a,b).bind("k1","test"); + THEN(a2.bind("k1", "${member.memberCode}")); - THEN(SWITCH(y).TO(d,c), WHEN(a, b), IF(x, c, d)).bind("k1", "test") - - - - THEN(a,IF(NOT(x), b, c)); + THEN(a3.bind("k1", "${memberContext.id}")); - THEN(d, sub.bind("k1", "test2")) + THEN(a4.bind("k1", "${userCx.info}")); + + + + THEN(a5.bind("k1", "${id}")); \ No newline at end of file