Kaynağa Gözat

bug #I5C23U 子流程用getChainName取不到当前ChainName的问题
bug #I5BZW7 隐式流程的requestData获取不到的问题

everywhere.z 2 yıl önce
ebeveyn
işleme
7a7a9ef64d
27 değiştirilmiş dosya ile 92 ekleme ve 26 silme
  1. 1 1
      liteflow-core/pom.xml
  2. 0 1
      liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java
  3. 4 0
      liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java
  4. 19 6
      liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java
  5. 29 3
      liteflow-core/src/main/java/com/yomahub/liteflow/slot/Slot.java
  6. 1 1
      liteflow-core/src/main/java/com/yomahub/liteflow/util/LOGOPrinter.java
  7. 1 1
      liteflow-script-common/pom.xml
  8. 1 1
      liteflow-script-groovy/pom.xml
  9. 1 1
      liteflow-script-qlexpress/pom.xml
  10. 1 1
      liteflow-spring-boot-starter/pom.xml
  11. 1 1
      liteflow-spring/pom.xml
  12. 1 1
      liteflow-testcase-declare-component/pom.xml
  13. 2 0
      liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java
  14. 4 0
      liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java
  15. 1 1
      liteflow-testcase-nospring/pom.xml
  16. 2 0
      liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowTest.java
  17. 5 0
      liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java
  18. 1 1
      liteflow-testcase-script-groovy/pom.xml
  19. 1 1
      liteflow-testcase-script-qlexpress/pom.xml
  20. 1 1
      liteflow-testcase-springboot/pom.xml
  21. 2 0
      liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java
  22. 1 2
      liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java
  23. 4 0
      liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java
  24. 1 1
      liteflow-testcase-springnative/pom.xml
  25. 2 0
      liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringTest.java
  26. 4 0
      liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java
  27. 1 1
      pom.xml

+ 1 - 1
liteflow-core/pom.xml

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

+ 0 - 1
liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java

