Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #I5IA5U 提供节点包装语法+替补节点的功能,增加el表达式来完成
- Loading branch information
Showing
14 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/NodeOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.yomahub.liteflow.builder.el.operator; | ||
|
||
import cn.hutool.core.util.ArrayUtil; | ||
import cn.hutool.core.util.ObjectUtil; | ||
import cn.hutool.core.util.StrUtil; | ||
import com.ql.util.express.Operator; | ||
import com.yomahub.liteflow.flow.FlowBus; | ||
import com.yomahub.liteflow.flow.element.Node; | ||
import com.yomahub.liteflow.property.LiteflowConfig; | ||
import com.yomahub.liteflow.property.LiteflowConfigGetter; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* EL规则中的node的操作符 | ||
* @author Bryan.Zhang | ||
* @since 2.8.3 | ||
*/ | ||
public class NodeOperator extends Operator { | ||
|
||
private final Logger LOG = LoggerFactory.getLogger(this.getClass()); | ||
|
||
@Override | ||
public Object executeInner(Object[] objects) throws Exception { | ||
if (ArrayUtil.isEmpty(objects)){ | ||
throw new Exception(); | ||
} | ||
|
||
if (objects.length != 1){ | ||
LOG.error("parameter error"); | ||
throw new Exception(); | ||
} | ||
|
||
String nodeId; | ||
if (objects[0] instanceof String){ | ||
nodeId = (String) objects[0]; | ||
}else{ | ||
LOG.error("The value must be Node item!"); | ||
throw new Exception(); | ||
} | ||
|
||
if (FlowBus.containNode(nodeId)){ | ||
return FlowBus.getNode(nodeId); | ||
}else{ | ||
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); | ||
if (StrUtil.isNotBlank(liteflowConfig.getSubstituteCmpClass())){ | ||
Node substituteNode = FlowBus.getNodeMap().values().stream().filter(node | ||
-> node.getInstance().getClass().getName().equals(liteflowConfig.getSubstituteCmpClass())).findFirst().orElse(null); | ||
if (ObjectUtil.isNotNull(substituteNode)){ | ||
return substituteNode; | ||
}else{ | ||
String error = StrUtil.format("This node[{}] cannot be found", nodeId); | ||
LOG.error(error); | ||
throw new Exception(); | ||
} | ||
}else{ | ||
String error = StrUtil.format("This node[{}] cannot be found, or you can configure an substitute node", nodeId); | ||
LOG.error(error); | ||
throw new Exception(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...boot/src/test/java/com/yomahub/liteflow/test/substituteNode/SubstituteSpringbootTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.yomahub.liteflow.test.substituteNode; | ||
|
||
import com.yomahub.liteflow.core.FlowExecutor; | ||
import com.yomahub.liteflow.flow.LiteflowResponse; | ||
import com.yomahub.liteflow.test.BaseTest; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
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.junit4.SpringRunner; | ||
|
||
import javax.annotation.Resource; | ||
|
||
/** | ||
* springboot环境EL替补节点的测试 | ||
* @author Bryan.Zhang | ||
*/ | ||
@RunWith(SpringRunner.class) | ||
@TestPropertySource(value = "classpath:/substituteNode/application.properties") | ||
@SpringBootTest(classes = SubstituteSpringbootTest.class) | ||
@EnableAutoConfiguration | ||
@ComponentScan({"com.yomahub.liteflow.test.substituteNode.cmp"}) | ||
public class SubstituteSpringbootTest extends BaseTest { | ||
|
||
@Resource | ||
private FlowExecutor flowExecutor; | ||
|
||
//最简单的情况 | ||
@Test | ||
public void testSub1() throws Exception{ | ||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); | ||
Assert.assertTrue(response.isSuccess()); | ||
} | ||
|
||
//有替补节点 | ||
@Test | ||
public void testSub2() throws Exception{ | ||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); | ||
Assert.assertTrue(response.isSuccess()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...stcase-el-springboot/src/test/java/com/yomahub/liteflow/test/substituteNode/cmp/ACmp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.substituteNode.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!"); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...stcase-el-springboot/src/test/java/com/yomahub/liteflow/test/substituteNode/cmp/BCmp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.substituteNode.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!"); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...stcase-el-springboot/src/test/java/com/yomahub/liteflow/test/substituteNode/cmp/CCmp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.substituteNode.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!"); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...case-el-springboot/src/test/java/com/yomahub/liteflow/test/substituteNode/cmp/SubCmp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.substituteNode.cmp; | ||
|
||
import com.yomahub.liteflow.core.NodeComponent; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component("sub") | ||
public class SubCmp extends NodeComponent { | ||
|
||
@Override | ||
public void process() { | ||
System.out.println("SubCmp executed!"); | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
.../liteflow-testcase-el-springboot/src/test/resources/substituteNode/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
liteflow.rule-source=substituteNode/flow.el.xml | ||
liteflow.substitute-cmp-class=com.yomahub.liteflow.test.substituteNode.cmp.SubCmp |
10 changes: 10 additions & 0 deletions
10
...testcase-el/liteflow-testcase-el-springboot/src/test/resources/substituteNode/flow.el.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<flow> | ||
<chain name="chain1"> | ||
THEN(node("a"), node("b"), node("c")); | ||
</chain> | ||
|
||
<chain name="chain2"> | ||
THEN(node("a"), node("b"), node("93-nodeTEST")); | ||
</chain> | ||
</flow> |