feat(core): 支持无 chain 配置启动

放宽 DTD 与 JSON 解析对 chain 节点的强校验,允许 ruleSource 下未定义任何 chain 时正常启动;新增 NoChainELSpringbootTest 用例。
This commit is contained in:
everywhere.z
2026-04-30 14:27:49 +08:00
parent 2feb4b636c
commit 192579ee8e
6 changed files with 49 additions and 15 deletions

View File

@@ -11,7 +11,6 @@ package com.yomahub.liteflow.core;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Tuple;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.*;
import cn.hutool.crypto.digest.MD5;
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
@@ -217,16 +216,6 @@ public class FlowExecutor {
}
}
// 如果是ruleSource方式的最后判断下有没有解析出来,如果没有解析出来则报错
if (StrUtil.isBlank(liteflowConfig.getRuleSourceExtData())
&& MapUtil.isEmpty(liteflowConfig.getRuleSourceExtDataMap())) {
if (FlowBus.getChainMap().isEmpty()) {
String errMsg = StrUtil.format("no valid rule config found in rule path [{}]",
liteflowConfig.getRuleSource());
throw new ConfigErrorException(errMsg);
}
}
// 执行钩子
if (isStart) {
FlowInitHook.executeHook();
@@ -722,4 +711,4 @@ public class FlowExecutor {
public AtomicBoolean getStartUpPhase() {
return startUpPhase;
}
}
}

View File

@@ -226,8 +226,13 @@ public class ParserHelper {
// 这样就不用去像之前的版本那样回归调用
// 同时也解决了不能循环依赖的问题
flowJsonObjectList.forEach(jsonObject -> {
JsonNode flowNode = jsonObject.get(FLOW);
if (flowNode == null || !flowNode.has(CHAIN)) {
return;
}
// 解析chain节点
Iterator<JsonNode> iterator = jsonObject.get(FLOW).get(CHAIN).elements();
Iterator<JsonNode> iterator = flowNode.get(CHAIN).elements();
// 先在元数据里放上chain
while (iterator.hasNext()) {
JsonNode innerJsonObject = iterator.next();

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!ELEMENT flow ((nodes)? , (chain)+)>
<!ELEMENT flow ((nodes)? , (chain)*)>
<!ELEMENT nodes (node)+>
<!ELEMENT node (#PCDATA | EMPTY)*>
<!ELEMENT chain ((route)? | (body)? | #PCDATA)>
@@ -23,4 +23,4 @@
enable (true|false) #IMPLIED
namespace CDATA #IMPLIED
thread-pool-executor-class CDATA #IMPLIED
>
>

View File

@@ -0,0 +1,35 @@
package com.yomahub.liteflow.test.base;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.TestPropertySource;
import javax.annotation.Resource;
/**
* springboot环境下没有chain的启动测试
*
* @author Bryan.Zhang
*/
@TestPropertySource(value = "classpath:/base/noChain/application.properties")
@SpringBootTest(classes = NoChainELSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({ "com.yomahub.liteflow.test.base.cmp" })
public class NoChainELSpringbootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Test
public void testStartWithoutChain() {
Assertions.assertNotNull(flowExecutor);
Assertions.assertTrue(FlowBus.getChainMap().isEmpty());
}
}

View File

@@ -0,0 +1 @@
liteflow.rule-source=base/noChain/flow.el.xml

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE flow PUBLIC "liteflow" "liteflow.dtd">
<flow>
</flow>