From db5899ac6ec606e8e9eed83d4a76b59c060d82d1 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Wed, 15 Jun 2022 00:23:46 +0800 Subject: [PATCH] =?UTF-8?q?bug=20#I5CB1Y=20=E5=A3=B0=E6=98=8E=E5=BC=8F?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=97=A0=E6=B3=95=E8=BF=9B=E5=85=A5beforePro?= =?UTF-8?q?cess=E5=92=8CafterProcess=E6=96=B9=E6=B3=95=20bug=20#I5C7LM=20?= =?UTF-8?q?=E5=A3=B0=E6=98=8E=E5=BC=8F=E7=BB=84=E4=BB=B6=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=90=8D=E8=87=AA=E5=AE=9A=E4=B9=89=E4=BC=9A=E5=87=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteflow-core/pom.xml | 2 +- .../liteflow/core/proxy/ComponentProxy.java | 17 ++++--- .../yomahub/liteflow/util/LOGOPrinter.java | 2 +- liteflow-script-common/pom.xml | 2 +- liteflow-script-groovy/pom.xml | 2 +- liteflow-script-qlexpress/pom.xml | 2 +- liteflow-spring-boot-starter/pom.xml | 2 +- liteflow-spring/pom.xml | 2 +- liteflow-testcase-declare-component/pom.xml | 2 +- .../CustomMethodNameSpringbootTest.java | 38 +++++++++++++++ .../test/customMethodName/cmp/ACmp.java | 46 +++++++++++++++++++ .../test/customMethodName/cmp/BCmp.java | 25 ++++++++++ .../customMethodName/application.properties | 1 + .../test/resources/customMethodName/flow.xml | 6 +++ liteflow-testcase-nospring/pom.xml | 2 +- liteflow-testcase-script-groovy/pom.xml | 2 +- liteflow-testcase-script-qlexpress/pom.xml | 2 +- liteflow-testcase-springboot/pom.xml | 2 +- liteflow-testcase-springnative/pom.xml | 2 +- pom.xml | 2 +- 20 files changed, 141 insertions(+), 20 deletions(-) create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/resources/customMethodName/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/customMethodName/flow.xml diff --git a/liteflow-core/pom.xml b/liteflow-core/pom.xml index c2fe5c3e..5257cb32 100644 --- a/liteflow-core/pom.xml +++ b/liteflow-core/pom.xml @@ -9,7 +9,7 @@ com.yomahub liteflow - 2.7.2 + 2.7.3 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java index 515b222e..50b8d5ba 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java @@ -1,5 +1,6 @@ package com.yomahub.liteflow.core.proxy; +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.*; import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; @@ -100,15 +101,16 @@ public class ComponentProxy { //获取当前调用方法,是否在被代理的对象方法里面(根据@LiteFlowMethod这个标注去判断) //如果在里面,则返回那个LiteFlowMethodBean,不在则返回null LiteFlowMethodBean liteFlowMethodBean = liteFlowMethodBeanList.stream().filter( - liteFlowMethodBean1 -> liteFlowMethodBean1.getMethod().getName().equals(method.getName()) + liteFlowMethodBean1 -> liteFlowMethodBean1.getMethodName().equals(method.getName()) ).findFirst().orElse(null); //如果被代理的对象里有此标注标的方法,则调用此被代理的对象里的方法,如果没有,则调用父类里的方法 - if (liteFlowMethodBean != null){ + //beforeProcess和afterProcess这2个方法除外 + if (!ListUtil.toList("beforeProcess","afterProcess").contains(liteFlowMethodBean.getMethodName())) { //进行检查,检查被代理的bean里是否有且仅有NodeComponent这个类型的参数 boolean checkFlag = liteFlowMethodBean.getMethod().getParameterTypes().length == 1 && Arrays.asList(liteFlowMethodBean.getMethod().getParameterTypes()).contains(NodeComponent.class); - if (!checkFlag){ + if (!checkFlag) { String errMsg = StrUtil.format("Method[{}.{}] must have NodeComponent parameter(and only one parameter)", bean.getClass().getName(), liteFlowMethodBean.getMethod().getName()); LOG.error(errMsg); throw new ComponentMethodDefineErrorException(errMsg); @@ -120,9 +122,12 @@ public class ComponentProxy { InvocationTargetException targetEx = (InvocationTargetException)e; throw targetEx.getTargetException(); } - }else{ - //理论上来说这句应该执行不到,因为前面在设置拦截对象类型的时候,已经根据当前bean所覆盖的方法进行了动态判断 - return method.invoke(proxy, args); + } + try{ + return liteFlowMethodBean.getMethod().invoke(bean, args); + }catch (Exception e){ + InvocationTargetException targetEx = (InvocationTargetException)e; + throw targetEx.getTargetException(); } } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LOGOPrinter.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LOGOPrinter.java index e4996129..1da50086 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LOGOPrinter.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LOGOPrinter.java @@ -19,7 +19,7 @@ public class LOGOPrinter { str.append(" | | | | | | | _| _____| |_ | | | | | \\ \\ /\\ / / \n"); str.append(" | |___ | | | | | |__|_____| _| | |__| |_| |\\ V V / \n"); str.append(" |_____|___| |_| |_____| |_| |_____\\___/ \\_/\\_/ \n\n"); - str.append(" Version: v2.7.2\n"); + str.append(" Version: v2.7.3\n"); str.append(" 轻量且强大的规则引擎框架。\n"); str.append(" Small but powerful rules engine.\n"); str.append("================================================================================================\n"); diff --git a/liteflow-script-common/pom.xml b/liteflow-script-common/pom.xml index 77677ed9..f70dd30b 100644 --- a/liteflow-script-common/pom.xml +++ b/liteflow-script-common/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.2 + 2.7.3 4.0.0 diff --git a/liteflow-script-groovy/pom.xml b/liteflow-script-groovy/pom.xml index 006dcec1..5118a2b5 100644 --- a/liteflow-script-groovy/pom.xml +++ b/liteflow-script-groovy/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.2 + 2.7.3 4.0.0 diff --git a/liteflow-script-qlexpress/pom.xml b/liteflow-script-qlexpress/pom.xml index 5c64d438..78d938aa 100644 --- a/liteflow-script-qlexpress/pom.xml +++ b/liteflow-script-qlexpress/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.2 + 2.7.3 4.0.0 diff --git a/liteflow-spring-boot-starter/pom.xml b/liteflow-spring-boot-starter/pom.xml index 37873d03..eab11d1d 100644 --- a/liteflow-spring-boot-starter/pom.xml +++ b/liteflow-spring-boot-starter/pom.xml @@ -10,7 +10,7 @@ liteflow com.yomahub - 2.7.2 + 2.7.3 diff --git a/liteflow-spring/pom.xml b/liteflow-spring/pom.xml index 6c0d48e4..eaa95e2a 100644 --- a/liteflow-spring/pom.xml +++ b/liteflow-spring/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.2 + 2.7.3 4.0.0 diff --git a/liteflow-testcase-declare-component/pom.xml b/liteflow-testcase-declare-component/pom.xml index 6cbb9079..f5453cfc 100644 --- a/liteflow-testcase-declare-component/pom.xml +++ b/liteflow-testcase-declare-component/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.2 + 2.7.3 4.0.0 diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameSpringbootTest.java new file mode 100644 index 00000000..1c1e046e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameSpringbootTest.java @@ -0,0 +1,38 @@ +package com.yomahub.liteflow.test.customMethodName; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +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 org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 声明式组件自定义方法的测试用例 + * @author Bryan.Zhang + * @since 2.7.2 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/customMethodName/application.properties") +@SpringBootTest(classes = CustomMethodNameSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.customMethodName.cmp"}) +public class CustomMethodNameSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testCustomMethodName() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/ACmp.java new file mode 100644 index 00000000..1ff2e18b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/ACmp.java @@ -0,0 +1,46 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customMethodName.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.slot.Slot; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void processAcmp(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS) + public boolean isAcmpAccess(NodeComponent bindCmp){ + return true; + } + + @LiteflowMethod(LiteFlowMethodEnum.BEFORE_PROCESS) + public void beforeAcmp(String nodeId, Slot slot){ + System.out.println("before A"); + } + + @LiteflowMethod(LiteFlowMethodEnum.AFTER_PROCESS) + public void afterAcmp(String nodeId, Slot slot){ + System.out.println("after A"); + } + + @LiteflowMethod(LiteFlowMethodEnum.ON_SUCCESS) + public void onAcmpSuccess(NodeComponent bindCmp){ + System.out.println("Acmp success"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/BCmp.java new file mode 100644 index 00000000..ba4c72df --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customMethodName.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void processBcmp(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/resources/customMethodName/application.properties b/liteflow-testcase-declare-component/src/test/resources/customMethodName/application.properties new file mode 100644 index 00000000..78d5f590 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/customMethodName/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=customMethodName/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/customMethodName/flow.xml b/liteflow-testcase-declare-component/src/test/resources/customMethodName/flow.xml new file mode 100644 index 00000000..cd988fe7 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/customMethodName/flow.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-nospring/pom.xml b/liteflow-testcase-nospring/pom.xml index 13ef6343..8726bceb 100644 --- a/liteflow-testcase-nospring/pom.xml +++ b/liteflow-testcase-nospring/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.2 + 2.7.3 4.0.0 diff --git a/liteflow-testcase-script-groovy/pom.xml b/liteflow-testcase-script-groovy/pom.xml index 5cb568db..a01c97b7 100644 --- a/liteflow-testcase-script-groovy/pom.xml +++ b/liteflow-testcase-script-groovy/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.2 + 2.7.3 4.0.0 diff --git a/liteflow-testcase-script-qlexpress/pom.xml b/liteflow-testcase-script-qlexpress/pom.xml index 16821510..9ab88911 100644 --- a/liteflow-testcase-script-qlexpress/pom.xml +++ b/liteflow-testcase-script-qlexpress/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.2 + 2.7.3 4.0.0 diff --git a/liteflow-testcase-springboot/pom.xml b/liteflow-testcase-springboot/pom.xml index 7bad9704..983636ce 100644 --- a/liteflow-testcase-springboot/pom.xml +++ b/liteflow-testcase-springboot/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.2 + 2.7.3 4.0.0 diff --git a/liteflow-testcase-springnative/pom.xml b/liteflow-testcase-springnative/pom.xml index e4ac2cda..ccfa7fc0 100644 --- a/liteflow-testcase-springnative/pom.xml +++ b/liteflow-testcase-springnative/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.7.2 + 2.7.3 4.0.0 diff --git a/pom.xml b/pom.xml index 41e2d2b5..e7ddad6e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.yomahub liteflow pom - 2.7.2 + 2.7.3 liteflow a lightweight and practical micro-process framework https://github.com/bryan31/liteflow