!126 修正不规范的问题,chain的name和id混用情况

Merge pull request !126 from ousinka/master
This commit is contained in:
铂赛东 2022-11-06 03:07:56 +00:00 committed by Gitee
commit e5b35e4e00
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
10 changed files with 235 additions and 35 deletions

View File

@ -49,6 +49,13 @@ public class LiteFlowChainBuilder {
//在parser中chain的build是2段式的因为涉及到依赖问题以前是递归parser
//2.6.8之后取消了递归的模式两段式组装先把带有chainName的chain对象放进去第二段再组装chain里面的condition
//所以这里setChainName的时候需要判断下
/**
*
* @param chainName
* @return
* @deprecated 请使用 {@link #setChainId(String)}
*/
@Deprecated
public LiteFlowChainBuilder setChainName(String chainName) {
if (FlowBus.containChain(chainName)) {
this.chain = FlowBus.getChain(chainName);
@ -57,6 +64,15 @@ public class LiteFlowChainBuilder {
}
return this;
}
public LiteFlowChainBuilder setChainId(String chainId) {
if (FlowBus.containChain(chainId)) {
this.chain = FlowBus.getChain(chainId);
} else {
this.chain.setChainId(chainId);
}
return this;
}
public LiteFlowChainBuilder setCondition(Condition condition) {
//这里把condition组装进conditionList

View File

@ -86,6 +86,12 @@ public class LiteFlowChainELBuilder {
//在parser中chain的build是2段式的因为涉及到依赖问题以前是递归parser
//2.6.8之后取消了递归的模式两段式组装先把带有chainName的chain对象放进去第二段再组装chain里面的condition
//所以这里setChainName的时候需要判断下
/**
*
* @param chainName
* @return
* @deprecated 请使用 {@link #setChainId(String)}
*/
public LiteFlowChainELBuilder setChainName(String chainName) {
if (FlowBus.containChain(chainName)) {
this.chain = FlowBus.getChain(chainName);
@ -94,6 +100,15 @@ public class LiteFlowChainELBuilder {
}
return this;
}
public LiteFlowChainELBuilder setChainId(String chainId) {
if (FlowBus.containChain(chainId)) {
this.chain = FlowBus.getChain(chainId);
} else {
this.chain.setChainId(chainId);
}
return this;
}
public LiteFlowChainELBuilder setEL(String elStr) {
if (StrUtil.isBlank(elStr)) {

View File

@ -305,9 +305,17 @@ public abstract class NodeComponent{
return getSlot().getChainReqDataFromQueue(this.getCurrChainName());
}
/**
* @deprecated 请使用 {@link #getChainId()}
*/
@Deprecated
public String getChainName(){
return getSlot().getChainName();
}
public String getChainId(){
return getSlot().getChainId();
}
public String getDisplayName(){
if(StrUtil.isEmpty(this.name)){
@ -317,17 +325,43 @@ public abstract class NodeComponent{
}
}
/**
*
* @param currChainName
* @deprecated 请使用 {@link #setCurrChainId(String)}
*/
@Deprecated
public void setCurrChainName(String currChainName){
this.currChainNameTL.set(currChainName);
}
/**
* @deprecated 请使用 {@link #getCurrChainId()}
*/
@Deprecated
public String getCurrChainName(){
return this.currChainNameTL.get();
}
/**
* @deprecated 请使用 {@link #removeCurrChainId()}
*/
@Deprecated
public void removeCurrChainName(){
this.currChainNameTL.remove();
}
public void setCurrChainId(String currChainName){
this.currChainNameTL.set(currChainName);
}
public String getCurrChainId(){
return this.currChainNameTL.get();
}
public void removeCurrChainId(){
this.currChainNameTL.remove();
}
public void setCmpData(String cmpData){
this.cmpDataTL.set(cmpData);

View File

@ -29,7 +29,7 @@ public class Chain implements Executable {
private static final Logger LOG = LoggerFactory.getLogger(Chain.class);
private String chainName;
private String chainId;
private List<Condition> conditionList = new ArrayList<>();
@ -40,13 +40,13 @@ public class Chain implements Executable {
private List<Condition> finallyConditionList = new ArrayList<>();
public Chain(String chainName){
this.chainName = chainName;
this.chainId = chainName;
}
public Chain(){}
public Chain(String chainName, List<Condition> conditionList) {
this.chainName = chainName;
this.chainId = chainName;
this.conditionList = conditionList;
}
@ -58,29 +58,46 @@ public class Chain implements Executable {
this.conditionList = conditionList;
}
/**
* @deprecated 请使用{@link #getChainId()}
*/
@Deprecated
public String getChainName() {
return chainName;
return chainId;
}
/**
*
* @param chainName
* @deprecated 请使用 {@link #setChainId(String)}
*/
public void setChainName(String chainName) {
this.chainName = chainName;
this.chainId = chainName;
}
public String getChainId() {
return chainId;
}
public void setChainId(String chainId) {
this.chainId = chainId;
}
//执行chain的主方法
@Override
public void execute(Integer slotIndex) throws Exception {
if (CollUtil.isEmpty(conditionList)) {
throw new FlowSystemException("no conditionList in this chain[" + chainName + "]");
throw new FlowSystemException("no conditionList in this chain[" + chainId + "]");
}
Slot slot = DataBus.getSlot(slotIndex);
try {
//设置主ChainName
slot.setChainName(chainName);
slot.setChainId(chainId);
//执行前置
this.executePre(slotIndex);
//执行主体Condition
for (Condition condition : conditionList) {
condition.setCurrChainName(chainName);
condition.setCurrChainName(chainId);
condition.execute(slotIndex);
}
}catch (ChainEndException e){
@ -89,8 +106,8 @@ public class Chain implements Executable {
throw e;
}catch (Exception e){
//这里事先取到exception set到slot里为了方便finally取到exception
if (slot.isSubChain(chainName)){
slot.setSubException(chainName, e);
if (slot.isSubChain(chainId)){
slot.setSubException(chainId, e);
}else{
slot.setException(e);
}
@ -121,8 +138,8 @@ public class Chain implements Executable {
}
@Override
public String getExecuteName() {
return chainName;
public String getExecuteId() {
return chainId;
}
public List<Condition> getPreConditionList() {
return preConditionList;

View File

@ -18,9 +18,28 @@ public interface Executable{
ExecuteTypeEnum getExecuteType();
String getExecuteName();
/**
*
* @return
* @deprecated 请使用 {@link #getExecuteId()}
*/
@Deprecated
default String getExecuteName() {
return getExecuteId();
}
/**
*
* @param currentChainName
* @deprecated 请使用 {@link #setCurrChainId(String)}
*/
default void setCurrChainName(String currentChainName){
setCurrChainId(currentChainName);
}
String getExecuteId();
default void setCurrChainId(String currentChainId){
}
}

View File

@ -149,7 +149,7 @@ public class Node implements Executable,Cloneable{
instance.removeSlotIndex();
instance.removeIsEnd();
instance.removeTag();
instance.removeCurrChainName();
instance.removeCurrChainId();
instance.removeCmpData();
}
}
@ -182,7 +182,7 @@ public class Node implements Executable,Cloneable{
}
@Override
public String getExecuteName() {
public String getExecuteId() {
return id;
}
@ -211,8 +211,8 @@ public class Node implements Executable,Cloneable{
}
@Override
public void setCurrChainName(String currentChainName) {
instance.setCurrChainName(currentChainName);
public void setCurrChainId(String currentChainId) {
instance.setCurrChainId(currentChainId);
}
public String getCmpData() {

View File

@ -7,7 +7,6 @@
*/
package com.yomahub.liteflow.flow.element.condition;
import com.yomahub.liteflow.common.LocalDefaultFlowConstant;
import com.yomahub.liteflow.enums.ExecuteTypeEnum;
import com.yomahub.liteflow.flow.element.Executable;
import com.yomahub.liteflow.enums.ConditionTypeEnum;
@ -38,7 +37,7 @@ public abstract class Condition implements Executable{
}
@Override
public String getExecuteName() {
public String getExecuteId() {
return this.id;
}
@ -64,12 +63,22 @@ public abstract class Condition implements Executable{
this.id = id;
}
/**
*
* @return
* @deprecated 请使用 {@link #setCurrChainId(String)}
*/
@Deprecated
public String getCurrChainName() {
return currChainName;
}
public String getCurrChainId() {
return currChainName;
}
@Override
public void setCurrChainName(String currChainName) {
public void setCurrChainId(String currChainName) {
this.currChainName = currChainName;
}
}

View File

@ -1,11 +1,9 @@
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.StrUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.yomahub.liteflow.annotation.*;
import com.yomahub.liteflow.builder.LiteFlowNodeBuilder;
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
import com.yomahub.liteflow.builder.prop.NodePropBean;
@ -85,6 +83,10 @@ public class ParserHelper {
.build();
}
/**
* xml 形式的主要解析过程
* @param documentList documentList
*/
/**
* xml 形式的主要解析过程
* @param documentList documentList
@ -119,6 +121,31 @@ public class ParserHelper {
}
}
}
public static void parseDocument(List<Document> documentList, Set<String> chainNameSet, Consumer<Element> parseOneChainConsumer) {
//先在元数据里放上chain
//先放有一个好处可以在parse的时候先映射到FlowBus的chainMap然后再去解析
//这样就不用去像之前的版本那样回归调用
//同时也解决了不能循环依赖的问题
documentList.forEach(document -> {
// 解析chain节点
List<Element> chainList = document.getRootElement().elements(CHAIN);
//先在元数据里放上chain
chainList.forEach(e -> {
//校验加载的 chainName 是否有重复的
//TODO 这里是否有个问题当混合格式加载的时候2个同名的Chain在不同的文件里就不行了
String chainName = Optional.ofNullable(e.attributeValue(ID)).orElse(e.attributeValue(NAME));
if (!chainNameSet.add(chainName)) {
throw new ChainDuplicateException(String.format("[chain name duplicate] chainName=%s", chainName));
}
FlowBus.addChain(chainName);
});
});
// 清空
chainNameSet.clear();
}
public static void parseChainDocument(List<Document> documentList, Set<String> chainNameSet, Consumer<Element> parseOneChainConsumer){
//先在元数据里放上chain
@ -133,7 +160,7 @@ public class ParserHelper {
chainList.forEach(e -> {
//校验加载的 chainName 是否有重复的
//TODO 这里是否有个问题当混合格式加载的时候2个同名的Chain在不同的文件里就不行了
String chainName = e.attributeValue(NAME);
String chainName = Optional.ofNullable(e.attributeValue(ID)).orElse(e.attributeValue(NAME));
if (!chainNameSet.add(chainName)) {
throw new ChainDuplicateException(String.format("[chain name duplicate] chainName=%s", chainName));
}
@ -152,7 +179,7 @@ public class ParserHelper {
}
}
public static void parseNodeJson(List<JsonNode> flowJsonObjectList) {
public static void parseNodeJson(List<JsonNode> flowJsonObjectList) {
for (JsonNode flowJsonNode : flowJsonObjectList) {
// 当存在<nodes>节点定义时解析node节点
if (flowJsonNode.get(FLOW).has(NODES)) {
@ -180,6 +207,33 @@ public class ParserHelper {
}
}
}
}
public static void parseJsonNode(List<JsonNode> flowJsonObjectList, Set<String> chainNameSet, Consumer<JsonNode> parseOneChainConsumer) {
//先在元数据里放上chain
//先放有一个好处可以在parse的时候先映射到FlowBus的chainMap然后再去解析
//这样就不用去像之前的版本那样回归调用
//同时也解决了不能循环依赖的问题
flowJsonObjectList.forEach(jsonObject -> {
// 解析chain节点
Iterator<JsonNode> iterator = jsonObject.get(FLOW).get(CHAIN).elements();
//先在元数据里放上chain
while (iterator.hasNext()) {
JsonNode innerJsonObject = iterator.next();
//校验加载的 chainName 是否有重复的
// TODO 这里是否有个问题当混合格式加载的时候2个同名的Chain在不同的文件里就不行了
//String chainName = innerJsonObject.get(NAME).textValue();
String chainName = Optional.ofNullable(innerJsonObject.get(ID)).orElse(innerJsonObject.get(NAME)).textValue();
if (!chainNameSet.add(chainName)) {
throw new ChainDuplicateException(String.format("[chain name duplicate] chainName=%s", chainName));
}
FlowBus.addChain(chainName);
}
});
// 清空
chainNameSet.clear();
}
public static void parseChainJson(List<JsonNode> flowJsonObjectList, Set<String> chainNameSet, Consumer<JsonNode> parseOneChainConsumer){
@ -195,12 +249,12 @@ public class ParserHelper {
JsonNode innerJsonObject = iterator.next();
//校验加载的 chainName 是否有重复的
// TODO 这里是否有个问题当混合格式加载的时候2个同名的Chain在不同的文件里就不行了
String chainName = innerJsonObject.get(NAME).textValue();
String chainName = Optional.ofNullable(innerJsonObject.get(ID)).orElse(innerJsonObject.get(NAME)).textValue();
if (!chainNameSet.add(chainName)) {
throw new ChainDuplicateException(String.format("[chain name duplicate] chainName=%s", chainName));
}
FlowBus.addChain(innerJsonObject.get(NAME).textValue());
FlowBus.addChain(chainName);
}
});
// 清空
@ -223,9 +277,9 @@ public class ParserHelper {
*/
public static void parseOneChainEl(JsonNode chainNode) {
//构建chainBuilder
String chainName = chainNode.get(NAME).textValue();
String chainId = Optional.ofNullable(chainNode.get(ID)).orElse(chainNode.get(NAME)).textValue();
String el = chainNode.get(VALUE).textValue();
LiteFlowChainELBuilder chainELBuilder = LiteFlowChainELBuilder.createChain().setChainName(chainName);
LiteFlowChainELBuilder chainELBuilder = LiteFlowChainELBuilder.createChain().setChainId(chainId);
chainELBuilder.setEL(el).build();
}
@ -236,10 +290,10 @@ public class ParserHelper {
*/
public static void parseOneChainEl(Element e) {
//构建chainBuilder
String chainName = e.attributeValue(NAME);
String chainId = Optional.ofNullable(e.attributeValue(ID)).orElse(e.attributeValue(NAME));
String text = e.getText();
String el = RegexUtil.removeComments(text);
LiteFlowChainELBuilder chainELBuilder = LiteFlowChainELBuilder.createChain().setChainName(chainName);
LiteFlowChainELBuilder chainELBuilder = LiteFlowChainELBuilder.createChain().setChainId(chainId);
chainELBuilder.setEL(el).build();
}

View File

@ -9,7 +9,7 @@ public class ScriptExecuteWrap {
private int slotIndex;
private String currChainName;
private String currChainId;
private String nodeId;
@ -25,12 +25,29 @@ public class ScriptExecuteWrap {
this.slotIndex = slotIndex;
}
/**
* @deprecated 请使用 {@link #getCurrChainId()}
*/
@Deprecated
public String getCurrChainName() {
return currChainName;
return currChainId;
}
/**
*
* @param currChainName
* @deprecated 请使用{@link #setCurrChainId(String)}
*/
public void setCurrChainName(String currChainName) {
this.currChainName = currChainName;
this.currChainId = currChainName;
}
public String getCurrChainId() {
return currChainId;
}
public void setCurrChainId(String currChainId) {
this.currChainId = currChainId;
}
public String getNodeId() {

View File

@ -18,6 +18,7 @@ import com.yomahub.liteflow.property.LiteflowConfigGetter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.Charset;
import java.util.Deque;
import java.util.Iterator;
import java.util.List;
@ -235,13 +236,31 @@ public class Slot{
return (boolean) metaDataMap.get(BREAK_PREFIX + key);
}
/**
*
* @param chainName
* @Deprecated 请使用 {@link #setChainId(String)}
*/
@Deprecated
public void setChainName(String chainName) {
setChainId(chainName);
}
/**
* @deprecated 请使用 {@link #getChainId()}
*/
@Deprecated
public String getChainName() {
return getChainId();
}
public void setChainId(String chainId) {
if (!hasMetaData(CHAIN_NAME)){
this.putMetaDataMap(CHAIN_NAME, chainName);
this.putMetaDataMap(CHAIN_NAME, chainId);
}
}
public String getChainName() {
public String getChainId() {
return (String) metaDataMap.get(CHAIN_NAME);
}