enhancement #I5X7IT rule-source-ext-data支持在springboot yml配置文件中的原生配置

This commit is contained in:
everywhere.z 2022-10-23 17:02:34 +08:00
parent 676e974c91
commit 805143bf1f
8 changed files with 86 additions and 25 deletions

View File

@ -11,6 +11,8 @@ package com.yomahub.liteflow.property;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import java.util.Map;
/**
* liteflow的配置实体类
* 这个类中的属性为什么不用基本类型而用包装类型呢
@ -32,6 +34,8 @@ public class LiteflowConfig {
//流程资源扩展数据
private String ruleSourceExtData;
private Map<String, String> ruleSourceExtDataMap;
//slot的数量
private Integer slotSize;
@ -340,4 +344,12 @@ public class LiteflowConfig {
public void setRuleSourceExtData(String ruleSourceExtData) {
this.ruleSourceExtData = ruleSourceExtData;
}
public Map<String, String> getRuleSourceExtDataMap() {
return ruleSourceExtDataMap;
}
public void setRuleSourceExtDataMap(Map<String, String> ruleSourceExtDataMap) {
this.ruleSourceExtDataMap = ruleSourceExtDataMap;
}
}

View File

@ -1,5 +1,8 @@
package com.yomahub.liteflow.parser.etcd;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.parser.el.ClassXmlFlowELParser;
import com.yomahub.liteflow.parser.etcd.exception.EtcdException;
@ -9,6 +12,7 @@ import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.util.JsonUtil;
import java.util.Objects;
import java.util.function.Consumer;
/**
@ -23,13 +27,17 @@ public class EtcdXmlELParser extends ClassXmlFlowELParser {
public EtcdXmlELParser() {
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
if (StrUtil.isBlank(liteflowConfig.getRuleSourceExtData())){
throw new EtcdException("rule-source-ext-data is empty");
}
try{
EtcdParserVO etcdParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), EtcdParserVO.class);
assert etcdParserVO != null;
EtcdParserVO etcdParserVO = null;
if(MapUtil.isNotEmpty((liteflowConfig.getRuleSourceExtDataMap()))){
etcdParserVO = BeanUtil.toBean(liteflowConfig.getRuleSourceExtDataMap(), EtcdParserVO.class, CopyOptions.create());
}else if (StrUtil.isNotBlank(liteflowConfig.getRuleSourceExtData())){
etcdParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), EtcdParserVO.class);
}
if (Objects.isNull(etcdParserVO)) {
throw new EtcdException("rule-source-ext-data is empty");
}
if (StrUtil.isBlank(etcdParserVO.getNodePath())){
etcdParserVO.setNodePath("/lite-flow/flow");

View File

@ -1,5 +1,8 @@
package com.yomahub.liteflow.parser.nacos;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.parser.el.ClassXmlFlowELParser;
import com.yomahub.liteflow.parser.nacos.exception.NacosException;
@ -9,6 +12,7 @@ import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.util.JsonUtil;
import java.util.Objects;
import java.util.function.Consumer;
/**
@ -23,13 +27,18 @@ public class NacosXmlELParser extends ClassXmlFlowELParser {
public NacosXmlELParser() {
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
if (StrUtil.isBlank(liteflowConfig.getRuleSourceExtData())){
throw new NacosException("rule-source-ext-data for nacos is empty");
}
try{
NacosParserVO nacosParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), NacosParserVO.class);
assert nacosParserVO != null;
NacosParserVO nacosParserVO = null;
if(MapUtil.isNotEmpty((liteflowConfig.getRuleSourceExtDataMap()))){
nacosParserVO = BeanUtil.toBean(liteflowConfig.getRuleSourceExtDataMap(), NacosParserVO.class, CopyOptions.create());
}else if (StrUtil.isNotBlank(liteflowConfig.getRuleSourceExtData())){
nacosParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), NacosParserVO.class);
}
if (Objects.isNull(nacosParserVO)) {
throw new NacosException("rule-source-ext-data is empty");
}
if (StrUtil.isBlank(nacosParserVO.getServerAddr())){
nacosParserVO.setServerAddr("127.0.0.1:8848");
}

View File

@ -1,5 +1,8 @@
package com.yomahub.liteflow.parser.sql;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.StrFormatter;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.parser.el.ClassXmlFlowELParser;
@ -10,6 +13,7 @@ import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.util.JsonUtil;
import java.util.Map;
import java.util.Objects;
/**
@ -29,12 +33,13 @@ public class SQLXmlELParser extends ClassXmlFlowELParser {
public SQLXmlELParser() {
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
if (StrUtil.isBlank(liteflowConfig.getRuleSourceExtData())) {
throw new ELSQLException(ERROR_COMMON_MSG);
}
try {
SQLParserVO sqlParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), SQLParserVO.class);
SQLParserVO sqlParserVO = null;
if(MapUtil.isNotEmpty((liteflowConfig.getRuleSourceExtDataMap()))){
sqlParserVO = BeanUtil.toBean(liteflowConfig.getRuleSourceExtDataMap(), SQLParserVO.class, CopyOptions.create());
}else if (StrUtil.isNotBlank(liteflowConfig.getRuleSourceExtData())){
sqlParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), SQLParserVO.class);
}
if (Objects.isNull(sqlParserVO)) {
throw new ELSQLException(ERROR_COMMON_MSG);
}

View File

@ -1,5 +1,8 @@
package com.yomahub.liteflow.parser.zk;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.parser.el.ClassXmlFlowELParser;
import com.yomahub.liteflow.parser.zk.exception.ZkException;
@ -8,8 +11,8 @@ import com.yomahub.liteflow.parser.zk.vo.ZkParserVO;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.util.JsonUtil;
import org.apache.curator.framework.CuratorFramework;
import java.util.Objects;
import java.util.function.Consumer;
/**
@ -31,13 +34,17 @@ public class ZkXmlELParser extends ClassXmlFlowELParser {
};
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
if (StrUtil.isBlank(liteflowConfig.getRuleSourceExtData())){
throw new ZkException("rule-source-ext-data is empty");
}
try{
ZkParserVO zkParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), ZkParserVO.class);
assert zkParserVO != null;
ZkParserVO zkParserVO = null;
if(MapUtil.isNotEmpty((liteflowConfig.getRuleSourceExtDataMap()))){
zkParserVO = BeanUtil.toBean(liteflowConfig.getRuleSourceExtDataMap(), ZkParserVO.class, CopyOptions.create());
}else if (StrUtil.isNotBlank(liteflowConfig.getRuleSourceExtData())){
zkParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), ZkParserVO.class);
}
if (Objects.isNull(zkParserVO)) {
throw new ZkException("rule-source-ext-data is empty");
}
if (StrUtil.isBlank(zkParserVO.getNodePath())){
zkParserVO.setNodePath("/lite-flow/flow");

View File

@ -2,6 +2,8 @@ package com.yomahub.liteflow.springboot;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.Map;
/**
* 执行流程主要的参数类
* @author Bryan.Zhang
@ -15,9 +17,12 @@ public class LiteflowProperty {
//流程定义资源地址
private String ruleSource;
//流程资源扩展数据
//流程资源扩展数据String格式
private String ruleSourceExtData;
//流程资源扩展数据Map格式
private Map<String, String> ruleSourceExtDataMap;
//slot的数量
private int slotSize;
@ -208,4 +213,12 @@ public class LiteflowProperty {
public void setRuleSourceExtData(String ruleSourceExtData) {
this.ruleSourceExtData = ruleSourceExtData;
}
public Map<String, String> getRuleSourceExtDataMap() {
return ruleSourceExtDataMap;
}
public void setRuleSourceExtDataMap(Map<String, String> ruleSourceExtDataMap) {
this.ruleSourceExtDataMap = ruleSourceExtDataMap;
}
}

View File

@ -26,6 +26,7 @@ public class LiteflowPropertyAutoConfiguration {
LiteflowConfig liteflowConfig = new LiteflowConfig();
liteflowConfig.setRuleSource(property.getRuleSource());
liteflowConfig.setRuleSourceExtData(property.getRuleSourceExtData());
liteflowConfig.setRuleSourceExtDataMap(property.getRuleSourceExtDataMap());
liteflowConfig.setSlotSize(property.getSlotSize());
liteflowConfig.setThreadExecutorClass(property.getThreadExecutorClass());
liteflowConfig.setWhenMaxWaitSeconds(property.getWhenMaxWaitSeconds());

View File

@ -6,6 +6,12 @@
"description": "rule source extended data.",
"sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty"
},
{
"name": "liteflow.rule-source-ext-data-map",
"type": "java.util.Map",
"description": "rule source extended data map.",
"sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty"
},
{
"name": "liteflow.request-id-generator-class",
"type": "java.lang.String",