mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
enhancement #ICO3IK 在switch节点中,希望能拿到target的列表信息
This commit is contained in:
@@ -7,9 +7,18 @@
|
||||
*/
|
||||
package com.yomahub.liteflow.core;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.yomahub.liteflow.flow.element.Condition;
|
||||
import com.yomahub.liteflow.flow.element.Executable;
|
||||
import com.yomahub.liteflow.flow.element.condition.SwitchCondition;
|
||||
import com.yomahub.liteflow.slot.DataBus;
|
||||
import com.yomahub.liteflow.core.proxy.LiteFlowProxyUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 条件路由节点抽象类
|
||||
*
|
||||
@@ -32,4 +41,13 @@ public abstract class NodeSwitchComponent extends NodeComponent {
|
||||
return DataBus.getSlot(slotIndex).getSwitchResult(this.getMetaValueKey());
|
||||
}
|
||||
|
||||
public List<String> getTargetList(){
|
||||
Condition condition = this.getSlot().getCurrentCondition();
|
||||
if (condition instanceof SwitchCondition){
|
||||
return ((SwitchCondition)condition).getTargetList().stream().map(Executable::getId).collect(Collectors.toList());
|
||||
}else{
|
||||
return ListUtil.empty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,11 +55,9 @@ public class SwitchCondition extends Condition {
|
||||
String[] target = targetId.split(TAG_FLAG, 2);
|
||||
String _targetId = target[0];
|
||||
String _targetTag = target[1];
|
||||
targetExecutor = targetList.stream().filter(executable -> {
|
||||
return (StrUtil.startWith(_targetId, TAG_PREFIX) && ObjectUtil.equal(_targetTag,executable.getTag()))
|
||||
|| ((StrUtil.isEmpty(_targetId) || _targetId.equals(executable.getId()))
|
||||
&& (StrUtil.isEmpty(_targetTag) || _targetTag.equals(executable.getTag())));
|
||||
}).findFirst().orElse(null);
|
||||
targetExecutor = targetList.stream().filter(executable -> (StrUtil.startWith(_targetId, TAG_PREFIX) && ObjectUtil.equal(_targetTag,executable.getTag()))
|
||||
|| ((StrUtil.isEmpty(_targetId) || _targetId.equals(executable.getId()))
|
||||
&& (StrUtil.isEmpty(_targetTag) || _targetTag.equals(executable.getTag())))).findFirst().orElse(null);
|
||||
}
|
||||
else {
|
||||
targetExecutor = targetList.stream()
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.yomahub.liteflow.test.switchcase;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -11,6 +14,7 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* springboot环境EL常规的例子测试
|
||||
@@ -119,4 +123,15 @@ public class SwitchELSpringbootTest extends BaseTest {
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
// 获取targetList
|
||||
@Test
|
||||
public void testSwitch14() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain14", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
List<String> targetList = context.getData("targetList");
|
||||
boolean flag = CollectionUtil.isEqualList(targetList, ListUtil.toList("sub1", "d", "a", "chain10"));
|
||||
Assertions.assertTrue(flag);
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package com.yomahub.liteflow.test.switchcase.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeSwitchComponent;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("e")
|
||||
@@ -15,6 +16,9 @@ public class ESwitchCmp extends NodeSwitchComponent {
|
||||
|
||||
@Override
|
||||
public String processSwitch() throws Exception {
|
||||
DefaultContext context = this.getFirstContextBean();
|
||||
context.setData("targetList", this.getTargetList());
|
||||
|
||||
return "d";
|
||||
}
|
||||
|
||||
|
||||
@@ -83,4 +83,8 @@
|
||||
<chain name="sub1">
|
||||
THEN(a);
|
||||
</chain>
|
||||
|
||||
<chain name="chain14">
|
||||
SWITCH(e).TO(sub1, d, a, chain10);
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user