mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-23 18:48:09 +08:00
enhancement #I5U1FH 去除老的表达式的支持,精简代码
This commit is contained in:
@@ -1,158 +0,0 @@
|
||||
package com.yomahub.liteflow.builder;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.flow.element.Chain;
|
||||
import com.yomahub.liteflow.flow.element.condition.*;
|
||||
import com.yomahub.liteflow.builder.entity.ExecutableEntity;
|
||||
import com.yomahub.liteflow.flow.element.Node;
|
||||
import com.yomahub.liteflow.enums.ConditionTypeEnum;
|
||||
import com.yomahub.liteflow.exception.ExecutableItemNotFoundException;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.parser.RegexEntity;
|
||||
import com.yomahub.liteflow.parser.RegexNodeEntity;
|
||||
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Condition基于代码形式的组装器
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.6.8
|
||||
*/
|
||||
public class LiteFlowConditionBuilder {
|
||||
|
||||
protected Condition condition;
|
||||
|
||||
public static LiteFlowConditionBuilder createCondition(ConditionTypeEnum conditionType){
|
||||
switch (conditionType){
|
||||
case TYPE_THEN:
|
||||
return createThenCondition();
|
||||
case TYPE_WHEN:
|
||||
return createWhenCondition();
|
||||
case TYPE_PRE:
|
||||
return createPreCondition();
|
||||
case TYPE_FINALLY:
|
||||
return createFinallyCondition();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static LiteFlowConditionBuilder createThenCondition(){
|
||||
return new LiteFlowConditionBuilder(new ThenCondition());
|
||||
}
|
||||
|
||||
public static LiteFlowWhenConditionBuilder createWhenCondition(){
|
||||
return new LiteFlowWhenConditionBuilder(new WhenCondition());
|
||||
}
|
||||
|
||||
public static LiteFlowConditionBuilder createPreCondition(){
|
||||
return new LiteFlowConditionBuilder(new PreCondition());
|
||||
}
|
||||
|
||||
public static LiteFlowConditionBuilder createFinallyCondition(){
|
||||
return new LiteFlowConditionBuilder(new FinallyCondition());
|
||||
}
|
||||
|
||||
public LiteFlowConditionBuilder(Condition condition){
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public LiteFlowConditionBuilder setValue(String value){
|
||||
if (StrUtil.isBlank(value)){
|
||||
return this;
|
||||
}
|
||||
String[] condArray = value.split(",");
|
||||
|
||||
RegexEntity regexEntity;
|
||||
String itemExpression;
|
||||
for (String s : condArray) {
|
||||
itemExpression = s.trim();
|
||||
regexEntity = RegexEntity.parse(itemExpression);
|
||||
// 先转化为执行实体对象
|
||||
ExecutableEntity executableEntity = convertExecutableEntity(regexEntity);
|
||||
// 构建节点或流程
|
||||
setExecutable(executableEntity);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
// 将正则表达式实体转化为执行实体
|
||||
private ExecutableEntity convertExecutableEntity(RegexEntity regexEntity) {
|
||||
RegexNodeEntity item = regexEntity.getItem();
|
||||
ExecutableEntity executableEntity = new ExecutableEntity(item.getId(), item.getTag());
|
||||
if (ObjectUtil.isNotNull(regexEntity.getRealItemArray())) {
|
||||
for (RegexNodeEntity realItem : regexEntity.getRealItemArray()) {
|
||||
executableEntity.addNodeCondComponent(new ExecutableEntity(realItem.getId(), realItem.getTag()));
|
||||
}
|
||||
}
|
||||
return executableEntity;
|
||||
}
|
||||
|
||||
// 设置执行节点或者流程
|
||||
public LiteFlowConditionBuilder setExecutable(ExecutableEntity executableEntity) {
|
||||
if (FlowBus.containNode(executableEntity.getId())) {
|
||||
Node node = FlowBus.copyNode(executableEntity.getId());
|
||||
node.setTag(executableEntity.getTag());
|
||||
|
||||
//如果没有条件节点,说明是普通组件,如果有条件节点,就去构建SwitchCondition
|
||||
if (CollUtil.isEmpty(executableEntity.getNodeCondComponents())) {
|
||||
this.condition.getExecutableList().add(node);
|
||||
}else{
|
||||
buildSwitchNode(node, executableEntity.getNodeCondComponents());
|
||||
}
|
||||
} else if (hasChain(executableEntity.getId())) {
|
||||
Chain chain = FlowBus.getChain(executableEntity.getId());
|
||||
this.condition.getExecutableList().add(chain);
|
||||
} else {
|
||||
//元数据没有的话,从spring上下文再取一遍
|
||||
//这部分有2个目的
|
||||
//一是为了防止标有@Lazy懒加载的组件,二是spring负责扫描,而用动态代码的形式加载组件这种情况。
|
||||
NodeComponent nodeComponent = ContextAwareHolder.loadContextAware().getBean(executableEntity.getId());
|
||||
if (ObjectUtil.isNotNull(nodeComponent)){
|
||||
FlowBus.addSpringScanNode(executableEntity.getId(), nodeComponent);
|
||||
setExecutable(executableEntity);
|
||||
} else{
|
||||
String errorMsg = StrUtil.format("executable node[{}] is not found!", executableEntity.getId());
|
||||
throw new ExecutableItemNotFoundException(errorMsg);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
// 构建条件节点
|
||||
private void buildSwitchNode(Node node, List<ExecutableEntity> executableEntities) {
|
||||
if (CollUtil.isEmpty(executableEntities)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SwitchCondition switchCondition = new SwitchCondition();
|
||||
switchCondition.setSwitchNode(node);
|
||||
|
||||
for (ExecutableEntity realItem : executableEntities) {
|
||||
if (FlowBus.containNode(realItem.getId())) {
|
||||
Node targetNode = FlowBus.copyNode(realItem.getId());
|
||||
targetNode.setTag(realItem.getTag());
|
||||
switchCondition.addTargetItem(targetNode);
|
||||
} else if (hasChain(realItem.getId())) {
|
||||
Chain chain = FlowBus.getChain(realItem.getId());
|
||||
switchCondition.addTargetItem(chain);
|
||||
} else{
|
||||
String errorMsg = StrUtil.format("executable node[{}] is not found!", realItem.getId());
|
||||
throw new ExecutableItemNotFoundException(errorMsg);
|
||||
}
|
||||
}
|
||||
this.condition.getExecutableList().add(switchCondition);
|
||||
}
|
||||
|
||||
public Condition build(){
|
||||
return this.condition;
|
||||
}
|
||||
|
||||
private boolean hasChain(String chainId){
|
||||
return FlowBus.containChain(chainId);
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package com.yomahub.liteflow.builder;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.common.LocalDefaultFlowConstant;
|
||||
import com.yomahub.liteflow.flow.element.condition.Condition;
|
||||
import com.yomahub.liteflow.flow.element.condition.WhenCondition;
|
||||
|
||||
/**
|
||||
* WhenCondition基于代码形式的组装器
|
||||
* 这个为LiteFlowConditionBuilder的子类,因为when有单独的设置项,所以区分开
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.6.8
|
||||
*/
|
||||
public class LiteFlowWhenConditionBuilder extends LiteFlowConditionBuilder{
|
||||
|
||||
public LiteFlowWhenConditionBuilder(Condition condition) {
|
||||
super(condition);
|
||||
}
|
||||
|
||||
public LiteFlowWhenConditionBuilder setErrorResume(boolean errorResume){
|
||||
WhenCondition whenCondition = (WhenCondition) this.condition;
|
||||
whenCondition.setErrorResume(errorResume);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LiteFlowWhenConditionBuilder setErrorResume(String errorResume){
|
||||
if (StrUtil.isBlank(errorResume)){
|
||||
return this;
|
||||
}
|
||||
return setErrorResume(Boolean.parseBoolean(errorResume));
|
||||
}
|
||||
|
||||
public LiteFlowWhenConditionBuilder setGroup(String group){
|
||||
WhenCondition whenCondition = (WhenCondition) this.condition;
|
||||
if (StrUtil.isBlank(group)){
|
||||
whenCondition.setGroup(LocalDefaultFlowConstant.DEFAULT);
|
||||
}else{
|
||||
whenCondition.setGroup(group);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public LiteFlowWhenConditionBuilder setAny(boolean any){
|
||||
WhenCondition whenCondition = (WhenCondition) this.condition;
|
||||
whenCondition.setAny(any);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LiteFlowWhenConditionBuilder setAny(String any){
|
||||
if (StrUtil.isBlank(any)){
|
||||
return this;
|
||||
}
|
||||
return setAny(Boolean.parseBoolean(any));
|
||||
}
|
||||
|
||||
|
||||
public LiteFlowWhenConditionBuilder setThreadExecutorClass(String executorServiceName){
|
||||
WhenCondition whenCondition = (WhenCondition) this.condition;
|
||||
if (StrUtil.isBlank(executorServiceName)) {
|
||||
return this;
|
||||
}
|
||||
whenCondition.setThreadExecutorClass(executorServiceName);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
package com.yomahub.liteflow.flow;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
@@ -20,9 +19,6 @@ import com.yomahub.liteflow.exception.ComponentCannotRegisterException;
|
||||
import com.yomahub.liteflow.exception.NullNodeTypeException;
|
||||
import com.yomahub.liteflow.flow.element.Chain;
|
||||
import com.yomahub.liteflow.flow.element.Node;
|
||||
import com.yomahub.liteflow.parser.LocalJsonFlowParser;
|
||||
import com.yomahub.liteflow.parser.LocalXmlFlowParser;
|
||||
import com.yomahub.liteflow.parser.LocalYmlFlowParser;
|
||||
import com.yomahub.liteflow.parser.el.LocalJsonFlowELParser;
|
||||
import com.yomahub.liteflow.parser.el.LocalXmlFlowELParser;
|
||||
import com.yomahub.liteflow.parser.el.LocalYmlFlowELParser;
|
||||
@@ -315,13 +311,7 @@ public class FlowBus {
|
||||
}
|
||||
|
||||
public static void refreshFlowMetaData(FlowParserTypeEnum type, String content) throws Exception {
|
||||
if (type.equals(FlowParserTypeEnum.TYPE_XML)) {
|
||||
new LocalXmlFlowParser().parse(content);
|
||||
} else if (type.equals(FlowParserTypeEnum.TYPE_JSON)) {
|
||||
new LocalJsonFlowParser().parse(content);
|
||||
} else if (type.equals(FlowParserTypeEnum.TYPE_YML)) {
|
||||
new LocalYmlFlowParser().parse(content);
|
||||
} else if (type.equals(FlowParserTypeEnum.TYPE_EL_XML)) {
|
||||
if (type.equals(FlowParserTypeEnum.TYPE_EL_XML)) {
|
||||
new LocalXmlFlowELParser().parse(content);
|
||||
} else if (type.equals(FlowParserTypeEnum.TYPE_EL_JSON)) {
|
||||
new LocalJsonFlowELParser().parse(content);
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.yomahub.liteflow.parser;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 基于自定义的Json方式解析器
|
||||
* @author guodongqing
|
||||
* @since 1.2.5
|
||||
*/
|
||||
public abstract class ClassJsonFlowParser extends JsonFlowParser {
|
||||
@Override
|
||||
public void parseMain(List<String> pathList) throws Exception {
|
||||
String content = parseCustom();
|
||||
parse(content);
|
||||
}
|
||||
|
||||
public abstract String parseCustom();
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.yomahub.liteflow.parser;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 基于自定义的xml方式解析器
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
public abstract class ClassXmlFlowParser extends XmlFlowParser {
|
||||
@Override
|
||||
public void parseMain(List<String> pathList) throws Exception {
|
||||
String content = parseCustom();
|
||||
parse(content);
|
||||
}
|
||||
|
||||
public abstract String parseCustom();
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.yomahub.liteflow.parser;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 基于自定义的Yml方式解析器
|
||||
* @author guodongqing
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public abstract class ClassYmlFlowParser extends YmlFlowParser{
|
||||
@Override
|
||||
public void parseMain(List<String> pathList) throws Exception {
|
||||
String content = parseCustom();
|
||||
parse(content);
|
||||
}
|
||||
|
||||
public abstract String parseCustom();
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.yomahub.liteflow.parser;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.yomahub.liteflow.parser.base.BaseJsonFlowParser;
|
||||
import com.yomahub.liteflow.parser.helper.ParserHelper;
|
||||
|
||||
/**
|
||||
* Json格式解析器
|
||||
*
|
||||
* @author guodongqing
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public abstract class JsonFlowParser extends BaseJsonFlowParser {
|
||||
|
||||
/**
|
||||
* 解析一个chain的过程
|
||||
*/
|
||||
@Override
|
||||
public void parseOneChain(JsonNode chainObject) {
|
||||
ParserHelper.parseOneChain(chainObject);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.yomahub.liteflow.parser;
|
||||
|
||||
import com.yomahub.liteflow.spi.holder.PathContentParserHolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author guodongqing
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public class LocalJsonFlowParser extends JsonFlowParser{
|
||||
|
||||
@Override
|
||||
public void parseMain(List<String> pathList) throws Exception {
|
||||
List<String> contentList = PathContentParserHolder.loadContextAware().parseContent(pathList);
|
||||
parse(contentList);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.parser;
|
||||
|
||||
import com.yomahub.liteflow.spi.holder.PathContentParserHolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 基于本地的xml方式解析器
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
public class LocalXmlFlowParser extends XmlFlowParser{
|
||||
|
||||
@Override
|
||||
public void parseMain(List<String> pathList) throws Exception {
|
||||
List<String> contentList = PathContentParserHolder.loadContextAware().parseContent(pathList);
|
||||
parse(contentList);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.yomahub.liteflow.parser;
|
||||
|
||||
import com.yomahub.liteflow.spi.holder.PathContentParserHolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Yaml格式转换
|
||||
*
|
||||
* @author guodongqing
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public class LocalYmlFlowParser extends YmlFlowParser {
|
||||
|
||||
@Override
|
||||
public void parseMain(List<String> pathList) throws Exception {
|
||||
List<String> contentList = PathContentParserHolder.loadContextAware().parseContent(pathList);
|
||||
parse(contentList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.parser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 正则实体,主要用于条件节点
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
public class RegexEntity {
|
||||
|
||||
private static final Pattern p = Pattern.compile("[^\\)\\(]+");
|
||||
|
||||
private RegexNodeEntity item;
|
||||
|
||||
private RegexNodeEntity[] realItemArray;
|
||||
|
||||
public static RegexEntity parse(String nodeStr){
|
||||
List<String> list = new ArrayList<String>();
|
||||
Matcher m = p.matcher(nodeStr);
|
||||
while(m.find()){
|
||||
list.add(m.group());
|
||||
}
|
||||
|
||||
RegexEntity regexEntity = new RegexEntity();
|
||||
regexEntity.setItem(RegexNodeEntity.parse(list.get(0)));
|
||||
try{
|
||||
String[] array = list.get(1).split("\\|");
|
||||
|
||||
List<RegexNodeEntity> regexNodeEntityList
|
||||
= Arrays.stream(array).map(s -> RegexNodeEntity.parse(s.trim())).collect(Collectors.toList());
|
||||
|
||||
regexEntity.setRealItemArray(regexNodeEntityList.toArray(new RegexNodeEntity[]{}));
|
||||
}catch (Exception ignored){}
|
||||
return regexEntity;
|
||||
}
|
||||
|
||||
public RegexNodeEntity getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(RegexNodeEntity item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public RegexNodeEntity[] getRealItemArray() {
|
||||
return realItemArray;
|
||||
}
|
||||
|
||||
public void setRealItemArray(RegexNodeEntity[] realItemArray) {
|
||||
this.realItemArray = realItemArray;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.yomahub.liteflow.parser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 节点解析,主要用于解析节点name的重命名
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.6.2
|
||||
*/
|
||||
public class RegexNodeEntity {
|
||||
|
||||
private static final Pattern p = Pattern.compile("[^\\[\\]]+");
|
||||
|
||||
private String id;
|
||||
|
||||
private String tag;
|
||||
|
||||
public static RegexNodeEntity parse(String itemStr){
|
||||
List<String> list = new ArrayList<String>();
|
||||
Matcher m = p.matcher(itemStr);
|
||||
while(m.find()){
|
||||
list.add(m.group());
|
||||
}
|
||||
|
||||
RegexNodeEntity regexNodeEntity = new RegexNodeEntity();
|
||||
regexNodeEntity.setId(list.get(0));
|
||||
try{
|
||||
regexNodeEntity.setTag(list.get(1));
|
||||
}catch (Exception ignored){}
|
||||
return regexNodeEntity;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.yomahub.liteflow.parser;
|
||||
|
||||
import com.yomahub.liteflow.parser.base.BaseXmlFlowParser;
|
||||
import com.yomahub.liteflow.parser.helper.ParserHelper;
|
||||
import org.dom4j.Element;
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* xml形式的解析器
|
||||
*
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
public abstract class XmlFlowParser extends BaseXmlFlowParser {
|
||||
|
||||
/**
|
||||
* 解析一个chain的过程
|
||||
*/
|
||||
@Override
|
||||
public void parseOneChain(Element e) {
|
||||
ParserHelper.parseOneChain(e);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.yomahub.liteflow.parser;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.yomahub.liteflow.parser.base.BaseYmlFlowParser;
|
||||
import com.yomahub.liteflow.parser.helper.ParserHelper;
|
||||
|
||||
/**
|
||||
* Yml格式解析器,转换为json格式进行解析
|
||||
* @author guodongqing
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public abstract class YmlFlowParser extends BaseYmlFlowParser {
|
||||
|
||||
/**
|
||||
* 解析一个chain的过程
|
||||
*/
|
||||
@Override
|
||||
public void parseOneChain(JsonNode chainObject) {
|
||||
ParserHelper.parseOneChain(chainObject);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.yomahub.liteflow.parser.el;
|
||||
|
||||
import com.yomahub.liteflow.parser.JsonFlowParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.yomahub.liteflow.parser.factory;
|
||||
|
||||
import com.yomahub.liteflow.parser.JsonFlowParser;
|
||||
import com.yomahub.liteflow.parser.XmlFlowParser;
|
||||
import com.yomahub.liteflow.parser.YmlFlowParser;
|
||||
import com.yomahub.liteflow.parser.base.BaseJsonFlowParser;
|
||||
import com.yomahub.liteflow.parser.base.BaseXmlFlowParser;
|
||||
import com.yomahub.liteflow.parser.base.BaseYmlFlowParser;
|
||||
@@ -19,24 +16,6 @@ import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
*/
|
||||
public class ClassParserFactory implements FlowParserFactory {
|
||||
|
||||
@Override
|
||||
public JsonFlowParser createJsonParser(String path) {
|
||||
Class<?> c = forName(path);
|
||||
return (JsonFlowParser) ContextAwareHolder.loadContextAware().registerBean(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlFlowParser createXmlParser(String path) {
|
||||
Class<?> c = forName(path);
|
||||
return (XmlFlowParser) ContextAwareHolder.loadContextAware().registerBean(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YmlFlowParser createYmlParser(String path) {
|
||||
Class<?> c = forName(path);
|
||||
return (YmlFlowParser) ContextAwareHolder.loadContextAware().registerBean(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseJsonFlowParser createJsonELParser(String path) {
|
||||
Class<?> c = forName(path);
|
||||
|
||||
@@ -12,12 +12,6 @@ import com.yomahub.liteflow.parser.base.BaseYmlFlowParser;
|
||||
*/
|
||||
public interface FlowParserFactory {
|
||||
|
||||
BaseJsonFlowParser createJsonParser(String path);
|
||||
|
||||
BaseXmlFlowParser createXmlParser(String path);
|
||||
|
||||
BaseYmlFlowParser createYmlParser(String path);
|
||||
|
||||
BaseJsonFlowParser createJsonELParser(String path);
|
||||
|
||||
BaseXmlFlowParser createXmlELParser(String path);
|
||||
|
||||
@@ -4,9 +4,6 @@ import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.exception.ErrorSupportPathException;
|
||||
import com.yomahub.liteflow.parser.ClassJsonFlowParser;
|
||||
import com.yomahub.liteflow.parser.ClassXmlFlowParser;
|
||||
import com.yomahub.liteflow.parser.ClassYmlFlowParser;
|
||||
import com.yomahub.liteflow.parser.base.FlowParser;
|
||||
import com.yomahub.liteflow.parser.el.ClassJsonFlowELParser;
|
||||
import com.yomahub.liteflow.parser.el.ClassXmlFlowELParser;
|
||||
@@ -49,9 +46,9 @@ public class FlowParserProvider {
|
||||
*/
|
||||
private static final Map<Predicate<String>, Function<String, FlowParser>> LOCAL_PARSER_DICT =
|
||||
new HashMap<Predicate<String>, Function<String, FlowParser>>() {{
|
||||
put(path -> ReUtil.isMatch(LOCAL_XML_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createXmlParser);
|
||||
put(path -> ReUtil.isMatch(LOCAL_JSON_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createJsonParser);
|
||||
put(path -> ReUtil.isMatch(LOCAL_YML_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createYmlParser);
|
||||
put(path -> ReUtil.isMatch(LOCAL_XML_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createXmlELParser);
|
||||
put(path -> ReUtil.isMatch(LOCAL_JSON_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createJsonELParser);
|
||||
put(path -> ReUtil.isMatch(LOCAL_YML_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createYmlELParser);
|
||||
put(path -> ReUtil.isMatch(LOCAL_EL_XML_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createXmlELParser);
|
||||
put(path -> ReUtil.isMatch(LOCAL_EL_JSON_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createJsonELParser);
|
||||
put(path -> ReUtil.isMatch(LOCAL_EL_YML_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createYmlELParser);
|
||||
@@ -68,9 +65,6 @@ public class FlowParserProvider {
|
||||
*/
|
||||
private static final Map<Predicate<Class<?>>, Function<String, FlowParser>> CLASS_PARSER_DICT =
|
||||
new HashMap<Predicate<Class<?>>, Function<String, FlowParser>>() {{
|
||||
put(ClassXmlFlowParser.class::isAssignableFrom, CLASS_PARSER_FACTORY::createXmlParser);
|
||||
put(ClassJsonFlowParser.class::isAssignableFrom, CLASS_PARSER_FACTORY::createJsonParser);
|
||||
put(ClassYmlFlowParser.class::isAssignableFrom, CLASS_PARSER_FACTORY::createYmlParser);
|
||||
put(ClassXmlFlowELParser.class::isAssignableFrom, CLASS_PARSER_FACTORY::createXmlELParser);
|
||||
put(ClassJsonFlowELParser.class::isAssignableFrom, CLASS_PARSER_FACTORY::createJsonELParser);
|
||||
put(ClassYmlFlowELParser.class::isAssignableFrom, CLASS_PARSER_FACTORY::createYmlELParser);
|
||||
|
||||
@@ -11,21 +11,6 @@ import com.yomahub.liteflow.parser.el.*;
|
||||
*/
|
||||
public class LocalParserFactory implements FlowParserFactory {
|
||||
|
||||
@Override
|
||||
public JsonFlowParser createJsonParser(String path) {
|
||||
return new LocalJsonFlowParser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlFlowParser createXmlParser(String path) {
|
||||
return new LocalXmlFlowParser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public YmlFlowParser createYmlParser(String path) {
|
||||
return new LocalYmlFlowParser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonFlowELParser createJsonELParser(String path) {
|
||||
return new LocalJsonFlowELParser();
|
||||
|
||||
@@ -3,30 +3,23 @@ package com.yomahub.liteflow.parser.helper;
|
||||
import cn.hutool.core.annotation.AnnotationUtil;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.yomahub.liteflow.annotation.*;
|
||||
import com.yomahub.liteflow.builder.LiteFlowChainBuilder;
|
||||
import com.yomahub.liteflow.builder.LiteFlowConditionBuilder;
|
||||
import com.yomahub.liteflow.builder.LiteFlowNodeBuilder;
|
||||
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
|
||||
import com.yomahub.liteflow.builder.prop.ChainPropBean;
|
||||
import com.yomahub.liteflow.builder.prop.NodePropBean;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.core.NodeIfComponent;
|
||||
import com.yomahub.liteflow.core.NodeSwitchComponent;
|
||||
import com.yomahub.liteflow.enums.ConditionTypeEnum;
|
||||
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||
import com.yomahub.liteflow.exception.*;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.util.JsonUtil;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -140,48 +133,6 @@ public class ParserHelper {
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建 chain
|
||||
*
|
||||
* @param chainPropBean 构建 chain 的中间属性
|
||||
* @param chainBuilder chainBuilder
|
||||
*/
|
||||
public static void buildChain(ChainPropBean chainPropBean, LiteFlowChainBuilder chainBuilder) {
|
||||
String condValueStr = chainPropBean.getCondValueStr();
|
||||
String group = chainPropBean.getGroup();
|
||||
String errorResume = chainPropBean.getErrorResume();
|
||||
String any = chainPropBean.getAny();
|
||||
String threadExecutorClass = chainPropBean.getThreadExecutorClass();
|
||||
ConditionTypeEnum conditionType = chainPropBean.getConditionType();
|
||||
|
||||
if (ObjectUtil.isNull(conditionType)) {
|
||||
throw new NotSupportConditionException("ConditionType is not supported");
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(condValueStr)) {
|
||||
throw new EmptyConditionValueException("Condition value cannot be empty");
|
||||
}
|
||||
|
||||
//如果是when类型的话,有特殊化参数要设置,只针对于when的
|
||||
if (conditionType.equals(ConditionTypeEnum.TYPE_WHEN)) {
|
||||
chainBuilder.setCondition(
|
||||
LiteFlowConditionBuilder.createWhenCondition()
|
||||
.setErrorResume(errorResume)
|
||||
.setGroup(group)
|
||||
.setAny(any)
|
||||
.setThreadExecutorClass(threadExecutorClass)
|
||||
.setValue(condValueStr)
|
||||
.build()
|
||||
).build();
|
||||
} else {
|
||||
chainBuilder.setCondition(
|
||||
LiteFlowConditionBuilder.createCondition(conditionType)
|
||||
.setValue(condValueStr)
|
||||
.build()
|
||||
).build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xml 形式的主要解析过程
|
||||
*
|
||||
@@ -307,83 +258,6 @@ public class ParserHelper {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解析一个chain的过程
|
||||
*
|
||||
* @param chainNode chain 节点
|
||||
*/
|
||||
public static void parseOneChain(JsonNode chainNode) {
|
||||
String condValueStr;
|
||||
ConditionTypeEnum conditionType;
|
||||
String group;
|
||||
String errorResume;
|
||||
String any;
|
||||
String threadExecutorClass;
|
||||
|
||||
//构建chainBuilder
|
||||
String chainName = chainNode.get(NAME).textValue();
|
||||
LiteFlowChainBuilder chainBuilder = LiteFlowChainBuilder.createChain().setChainName(chainName);
|
||||
Iterator<JsonNode> iterator = chainNode.get(CONDITION).iterator();
|
||||
while (iterator.hasNext()) {
|
||||
JsonNode condNode = iterator.next();
|
||||
conditionType = ConditionTypeEnum.getEnumByCode(condNode.get(TYPE).textValue());
|
||||
condValueStr = condNode.get(VALUE).textValue();
|
||||
errorResume = condNode.hasNonNull(ERROR_RESUME) ? condNode.get(ERROR_RESUME).textValue() : "";
|
||||
group = condNode.hasNonNull(GROUP) ? condNode.get(GROUP).textValue() : "";
|
||||
any = condNode.hasNonNull(ANY) ? condNode.get(ANY).textValue() : "";
|
||||
threadExecutorClass = condNode.hasNonNull(THREAD_EXECUTOR_CLASS) ? condNode.get(THREAD_EXECUTOR_CLASS).textValue() : "";
|
||||
|
||||
ChainPropBean chainPropBean = new ChainPropBean()
|
||||
.setCondValueStr(condValueStr)
|
||||
.setGroup(group)
|
||||
.setErrorResume(errorResume)
|
||||
.setAny(any)
|
||||
.setThreadExecutorClass(threadExecutorClass)
|
||||
.setConditionType(conditionType);
|
||||
|
||||
// 构建 chain
|
||||
ParserHelper.buildChain(chainPropBean, chainBuilder);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 解析一个chain的过程
|
||||
* @param e chain 节点
|
||||
*/
|
||||
public static void parseOneChain(Element e) {
|
||||
String condValueStr;
|
||||
String group;
|
||||
String errorResume;
|
||||
String any;
|
||||
String threadExecutorClass;
|
||||
ConditionTypeEnum conditionType;
|
||||
|
||||
//构建chainBuilder
|
||||
String chainName = e.attributeValue(NAME);
|
||||
LiteFlowChainBuilder chainBuilder = LiteFlowChainBuilder.createChain().setChainName(chainName);
|
||||
|
||||
for (Iterator<Element> it = e.elementIterator(); it.hasNext(); ) {
|
||||
Element condE = it.next();
|
||||
conditionType = ConditionTypeEnum.getEnumByCode(condE.getName());
|
||||
condValueStr = condE.attributeValue(VALUE);
|
||||
errorResume = condE.attributeValue(ERROR_RESUME);
|
||||
group = condE.attributeValue(GROUP);
|
||||
any = condE.attributeValue(ANY);
|
||||
threadExecutorClass = condE.attributeValue(THREAD_EXECUTOR_CLASS);
|
||||
|
||||
ChainPropBean chainPropBean = new ChainPropBean()
|
||||
.setCondValueStr(condValueStr)
|
||||
.setGroup(group)
|
||||
.setErrorResume(errorResume)
|
||||
.setAny(any)
|
||||
.setThreadExecutorClass(threadExecutorClass)
|
||||
.setConditionType(conditionType);
|
||||
|
||||
// 构建 chain
|
||||
ParserHelper.buildChain(chainPropBean, chainBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析一个chain的过程
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user