兼容SwitchComponent返回"tag:xxx"格式

This commit is contained in:
码农小易 2022-11-07 13:59:56 +08:00
parent 6edd4b34c1
commit 9162607cb0
16 changed files with 158 additions and 1 deletions

View File

@ -29,6 +29,7 @@ public class SwitchCondition extends Condition{
private final Map<String, Executable> targetMap = new HashMap<>();
private final String TAG_PREFIX = "tag";
private final String TAG_FLAG = ":";
@ -55,7 +56,7 @@ public class SwitchCondition extends Condition{
targetExecutor = targetMap.values().stream().filter(executable -> {
if (executable instanceof Node){
Node node = (Node) executable;
return (StrUtil.isEmpty(_targetId) || _targetId.equals(node.getId())) && (StrUtil.isEmpty(_targetTag) || _targetTag.equals(node.getTag()));
return (StrUtil.startWith(_targetId, TAG_PREFIX) && _targetTag.equals(node.getTag())) || ((StrUtil.isEmpty(_targetId) || _targetId.equals(node.getId())) && (StrUtil.isEmpty(_targetTag) || _targetTag.equals(node.getTag())));
}else{
return false;
}

View File

@ -57,4 +57,11 @@ public class SwitchELDeclMultiSpringbootTest extends BaseTest {
Assert.assertEquals("a==>g==>d",response.getExecuteStepStr());
}
@Test
public void testSwitch5() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>h==>b",response.getExecuteStepStr());
}
}

View File

@ -44,6 +44,11 @@ public class CmpConfig {
public String processG(NodeComponent bindCmp) {
return "d:td";
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "h",nodeType = NodeTypeEnum.SWITCH)
public String processH(NodeComponent bindCmp) {
return "tag:td";
}
}

View File

@ -28,4 +28,11 @@
SWITCH(g).to(b.tag("td"), d.tag("td"))
);
</chain>
<chain name="chain5">
THEN(
a,
SWITCH(h).to(b.tag("td"), d.tag("td"))
);
</chain>
</flow>

View File

@ -56,4 +56,11 @@ public class SwitchELDeclSpringbootTest extends BaseTest {
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>g==>d",response.getExecuteStepStr());
}
@Test
public void testSwitch5() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>h==>b",response.getExecuteStepStr());
}
}

View File

@ -0,0 +1,23 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.enums.NodeTypeEnum;
import org.springframework.stereotype.Component;
@Component("h")
public class HSwitchCmp {
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH)
public String processSwitch(NodeComponent bindCmp) throws Exception {
return "tag:td";
}
}

View File

@ -28,4 +28,11 @@
SWITCH(g).to(b.tag("td"), d.tag("td"))
);
</chain>
<chain name="chain5">
THEN(
a,
SWITCH(h).to(b.tag("td"), d.tag("td"))
);
</chain>
</flow>

View File

@ -47,4 +47,11 @@ public class SwitchTest extends BaseTest{
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>g==>d",response.getExecuteStepStr());
}
@Test
public void testSwitch5() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>h==>b",response.getExecuteStepStr());
}
}

View File

@ -0,0 +1,18 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
public class HSwitchCmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
return "tag:td";
}
}

View File

@ -8,6 +8,7 @@
<node id="e" class="com.yomahub.liteflow.test.switchcase.cmp.ESwitchCmp"/>
<node id="f" class="com.yomahub.liteflow.test.switchcase.cmp.FSwitchCmp"/>
<node id="g" class="com.yomahub.liteflow.test.switchcase.cmp.GSwitchCmp"/>
<node id="h" class="com.yomahub.liteflow.test.switchcase.cmp.HSwitchCmp"/>
</nodes>
<chain name="chain1">
@ -38,4 +39,11 @@
SWITCH(g).to(b.tag("td"), d.tag("td"))
);
</chain>
<chain name="chain5">
THEN(
a,
SWITCH(h).to(b.tag("td"), d.tag("td"))
);
</chain>
</flow>

View File

@ -58,4 +58,11 @@ public class SwitchELSpringbootTest extends BaseTest {
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>g==>d",response.getExecuteStepStr());
}
@Test
public void testSwitch5() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>h==>b",response.getExecuteStepStr());
}
}

View File

@ -0,0 +1,20 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.springframework.stereotype.Component;
@Component("h")
public class HSwitchCmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
return "tag:td";
}
}

View File

@ -28,4 +28,11 @@
SWITCH(g).to(b.tag("td"), d.tag("td"))
);
</chain>
<chain name="chain5">
THEN(
a,
SWITCH(h).to(b.tag("td"), d.tag("td"))
);
</chain>
</flow>

View File

@ -45,4 +45,10 @@ public class SwitchELSpringTest extends BaseTest {
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>g==>d",response.getExecuteStepStr());
}
@Test
public void testSwitch5() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>h==>b",response.getExecuteStepStr());
}
}

View File

@ -0,0 +1,20 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.springframework.stereotype.Component;
@Component("h")
public class HSwitchCmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
return "tag:td";
}
}

View File

@ -28,4 +28,11 @@
SWITCH(g).to(b.tag("td"), d.tag("td"))
);
</chain>
<chain name="chain5">
THEN(
a,
SWITCH(h).to(b.tag("td"), d.tag("td"))
);
</chain>
</flow>