mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
feature #I8YNCB 支持查看一个chainId下的所有node
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
package com.yomahub.liteflow.flow;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.annotation.FallbackCmp;
|
||||
import com.yomahub.liteflow.annotation.util.AnnoUtil;
|
||||
@@ -38,6 +37,7 @@ import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
import com.yomahub.liteflow.spi.holder.DeclComponentParserHolder;
|
||||
import com.yomahub.liteflow.util.CopyOnWriteHashMap;
|
||||
import com.yomahub.liteflow.core.proxy.LiteFlowProxyUtil;
|
||||
import com.yomahub.liteflow.util.NodeScanner;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -242,6 +242,12 @@ public class FlowBus {
|
||||
return nodeMap.get(nodeId);
|
||||
}
|
||||
|
||||
// 获取某一个 chainId 下的所有 nodeId
|
||||
public static List<Node> getNodeByChainId(String chainId) {
|
||||
Chain chain = getChain(chainId);
|
||||
return NodeScanner.getNodesInChain(chain);
|
||||
}
|
||||
|
||||
public static Map<String, Node> getNodeMap() {
|
||||
return nodeMap;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.yomahub.liteflow.util;
|
||||
|
||||
import com.yomahub.liteflow.flow.element.Chain;
|
||||
import com.yomahub.liteflow.flow.element.Condition;
|
||||
import com.yomahub.liteflow.flow.element.Executable;
|
||||
import com.yomahub.liteflow.flow.element.Node;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 节点扫描器
|
||||
*
|
||||
* @author DaleLee
|
||||
* @since 2.12.0
|
||||
*/
|
||||
public class NodeScanner {
|
||||
|
||||
/**
|
||||
* 获取 Chain 中的所有 Node
|
||||
*
|
||||
* @param chain Chain
|
||||
* @return Node 集合
|
||||
*/
|
||||
public static List<Node> getNodesInChain(Chain chain) {
|
||||
List<Node> result = new ArrayList<>();
|
||||
if (chain == null) {
|
||||
return result;
|
||||
}
|
||||
for (Condition condition : chain.getConditionList()) {
|
||||
result.addAll(getNodesInCondition(condition));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Condition 中的所有 Node
|
||||
*
|
||||
* @param condition Condition
|
||||
* @return Node 集合
|
||||
*/
|
||||
public static List<Node> getNodesInCondition(Condition condition) {
|
||||
List<Node> result = new ArrayList<>();
|
||||
if (condition == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 层序遍历
|
||||
Queue<Executable> queue = new LinkedList<>();
|
||||
queue.offer(condition);
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
Executable cur = queue.poll();
|
||||
if (cur instanceof Condition) {
|
||||
Map<String, List<Executable>> executableGroup = ((Condition) cur).getExecutableGroup();
|
||||
for (List<Executable> executables : executableGroup.values()) {
|
||||
executables.forEach(queue::offer);
|
||||
}
|
||||
} else if (cur instanceof Node) {
|
||||
result.add((Node) cur);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.yomahub.liteflow.test.script.graaljs.getnodes;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.flow.element.Node;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
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 org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/getnodes/application.properties")
|
||||
@SpringBootTest(classes = LiteFlowScriptGetNodesGraaljsTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan("com.yomahub.liteflow.test.script.graaljs.getnodes.cmp")
|
||||
public class LiteFlowScriptGetNodesGraaljsTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@Test
|
||||
public void getNodesTest1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
List<Node> nodes = FlowBus.getNodeByChainId("chain1");
|
||||
Assertions.assertEquals(5, nodes.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNodesTest2() {
|
||||
List<Node> nodes = FlowBus.getNodeByChainId("chain2");
|
||||
Assertions.assertEquals(5, nodes.size());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.script.graaljs.getnodes.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("a")
|
||||
public class ACmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("ACmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.script.graaljs.getnodes.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("b")
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.script.graaljs.getnodes.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("c")
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=getnodes/flow.xml
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="s1" name="普通脚本1" type="script" language="js">
|
||||
<![CDATA[
|
||||
var a=1;
|
||||
var b=2;
|
||||
var c=3;
|
||||
defaultContext.setData("s1",a+b+c);
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s2" name="普通脚本2" type="script" language="js">
|
||||
<![CDATA[
|
||||
var a=1;
|
||||
var b=2;
|
||||
var c=3;
|
||||
defaultContext.setData("s2",a*b+c);
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(a, b, c, s1, s2);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(a, WHEN(b, c), WHEN(s1, s2));
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user