bug #I5CB1Y 声明式组件无法进入beforeProcess和afterProcess方法

bug #I5C7LM 声明式组件的方法名自定义会出问题
This commit is contained in:
everywhere.z 2022-06-15 00:23:46 +08:00
parent 7a7a9ef64d
commit db5899ac6e
20 changed files with 141 additions and 20 deletions

View File

@ -9,7 +9,7 @@
<parent>
<groupId>com.yomahub</groupId>
<artifactId>liteflow</artifactId>
<version>2.7.2</version>
<version>2.7.3</version>
</parent>
<dependencies>

View File

@ -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();
}
}
}

View File

@ -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");

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.2</version>
<version>2.7.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.2</version>
<version>2.7.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.2</version>
<version>2.7.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -10,7 +10,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.2</version>
<version>2.7.3</version>
</parent>
<dependencies>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.2</version>
<version>2.7.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.2</version>
<version>2.7.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -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<DefaultContext> response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
}
}

View File

@ -0,0 +1,46 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @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<DefaultContext> slot){
System.out.println("before A");
}
@LiteflowMethod(LiteFlowMethodEnum.AFTER_PROCESS)
public void afterAcmp(String nodeId, Slot<DefaultContext> slot){
System.out.println("after A");
}
@LiteflowMethod(LiteFlowMethodEnum.ON_SUCCESS)
public void onAcmpSuccess(NodeComponent bindCmp){
System.out.println("Acmp success");
}
}

View File

@ -0,0 +1,25 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @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!");
}
}

View File

@ -0,0 +1 @@
liteflow.rule-source=customMethodName/flow.xml

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
<then value="a,b"/>
</chain>
</flow>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.2</version>
<version>2.7.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.2</version>
<version>2.7.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.2</version>
<version>2.7.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.2</version>
<version>2.7.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.yomahub</groupId>
<version>2.7.2</version>
<version>2.7.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<groupId>com.yomahub</groupId>
<artifactId>liteflow</artifactId>
<packaging>pom</packaging>
<version>2.7.2</version>
<version>2.7.3</version>
<name>liteflow</name>
<description>a lightweight and practical micro-process framework</description>
<url>https://github.com/bryan31/liteflow</url>