enhancement #I61EMZ 添加验证EL规则的api,供检查之用

This commit is contained in:
zendwang
2022-11-29 18:36:31 +08:00
parent d9d8ace091
commit 2921694314
2 changed files with 46 additions and 1 deletions

View File

@@ -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);
}
}
/**

View File

@@ -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);
}
}
}