mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
Merge branch 'v2.5.0-SNAPSHOT' of https://gitee.com/dromara/liteFlow into v2.5.0-SNAPSHOT
This commit is contained in:
@@ -19,13 +19,17 @@ public class Condition {
|
||||
// 增加errorResume属性,以区分当when调用链调用失败时是否继续往下执行 默认true继续执行
|
||||
private boolean errorResume = true;
|
||||
// 增加groupId属性,用于不同node进行同组合并
|
||||
private String groupId = LocalDefaultFlowConstant.DEFAULT;
|
||||
private String group = LocalDefaultFlowConstant.DEFAULT;
|
||||
// condition 类型 参数:ConditionTypeEnum 包含:then when
|
||||
private String conditionType;
|
||||
|
||||
private List<Executable> nodeList;
|
||||
|
||||
public Condition(List<Executable> nodeList) {
|
||||
this.nodeList = nodeList;
|
||||
}
|
||||
public Condition() {
|
||||
}
|
||||
|
||||
public List<Executable> getNodeList() {
|
||||
return nodeList;
|
||||
@@ -43,11 +47,19 @@ public class Condition {
|
||||
this.errorResume = errorResume;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public String getConditionType() {
|
||||
return conditionType;
|
||||
}
|
||||
|
||||
public void setConditionType(String conditionType) {
|
||||
this.conditionType = conditionType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,4 +19,11 @@ public class ThenCondition extends Condition {
|
||||
super(nodeList);
|
||||
}
|
||||
|
||||
public ThenCondition(Condition condition){
|
||||
super(condition.getNodeList());
|
||||
super.setConditionType(condition.getConditionType());
|
||||
super.setGroup(condition.getGroup());
|
||||
super.setErrorResume(condition.isErrorResume());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,4 +26,11 @@ public class WhenCondition extends Condition{
|
||||
super.setErrorResume(errorResume);
|
||||
}
|
||||
|
||||
public WhenCondition(Condition condition) {
|
||||
super(condition.getNodeList());
|
||||
super.setConditionType(condition.getConditionType());
|
||||
super.setGroup(condition.getGroup());
|
||||
super.setErrorResume(condition.isErrorResume());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.yomahub.liteflow.enums;
|
||||
|
||||
public enum ConditionTypeEnum {
|
||||
TYPE_THEN("then","then"),
|
||||
TYPE_WHEN("when","when")
|
||||
;
|
||||
private String type;
|
||||
private String name;
|
||||
|
||||
ConditionTypeEnum(String type, String name) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
package com.yomahub.liteflow.parser;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.yomahub.liteflow.entity.flow.Condition;
|
||||
import com.yomahub.liteflow.entity.flow.ThenCondition;
|
||||
import com.yomahub.liteflow.entity.flow.WhenCondition;
|
||||
import com.yomahub.liteflow.enums.ConditionTypeEnum;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -35,4 +41,23 @@ public abstract class FlowParser {
|
||||
return regexEntity;
|
||||
}
|
||||
|
||||
protected void buildBaseFlowConditions(List<Condition> conditionList,Condition condition){
|
||||
if (condition.getConditionType().equals(ConditionTypeEnum.TYPE_THEN.getType())) {
|
||||
if (conditionList.size() > 1 &&
|
||||
CollectionUtil.getLast(conditionList) instanceof ThenCondition) {
|
||||
CollectionUtil.getLast(conditionList).getNodeList().addAll(condition.getNodeList());
|
||||
} else {
|
||||
conditionList.add(new ThenCondition(condition));
|
||||
}
|
||||
} else if (condition.getConditionType().equals(ConditionTypeEnum.TYPE_WHEN.getType())) {
|
||||
if (conditionList.size() > 1 &&
|
||||
CollectionUtil.getLast(conditionList) instanceof WhenCondition &&
|
||||
CollectionUtil.getLast(conditionList).getGroup().equals(condition.getGroup())) {
|
||||
CollectionUtil.getLast(conditionList).getNodeList().addAll(condition.getNodeList());
|
||||
} else {
|
||||
conditionList.add(new WhenCondition(condition));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.yomahub.liteflow.common.LocalDefaultFlowConstant;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.entity.flow.*;
|
||||
import com.yomahub.liteflow.exception.ExecutableItemNotFoundException;
|
||||
@@ -105,6 +106,9 @@ public abstract class JsonFlowParser extends FlowParser{
|
||||
String[] condArray;
|
||||
List<Executable> chainNodeList;
|
||||
List<Condition> conditionList;
|
||||
String group;
|
||||
String errorResume;
|
||||
Condition condition;
|
||||
String chainName = chainObject.getString("name");
|
||||
JSONArray chainTopoArray = chainObject.getJSONArray("condition");
|
||||
conditionList = new ArrayList<>();
|
||||
@@ -112,9 +116,18 @@ public abstract class JsonFlowParser extends FlowParser{
|
||||
JSONObject condObject = (JSONObject) iterator.next();
|
||||
String condType = condObject.getString("type");
|
||||
condArrayStr = condObject.getString("value");
|
||||
group = condObject.getString("group");
|
||||
errorResume = condObject.getString("errorResume");
|
||||
if (StrUtil.isBlank(condType) || StrUtil.isBlank(condArrayStr)) {
|
||||
continue;
|
||||
}
|
||||
if (StrUtil.isBlank(group)) {
|
||||
group = LocalDefaultFlowConstant.DEFAULT;
|
||||
}
|
||||
if (StrUtil.isBlank(errorResume)) {
|
||||
errorResume = Boolean.TRUE.toString();
|
||||
}
|
||||
condition = new Condition();
|
||||
chainNodeList = new ArrayList<>();
|
||||
condArray = condArrayStr.split(",");
|
||||
RegexEntity regexEntity;
|
||||
@@ -149,14 +162,13 @@ public abstract class JsonFlowParser extends FlowParser{
|
||||
throw new ExecutableItemNotFoundException(errorMsg);
|
||||
}
|
||||
}
|
||||
if (condType.equals("then")) {
|
||||
conditionList.add(new ThenCondition(chainNodeList));
|
||||
} else if (condType.equals("when")) {
|
||||
conditionList.add(new WhenCondition(chainNodeList));
|
||||
}
|
||||
FlowBus.addChain(chainName, new Chain(chainName,conditionList));
|
||||
condition.setErrorResume(errorResume.equals(Boolean.TRUE.toString()));
|
||||
condition.setGroup(group);
|
||||
condition.setConditionType(condType);
|
||||
condition.setNodeList(chainNodeList);
|
||||
super.buildBaseFlowConditions(conditionList,condition);
|
||||
}
|
||||
|
||||
FlowBus.addChain(chainName, new Chain(chainName,conditionList));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.hutool.core.lang.PatternPool;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.yomahub.liteflow.common.LocalDefaultFlowConstant;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.entity.flow.Chain;
|
||||
@@ -106,13 +107,15 @@ public abstract class XmlFlowParser extends FlowParser{
|
||||
String[] condArray;
|
||||
String group;
|
||||
String errorResume;
|
||||
Condition condition;
|
||||
Element condE;
|
||||
List<Executable> chainNodeList;
|
||||
List<Condition> conditionList;
|
||||
|
||||
String chainName = e.attributeValue("name");
|
||||
conditionList = new ArrayList<>();
|
||||
for (Iterator<Element> it = e.elementIterator(); it.hasNext();) {
|
||||
Element condE = it.next();
|
||||
condE = it.next();
|
||||
condArrayStr = condE.attributeValue("value");
|
||||
errorResume = e.attributeValue("errorResume");
|
||||
group = e.attributeValue("group");
|
||||
@@ -125,6 +128,7 @@ public abstract class XmlFlowParser extends FlowParser{
|
||||
if (StrUtil.isBlank(errorResume)) {
|
||||
errorResume = Boolean.TRUE.toString();
|
||||
}
|
||||
condition = new Condition();
|
||||
chainNodeList = new ArrayList<>();
|
||||
condArray = condArrayStr.split(",");
|
||||
RegexEntity regexEntity;
|
||||
@@ -158,24 +162,11 @@ public abstract class XmlFlowParser extends FlowParser{
|
||||
throw new ExecutableItemNotFoundException(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (condE.getName().equals("then")) {
|
||||
if (conditionList.size() > 1 &&
|
||||
CollectionUtil.getLast(conditionList) instanceof ThenCondition ) {
|
||||
CollectionUtil.getLast(conditionList).getNodeList().addAll(chainNodeList);
|
||||
} else {
|
||||
conditionList.add(new ThenCondition(chainNodeList));
|
||||
}
|
||||
} else if (condE.getName().equals("when")) {
|
||||
if (conditionList.size() > 1 &&
|
||||
CollectionUtil.getLast(conditionList) instanceof WhenCondition &&
|
||||
CollectionUtil.getLast(conditionList).getGroupId().equals(group)) {
|
||||
CollectionUtil.getLast(conditionList).getNodeList().addAll(chainNodeList);
|
||||
} else {
|
||||
conditionList.add(new WhenCondition(chainNodeList, errorResume.equals(Boolean.TRUE.toString())));
|
||||
}
|
||||
}
|
||||
condition.setErrorResume(errorResume.equals(Boolean.TRUE.toString()));
|
||||
condition.setGroup(group);
|
||||
condition.setConditionType(condE.getName());
|
||||
condition.setNodeList(chainNodeList);
|
||||
super.buildBaseFlowConditions(conditionList,condition);
|
||||
}
|
||||
FlowBus.addChain(chainName, new Chain(chainName,conditionList));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user