@@ -370,7 +370,6 @@ public class FlowExecutor {
             if (ObjectUtil.isNotNull(param)){
                 slot.setRequestData(param);
             }
-            slot.setChainName(chainId);
         } else {
             if (ObjectUtil.isNotNull(param)){
                 slot.setChainReqData(chainId, param);

+ 4 - 0
liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java

@@ -300,6 +300,10 @@ public abstract class NodeComponent{
 		return getSlot().getRequestData();
 	}
 
+	public <T> T getSubChainReqData(){
+		return getSlot().getChainReqData(this.getChainName());
+	}
+
 	public String getChainName(){
 		return getSlot().getChainName();
 	}

+ 19 - 6
liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java

@@ -28,6 +28,7 @@ import com.yomahub.liteflow.thread.ExecutorHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.xml.crypto.Data;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CompletableFuture;
@@ -83,14 +84,26 @@ public class Chain implements Executable {
         if (CollUtil.isEmpty(conditionList)) {
             throw new FlowSystemException("no conditionList in this chain[" + chainName + "]");
         }
-        for (Condition condition : conditionList) {
-            if (condition instanceof ThenCondition) {
-                for (Executable executableItem : condition.getNodeList()) {
-                    executableItem.execute(slotIndex);
+        Slot<?> slot = DataBus.getSlot(slotIndex);
+        try{
+            //在子流程或者隐式流程里,slot需要取到的chainName是当前流程,所以这不再是set,而是push
+            //其底层结构是一个stack
+            slot.pushChainName(chainName);
+
+            //循环condition进行执行
+            for (Condition condition : conditionList) {
+                if (condition instanceof ThenCondition) {
+                    for (Executable executableItem : condition.getNodeList()) {
+                        executableItem.execute(slotIndex);
+                    }
+                } else if (condition instanceof WhenCondition) {
+                    executeAsyncCondition((WhenCondition) condition, slotIndex);
                 }
-            } else if (condition instanceof WhenCondition) {
-                executeAsyncCondition((WhenCondition) condition, slotIndex);
             }
+        }finally {
+            //流程结束后,需要把当前的chainName从stack结构中移出
+            //里面的逻辑判断了当只剩根chainName的时候,不移除
+            slot.popChainName();
         }
     }
 

+ 29 - 3
liteflow-core/src/main/java/com/yomahub/liteflow/slot/Slot.java

@@ -15,6 +15,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import java.util.Iterator;
 import java.util.Queue;
+import java.util.Stack;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
@@ -63,6 +64,10 @@ public class Slot<O>{
 		this.contextBean = contextBean;
 	}
 
+	private boolean hasMetaData(String key){
+		return metaDataMap.containsKey(key);
+	}
+
 	private <T> void putMetaDataMap(String key, T t) {
 		if (ObjectUtil.isNull(t)) {
 			//data slot is a ConcurrentHashMap, so null value will trigger NullPointerException
@@ -152,12 +157,33 @@ public class Slot<O>{
 		return (T) metaDataMap.get(COND_NODE_PREFIX + key);
 	}
 
-	public void setChainName(String chainName) {
-		putMetaDataMap(CHAIN_NAME, chainName);
+	public void pushChainName(String chainName) {
+		if (this.hasMetaData(CHAIN_NAME)){
+			Stack<String> stack = (Stack<String>)metaDataMap.get(CHAIN_NAME);
+			stack.push(chainName);
+		}else{
+			Stack<String> stack = new Stack<>();
+			stack.push(chainName);
+			this.putMetaDataMap(CHAIN_NAME, stack);
+		}
+	}
+
+	public void popChainName(){
+		if (this.hasMetaData(CHAIN_NAME)){
+			Stack<String> stack = (Stack<String>)metaDataMap.get(CHAIN_NAME);
+			if (stack.size() > 1){
+				stack.pop();
+			}
+		}
 	}
 
 	public String getChainName() {
-		return (String) metaDataMap.get(CHAIN_NAME);
+		try{
+			Stack<String> stack = (Stack<String>)metaDataMap.get(CHAIN_NAME);
+			return stack.peek();
+		}catch (Exception e){
+			return null;
+		}
 	}
 
 	public void addStep(CmpStep step){

+ 1 - 1
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.1\n");
+		str.append("		Version: v2.7.2\n");
 		str.append("		轻量且强大的规则引擎框架。\n");
 		str.append("		Small but powerful rules engine.\n");
 		str.append("================================================================================================\n");

+ 1 - 1
liteflow-script-common/pom.xml

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

+ 1 - 1
liteflow-script-groovy/pom.xml

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

+ 1 - 1
liteflow-script-qlexpress/pom.xml

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

+ 1 - 1
liteflow-spring-boot-starter/pom.xml

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

+ 1 - 1
liteflow-spring/pom.xml

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

+ 1 - 1
liteflow-testcase-declare-component/pom.xml

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

+ 2 - 0
liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java

@@ -45,5 +45,7 @@ public class ImplicitSubFlowSpringbootTest extends BaseTest {
         Assert.assertEquals(1, RUN_TIME_SLOT.size());
         //  set中第一次设置的requestId和response中的requestId一致
         Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId()));
+        //requestData的取值正确
+        Assert.assertEquals("it's implicit subflow.", response.getContextBean().getData("innerRequest"));
     }
 }

+ 4 - 0
liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java

@@ -4,6 +4,7 @@ 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 org.springframework.stereotype.Component;
 
 import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RUN_TIME_SLOT;
@@ -14,6 +15,9 @@ import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RU
 public class HCmp{
     @LiteflowMethod(LiteFlowMethodEnum.PROCESS)
     public void process(NodeComponent bindCmp) throws Exception {
+        String requestData = bindCmp.getSubChainReqData();
+        DefaultContext context = bindCmp.getContextBean();
+        context.setData("innerRequest", requestData);
 
         RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId());
 

+ 1 - 1
liteflow-testcase-nospring/pom.xml

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

+ 2 - 0
liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowTest.java

@@ -42,5 +42,7 @@ public class ImplicitSubFlowTest extends BaseTest {
         Assert.assertEquals(1, RUN_TIME_SLOT.size());
         //  set中第一次设置的requestId和response中的requestId一致
         Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId()));
+        //requestData的取值正确
+        Assert.assertEquals("it's implicit subflow.", response.getContextBean().getData("innerRequest"));
     }
 }

+ 5 - 0
liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java

@@ -1,12 +1,17 @@
 package com.yomahub.liteflow.test.subflow.cmp2;
 
 import com.yomahub.liteflow.core.NodeComponent;
+import com.yomahub.liteflow.slot.DefaultContext;
+
 import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT;
 
 
 public class HCmp extends NodeComponent {
     @Override
     public void process() throws Exception {
+        String requestData = this.getSubChainReqData();
+        DefaultContext context = this.getContextBean();
+        context.setData("innerRequest", requestData);
 
         RUN_TIME_SLOT.add(this.getSlot().getRequestId());
 

+ 1 - 1
liteflow-testcase-script-groovy/pom.xml

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

+ 1 - 1
liteflow-testcase-script-qlexpress/pom.xml

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

+ 1 - 1
liteflow-testcase-springboot/pom.xml

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

+ 2 - 0
liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java

@@ -45,5 +45,7 @@ public class ImplicitSubFlowSpringbootTest extends BaseTest {
         Assert.assertEquals(1, RUN_TIME_SLOT.size());
         //  set中第一次设置的requestId和response中的requestId一致
         Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId()));
+        //requestData的取值正确
+        Assert.assertEquals("it's implicit subflow.", response.getContextBean().getData("innerRequest"));
     }
 }

+ 1 - 2
liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java

@@ -1,6 +1,7 @@
 package com.yomahub.liteflow.test.subflow.cmp2;
 
 import com.yomahub.liteflow.core.NodeComponent;
+import com.yomahub.liteflow.slot.DefaultContext;
 import org.springframework.stereotype.Component;
 
 import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RUN_TIME_SLOT;
@@ -10,9 +11,7 @@ import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RU
 public class FCmp extends NodeComponent {
     @Override
     public void process() throws Exception {
-
         RUN_TIME_SLOT.add(this.getSlot().getRequestId());
-
         System.out.println("Fcomp executed!");
     }
 }

+ 4 - 0
liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java

@@ -1,6 +1,7 @@
 package com.yomahub.liteflow.test.subflow.cmp2;
 
 import com.yomahub.liteflow.core.NodeComponent;
+import com.yomahub.liteflow.slot.DefaultContext;
 import org.springframework.stereotype.Component;
 
 import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RUN_TIME_SLOT;
@@ -10,6 +11,9 @@ import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RU
 public class HCmp extends NodeComponent {
     @Override
     public void process() throws Exception {
+        String requestData = this.getSubChainReqData();
+        DefaultContext context = this.getContextBean();
+        context.setData("innerRequest", requestData);
 
         RUN_TIME_SLOT.add(this.getSlot().getRequestId());
 

+ 1 - 1
liteflow-testcase-springnative/pom.xml

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

+ 2 - 0
liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringTest.java

@@ -39,5 +39,7 @@ public class ImplicitSubFlowSpringTest extends BaseTest {
         Assert.assertEquals(1, RUN_TIME_SLOT.size());
         //  set中第一次设置的requestId和response中的requestId一致
         Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId()));
+        //requestData的取值正确
+        Assert.assertEquals("it's implicit subflow.", response.getContextBean().getData("innerRequest"));
     }
 }

+ 4 - 0
liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java

@@ -1,6 +1,7 @@
 package com.yomahub.liteflow.test.subflow.cmp2;
 
 import com.yomahub.liteflow.core.NodeComponent;
+import com.yomahub.liteflow.slot.DefaultContext;
 import org.springframework.stereotype.Component;
 
 import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringTest.RUN_TIME_SLOT;
@@ -10,6 +11,9 @@ import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringTest.RUN_TI
 public class HCmp extends NodeComponent {
     @Override
     public void process() throws Exception {
+        String requestData = this.getSubChainReqData();
+        DefaultContext context = this.getContextBean();
+        context.setData("innerRequest", requestData);
 
         RUN_TIME_SLOT.add(this.getSlot().getRequestId());
 

+ 1 - 1
pom.xml

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