feature #IBL9CK 增加bind关键字,能够在任何地方bind key和value

This commit is contained in:
everywhere.z
2025-02-10 17:29:09 +08:00
parent aa2b4d2685
commit 3bdbab8ace
5 changed files with 35 additions and 6 deletions

View File

@@ -60,4 +60,15 @@ public class BindDataSpringbootTest extends BaseTest {
Assertions.assertEquals("test", context.getData("y"));
Assertions.assertTrue(response.isSuccess());
}
// 测试bind关键字,对一个chain进行bind
@Test
public void testBind4() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
DefaultContext context = response.getFirstContextBean();
Assertions.assertEquals("test2", context.getData("a"));
Assertions.assertEquals("test2", context.getData("x"));
Assertions.assertEquals("test2", context.getData("c"));
Assertions.assertTrue(response.isSuccess());
}
}

View File

@@ -7,6 +7,7 @@
*/
package com.yomahub.liteflow.test.bindData.cmp;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@@ -18,6 +19,8 @@ public class ACmp extends NodeComponent {
public void process() {
DefaultContext context = this.getFirstContextBean();
String bindValue = this.getBindData("k1", String.class);
context.setData(this.getNodeId(), bindValue);
if (StrUtil.isNotBlank(bindValue)) {
context.setData(this.getNodeId(), bindValue);
}
}
}

View File

@@ -7,6 +7,7 @@
*/
package com.yomahub.liteflow.test.bindData.cmp;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@@ -18,7 +19,9 @@ public class CCmp extends NodeComponent {
public void process() {
DefaultContext context = this.getFirstContextBean();
String bindValue = this.getBindData("k1", String.class);
context.setData(this.getNodeId(), bindValue);
if (StrUtil.isNotBlank(bindValue)) {
context.setData(this.getNodeId(), bindValue);
}
}
}

View File

@@ -7,6 +7,7 @@
*/
package com.yomahub.liteflow.test.bindData.cmp;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@@ -18,7 +19,10 @@ public class DCmp extends NodeComponent {
public void process() {
DefaultContext context = this.getFirstContextBean();
String bindValue = this.getBindData("k1", String.class);
context.setData(this.getNodeId(), bindValue);
if (StrUtil.isNotBlank(bindValue)) {
context.setData(this.getNodeId(), bindValue);
}
}
}

View File

@@ -1,15 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE flow PUBLIC "liteflow" "liteflow.dtd">
<flow>
<chain name="chain1">
<chain id="chain1">
THEN(a.bind("k1", "test"), b);
</chain>
<chain name="chain2">
<chain id="chain2">
THEN(a,b).bind("k1","test");
</chain>
<chain name="chain3">
<chain id="chain3">
THEN(SWITCH(y).TO(d,c), WHEN(a, b), IF(x, c, d)).bind("k1", "test")
</chain>
<chain id="sub">
THEN(a,IF(NOT(x), b, c));
</chain>
<chain id="chain4">
THEN(d, sub.bind("k1", "test2"))
</chain>
</flow>