From 288899d3add137ce2366a22369ead68abb032c7e Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Fri, 21 Jul 2023 00:29:12 +0800 Subject: [PATCH] =?UTF-8?q?enhancement=20#I7KOPV=20=E7=B1=BB=E7=BA=A7?= =?UTF-8?q?=E5=88=AB=E5=A3=B0=E6=98=8E=E7=BB=84=E4=BB=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=BB=BA=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/annotation/LiteflowMethod.java | 8 ++++++- .../liteflow/core/proxy/ComponentProxy.java | 21 ++++++++++++++++++- .../com/yomahub/liteflow/flow/FlowBus.java | 2 +- .../spi/LiteflowComponentSupport.java | 2 +- .../local/LocalLiteflowComponentSupport.java | 2 +- .../solon/SolonLiteflowComponentSupport.java | 2 +- .../SpringLiteflowComponentSupport.java | 2 +- .../liteflow/test/base/cmp/CmpConfig.java | 2 +- 8 files changed, 33 insertions(+), 8 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java index 589cf4ee3..7eba135e7 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java @@ -18,10 +18,16 @@ public @interface LiteflowMethod { /** * 节点ID,用于区分节点 默认为空 则按照Spring模式下BeanName为准。 - * @return + * @return nodeId */ String nodeId() default ""; + /** + * 节点Name + * @return nodeName + */ + String nodeName() default ""; + /** * CMP类型定义 * @return AnnotationNodeTypeEnum 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 4ca355f87..5d6315946 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 @@ -13,6 +13,7 @@ import com.yomahub.liteflow.exception.LiteFlowException; import com.yomahub.liteflow.exception.ProxyException; import com.yomahub.liteflow.log.LFLog; import com.yomahub.liteflow.log.LFLoggerManager; +import com.yomahub.liteflow.spi.holder.LiteflowComponentSupportHolder; import com.yomahub.liteflow.util.LiteFlowProxyUtil; import com.yomahub.liteflow.util.SerialsUtil; import net.bytebuddy.ByteBuddy; @@ -28,6 +29,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Predicate; import java.util.stream.Collectors; /** @@ -94,8 +96,23 @@ public class ComponentProxy { boolean legal = classes.size() == 1; if (!legal) { throw new LiteFlowException("The cmpClass of the same nodeId must be the same,you declared nodeId:" - + activeNodeId + ",cmpClass:" + classes); + + activeNodeId + ",cmpClass:" + clazz); } + + + String activeNodeName; + if (isMethodCreate){ + // 获取process上的LiteflowMethod + LiteflowMethod mainliteflowMethod = methodList.stream().filter(liteflowMethod -> liteflowMethod.value().isMainMethod()).findFirst().orElse(null); + if (mainliteflowMethod == null){ + String errMsg = StrUtil.format("you have not defined @LiteFlowMethod on the processXXX method in class {}", clazz.getName()); + throw new LiteFlowException(errMsg); + } + activeNodeName = mainliteflowMethod.nodeName(); + }else{ + activeNodeName = LiteflowComponentSupportHolder.loadLiteflowComponentSupport().getCmpName(bean); + } + // 当前节点实际LiteflowRetry注解 AtomicReference liteflowRetryAtomicReference = new AtomicReference<>(null); // 相同nodeId只能有一个LiteflowRetry定义方法,且必须再Process方法上 @@ -151,6 +168,8 @@ public class ComponentProxy { NodeComponent nodeComponent = (NodeComponent) instance; // 重设nodeId nodeComponent.setNodeId(activeNodeId); + // 重设nodeName + nodeComponent.setName(activeNodeName); return nodeComponent; } catch (Exception e) { diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java index 2a82c62a5..1f8d1954d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java @@ -93,7 +93,7 @@ public class FlowBus { } nodeMap.put(nodeId, - new Node(ComponentInitializer.loadInstance().initComponent(nodeComponent, type, null, nodeId))); + new Node(ComponentInitializer.loadInstance().initComponent(nodeComponent, type, nodeComponent.getName(), nodeId))); } /** diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/LiteflowComponentSupport.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/LiteflowComponentSupport.java index da659f12a..710eb3921 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/LiteflowComponentSupport.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/LiteflowComponentSupport.java @@ -10,6 +10,6 @@ import com.yomahub.liteflow.core.NodeComponent; */ public interface LiteflowComponentSupport extends SpiPriority { - String getCmpName(NodeComponent nodeComponent); + String getCmpName(Object nodeComponent); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalLiteflowComponentSupport.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalLiteflowComponentSupport.java index 74426e82c..4303b47b8 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalLiteflowComponentSupport.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalLiteflowComponentSupport.java @@ -12,7 +12,7 @@ import com.yomahub.liteflow.spi.LiteflowComponentSupport; public class LocalLiteflowComponentSupport implements LiteflowComponentSupport { @Override - public String getCmpName(NodeComponent nodeComponent) { + public String getCmpName(Object nodeComponent) { return null; } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonLiteflowComponentSupport.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonLiteflowComponentSupport.java index 06b9de068..c25aa5220 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonLiteflowComponentSupport.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonLiteflowComponentSupport.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.spi.LiteflowComponentSupport; public class SolonLiteflowComponentSupport implements LiteflowComponentSupport { @Override - public String getCmpName(NodeComponent nodeComponent) { + public String getCmpName(Object nodeComponent) { // 判断NodeComponent是否是标识了@LiteflowComponent的标注 // 如果标注了,那么要从中取到name字段 LiteflowComponent liteflowComponent = nodeComponent.getClass().getAnnotation(LiteflowComponent.class); diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringLiteflowComponentSupport.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringLiteflowComponentSupport.java index a88fdb9e0..754ffcaa9 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringLiteflowComponentSupport.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringLiteflowComponentSupport.java @@ -15,7 +15,7 @@ import com.yomahub.liteflow.spi.LiteflowComponentSupport; public class SpringLiteflowComponentSupport implements LiteflowComponentSupport { @Override - public String getCmpName(NodeComponent nodeComponent) { + public String getCmpName(Object nodeComponent) { // 判断NodeComponent是否是标识了@LiteflowComponent的标注 // 如果标注了,那么要从中取到name字段 LiteflowComponent liteflowComponent = nodeComponent.getClass().getAnnotation(LiteflowComponent.class); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CmpConfig.java index 5689c278e..d5dab5786 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CmpConfig.java @@ -10,7 +10,7 @@ import javax.annotation.Resource; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a", nodeName = "A组件") public void processA(NodeComponent bindCmp) { System.out.println("ACmp executed!"); }