diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/CatchOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/CatchOperator.java index b12ba0673..362b484d7 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/CatchOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/CatchOperator.java @@ -3,7 +3,9 @@ package com.yomahub.liteflow.builder.el.operator; import com.yomahub.liteflow.builder.el.operator.base.BaseOperator; import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper; import com.yomahub.liteflow.flow.element.Executable; +import com.yomahub.liteflow.flow.element.Node; import com.yomahub.liteflow.flow.element.condition.CatchCondition; +import com.yomahub.liteflow.flow.element.condition.ThenCondition; /** * EL规则中的CATCH的操作符 用法:CATCH...DO... @@ -20,8 +22,15 @@ public class CatchOperator extends BaseOperator { Executable catchItem = OperatorHelper.convert(objects[0], Executable.class); CatchCondition catchCondition = new CatchCondition(); - catchCondition.setCatchItem(catchItem); + //如果是单个Node的话,要包装成THEN的CONDITION模式,否则CATCH不到异常 + if (catchItem instanceof Node){ + ThenCondition thenCondition = new ThenCondition(); + thenCondition.addExecutable(catchItem); + catchCondition.setCatchItem(thenCondition); + }else{ + catchCondition.setCatchItem(catchItem); + } return catchCondition; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/LiteFlowXmlScriptLoopGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/LiteFlowXmlScriptLoopGroovyELTest.java index 46cded74e..c7bb258f6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/LiteFlowXmlScriptLoopGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/LiteFlowXmlScriptLoopGroovyELTest.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.test.script.groovy.loop; 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; @@ -65,4 +66,14 @@ public class LiteFlowXmlScriptLoopGroovyELTest extends BaseTest { response.getExecuteStepStr()); } + // 测试在脚本中取到循环对象 + @Test + public void testLoop6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("e==>w==>w==>w", response.getExecuteStepStr()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("jack-tom-frank", context.getData("test")); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/ECmp.java new file mode 100644 index 000000000..20b64445f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/ECmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.script.groovy.loop.cmp; + +import cn.hutool.core.collection.CollUtil; +import com.yomahub.liteflow.core.NodeIteratorComponent; +import org.springframework.stereotype.Component; + +import java.util.Iterator; +import java.util.List; + +@Component("e") +public class ECmp extends NodeIteratorComponent { + @Override + public Iterator processIterator() throws Exception { + List list = CollUtil.toList("jack","tom","frank"); + return list.iterator(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/loop/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/loop/flow.xml index 25ef49658..a6ef34abb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/loop/flow.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/loop/flow.xml @@ -26,6 +26,17 @@ } ]]> + + + + @@ -47,4 +58,8 @@ WHILE(z).DO(THEN(a,d)).BREAK(y); + + + ITERATOR(e).DO(w); + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/CatchELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/CatchELSpringbootTest.java index fd7bb7ec5..32c8294e2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/CatchELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/CatchELSpringbootTest.java @@ -58,4 +58,10 @@ public class CatchELSpringbootTest extends BaseTest { Assert.assertEquals("LOOP_3==>a==>b==>a==>b==>a==>b", response.getExecuteStepStrWithoutTime()); } + @Test + public void testCatch5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("a==>d", response.getExecuteStepStrWithoutTime()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/catchcase/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/catchcase/flow.el.xml index 31017e0b8..eb9f7873a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/catchcase/flow.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/catchcase/flow.el.xml @@ -4,13 +4,13 @@ CATCH( THEN(a,b) - ).DO(c) + ).DO(c); CATCH( THEN(a,b) - ).DO(d) + ).DO(d); @@ -26,4 +26,10 @@ ) ); + + + CATCH( + a + ).DO(d); + \ No newline at end of file