diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java index c52e3b0b1..2de2c2f35 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java @@ -32,6 +32,11 @@ public class LiteFlowChainELBuilder { private Chain chain; + /** + * 是否只需要验证EL表达式 + */ + private Boolean onlyValidate; + /** * //这是主体的Condition,不包含前置和后置 * //声明这个变量,而不是用chain.getConditionList的目的,是为了辅助平滑加载 @@ -87,6 +92,7 @@ public class LiteFlowChainELBuilder { public LiteFlowChainELBuilder() { chain = new Chain(); + onlyValidate = Boolean.FALSE; conditionList = new ArrayList<>(); preConditionList = new ArrayList<>(); finallyConditionList = new ArrayList<>(); @@ -118,6 +124,11 @@ public class LiteFlowChainELBuilder { return this; } + public LiteFlowChainELBuilder setOnlyValidate() { + this.onlyValidate = Boolean.TRUE; + return this; + } + public LiteFlowChainELBuilder setEL(String elStr) { if (StrUtil.isBlank(elStr)) { String errMsg = StrUtil.format("no content in this chain[{}]", chain.getChainId()); @@ -176,7 +187,10 @@ public class LiteFlowChainELBuilder { checkBuild(); - FlowBus.addChain(this.chain); + // 仅校验EL表达式格式是否正确时,当前生成的chain 不加入元数据 + if (!this.onlyValidate) { + FlowBus.addChain(this.chain); + } } /** diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/Exception1Test.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/Exception1Test.java index e5ba075ea..4c9d36799 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/Exception1Test.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/Exception1Test.java @@ -1,13 +1,18 @@ package com.yomahub.liteflow.test.exception; +import com.yomahub.liteflow.builder.LiteFlowNodeBuilder; +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.core.FlowExecutorHolder; +import com.yomahub.liteflow.enums.NodeTypeEnum; import com.yomahub.liteflow.exception.ChainDuplicateException; import com.yomahub.liteflow.exception.ConfigErrorException; +import com.yomahub.liteflow.exception.ELParseException; import com.yomahub.liteflow.exception.FlowExecutorNotInitException; import com.yomahub.liteflow.property.LiteflowConfig; import com.yomahub.liteflow.property.LiteflowConfigGetter; import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -51,4 +56,30 @@ public class Exception1Test extends BaseTest { config.setRuleSource("error/flow.txt"); flowExecutor.reloadRule(); } + + @Test + public void testChainElBuilderOnlyValidate() { + LiteFlowNodeBuilder.createNode().setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp.ACmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp.BCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp.CCmp") + .build(); + try { + LiteFlowChainELBuilder.createChain().setChainId("chain3").setEL( + "THEN(a, b, d)" + ).setOnlyValidate().build(); + } catch ( Exception ex) { + Assert.assertTrue(ex instanceof ELParseException); + } + } }