Browse Source

bug #I6G0D5 NodeIfComponent 重写 isAccess 导致空指针报错

everywhere.z 2 năm trước cách đây
mục cha
commit
4a2d6a12c1

+ 5 - 0
liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ForCondition.java

@@ -28,6 +28,11 @@ public class ForCondition extends LoopCondition{
             throw new NoForNodeException(errorInfo);
         }
 
+        //先去判断isAccess方法,如果isAccess方法都返回false,整个FOR表达式不执行
+        if (!this.getForNode().isAccess(slotIndex)){
+            return;
+        }
+
         //执行forCount组件
         forNode.setCurrChainId(this.getCurrChainId());
         forNode.execute(slotIndex);

+ 5 - 0
liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IfCondition.java

@@ -27,6 +27,11 @@ public class IfCondition extends Condition {
     @Override
     public void execute(Integer slotIndex) throws Exception {
         if (ListUtil.toList(NodeTypeEnum.IF, NodeTypeEnum.IF_SCRIPT).contains(getIfNode().getType())){
+            //先去判断isAccess方法,如果isAccess方法都返回false,整个IF表达式不执行
+            if (!this.getIfNode().isAccess(slotIndex)){
+                return;
+            }
+
             //先执行IF节点
             this.getIfNode().setCurrChainId(this.getCurrChainId());
             this.getIfNode().execute(slotIndex);

+ 5 - 0
liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IteratorCondition.java

@@ -24,6 +24,11 @@ public class IteratorCondition extends LoopCondition{
             throw new NoIteratorNodeException(errorInfo);
         }
 
+        //先去判断isAccess方法,如果isAccess方法都返回false,整个ITERATOR表达式不执行
+        if (!this.getIteratorNode().isAccess(slotIndex)){
+            return;
+        }
+
         //执行Iterator组件
         iteratorNode.setCurrChainId(this.getCurrChainId());
         iteratorNode.execute(slotIndex);

+ 5 - 0
liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/SwitchCondition.java

@@ -36,6 +36,11 @@ public class SwitchCondition extends Condition{
     @Override
     public void execute(Integer slotIndex) throws Exception {
         if (ListUtil.toList(NodeTypeEnum.SWITCH, NodeTypeEnum.SWITCH_SCRIPT).contains(this.getSwitchNode().getType())){
+            //先去判断isAccess方法,如果isAccess方法都返回false,整个SWITCH表达式不执行
+            if (!this.getSwitchNode().isAccess(slotIndex)){
+                return;
+            }
+
             //先执行switch节点
             this.getSwitchNode().setCurrChainId(this.getCurrChainId());
             this.getSwitchNode().execute(slotIndex);

+ 5 - 0
liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhileCondition.java

@@ -28,6 +28,11 @@ public class WhileCondition extends LoopCondition{
             throw new NoWhileNodeException(errorInfo);
         }
 
+        //先去判断isAccess方法,如果isAccess方法都返回false,整个WHILE表达式不执行
+        if (!this.getWhileNode().isAccess(slotIndex)){
+            return;
+        }
+
         //获得要循环的可执行对象
         Executable executableItem = this.getDoExecutor();
 

+ 8 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfELSpringbootTest.java

@@ -84,4 +84,12 @@ public class IfELSpringbootTest extends BaseTest {
         Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime());
     }
 
+    //IF节点中isAccess返回false,这个情况相当于IF整个表达式串没执行
+    @Test
+    public void testIf8() throws Exception{
+        LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg");
+        Assert.assertTrue(response.isSuccess());
+        Assert.assertEquals("c", response.getExecuteStepStrWithoutTime());
+    }
+
 }

+ 24 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X2Cmp.java

@@ -0,0 +1,24 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.ifelse.cmp;
+
+import com.yomahub.liteflow.core.NodeIfComponent;
+import org.springframework.stereotype.Component;
+
+@Component("x2")
+public class X2Cmp extends NodeIfComponent {
+	@Override
+	public boolean processIf() throws Exception {
+		return true;
+	}
+
+	@Override
+	public boolean isAccess() {
+		return false;
+	}
+}

+ 4 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/ifelse/flow.el.xml

@@ -38,4 +38,8 @@
                               .ELIF(x1.tag("false"), d)
                               .ELSE(THEN(d, b, a));
     </chain>
+
+    <chain name="chain8">
+        THEN(IF(x2, a, b), c);
+    </chain>
 </flow>