bug #IADIXE [bug]使用迭代循环组件,下游getCurrLoopObj()获取为null

This commit is contained in:
everywhere.z
2024-07-23 23:04:06 +08:00
parent 702f30c0ff
commit 3634b92d0f
5 changed files with 80 additions and 0 deletions

View File

@@ -26,8 +26,10 @@ import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.util.ElRegexUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
/**
* Chain基于代码形式的组装器 EL表达式规则专属组装器
@@ -372,6 +374,21 @@ public class LiteFlowChainELBuilder {
// 放入当前主chain的ID
context.put(ChainConstant.CURR_CHAIN_ID, chain.getChainId());
// 只有当PARSE_ONE_ON_FIRST_EXEC时才会执行这个方法
// 那么会有一种级联的情况这个EL中含有其他的chain如果这时候不先解析其他chain就到导致诸如循环场景无法设置index或者obj的情况
// 所以这里要判断表达式里有没有其他的chain如果有进行先行解析
String[] itemArray = EXPRESS_RUNNER.getOutVarNames(chain.getEl());
Arrays.stream(itemArray).forEach(item -> {
if (FlowBus.containChain(item)){
Chain itemChain = FlowBus.getChain(item);
if (!itemChain.isCompiled()){
buildUnCompileChain(FlowBus.getChain(item));
}
}
});
// 解析el成为一个Condition
// 为什么这里只是一个Condition而不是一个List<Condition>呢
// 这里无论多复杂的外面必定有一个最外层的Condition所以这里只有一个内部可以嵌套很多层这点和以前的不太一样

View File

@@ -0,0 +1,35 @@
package com.yomahub.liteflow.test.iterator;
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;
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;
import java.util.List;
@TestPropertySource(value = "classpath:/iterator/application_IADIXE.properties")
@SpringBootTest(classes = IteratorCase_IADIXE.class)
@EnableAutoConfiguration
@ComponentScan({ "com.yomahub.liteflow.test.iterator.cmp" })
public class IteratorCase_IADIXE extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
// 最简单的情况
@Test
public void testIt1() throws Exception {
List<String> list = ListUtil.toList("1", "2", "3");
LiteflowResponse response = flowExecutor.execute2Resp("chain1", list);
Assertions.assertTrue(response.isSuccess());
}
}

View File

@@ -0,0 +1,14 @@
package com.yomahub.liteflow.test.iterator.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("d")
public class DCmp extends NodeComponent {
@Override
public void process() throws Exception {
System.out.println(this.getCurrLoopObj().toString());
}
}

View File

@@ -0,0 +1,2 @@
liteflow.rule-source=iterator/flow_IADIXE.xml
liteflow.parse-mode=PARSE_ONE_ON_FIRST_EXEC

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE flow PUBLIC "liteflow" "liteflow.dtd">
<flow>
<chain name="chain1">
ITERATOR(it).DO(chain2);
</chain>
<chain name="chain2">
THEN(c,d);
</chain>
</flow>