From 0f35cedf0fd4dc7aa8ecb9b997847b0e0f4f1453 Mon Sep 17 00:00:00 2001 From: Kugaaa Date: Wed, 12 Jul 2023 14:59:30 +0800 Subject: [PATCH 01/18] =?UTF-8?q?enhancement=20#I7GMTS=20=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E6=96=87=E4=BB=B6=E7=9B=91=E5=90=AC=20catch=20?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=EF=BC=8C=E4=BF=9D=E8=AF=81=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E4=B8=8D=E8=A2=AB=E5=81=9C=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yomahub/liteflow/monitor/MonitorFile.java | 12 +++++++-- .../MonitorFileELSpringbootTest.java | 27 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java b/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java index 756d54273..fb3226b77 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java @@ -63,13 +63,21 @@ public class MonitorFile { @Override public void onFileChange(File file) { LOG.info("file modify,filePath={}", file.getAbsolutePath()); - FlowExecutorHolder.loadInstance().reloadRule(); + this.reloadRule(); } @Override public void onFileDelete(File file) { LOG.info("file delete,filePath={}", file.getAbsolutePath()); - FlowExecutorHolder.loadInstance().reloadRule(); + this.reloadRule(); + } + + private void reloadRule() { + try { + FlowExecutorHolder.loadInstance().reloadRule(); + } catch (Exception e) { + LOG.error("reload rule error", e); + } } }); // 创建文件变化监听器 diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java index 2ffdd06e2..32c895be8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java @@ -7,8 +7,10 @@ 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.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.ComponentScan; @@ -23,6 +25,7 @@ import java.io.File; @SpringBootTest(classes = MonitorFileELSpringbootTest.class) @EnableAutoConfiguration @ComponentScan({ "com.yomahub.liteflow.test.monitorFile.cmp" }) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class MonitorFileELSpringbootTest extends BaseTest { @Resource @@ -39,4 +42,28 @@ public class MonitorFileELSpringbootTest extends BaseTest { Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); } + /** + * 测试文件变更,但是 EL 规则错误情况 + * 输出 ERROR 日志异常信息,但是不会停止监听线程,当下一次变更正确后替换为新规则 + */ + @Test + public void testMonitorError() throws Exception { + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + String content = FileUtil.readUtf8String(absolutePath); + + // 错误规则配置 + String newContent = content.replace("THEN(a, c, b);", "THEN(c, b, ;"); + FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + Thread.sleep(3000); + LiteflowResponse reloadFailedResponse = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>c==>b", reloadFailedResponse.getExecuteStepStr()); + + // 再次变更正确 + newContent = content.replace("THEN(a, c, b);", "THEN(c, b, a);"); + FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + Thread.sleep(3000); + LiteflowResponse reloadSuccessResponse = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("c==>b==>a", reloadSuccessResponse.getExecuteStepStr()); + } + } From 861342f478b26959252ec18d62114253c02e79b1 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Sun, 16 Jul 2023 15:41:57 +0800 Subject: [PATCH 02/18] =?UTF-8?q?enhancement=20#I7KZCZ=20=E5=9C=A8?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=95=B0=E6=8D=AE=E5=BA=93=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E4=BD=BF=E7=94=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E4=B8=AD=E5=B7=B2=E7=BB=8F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=9A=84=E6=95=B0=E6=8D=AE=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yomahub/liteflow/spi/ContextAware.java | 25 +- .../liteflow/spi/local/LocalContextAware.java | 71 +-- .../liteflow/parser/sql/SQLXmlELParser.java | 3 + .../liteflow/parser/sql/util/JDBCHelper.java | 505 ++++++++---------- .../parser/sql/util/LiteFlowJdbcUtil.java | 134 +++++ .../liteflow/parser/sql/vo/SQLParserVO.java | 329 ++++++------ .../liteflow/spi/solon/SolonContextAware.java | 124 +++-- .../liteflow/spi/spring/SpringAware.java | 140 ++--- .../liteflow/spring/LiteFlowSpringUtil.java | 275 ++++++++++ ...LWithXmlELMultiLanguageSpringbootTest.java | 34 ++ .../test/def/SQLWithXmlELSpringbootTest.java | 101 ++++ .../application-data-source-xml.properties | 21 + 12 files changed, 1158 insertions(+), 604 deletions(-) create mode 100644 liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/LiteFlowJdbcUtil.java create mode 100644 liteflow-spring/src/main/java/com/yomahub/liteflow/spring/LiteFlowSpringUtil.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELMultiLanguageSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-data-source-xml.properties diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextAware.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextAware.java index ea8197429..824de84fc 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextAware.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextAware.java @@ -1,5 +1,7 @@ package com.yomahub.liteflow.spi; +import java.util.Map; + /** * 环境容器SPI接口 * @@ -8,18 +10,27 @@ package com.yomahub.liteflow.spi; */ public interface ContextAware extends SpiPriority { - T getBean(String name); + T getBean(String name); - T getBean(Class clazz); + T getBean(Class clazz); - T registerBean(String beanName, Class clazz); + T registerBean(String beanName, Class clazz); - T registerBean(Class clazz); + T registerBean(Class clazz); - T registerBean(String beanName, Object bean); + T registerBean(String beanName, Object bean); - T registerOrGet(String beanName, Class clazz); + T registerOrGet(String beanName, Class clazz); - boolean hasBean(String beanName); + /** + * 获取指定类型对应的所有Bean,包括子类 + * + * @param Bean类型 + * @param type 类、接口,null表示获取所有bean + * @return 类型对应的bean,key是bean注册的name,value是Bean + */ + Map getBeansOfType(Class type); + + boolean hasBean(String beanName); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextAware.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextAware.java index 63d3cc806..8dd958324 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextAware.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextAware.java @@ -3,6 +3,8 @@ package com.yomahub.liteflow.spi.local; import cn.hutool.core.util.ReflectUtil; import com.yomahub.liteflow.spi.ContextAware; +import java.util.Map; + /** * 非Spring环境容器实现 其实非Spring没有环境容器,所以这是个空实现 * @@ -11,44 +13,49 @@ import com.yomahub.liteflow.spi.ContextAware; */ public class LocalContextAware implements ContextAware { - @Override - public T getBean(String name) { - return null; - } + @Override + public T getBean(String name) { + return null; + } - @Override - public T getBean(Class clazz) { - return null; - } + @Override + public T getBean(Class clazz) { + return null; + } - @Override - public T registerBean(String beanName, Class clazz) { - return ReflectUtil.newInstance(clazz); - } + @Override + public T registerBean(String beanName, Class clazz) { + return ReflectUtil.newInstance(clazz); + } - @Override - public T registerBean(Class clazz) { - return registerBean(null, clazz); - } + @Override + public T registerBean(Class clazz) { + return registerBean(null, clazz); + } - @Override - public T registerBean(String beanName, Object bean) { - return (T) bean; - } + @Override + public T registerBean(String beanName, Object bean) { + return (T) bean; + } - @Override - public T registerOrGet(String beanName, Class clazz) { - return registerBean(beanName, clazz); - } + @Override + public T registerOrGet(String beanName, Class clazz) { + return registerBean(beanName, clazz); + } - @Override - public boolean hasBean(String beanName) { - return false; - } + @Override + public Map getBeansOfType(Class type) { + return null; + } - @Override - public int priority() { - return 2; - } + @Override + public boolean hasBean(String beanName) { + return false; + } + + @Override + public int priority() { + return 2; + } } diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/SQLXmlELParser.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/SQLXmlELParser.java index 907818052..ce3bbe536 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/SQLXmlELParser.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/SQLXmlELParser.java @@ -71,6 +71,9 @@ public class SQLXmlELParser extends ClassXmlFlowELParser { * @param sqlParserVO sqlParserVO */ private void checkParserVO(SQLParserVO sqlParserVO) { + if (sqlParserVO.isDefaultDataSource()) { + return; + } if (StrUtil.isEmpty(sqlParserVO.getUrl())) { throw new ELSQLException(StrFormatter.format(ERROR_MSG_PATTERN, "url")); } diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/JDBCHelper.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/JDBCHelper.java index e7a8bc939..03435a21f 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/JDBCHelper.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/JDBCHelper.java @@ -9,7 +9,6 @@ import com.yomahub.liteflow.parser.sql.exception.ELSQLException; import com.yomahub.liteflow.parser.sql.vo.SQLParserVO; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -25,331 +24,279 @@ import java.util.Objects; */ public class JDBCHelper { - private static final String SQL_PATTERN = "SELECT {},{} FROM {} WHERE {}=?"; + private static final String SQL_PATTERN = "SELECT {},{} FROM {} WHERE {}=?"; - private static final String SCRIPT_SQL_CHECK_PATTERN = "SELECT 1 FROM {} WHERE {}=?"; + private static final String SCRIPT_SQL_CHECK_PATTERN = "SELECT 1 FROM {} WHERE {}=?"; - private static final String SCRIPT_SQL_PATTERN = "SELECT {},{},{},{} FROM {} WHERE {}=?"; + private static final String SCRIPT_SQL_PATTERN = "SELECT {},{},{},{} FROM {} WHERE {}=?"; - private static final String SCRIPT_WITH_LANGUAG_SQL_PATTERN = "SELECT {},{},{},{},{} FROM {} WHERE {}=?"; + private static final String SCRIPT_WITH_LANGUAG_SQL_PATTERN = "SELECT {},{},{},{},{} FROM {} WHERE {}=?"; - private static final String CHAIN_XML_PATTERN = "{}"; + private static final String CHAIN_XML_PATTERN = "{}"; - private static final String NODE_XML_PATTERN = "{}"; + private static final String NODE_XML_PATTERN = "{}"; - private static final String NODE_ITEM_XML_PATTERN = ""; + private static final String NODE_ITEM_XML_PATTERN = ""; - private static final String NODE_ITEM_WITH_LANGUAGE_XML_PATTERN = ""; + private static final String NODE_ITEM_WITH_LANGUAGE_XML_PATTERN = ""; - private static final String XML_PATTERN = "{}{}"; + private static final String XML_PATTERN = "{}{}"; - private static final Integer FETCH_SIZE_MAX = 1000; + private static final Integer FETCH_SIZE_MAX = 1000; - private SQLParserVO sqlParserVO; + private SQLParserVO sqlParserVO; - private static JDBCHelper INSTANCE; + private static JDBCHelper INSTANCE; - /** - * 初始化 INSTANCE - */ - public static void init(SQLParserVO sqlParserVO) { - try { - INSTANCE = new JDBCHelper(); - Class.forName(sqlParserVO.getDriverClassName()); - INSTANCE.setSqlParserVO(sqlParserVO); - } - catch (ClassNotFoundException e) { - throw new ELSQLException(e.getMessage()); - } - } + /** + * 初始化 INSTANCE + */ + public static void init(SQLParserVO sqlParserVO) { + try { + INSTANCE = new JDBCHelper(); + if (StrUtil.isNotBlank(sqlParserVO.getDriverClassName())) { + Class.forName(sqlParserVO.getDriverClassName()); + } + INSTANCE.setSqlParserVO(sqlParserVO); + } catch (ClassNotFoundException e) { + throw new ELSQLException(e.getMessage()); + } + } - /** - * 获取 INSTANCE - */ - public static JDBCHelper getInstance() { - return INSTANCE; - } + /** + * 获取 INSTANCE + */ + public static JDBCHelper getInstance() { + return INSTANCE; + } - /** - * 获取链接 - */ - public Connection getConn() { - Connection connection; - try { - connection = DriverManager.getConnection(sqlParserVO.getUrl(), sqlParserVO.getUsername(), - sqlParserVO.getPassword()); - } - catch (SQLException e) { - throw new ELSQLException(e.getMessage()); - } - return connection; - } + /** + * 获取 ElData 数据内容 + */ + public String getContent() { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; - /** - * 获取 ElData 数据内容 - */ - public String getContent() { - Connection conn = null; - PreparedStatement stmt = null; - ResultSet rs = null; + String chainTableName = sqlParserVO.getChainTableName(); + String elDataField = sqlParserVO.getElDataField(); + String chainNameField = sqlParserVO.getChainNameField(); + String chainApplicationNameField = sqlParserVO.getChainApplicationNameField(); + String applicationName = sqlParserVO.getApplicationName(); - String chainTableName = sqlParserVO.getChainTableName(); - String elDataField = sqlParserVO.getElDataField(); - String chainNameField = sqlParserVO.getChainNameField(); - String chainApplicationNameField = sqlParserVO.getChainApplicationNameField(); - String applicationName = sqlParserVO.getApplicationName(); + if (StrUtil.isBlank(chainTableName)) { + throw new ELSQLException("You did not define the chainTableName property"); + } - if (StrUtil.isBlank(chainTableName)) { - throw new ELSQLException("You did not define the chainTableName property"); - } + if (StrUtil.isBlank(applicationName) || StrUtil.isBlank(chainApplicationNameField)) { + throw new ELSQLException("You did not define the applicationName or chainApplicationNameField property"); + } - if (StrUtil.isBlank(applicationName) || StrUtil.isBlank(chainApplicationNameField)) { - throw new ELSQLException("You did not define the applicationName or chainApplicationNameField property"); - } + String sqlCmd = StrUtil.format(SQL_PATTERN, chainNameField, elDataField, chainTableName, + chainApplicationNameField); - String sqlCmd = StrUtil.format(SQL_PATTERN, chainNameField, elDataField, chainTableName, - chainApplicationNameField); + List result = new ArrayList<>(); + try { + conn = LiteFlowJdbcUtil.getConn(sqlParserVO); + stmt = conn.prepareStatement(sqlCmd, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + // 设置游标拉取数量 + stmt.setFetchSize(FETCH_SIZE_MAX); + stmt.setString(1, applicationName); + rs = stmt.executeQuery(); - List result = new ArrayList<>(); - try { - conn = getConn(); - stmt = conn.prepareStatement(sqlCmd, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - // 设置游标拉取数量 - stmt.setFetchSize(FETCH_SIZE_MAX); - stmt.setString(1, applicationName); - rs = stmt.executeQuery(); + while (rs.next()) { + String elData = getStringFromResultSet(rs, elDataField); + String chainName = getStringFromResultSet(rs, chainNameField); - while (rs.next()) { - String elData = getStringFromResultSet(rs, elDataField); - String chainName = getStringFromResultSet(rs, chainNameField); + result.add(StrUtil.format(CHAIN_XML_PATTERN, XmlUtil.escape(chainName), elData)); + } + } catch (Exception e) { + throw new ELSQLException(e.getMessage()); + } finally { + // 关闭连接 + LiteFlowJdbcUtil.close(conn, stmt, rs); + } - result.add(StrUtil.format(CHAIN_XML_PATTERN, XmlUtil.escape(chainName), elData)); - } - } - catch (Exception e) { - throw new ELSQLException(e.getMessage()); - } - finally { - // 关闭连接 - close(conn, stmt, rs); - } + String chainsContent = CollUtil.join(result, StrUtil.EMPTY); - String chainsContent = CollUtil.join(result, StrUtil.EMPTY); + String nodesContent; + if (hasScriptData()) { + nodesContent = getScriptNodes(); + } else { + nodesContent = StrUtil.EMPTY; + } - String nodesContent; - if (hasScriptData()) { - nodesContent = getScriptNodes(); - } - else { - nodesContent = StrUtil.EMPTY; - } + return StrUtil.format(XML_PATTERN, nodesContent, chainsContent); + } - return StrUtil.format(XML_PATTERN, nodesContent, chainsContent); - } + /** + * 获取脚本节点内容 + */ + public String getScriptNodes() { + String scriptLanguageField = sqlParserVO.getScriptLanguageField(); + if (StrUtil.isNotBlank(scriptLanguageField)) { + return getScriptNodesWithLanguage(); + } - public String getScriptNodes() { - String scriptLanguageField = sqlParserVO.getScriptLanguageField(); - if (StrUtil.isNotBlank(scriptLanguageField)) { - return getScriptNodesWithLanguage(); - } + List result = new ArrayList<>(); + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; - List result = new ArrayList<>(); - Connection conn = null; - PreparedStatement stmt = null; - ResultSet rs = null; + String scriptTableName = sqlParserVO.getScriptTableName(); + String scriptIdField = sqlParserVO.getScriptIdField(); + String scriptDataField = sqlParserVO.getScriptDataField(); + String scriptNameField = sqlParserVO.getScriptNameField(); + String scriptTypeField = sqlParserVO.getScriptTypeField(); + String scriptApplicationNameField = sqlParserVO.getScriptApplicationNameField(); + String applicationName = sqlParserVO.getApplicationName(); - String scriptTableName = sqlParserVO.getScriptTableName(); - String scriptIdField = sqlParserVO.getScriptIdField(); - String scriptDataField = sqlParserVO.getScriptDataField(); - String scriptNameField = sqlParserVO.getScriptNameField(); - String scriptTypeField = sqlParserVO.getScriptTypeField(); - String scriptApplicationNameField = sqlParserVO.getScriptApplicationNameField(); - String applicationName = sqlParserVO.getApplicationName(); + if (StrUtil.isBlank(applicationName) || StrUtil.isBlank(scriptApplicationNameField)) { + throw new ELSQLException("You did not define the applicationName or scriptApplicationNameField property"); + } - if (StrUtil.isBlank(applicationName) || StrUtil.isBlank(scriptApplicationNameField)) { - throw new ELSQLException("You did not define the applicationName or scriptApplicationNameField property"); - } + String sqlCmd = StrUtil.format(SCRIPT_SQL_PATTERN, scriptIdField, scriptDataField, scriptNameField, + scriptTypeField, scriptTableName, scriptApplicationNameField); + try { + conn = LiteFlowJdbcUtil.getConn(sqlParserVO); + stmt = conn.prepareStatement(sqlCmd, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + // 设置游标拉取数量 + stmt.setFetchSize(FETCH_SIZE_MAX); + stmt.setString(1, applicationName); + rs = stmt.executeQuery(); - String sqlCmd = StrUtil.format(SCRIPT_SQL_PATTERN, scriptIdField, scriptDataField, scriptNameField, - scriptTypeField, scriptTableName, scriptApplicationNameField); - try { - conn = getConn(); - stmt = conn.prepareStatement(sqlCmd, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - // 设置游标拉取数量 - stmt.setFetchSize(FETCH_SIZE_MAX); - stmt.setString(1, applicationName); - rs = stmt.executeQuery(); + while (rs.next()) { + String id = getStringFromResultSet(rs, scriptIdField); + String data = getStringFromResultSet(rs, scriptDataField); + String name = getStringFromResultSet(rs, scriptNameField); + String type = getStringFromResultSet(rs, scriptTypeField); - while (rs.next()) { - String id = getStringFromResultSet(rs, scriptIdField); - String data = getStringFromResultSet(rs, scriptDataField); - String name = getStringFromResultSet(rs, scriptNameField); - String type = getStringFromResultSet(rs, scriptTypeField); + NodeTypeEnum nodeTypeEnum = NodeTypeEnum.getEnumByCode(type); + if (Objects.isNull(nodeTypeEnum)) { + throw new ELSQLException(StrUtil.format("Invalid type value[{}]", type)); + } - NodeTypeEnum nodeTypeEnum = NodeTypeEnum.getEnumByCode(type); - if (Objects.isNull(nodeTypeEnum)) { - throw new ELSQLException(StrUtil.format("Invalid type value[{}]", type)); - } + if (!nodeTypeEnum.isScript()) { + throw new ELSQLException(StrUtil.format("The type value[{}] is not a script type", type)); + } - if (!nodeTypeEnum.isScript()) { - throw new ELSQLException(StrUtil.format("The type value[{}] is not a script type", type)); - } + result.add(StrUtil.format(NODE_ITEM_XML_PATTERN, XmlUtil.escape(id), XmlUtil.escape(name), type, data)); + } + } catch (Exception e) { + throw new ELSQLException(e.getMessage()); + } finally { + // 关闭连接 + LiteFlowJdbcUtil.close(conn, stmt, rs); + } + return StrUtil.format(NODE_XML_PATTERN, CollUtil.join(result, StrUtil.EMPTY)); + } - result.add(StrUtil.format(NODE_ITEM_XML_PATTERN, XmlUtil.escape(id), XmlUtil.escape(name), type, data)); - } - } - catch (Exception e) { - throw new ELSQLException(e.getMessage()); - } - finally { - // 关闭连接 - close(conn, stmt, rs); - } - return StrUtil.format(NODE_XML_PATTERN, CollUtil.join(result, StrUtil.EMPTY)); - } + /** + * 获取脚本节点(带语言) + * + * @return + */ + public String getScriptNodesWithLanguage() { - public String getScriptNodesWithLanguage() { + List result = new ArrayList<>(); + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; - List result = new ArrayList<>(); - Connection conn = null; - PreparedStatement stmt = null; - ResultSet rs = null; + String scriptTableName = sqlParserVO.getScriptTableName(); + String scriptIdField = sqlParserVO.getScriptIdField(); + String scriptDataField = sqlParserVO.getScriptDataField(); + String scriptNameField = sqlParserVO.getScriptNameField(); + String scriptTypeField = sqlParserVO.getScriptTypeField(); + String scriptApplicationNameField = sqlParserVO.getScriptApplicationNameField(); + String applicationName = sqlParserVO.getApplicationName(); + String scriptLanguageField = sqlParserVO.getScriptLanguageField(); - String scriptTableName = sqlParserVO.getScriptTableName(); - String scriptIdField = sqlParserVO.getScriptIdField(); - String scriptDataField = sqlParserVO.getScriptDataField(); - String scriptNameField = sqlParserVO.getScriptNameField(); - String scriptTypeField = sqlParserVO.getScriptTypeField(); - String scriptApplicationNameField = sqlParserVO.getScriptApplicationNameField(); - String applicationName = sqlParserVO.getApplicationName(); - String scriptLanguageField = sqlParserVO.getScriptLanguageField(); + if (StrUtil.isBlank(applicationName) || StrUtil.isBlank(scriptApplicationNameField)) { + throw new ELSQLException("You did not define the applicationName or scriptApplicationNameField property"); + } - if (StrUtil.isBlank(applicationName) || StrUtil.isBlank(scriptApplicationNameField)) { - throw new ELSQLException("You did not define the applicationName or scriptApplicationNameField property"); - } + String sqlCmd = StrUtil.format(SCRIPT_WITH_LANGUAG_SQL_PATTERN, scriptIdField, scriptDataField, scriptNameField, + scriptTypeField, scriptLanguageField, scriptTableName, scriptApplicationNameField); + try { + conn = LiteFlowJdbcUtil.getConn(sqlParserVO); + stmt = conn.prepareStatement(sqlCmd, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + // 设置游标拉取数量 + stmt.setFetchSize(FETCH_SIZE_MAX); + stmt.setString(1, applicationName); + rs = stmt.executeQuery(); - String sqlCmd = StrUtil.format(SCRIPT_WITH_LANGUAG_SQL_PATTERN, scriptIdField, scriptDataField, scriptNameField, - scriptTypeField, scriptLanguageField, scriptTableName, scriptApplicationNameField); - try { - conn = getConn(); - stmt = conn.prepareStatement(sqlCmd, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - // 设置游标拉取数量 - stmt.setFetchSize(FETCH_SIZE_MAX); - stmt.setString(1, applicationName); - rs = stmt.executeQuery(); + while (rs.next()) { + String id = getStringFromResultSet(rs, scriptIdField); + String data = getStringFromResultSet(rs, scriptDataField); + String name = getStringFromResultSet(rs, scriptNameField); + String type = getStringFromResultSet(rs, scriptTypeField); + String language = getStringFromResultSet(rs, scriptLanguageField); - while (rs.next()) { - String id = getStringFromResultSet(rs, scriptIdField); - String data = getStringFromResultSet(rs, scriptDataField); - String name = getStringFromResultSet(rs, scriptNameField); - String type = getStringFromResultSet(rs, scriptTypeField); - String language = getStringFromResultSet(rs, scriptLanguageField); + NodeTypeEnum nodeTypeEnum = NodeTypeEnum.getEnumByCode(type); + if (Objects.isNull(nodeTypeEnum)) { + throw new ELSQLException(StrUtil.format("Invalid type value[{}]", type)); + } - NodeTypeEnum nodeTypeEnum = NodeTypeEnum.getEnumByCode(type); - if (Objects.isNull(nodeTypeEnum)) { - throw new ELSQLException(StrUtil.format("Invalid type value[{}]", type)); - } + if (!nodeTypeEnum.isScript()) { + throw new ELSQLException(StrUtil.format("The type value[{}] is not a script type", type)); + } - if (!nodeTypeEnum.isScript()) { - throw new ELSQLException(StrUtil.format("The type value[{}] is not a script type", type)); - } + if (!ScriptTypeEnum.checkScriptType(language)) { + throw new ELSQLException(StrUtil.format("The language value[{}] is error", language)); + } - if (!ScriptTypeEnum.checkScriptType(language)) { - throw new ELSQLException(StrUtil.format("The language value[{}] is error", language)); - } + result.add(StrUtil.format(NODE_ITEM_WITH_LANGUAGE_XML_PATTERN, XmlUtil.escape(id), XmlUtil.escape(name), + type, language, data)); + } + } catch (Exception e) { + throw new ELSQLException(e.getMessage()); + } finally { + // 关闭连接 + LiteFlowJdbcUtil.close(conn, stmt, rs); + } + return StrUtil.format(NODE_XML_PATTERN, CollUtil.join(result, StrUtil.EMPTY)); + } - result.add(StrUtil.format(NODE_ITEM_WITH_LANGUAGE_XML_PATTERN, XmlUtil.escape(id), XmlUtil.escape(name), - type, language, data)); - } - } - catch (Exception e) { - throw new ELSQLException(e.getMessage()); - } - finally { - // 关闭连接 - close(conn, stmt, rs); - } - return StrUtil.format(NODE_XML_PATTERN, CollUtil.join(result, StrUtil.EMPTY)); - } + private boolean hasScriptData() { + if (StrUtil.isBlank(sqlParserVO.getScriptTableName())) { + return false; + } - /** - * 关闭连接 - * @param conn conn - * @param stmt stmt - * @param rs rs - */ - private void close(Connection conn, PreparedStatement stmt, ResultSet rs) { - // 关闭连接 - if (conn != null) { - try { - conn.close(); - } - catch (SQLException e) { - throw new ELSQLException(e.getMessage()); - } - } - // 关闭 statement - if (stmt != null) { - try { - stmt.close(); - } - catch (SQLException e) { - throw new ELSQLException(e.getMessage()); - } - } - // 关闭结果集 - if (rs != null) { - try { - rs.close(); - } - catch (SQLException e) { - throw new ELSQLException(e.getMessage()); - } - } - } + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; + String sqlCmd = StrUtil.format(SCRIPT_SQL_CHECK_PATTERN, sqlParserVO.getScriptTableName(), + sqlParserVO.getScriptApplicationNameField()); + try { + conn = LiteFlowJdbcUtil.getConn(sqlParserVO); + stmt = conn.prepareStatement(sqlCmd, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + stmt.setFetchSize(1); + stmt.setString(1, sqlParserVO.getApplicationName()); + rs = stmt.executeQuery(); + return rs.next(); + } catch (Exception e) { + return false; + } finally { + // 关闭连接 + LiteFlowJdbcUtil.close(conn, stmt, rs); + } + } - private boolean hasScriptData() { - if (StrUtil.isBlank(sqlParserVO.getScriptTableName())) { - return false; - } + private String getStringFromResultSet(ResultSet rs, String field) throws SQLException { + String data = rs.getString(field); + if (StrUtil.isBlank(data)) { + throw new ELSQLException(StrUtil.format("exist {} field value is empty", field)); + } + return data; + } - Connection conn = null; - PreparedStatement stmt = null; - ResultSet rs = null; - String sqlCmd = StrUtil.format(SCRIPT_SQL_CHECK_PATTERN, sqlParserVO.getScriptTableName(), - sqlParserVO.getScriptApplicationNameField()); - try { - conn = getConn(); - stmt = conn.prepareStatement(sqlCmd, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - stmt.setFetchSize(1); - stmt.setString(1, sqlParserVO.getApplicationName()); - rs = stmt.executeQuery(); - return rs.next(); - } - catch (Exception e) { - return false; - } - finally { - // 关闭连接 - close(conn, stmt, rs); - } - } + private SQLParserVO getSqlParserVO() { + return sqlParserVO; + } - // #region get set method - private String getStringFromResultSet(ResultSet rs, String field) throws SQLException { - String data = rs.getString(field); - if (StrUtil.isBlank(data)) { - throw new ELSQLException(StrUtil.format("exist {} field value is empty", field)); - } - return data; - } - - private SQLParserVO getSqlParserVO() { - return sqlParserVO; - } - - private void setSqlParserVO(SQLParserVO sqlParserVO) { - this.sqlParserVO = sqlParserVO; - } + private void setSqlParserVO(SQLParserVO sqlParserVO) { + this.sqlParserVO = sqlParserVO; + } } diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/LiteFlowJdbcUtil.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/LiteFlowJdbcUtil.java new file mode 100644 index 000000000..4b2b640ed --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/LiteFlowJdbcUtil.java @@ -0,0 +1,134 @@ +package com.yomahub.liteflow.parser.sql.util; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.parser.sql.exception.ELSQLException; +import com.yomahub.liteflow.parser.sql.vo.SQLParserVO; +import com.yomahub.liteflow.spi.holder.ContextAwareHolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.sql.DataSource; +import java.sql.*; +import java.util.Map; + +public class LiteFlowJdbcUtil { + private static final Logger LOG = LoggerFactory.getLogger(LiteFlowJdbcUtil.class); + private static final String CHECK_SQL_PATTERN = "SELECT {},{} FROM {} WHERE {}='{}'"; + + /** + * 获取链接 + * 此方法会根据配置,判读使用指定数据源,还是IOC容器中已有的数据源 + * + * @param sqlParserVO + * @return + */ + public static Connection getConn(SQLParserVO sqlParserVO) { + Connection connection = null; + String url = sqlParserVO.getUrl(); + String username = sqlParserVO.getUsername(); + String password = sqlParserVO.getPassword(); + + try { + // 如果不配置 jdbc 连接相关配置,代表使用项目数据源 + if (sqlParserVO.isDefaultDataSource()) { + String executeSql = buildCheckSql(sqlParserVO); + Map dataSourceMap = ContextAwareHolder.loadContextAware().getBeansOfType(DataSource.class); + // 遍历数据源,多数据源场景下,判断哪个数据源有 liteflow 配置 + for (Map.Entry entry : dataSourceMap.entrySet()) { + String dataSourceName = entry.getKey(); + DataSource dataSource = entry.getValue(); + + if (checkConnectionCanExecuteSql(dataSource.getConnection(), executeSql)) { + connection = dataSource.getConnection(); + LOG.info("use dataSourceName[{}],has found liteflow config", dataSourceName); + } else { + LOG.info("check dataSourceName[{}],but not has liteflow config", dataSourceName); + } + } + if (connection == null) { + throw new ELSQLException("can not found liteflow config in dataSourceName " + dataSourceMap.keySet()); + } + } + // 如果配置 jdbc 连接相关配置,代表使用指定链接信息 + else { + connection = DriverManager.getConnection(url, username, password); + } + + } catch (Exception e) { + throw new ELSQLException(e.getMessage()); + } + + return connection; + } + + /** + * 判断连接是否可以执行指定 sql + * + * @param conn 连接 + * @param sql 执行 sql + */ + public static boolean checkConnectionCanExecuteSql(Connection conn, String sql) { + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + stmt.setFetchSize(1); + rs = stmt.executeQuery(); + return rs.next(); + } catch (Exception e) { + return false; + } finally { + // 关闭连接 + close(conn, stmt, rs); + } + } + + /** + * 关闭 + * + * @param conn conn + * @param conn conn + * @param rs rs + */ + public static void close(Connection conn, PreparedStatement stmt, ResultSet rs) { + // 关闭连接 + if (conn != null) { + try { + conn.close(); + } catch (SQLException e) { + throw new ELSQLException(e.getMessage()); + } + } + // 关闭 statement + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { + throw new ELSQLException(e.getMessage()); + } + } + // 关闭结果集 + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + throw new ELSQLException(e.getMessage()); + } + } + } + + /** + * 构建检查 sql + * + * @param sqlParserVO + * @return + */ + private static String buildCheckSql(SQLParserVO sqlParserVO) { + String chainTableName = sqlParserVO.getChainTableName(); + String elDataField = sqlParserVO.getElDataField(); + String chainNameField = sqlParserVO.getChainNameField(); + String chainApplicationNameField = sqlParserVO.getChainApplicationNameField(); + String applicationName = sqlParserVO.getApplicationName(); + return StrUtil.format(CHECK_SQL_PATTERN, chainNameField, elDataField, chainTableName, chainApplicationNameField, applicationName); + } +} diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/vo/SQLParserVO.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/vo/SQLParserVO.java index 4459d1922..b549bafdc 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/vo/SQLParserVO.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/vo/SQLParserVO.java @@ -1,5 +1,7 @@ package com.yomahub.liteflow.parser.sql.vo; +import cn.hutool.core.util.StrUtil; + /** * 用于解析 RuleSourceExtData 的 VO 类,用于 sql 模式中 * @@ -8,212 +10,219 @@ package com.yomahub.liteflow.parser.sql.vo; */ public class SQLParserVO { - /** - * 连接地址 - */ - private String url; + /** + * 连接地址 + */ + private String url; - /** - * 驱动 - */ - private String driverClassName; + /** + * 驱动 + */ + private String driverClassName; - /** - * 账号名 - */ - private String username; + /** + * 账号名 + */ + private String username; - /** - * 密码 - */ - private String password; + /** + * 密码 + */ + private String password; - /** - * 应用名 - */ - private String applicationName; + /** + * 应用名 + */ + private String applicationName; - /** - * chain表名 - */ - private String chainTableName; + /** + * chain表名 + */ + private String chainTableName; - /** - * chain表里的应用名字段 - */ - private String chainApplicationNameField = "application_name"; + /** + * chain表里的应用名字段 + */ + private String chainApplicationNameField = "application_name"; - /** - * chainName - */ - private String chainNameField = "chain_name"; + /** + * chainName + */ + private String chainNameField = "chain_name"; - /** - * el 表达式相关数据 - */ - private String elDataField = "el_data"; + /** + * el 表达式相关数据 + */ + private String elDataField = "el_data"; - /** - * 脚本 node 表名 - */ - private String scriptTableName; + /** + * 脚本 node 表名 + */ + private String scriptTableName; - /** - * script表里的应用名字段 - */ - private String scriptApplicationNameField = "application_name"; + /** + * script表里的应用名字段 + */ + private String scriptApplicationNameField = "application_name"; - /** - * 脚本 node id 字段 - */ - private String scriptIdField = "script_id"; + /** + * 脚本 node id 字段 + */ + private String scriptIdField = "script_id"; - /** - * 脚本 node name 字段 - */ - private String scriptNameField = "script_name"; + /** + * 脚本 node name 字段 + */ + private String scriptNameField = "script_name"; - /** - * 脚本 node data 字段 - */ - private String scriptDataField = "script_data"; + /** + * 脚本 node data 字段 + */ + private String scriptDataField = "script_data"; - /** - * 脚本 node type 字段 - */ - private String scriptTypeField = "script_type"; + /** + * 脚本 node type 字段 + */ + private String scriptTypeField = "script_type"; - /** - * 脚本 node language 字段 - */ - private String scriptLanguageField; + /** + * 脚本 node language 字段 + */ + private String scriptLanguageField; - public String getUrl() { - return url; - } + public String getUrl() { + return url; + } - public void setUrl(String url) { - this.url = url; - } + public void setUrl(String url) { + this.url = url; + } - public String getDriverClassName() { - return driverClassName; - } + public String getDriverClassName() { + return driverClassName; + } - public void setDriverClassName(String driverClassName) { - this.driverClassName = driverClassName; - } + public void setDriverClassName(String driverClassName) { + this.driverClassName = driverClassName; + } - public String getUsername() { - return username; - } + public String getUsername() { + return username; + } - public void setUsername(String username) { - this.username = username; - } + public void setUsername(String username) { + this.username = username; + } - public String getPassword() { - return password; - } + public String getPassword() { + return password; + } - public void setPassword(String password) { - this.password = password; - } + public void setPassword(String password) { + this.password = password; + } - public String getApplicationName() { - return applicationName; - } + public String getApplicationName() { + return applicationName; + } - public void setApplicationName(String applicationName) { - this.applicationName = applicationName; - } + public void setApplicationName(String applicationName) { + this.applicationName = applicationName; + } - public String getChainTableName() { - return chainTableName; - } + public String getChainTableName() { + return chainTableName; + } - public void setChainTableName(String chainTableName) { - this.chainTableName = chainTableName; - } + public void setChainTableName(String chainTableName) { + this.chainTableName = chainTableName; + } - public String getChainApplicationNameField() { - return chainApplicationNameField; - } + public String getChainApplicationNameField() { + return chainApplicationNameField; + } - public void setChainApplicationNameField(String chainApplicationNameField) { - this.chainApplicationNameField = chainApplicationNameField; - } + public void setChainApplicationNameField(String chainApplicationNameField) { + this.chainApplicationNameField = chainApplicationNameField; + } - public String getChainNameField() { - return chainNameField; - } + public String getChainNameField() { + return chainNameField; + } - public void setChainNameField(String chainNameField) { - this.chainNameField = chainNameField; - } + public void setChainNameField(String chainNameField) { + this.chainNameField = chainNameField; + } - public String getElDataField() { - return elDataField; - } + public String getElDataField() { + return elDataField; + } - public void setElDataField(String elDataField) { - this.elDataField = elDataField; - } + public void setElDataField(String elDataField) { + this.elDataField = elDataField; + } - public String getScriptTableName() { - return scriptTableName; - } + public String getScriptTableName() { + return scriptTableName; + } - public void setScriptTableName(String scriptTableName) { - this.scriptTableName = scriptTableName; - } + public void setScriptTableName(String scriptTableName) { + this.scriptTableName = scriptTableName; + } - public String getScriptApplicationNameField() { - return scriptApplicationNameField; - } + public String getScriptApplicationNameField() { + return scriptApplicationNameField; + } - public void setScriptApplicationNameField(String scriptApplicationNameField) { - this.scriptApplicationNameField = scriptApplicationNameField; - } + public void setScriptApplicationNameField(String scriptApplicationNameField) { + this.scriptApplicationNameField = scriptApplicationNameField; + } - public String getScriptIdField() { - return scriptIdField; - } + public String getScriptIdField() { + return scriptIdField; + } - public void setScriptIdField(String scriptIdField) { - this.scriptIdField = scriptIdField; - } + public void setScriptIdField(String scriptIdField) { + this.scriptIdField = scriptIdField; + } - public String getScriptNameField() { - return scriptNameField; - } + public String getScriptNameField() { + return scriptNameField; + } - public void setScriptNameField(String scriptNameField) { - this.scriptNameField = scriptNameField; - } + public void setScriptNameField(String scriptNameField) { + this.scriptNameField = scriptNameField; + } - public String getScriptDataField() { - return scriptDataField; - } + public String getScriptDataField() { + return scriptDataField; + } - public void setScriptDataField(String scriptDataField) { - this.scriptDataField = scriptDataField; - } + public void setScriptDataField(String scriptDataField) { + this.scriptDataField = scriptDataField; + } - public String getScriptTypeField() { - return scriptTypeField; - } + public String getScriptTypeField() { + return scriptTypeField; + } - public void setScriptTypeField(String scriptTypeField) { - this.scriptTypeField = scriptTypeField; - } + public void setScriptTypeField(String scriptTypeField) { + this.scriptTypeField = scriptTypeField; + } - public String getScriptLanguageField() { - return scriptLanguageField; - } + public String getScriptLanguageField() { + return scriptLanguageField; + } - public void setScriptLanguageField(String scriptLanguageField) { - this.scriptLanguageField = scriptLanguageField; - } + public void setScriptLanguageField(String scriptLanguageField) { + this.scriptLanguageField = scriptLanguageField; + } + + /** + * 判断配资是否使用 IOC 已有数据源 + */ + public boolean isDefaultDataSource() { + return StrUtil.isBlank(url) && StrUtil.isBlank(username) && StrUtil.isBlank(password) && StrUtil.isBlank(driverClassName); + } } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonContextAware.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonContextAware.java index 8488019a5..4cb16d9e0 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonContextAware.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonContextAware.java @@ -1,10 +1,15 @@ package com.yomahub.liteflow.spi.solon; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import com.yomahub.liteflow.spi.ContextAware; import org.noear.solon.Solon; import org.noear.solon.core.BeanWrap; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * 基于代码形式的 Solon 上下文工具类 * @@ -12,73 +17,76 @@ import org.noear.solon.core.BeanWrap; */ public class SolonContextAware implements ContextAware { - @Override - public T getBean(String name) { - try { - return Solon.context().getBean(name); - } - catch (Exception e) { - return null; - } - } + @Override + public T getBean(String name) { + try { + return Solon.context().getBean(name); + } catch (Exception e) { + return null; + } + } - @Override - public T getBean(Class clazz) { - try { - return Solon.context().getBean(clazz); - } - catch (Exception e) { - return null; - } - } + @Override + public T getBean(Class clazz) { + try { + return Solon.context().getBean(clazz); + } catch (Exception e) { + return null; + } + } - private T getBean(String beanName, Class clazz) { - try { - return Solon.context().getBean(beanName); - } - catch (Exception e) { - return null; - } - } + private T getBean(String beanName, Class clazz) { + try { + return Solon.context().getBean(beanName); + } catch (Exception e) { + return null; + } + } - @Override - public T registerBean(String beanName, Class c) { - BeanWrap beanWrap = new BeanWrap(Solon.context(), c, null, beanName); - Solon.context().putWrap(beanName, beanWrap); + @Override + public T registerBean(String beanName, Class c) { + BeanWrap beanWrap = new BeanWrap(Solon.context(), c, null, beanName); + Solon.context().putWrap(beanName, beanWrap); - return beanWrap.get(); - } + return beanWrap.get(); + } - @Override - public T registerBean(Class c) { - return registerBean(c.getName(), c); - } + @Override + public T registerBean(Class c) { + return registerBean(c.getName(), c); + } - @Override - public T registerBean(String beanName, Object bean) { - BeanWrap beanWrap = new BeanWrap(Solon.context(), bean.getClass(), bean, beanName); - Solon.context().putWrap(beanName, beanWrap); + @Override + public T registerBean(String beanName, Object bean) { + BeanWrap beanWrap = new BeanWrap(Solon.context(), bean.getClass(), bean, beanName); + Solon.context().putWrap(beanName, beanWrap); - return beanWrap.get(); - } + return beanWrap.get(); + } - @Override - public T registerOrGet(String beanName, Class clazz) { - T t = getBean(beanName, clazz); - if (ObjectUtil.isNull(t)) { - t = registerBean(beanName, clazz); - } - return t; - } + @Override + public T registerOrGet(String beanName, Class clazz) { + T t = getBean(beanName, clazz); + if (ObjectUtil.isNull(t)) { + t = registerBean(beanName, clazz); + } + return t; + } - @Override - public boolean hasBean(String beanName) { - return Solon.context().hasWrap(beanName); - } + @Override + public Map getBeansOfType(Class type) { + List wrapsOfType = Solon.context().getWrapsOfType(type); + return CollUtil.toMap(wrapsOfType, new HashMap(), BeanWrap::name, BeanWrap::get); + } - @Override - public int priority() { - return 1; - } + @Override + public boolean hasBean(String beanName) { + return Solon.context().hasWrap(beanName); + } + + @Override + public int priority() { + return 1; + } } diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringAware.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringAware.java index 232adecbc..41e604f00 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringAware.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringAware.java @@ -1,10 +1,8 @@ package com.yomahub.liteflow.spi.spring; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.ReflectUtil; import com.yomahub.liteflow.spi.ContextAware; import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.GenericBeanDefinition; @@ -12,6 +10,8 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ConfigurableApplicationContext; +import java.util.Map; + /** * 基于代码形式的spring上下文工具类 * @@ -19,83 +19,87 @@ import org.springframework.context.ConfigurableApplicationContext; */ public class SpringAware implements ApplicationContextAware, ContextAware { - private static ApplicationContext applicationContext = null; + private static ApplicationContext applicationContext = null; - public SpringAware() { - } + public SpringAware() { + } - @Override - public void setApplicationContext(ApplicationContext ac) throws BeansException { - applicationContext = ac; - } + @Override + public void setApplicationContext(ApplicationContext ac) throws BeansException { + applicationContext = ac; + } - public static ApplicationContext getApplicationContext() { - return applicationContext; - } + public static ApplicationContext getApplicationContext() { + return applicationContext; + } - @Override - public T getBean(String name) { - T t = (T) applicationContext.getBean(name); - return t; - } + @Override + public T getBean(String name) { + T t = (T) applicationContext.getBean(name); + return t; + } - @Override - public T getBean(Class clazz) { - T t = applicationContext.getBean(clazz); - return t; - } + @Override + public Map getBeansOfType(Class type) { + return applicationContext.getBeansOfType(type); + } - private T getBean(String beanName, Class clazz) { - T t = applicationContext.getBean(beanName, clazz); - return t; - } + @Override + public T getBean(Class clazz) { + T t = applicationContext.getBean(clazz); + return t; + } - @Override - public T registerBean(String beanName, Class c) { - DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) applicationContext - .getAutowireCapableBeanFactory(); - BeanDefinition beanDefinition = new GenericBeanDefinition(); - beanDefinition.setBeanClassName(c.getName()); - beanFactory.setAllowBeanDefinitionOverriding(true); - beanFactory.registerBeanDefinition(beanName, beanDefinition); - return getBean(beanName); - } + private T getBean(String beanName, Class clazz) { + T t = applicationContext.getBean(beanName, clazz); + return t; + } - @Override - public T registerBean(Class c) { - return registerBean(c.getName(), c); - } + @Override + public T registerBean(String beanName, Class c) { + DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) applicationContext + .getAutowireCapableBeanFactory(); + BeanDefinition beanDefinition = new GenericBeanDefinition(); + beanDefinition.setBeanClassName(c.getName()); + beanFactory.setAllowBeanDefinitionOverriding(true); + beanFactory.registerBeanDefinition(beanName, beanDefinition); + return getBean(beanName); + } - @Override - public T registerBean(String beanName, Object bean) { - ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext; - DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) configurableApplicationContext - .getAutowireCapableBeanFactory(); - defaultListableBeanFactory.registerSingleton(beanName, bean); - return (T) configurableApplicationContext.getBean(beanName); - } + @Override + public T registerBean(Class c) { + return registerBean(c.getName(), c); + } - @Override - public T registerOrGet(String beanName, Class clazz) { - if (ObjectUtil.isNull(applicationContext)) { - return null; - } - try { - return getBean(beanName, clazz); - } - catch (Exception e) { - return registerBean(beanName, clazz); - } - } + @Override + public T registerBean(String beanName, Object bean) { + ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext; + DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) configurableApplicationContext + .getAutowireCapableBeanFactory(); + defaultListableBeanFactory.registerSingleton(beanName, bean); + return (T) configurableApplicationContext.getBean(beanName); + } - @Override - public boolean hasBean(String beanName) { - return applicationContext.containsBean(beanName); - } + @Override + public T registerOrGet(String beanName, Class clazz) { + if (ObjectUtil.isNull(applicationContext)) { + return null; + } + try { + return getBean(beanName, clazz); + } catch (Exception e) { + return registerBean(beanName, clazz); + } + } - @Override - public int priority() { - return 1; - } + @Override + public boolean hasBean(String beanName) { + return applicationContext.containsBean(beanName); + } + + @Override + public int priority() { + return 1; + } } diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/LiteFlowSpringUtil.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/LiteFlowSpringUtil.java new file mode 100644 index 000000000..fe0197188 --- /dev/null +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/LiteFlowSpringUtil.java @@ -0,0 +1,275 @@ +package com.yomahub.liteflow.spring; + +import cn.hutool.core.exceptions.UtilException; +import cn.hutool.core.lang.TypeReference; +import cn.hutool.core.util.ArrayUtil; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.ListableBeanFactory; +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.ResolvableType; + +import java.lang.reflect.ParameterizedType; +import java.util.Arrays; +import java.util.Map; + + +public class LiteFlowSpringUtil implements BeanFactoryPostProcessor, ApplicationContextAware { + + /** + * "@PostConstruct"注解标记的类中,由于ApplicationContext还未加载,导致空指针
+ * 因此实现BeanFactoryPostProcessor注入ConfigurableListableBeanFactory实现bean的操作 + */ + private static ConfigurableListableBeanFactory beanFactory; + /** + * Spring应用上下文环境 + */ + private static ApplicationContext applicationContext; + + @SuppressWarnings("NullableProblems") + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { + LiteFlowSpringUtil.beanFactory = beanFactory; + } + + @SuppressWarnings("NullableProblems") + @Override + public void setApplicationContext(ApplicationContext applicationContext) { + LiteFlowSpringUtil.applicationContext = applicationContext; + } + + /** + * 获取{@link ApplicationContext} + * + * @return {@link ApplicationContext} + */ + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + /** + * 获取{@link ListableBeanFactory},可能为{@link ConfigurableListableBeanFactory} 或 {@link ApplicationContextAware} + * + * @return {@link ListableBeanFactory} + * @since 5.7.0 + */ + public static ListableBeanFactory getBeanFactory() { + final ListableBeanFactory factory = null == beanFactory ? applicationContext : beanFactory; + if (null == factory) { + throw new UtilException("No ConfigurableListableBeanFactory or ApplicationContext injected, maybe not in the Spring environment?"); + } + return factory; + } + + /** + * 获取{@link ConfigurableListableBeanFactory} + * + * @return {@link ConfigurableListableBeanFactory} + * @throws UtilException 当上下文非ConfigurableListableBeanFactory抛出异常 + * @since 5.7.7 + */ + public static ConfigurableListableBeanFactory getConfigurableBeanFactory() throws UtilException { + final ConfigurableListableBeanFactory factory; + if (null != beanFactory) { + factory = beanFactory; + } else if (applicationContext instanceof ConfigurableApplicationContext) { + factory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory(); + } else { + throw new UtilException("No ConfigurableListableBeanFactory from context!"); + } + return factory; + } + + //通过name获取 Bean. + + /** + * 通过name获取 Bean + * + * @param Bean类型 + * @param name Bean名称 + * @return Bean + */ + @SuppressWarnings("unchecked") + public static T getBean(String name) { + return (T) getBeanFactory().getBean(name); + } + + /** + * 通过class获取Bean + * + * @param Bean类型 + * @param clazz Bean类 + * @return Bean对象 + */ + public static T getBean(Class clazz) { + return getBeanFactory().getBean(clazz); + } + + /** + * 通过name,以及Clazz返回指定的Bean + * + * @param bean类型 + * @param name Bean名称 + * @param clazz bean类型 + * @return Bean对象 + */ + public static T getBean(String name, Class clazz) { + return getBeanFactory().getBean(name, clazz); + } + + /** + * 通过类型参考返回带泛型参数的Bean + * + * @param reference 类型参考,用于持有转换后的泛型类型 + * @param Bean类型 + * @return 带泛型参数的Bean + * @since 5.4.0 + */ + @SuppressWarnings("unchecked") + public static T getBean(TypeReference reference) { + final ParameterizedType parameterizedType = (ParameterizedType) reference.getType(); + final Class rawType = (Class) parameterizedType.getRawType(); + final Class[] genericTypes = Arrays.stream(parameterizedType.getActualTypeArguments()).map(type -> (Class) type).toArray(Class[]::new); + final String[] beanNames = getBeanFactory().getBeanNamesForType(ResolvableType.forClassWithGenerics(rawType, genericTypes)); + return getBean(beanNames[0], rawType); + } + + /** + * 获取指定类型对应的所有Bean,包括子类 + * + * @param Bean类型 + * @param type 类、接口,null表示获取所有bean + * @return 类型对应的bean,key是bean注册的name,value是Bean + * @since 5.3.3 + */ + public static Map getBeansOfType(Class type) { + return getBeanFactory().getBeansOfType(type); + } + + /** + * 获取指定类型对应的Bean名称,包括子类 + * + * @param type 类、接口,null表示获取所有bean名称 + * @return bean名称 + * @since 5.3.3 + */ + public static String[] getBeanNamesForType(Class type) { + return getBeanFactory().getBeanNamesForType(type); + } + + /** + * 获取配置文件配置项的值 + * + * @param key 配置项key + * @return 属性值 + * @since 5.3.3 + */ + public static String getProperty(String key) { + if (null == applicationContext) { + return null; + } + return applicationContext.getEnvironment().getProperty(key); + } + + /** + * 获取应用程序名称 + * + * @return 应用程序名称 + * @since 5.7.12 + */ + public static String getApplicationName() { + return getProperty("spring.application.name"); + } + + /** + * 获取当前的环境配置,无配置返回null + * + * @return 当前的环境配置 + * @since 5.3.3 + */ + public static String[] getActiveProfiles() { + if (null == applicationContext) { + return null; + } + return applicationContext.getEnvironment().getActiveProfiles(); + } + + /** + * 获取当前的环境配置,当有多个环境配置时,只获取第一个 + * + * @return 当前的环境配置 + * @since 5.3.3 + */ + public static String getActiveProfile() { + final String[] activeProfiles = getActiveProfiles(); + return ArrayUtil.isNotEmpty(activeProfiles) ? activeProfiles[0] : null; + } + + /** + * 动态向Spring注册Bean + *

+ * 由{@link org.springframework.beans.factory.BeanFactory} 实现,通过工具开放API + *

+ * 更新: shadow 2021-07-29 17:20:44 增加自动注入,修复注册bean无法反向注入的问题 + * + * @param Bean类型 + * @param beanName 名称 + * @param bean bean + * @author shadow + * @since 5.4.2 + */ + public static void registerBean(String beanName, T bean) { + final ConfigurableListableBeanFactory factory = getConfigurableBeanFactory(); + factory.autowireBean(bean); + factory.registerSingleton(beanName, bean); + } + + /** + * 注销bean + *

+ * 将Spring中的bean注销,请谨慎使用 + * + * @param beanName bean名称 + * @author shadow + * @since 5.7.7 + */ + public static void unregisterBean(String beanName) { + final ConfigurableListableBeanFactory factory = getConfigurableBeanFactory(); + if (factory instanceof DefaultSingletonBeanRegistry) { + DefaultSingletonBeanRegistry registry = (DefaultSingletonBeanRegistry) factory; + registry.destroySingleton(beanName); + } else { + throw new UtilException("Can not unregister bean, the factory is not a DefaultSingletonBeanRegistry!"); + } + } + + /** + * 发布事件 + * + * @param event 待发布的事件,事件必须是{@link ApplicationEvent}的子类 + * @since 5.7.12 + */ + public static void publishEvent(ApplicationEvent event) { + if (null != applicationContext) { + applicationContext.publishEvent(event); + } + } + + /** + * 发布事件 + * Spring 4.2+ 版本事件可以不再是{@link ApplicationEvent}的子类 + * + * @param event 待发布的事件 + * @since 5.7.21 + */ + public static void publishEvent(Object event) { + if (null != applicationContext) { + applicationContext.publishEvent(event); + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELMultiLanguageSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELMultiLanguageSpringbootTest.java new file mode 100644 index 000000000..c573fd243 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELMultiLanguageSpringbootTest.java @@ -0,0 +1,34 @@ +package com.yomahub.liteflow.test.def; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; + +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/application-xml.properties") +@SpringBootTest(classes = SQLWithXmlELMultiLanguageSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.sql.cmp"}) +public class SQLWithXmlELMultiLanguageSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMultiLanguage1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("x2[python脚本]==>x0[if 脚本]==>a==>b", response.getExecuteStepStrWithoutTime()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java new file mode 100644 index 000000000..87edf48cd --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java @@ -0,0 +1,101 @@ +package com.yomahub.liteflow.test.def; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.parser.sql.exception.ELSQLException; +import com.yomahub.liteflow.parser.sql.vo.SQLParserVO; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.util.JsonUtil; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; + +/** + * @author tangkc + * @since 2.9.0 + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/application-xml.properties") +@SpringBootTest(classes = SQLWithXmlELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.sql.cmp"}) +public class SQLWithXmlELSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testSQLWithXml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertEquals("a==>b==>c", response.getExecuteStepStr()); + + // 修改数据库 + changeData(); + + // 重新加载规则 + flowExecutor.reloadRule(); + Assertions.assertEquals("a==>c==>b", flowExecutor.execute2Resp("chain1", "arg").getExecuteStepStr()); + } + + @Test + public void testSQLWithScriptXml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("x0[if 脚本]==>a==>b", response.getExecuteStepStrWithoutTime()); + + // 修改数据库 + changeScriptData(); + // 重新加载规则 + flowExecutor.reloadRule(); + Assertions.assertEquals("x0[if 脚本]", flowExecutor.execute2Resp("chain3", "arg").getExecuteStepStr()); + } + + /** + * 修改数据库数据 + */ + private void changeData() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + SQLParserVO sqlParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), SQLParserVO.class); + Connection connection; + try { + connection = DriverManager.getConnection(sqlParserVO.getUrl(), sqlParserVO.getUsername(), + sqlParserVO.getPassword()); + Statement statement = connection.createStatement(); + statement.executeUpdate("UPDATE EL_TABLE SET EL_DATA='THEN(a, c, b);' WHERE chain_name='chain1'"); + } catch (SQLException e) { + throw new ELSQLException(e.getMessage()); + } + } + + /** + * 修改数据库数据 + */ + private void changeScriptData() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + SQLParserVO sqlParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), SQLParserVO.class); + Connection connection; + try { + connection = DriverManager.getConnection(sqlParserVO.getUrl(), sqlParserVO.getUsername(), + sqlParserVO.getPassword()); + Statement statement = connection.createStatement(); + statement.executeUpdate( + "UPDATE SCRIPT_NODE_TABLE SET SCRIPT_NODE_DATA='return false;' WHERE SCRIPT_NODE_ID='x0'"); + } catch (SQLException e) { + throw new ELSQLException(e.getMessage()); + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-data-source-xml.properties b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-data-source-xml.properties new file mode 100644 index 000000000..4458be232 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-data-source-xml.properties @@ -0,0 +1,21 @@ +liteflow.rule-source-ext-data={\ + "applicationName":"demo",\ + "chainTableName":"EL_TABLE",\ + "chainApplicationNameField":"application_name",\ + "chainNameField":"chain_name",\ + "elDataField":"EL_DATA",\ + "scriptTableName":"script_node_table",\ + "scriptApplicationNameField":"application_name",\ + "scriptIdField":"script_node_id",\ + "scriptNameField":"script_node_name",\ + "scriptDataField":"script_node_data",\ + "scriptLanguageField":"script_language",\ + "scriptTypeField":"script_node_type"\ + } +spring.datasource.driver-class-name=org.h2.Driver +spring.datasource.url=jdbc:h2:mem:test_db;MODE=MySQL +spring.datasource.username=root +spring.datasource.password=123456 +spring.datasource.schema=classpath:/sql/schema.sql +spring.datasource.data=classpath:/sql/data.sql +spring.datasource.platform=h2 \ No newline at end of file From f0d92de9c3f7dda7403e8fd8a91a899e2ead4b78 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Sun, 16 Jul 2023 22:12:30 +0800 Subject: [PATCH 03/18] =?UTF-8?q?enhancement=20#I7LGZR=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=9C=AA=E5=A1=AB=E5=86=99=20chainId=20=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/parser/helper/ParserHelper.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java index 983521d3e..eb239f76f 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java @@ -140,6 +140,8 @@ public class ParserHelper { // 校验加载的 chainName 是否有重复的 // TODO 这里是否有个问题,当混合格式加载的时候,2个同名的Chain在不同的文件里,就不行了 String chainName = Optional.ofNullable(e.attributeValue(ID)).orElse(e.attributeValue(NAME)); + // 检查 chainName + checkChainId(chainName, e.getText()); if (!chainNameSet.add(chainName)) { throw new ChainDuplicateException(String.format("[chain name duplicate] chainName=%s", chainName)); } @@ -202,9 +204,11 @@ public class ParserHelper { JsonNode innerJsonObject = iterator.next(); // 校验加载的 chainName 是否有重复的 // TODO 这里是否有个问题,当混合格式加载的时候,2个同名的Chain在不同的文件里,就不行了 - String chainName = Optional.ofNullable(innerJsonObject.get(ID)) - .orElse(innerJsonObject.get(NAME)) - .textValue(); + JsonNode chainNameJsonNode = Optional.ofNullable(innerJsonObject.get(ID)) + .orElse(innerJsonObject.get(NAME)); + String chainName = Optional.ofNullable(chainNameJsonNode).map(JsonNode::textValue).orElse(null); + // 检查 chainName + checkChainId(chainName, innerJsonObject.toPrettyString()); if (!chainNameSet.add(chainName)) { throw new ChainDuplicateException(String.format("[chain name duplicate] chainName=%s", chainName)); } @@ -250,6 +254,17 @@ public class ParserHelper { chainELBuilder.setEL(el).build(); } + /** + * 检查 chainId + * @param chainId chainId + * @param elData elData + */ + private static void checkChainId(String chainId, String elData) { + if (StrUtil.isBlank(chainId)) { + throw new ParseException("missing chain id in expression \r\n" + elData); + } + } + private static class RegexUtil { // java 注释的正则表达式 From 62419c44196b6a8af9531789b55c7cd8b0aacb14 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Sun, 16 Jul 2023 23:18:37 +0800 Subject: [PATCH 04/18] =?UTF-8?q?I7L5DX=20#I7L5DX=202.10.5=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=B8=ADScriptBean=E6=B3=A8=E8=A7=A3=E6=B3=A8?= =?UTF-8?q?=E5=85=A5bean=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/core/proxy/ComponentProxy.java | 3 +- .../liteflow/exception/ProxyException.java | 31 +++++++++++++++++++ .../script/proxy/ScriptBeanProxy.java | 22 +++++++++---- .../LiteFlowScriptScriptbeanGroovyELTest.java | 9 ++++++ .../groovy/scriptbean/bean/DemoBean5.java | 26 ++++++++++++++++ .../src/test/resources/scriptbean/flow.xml | 11 +++++++ 6 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/exception/ProxyException.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean5.java diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java index a0d5ebea1..4ca355f87 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java @@ -10,6 +10,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; import com.yomahub.liteflow.exception.ComponentMethodDefineErrorException; import com.yomahub.liteflow.exception.LiteFlowException; +import com.yomahub.liteflow.exception.ProxyException; import com.yomahub.liteflow.log.LFLog; import com.yomahub.liteflow.log.LFLoggerManager; import com.yomahub.liteflow.util.LiteFlowProxyUtil; @@ -153,7 +154,7 @@ public class ComponentProxy { return nodeComponent; } catch (Exception e) { - throw new LiteFlowException(e); + throw new ProxyException(e); } }).collect(Collectors.toList()); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ProxyException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ProxyException.java new file mode 100644 index 000000000..77e21c118 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ProxyException.java @@ -0,0 +1,31 @@ + +package com.yomahub.liteflow.exception; + +/** + * @author Bryan.Zhang + */ +public class ProxyException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** 异常信息 */ + private String message; + + public ProxyException(String message) { + this.message = message; + } + + public ProxyException(Throwable cause) { + super(cause); + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/script/proxy/ScriptBeanProxy.java b/liteflow-core/src/main/java/com/yomahub/liteflow/script/proxy/ScriptBeanProxy.java index c70c13a25..35c029221 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/script/proxy/ScriptBeanProxy.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/script/proxy/ScriptBeanProxy.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.script.proxy; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.*; import com.yomahub.liteflow.exception.LiteFlowException; +import com.yomahub.liteflow.exception.ProxyException; import com.yomahub.liteflow.exception.ScriptBeanMethodInvokeException; import com.yomahub.liteflow.log.LFLog; import com.yomahub.liteflow.log.LFLoggerManager; @@ -10,8 +11,18 @@ import com.yomahub.liteflow.script.annotation.ScriptBean; import com.yomahub.liteflow.util.LiteFlowProxyUtil; import com.yomahub.liteflow.util.SerialsUtil; import net.bytebuddy.ByteBuddy; +import net.bytebuddy.description.method.ParameterDescription; +import net.bytebuddy.description.modifier.Visibility; +import net.bytebuddy.dynamic.DynamicType; +import net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy; +import net.bytebuddy.implementation.FixedValue; import net.bytebuddy.implementation.InvocationHandlerAdapter; +import net.bytebuddy.implementation.MethodCall; +import net.bytebuddy.implementation.MethodDelegation; +import net.bytebuddy.implementation.bytecode.constant.DefaultValue; import net.bytebuddy.matcher.ElementMatchers; + +import java.lang.reflect.Constructor; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.util.Arrays; @@ -56,19 +67,18 @@ public class ScriptBeanProxy { } try { - return new ByteBuddy().subclass(orignalClass) - .name(StrUtil.format("{}.ByteBuddy${}", ClassUtil.getPackage(orignalClass), - SerialsUtil.generateShortUUID())) + Class c = new ByteBuddy().subclass(orignalClass).name(StrUtil.format("{}.ByteBuddy${}", ClassUtil.getPackage(orignalClass),SerialsUtil.generateShortUUID())) .method(ElementMatchers.any()) .intercept(InvocationHandlerAdapter.of(new AopInvocationHandler(bean, methodNameList))) .annotateType(orignalClass.getAnnotations()) .make() .load(ScriptBeanProxy.class.getClassLoader()) - .getLoaded() - .newInstance(); + .getLoaded(); + + return ReflectUtil.newInstanceIfPossible(c); } catch (Exception e) { - throw new LiteFlowException(e); + throw new ProxyException(e); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/LiteFlowScriptScriptbeanGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/LiteFlowScriptScriptbeanGroovyELTest.java index 2cf256c31..11c33edef 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/LiteFlowScriptScriptbeanGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/LiteFlowScriptScriptbeanGroovyELTest.java @@ -92,4 +92,13 @@ public class LiteFlowScriptScriptbeanGroovyELTest extends BaseTest { Assertions.assertEquals("hello", context.get("demo")); } + //测试用构造方法的方式注入bean的场景 + @Test + public void testScriptBean8() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals("hello,jordan", context.getData("demo")); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean5.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean5.java new file mode 100644 index 000000000..bc7aeaff7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean5.java @@ -0,0 +1,26 @@ +package com.yomahub.liteflow.test.script.groovy.scriptbean.bean; + +import com.yomahub.liteflow.script.annotation.ScriptBean; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component +@ScriptBean("demo5") +public class DemoBean5 { + + private final DemoBean2 demoBean2; + + public DemoBean5(DemoBean2 demoBean2) { + this.demoBean2 = demoBean2; + } + + public String getDemoStr1() { + return "hello"; + } + + public String getDemoStr2(String name) { + return demoBean2.getDemoStr2(name); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/scriptbean/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/scriptbean/flow.xml index ac6c14749..f90327b4f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/scriptbean/flow.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/scriptbean/flow.xml @@ -50,6 +50,13 @@ abcCx.put("demo", str) ]]> + + + + @@ -79,4 +86,8 @@ THEN(a,b,c,s5); + + + THEN(a,b,c,f); + \ No newline at end of file From fd0769dd9a9e79346257650514d1a96872c4153e Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Mon, 17 Jul 2023 08:43:56 +0800 Subject: [PATCH 05/18] =?UTF-8?q?enhancement=20#I7KZCZ=20=E5=9C=A8?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=95=B0=E6=8D=AE=E5=BA=93=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E4=BD=BF=E7=94=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E4=B8=AD=E5=B7=B2=E7=BB=8F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=9A=84=E6=95=B0=E6=8D=AE=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/spring/LiteFlowSpringUtil.java | 275 ------------------ 1 file changed, 275 deletions(-) delete mode 100644 liteflow-spring/src/main/java/com/yomahub/liteflow/spring/LiteFlowSpringUtil.java diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/LiteFlowSpringUtil.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/LiteFlowSpringUtil.java deleted file mode 100644 index fe0197188..000000000 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/LiteFlowSpringUtil.java +++ /dev/null @@ -1,275 +0,0 @@ -package com.yomahub.liteflow.spring; - -import cn.hutool.core.exceptions.UtilException; -import cn.hutool.core.lang.TypeReference; -import cn.hutool.core.util.ArrayUtil; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.ListableBeanFactory; -import org.springframework.beans.factory.config.BeanFactoryPostProcessor; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.context.ApplicationEvent; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.core.ResolvableType; - -import java.lang.reflect.ParameterizedType; -import java.util.Arrays; -import java.util.Map; - - -public class LiteFlowSpringUtil implements BeanFactoryPostProcessor, ApplicationContextAware { - - /** - * "@PostConstruct"注解标记的类中,由于ApplicationContext还未加载,导致空指针
- * 因此实现BeanFactoryPostProcessor注入ConfigurableListableBeanFactory实现bean的操作 - */ - private static ConfigurableListableBeanFactory beanFactory; - /** - * Spring应用上下文环境 - */ - private static ApplicationContext applicationContext; - - @SuppressWarnings("NullableProblems") - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { - LiteFlowSpringUtil.beanFactory = beanFactory; - } - - @SuppressWarnings("NullableProblems") - @Override - public void setApplicationContext(ApplicationContext applicationContext) { - LiteFlowSpringUtil.applicationContext = applicationContext; - } - - /** - * 获取{@link ApplicationContext} - * - * @return {@link ApplicationContext} - */ - public static ApplicationContext getApplicationContext() { - return applicationContext; - } - - /** - * 获取{@link ListableBeanFactory},可能为{@link ConfigurableListableBeanFactory} 或 {@link ApplicationContextAware} - * - * @return {@link ListableBeanFactory} - * @since 5.7.0 - */ - public static ListableBeanFactory getBeanFactory() { - final ListableBeanFactory factory = null == beanFactory ? applicationContext : beanFactory; - if (null == factory) { - throw new UtilException("No ConfigurableListableBeanFactory or ApplicationContext injected, maybe not in the Spring environment?"); - } - return factory; - } - - /** - * 获取{@link ConfigurableListableBeanFactory} - * - * @return {@link ConfigurableListableBeanFactory} - * @throws UtilException 当上下文非ConfigurableListableBeanFactory抛出异常 - * @since 5.7.7 - */ - public static ConfigurableListableBeanFactory getConfigurableBeanFactory() throws UtilException { - final ConfigurableListableBeanFactory factory; - if (null != beanFactory) { - factory = beanFactory; - } else if (applicationContext instanceof ConfigurableApplicationContext) { - factory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory(); - } else { - throw new UtilException("No ConfigurableListableBeanFactory from context!"); - } - return factory; - } - - //通过name获取 Bean. - - /** - * 通过name获取 Bean - * - * @param Bean类型 - * @param name Bean名称 - * @return Bean - */ - @SuppressWarnings("unchecked") - public static T getBean(String name) { - return (T) getBeanFactory().getBean(name); - } - - /** - * 通过class获取Bean - * - * @param Bean类型 - * @param clazz Bean类 - * @return Bean对象 - */ - public static T getBean(Class clazz) { - return getBeanFactory().getBean(clazz); - } - - /** - * 通过name,以及Clazz返回指定的Bean - * - * @param bean类型 - * @param name Bean名称 - * @param clazz bean类型 - * @return Bean对象 - */ - public static T getBean(String name, Class clazz) { - return getBeanFactory().getBean(name, clazz); - } - - /** - * 通过类型参考返回带泛型参数的Bean - * - * @param reference 类型参考,用于持有转换后的泛型类型 - * @param Bean类型 - * @return 带泛型参数的Bean - * @since 5.4.0 - */ - @SuppressWarnings("unchecked") - public static T getBean(TypeReference reference) { - final ParameterizedType parameterizedType = (ParameterizedType) reference.getType(); - final Class rawType = (Class) parameterizedType.getRawType(); - final Class[] genericTypes = Arrays.stream(parameterizedType.getActualTypeArguments()).map(type -> (Class) type).toArray(Class[]::new); - final String[] beanNames = getBeanFactory().getBeanNamesForType(ResolvableType.forClassWithGenerics(rawType, genericTypes)); - return getBean(beanNames[0], rawType); - } - - /** - * 获取指定类型对应的所有Bean,包括子类 - * - * @param Bean类型 - * @param type 类、接口,null表示获取所有bean - * @return 类型对应的bean,key是bean注册的name,value是Bean - * @since 5.3.3 - */ - public static Map getBeansOfType(Class type) { - return getBeanFactory().getBeansOfType(type); - } - - /** - * 获取指定类型对应的Bean名称,包括子类 - * - * @param type 类、接口,null表示获取所有bean名称 - * @return bean名称 - * @since 5.3.3 - */ - public static String[] getBeanNamesForType(Class type) { - return getBeanFactory().getBeanNamesForType(type); - } - - /** - * 获取配置文件配置项的值 - * - * @param key 配置项key - * @return 属性值 - * @since 5.3.3 - */ - public static String getProperty(String key) { - if (null == applicationContext) { - return null; - } - return applicationContext.getEnvironment().getProperty(key); - } - - /** - * 获取应用程序名称 - * - * @return 应用程序名称 - * @since 5.7.12 - */ - public static String getApplicationName() { - return getProperty("spring.application.name"); - } - - /** - * 获取当前的环境配置,无配置返回null - * - * @return 当前的环境配置 - * @since 5.3.3 - */ - public static String[] getActiveProfiles() { - if (null == applicationContext) { - return null; - } - return applicationContext.getEnvironment().getActiveProfiles(); - } - - /** - * 获取当前的环境配置,当有多个环境配置时,只获取第一个 - * - * @return 当前的环境配置 - * @since 5.3.3 - */ - public static String getActiveProfile() { - final String[] activeProfiles = getActiveProfiles(); - return ArrayUtil.isNotEmpty(activeProfiles) ? activeProfiles[0] : null; - } - - /** - * 动态向Spring注册Bean - *

- * 由{@link org.springframework.beans.factory.BeanFactory} 实现,通过工具开放API - *

- * 更新: shadow 2021-07-29 17:20:44 增加自动注入,修复注册bean无法反向注入的问题 - * - * @param Bean类型 - * @param beanName 名称 - * @param bean bean - * @author shadow - * @since 5.4.2 - */ - public static void registerBean(String beanName, T bean) { - final ConfigurableListableBeanFactory factory = getConfigurableBeanFactory(); - factory.autowireBean(bean); - factory.registerSingleton(beanName, bean); - } - - /** - * 注销bean - *

- * 将Spring中的bean注销,请谨慎使用 - * - * @param beanName bean名称 - * @author shadow - * @since 5.7.7 - */ - public static void unregisterBean(String beanName) { - final ConfigurableListableBeanFactory factory = getConfigurableBeanFactory(); - if (factory instanceof DefaultSingletonBeanRegistry) { - DefaultSingletonBeanRegistry registry = (DefaultSingletonBeanRegistry) factory; - registry.destroySingleton(beanName); - } else { - throw new UtilException("Can not unregister bean, the factory is not a DefaultSingletonBeanRegistry!"); - } - } - - /** - * 发布事件 - * - * @param event 待发布的事件,事件必须是{@link ApplicationEvent}的子类 - * @since 5.7.12 - */ - public static void publishEvent(ApplicationEvent event) { - if (null != applicationContext) { - applicationContext.publishEvent(event); - } - } - - /** - * 发布事件 - * Spring 4.2+ 版本事件可以不再是{@link ApplicationEvent}的子类 - * - * @param event 待发布的事件 - * @since 5.7.21 - */ - public static void publishEvent(Object event) { - if (null != applicationContext) { - applicationContext.publishEvent(event); - } - } -} From 8c5b103752e65774efe653b6b33f52a7731a8c52 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Tue, 18 Jul 2023 22:40:29 +0800 Subject: [PATCH 06/18] =?UTF-8?q?enhancement=20#I7KZCZ=20=E5=9C=A8?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=95=B0=E6=8D=AE=E5=BA=93=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E4=BD=BF=E7=94=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E4=B8=AD=E5=B7=B2=E7=BB=8F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=9A=84=E6=95=B0=E6=8D=AE=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../def/SQLWithXmlELMultiLanguageSpringbootTest.java | 2 +- .../test/def/SQLWithXmlELSpringbootTest.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELMultiLanguageSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELMultiLanguageSpringbootTest.java index c573fd243..ee72f5f9a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELMultiLanguageSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELMultiLanguageSpringbootTest.java @@ -15,7 +15,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import javax.annotation.Resource; @ExtendWith(SpringExtension.class) -@TestPropertySource(value = "classpath:/application-xml.properties") +@TestPropertySource(value = "classpath:/application-data-source-xml.properties") @SpringBootTest(classes = SQLWithXmlELMultiLanguageSpringbootTest.class) @EnableAutoConfiguration @ComponentScan({"com.yomahub.liteflow.test.sql.cmp"}) diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java index 87edf48cd..8e86d5129 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java @@ -18,8 +18,8 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; import javax.annotation.Resource; +import javax.sql.DataSource; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; @@ -28,7 +28,7 @@ import java.sql.Statement; * @since 2.9.0 */ @ExtendWith(SpringExtension.class) -@TestPropertySource(value = "classpath:/application-xml.properties") +@TestPropertySource(value = "classpath:/application-data-source-xml.properties") @SpringBootTest(classes = SQLWithXmlELSpringbootTest.class) @EnableAutoConfiguration @ComponentScan({"com.yomahub.liteflow.test.sql.cmp"}) @@ -36,6 +36,8 @@ public class SQLWithXmlELSpringbootTest extends BaseTest { @Resource private FlowExecutor flowExecutor; + @Resource + private DataSource dataSource; @Test public void testSQLWithXml() { @@ -71,8 +73,7 @@ public class SQLWithXmlELSpringbootTest extends BaseTest { SQLParserVO sqlParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), SQLParserVO.class); Connection connection; try { - connection = DriverManager.getConnection(sqlParserVO.getUrl(), sqlParserVO.getUsername(), - sqlParserVO.getPassword()); + connection = dataSource.getConnection(); Statement statement = connection.createStatement(); statement.executeUpdate("UPDATE EL_TABLE SET EL_DATA='THEN(a, c, b);' WHERE chain_name='chain1'"); } catch (SQLException e) { @@ -88,8 +89,7 @@ public class SQLWithXmlELSpringbootTest extends BaseTest { SQLParserVO sqlParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), SQLParserVO.class); Connection connection; try { - connection = DriverManager.getConnection(sqlParserVO.getUrl(), sqlParserVO.getUsername(), - sqlParserVO.getPassword()); + connection = dataSource.getConnection(); Statement statement = connection.createStatement(); statement.executeUpdate( "UPDATE SCRIPT_NODE_TABLE SET SCRIPT_NODE_DATA='return false;' WHERE SCRIPT_NODE_ID='x0'"); From ae21f6a5dc594afeab857a79c95f1998739a9b5f Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Tue, 18 Jul 2023 22:41:37 +0800 Subject: [PATCH 07/18] =?UTF-8?q?enhancement=20#I7KZCZ=20=E5=9C=A8?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=95=B0=E6=8D=AE=E5=BA=93=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E4=BD=BF=E7=94=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E4=B8=AD=E5=B7=B2=E7=BB=8F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=9A=84=E6=95=B0=E6=8D=AE=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/test/def/SQLWithXmlELSpringbootTest.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java index 8e86d5129..9d9287230 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java @@ -3,11 +3,7 @@ package com.yomahub.liteflow.test.def; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.parser.sql.exception.ELSQLException; -import com.yomahub.liteflow.parser.sql.vo.SQLParserVO; -import com.yomahub.liteflow.property.LiteflowConfig; -import com.yomahub.liteflow.property.LiteflowConfigGetter; import com.yomahub.liteflow.test.BaseTest; -import com.yomahub.liteflow.util.JsonUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -69,8 +65,6 @@ public class SQLWithXmlELSpringbootTest extends BaseTest { * 修改数据库数据 */ private void changeData() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - SQLParserVO sqlParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), SQLParserVO.class); Connection connection; try { connection = dataSource.getConnection(); @@ -85,8 +79,6 @@ public class SQLWithXmlELSpringbootTest extends BaseTest { * 修改数据库数据 */ private void changeScriptData() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - SQLParserVO sqlParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), SQLParserVO.class); Connection connection; try { connection = dataSource.getConnection(); From d9ebc78754dc0c94c37bbb3c1f6bd4049a9ea29d Mon Sep 17 00:00:00 2001 From: luoyi <972849752@qq.com> Date: Wed, 19 Jul 2023 11:19:08 +0800 Subject: [PATCH 08/18] =?UTF-8?q?bug=20#I7KY2N=20=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E8=BF=90=E7=AE=97=E5=A2=9E=E5=8A=A0=E7=9F=AD=E8=B7=AF=E6=95=88?= =?UTF-8?q?=E6=9E=9C=EF=BC=8C=E9=81=BF=E5=85=8D=E5=A4=9A=E4=BD=99=E8=AE=A1?= =?UTF-8?q?=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../element/condition/AndOrCondition.java | 39 ++++++++++++------- .../BooleanOptELSpringbootTest.java | 11 +++++- .../src/test/resources/booleanOpt/flow.xml | 5 +++ 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/AndOrCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/AndOrCondition.java index 3c70b6b83..129a93da3 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/AndOrCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/AndOrCondition.java @@ -1,7 +1,6 @@ package com.yomahub.liteflow.flow.element.condition; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.enums.ConditionTypeEnum; import com.yomahub.liteflow.exception.AndOrConditionException; @@ -11,7 +10,9 @@ import com.yomahub.liteflow.log.LFLog; import com.yomahub.liteflow.log.LFLoggerManager; import com.yomahub.liteflow.slot.DataBus; import com.yomahub.liteflow.slot.Slot; + import java.util.List; +import java.util.function.Predicate; public class AndOrCondition extends Condition { @@ -23,21 +24,10 @@ public class AndOrCondition extends Condition { public void executeCondition(Integer slotIndex) throws Exception { List itemList = this.getItem(); - if (CollUtil.isEmpty(itemList)){ throw new AndOrConditionException("boolean item list is null"); } - boolean[] booleanArray = new boolean[itemList.size()]; - - for (int i = 0; i < itemList.size(); i++) { - Executable item = itemList.get(i); - item.setCurrChainId(this.getCurrChainId()); - item.execute(slotIndex); - booleanArray[i] = item.getItemResultMetaValue(slotIndex); - LOG.info("the result of boolean component [{}] is [{}]", item.getId(), booleanArray[i]); - } - BooleanConditionTypeEnum booleanConditionType = this.getBooleanConditionType(); Slot slot = DataBus.getSlot(slotIndex); @@ -45,16 +35,37 @@ public class AndOrCondition extends Condition { String resultKey = StrUtil.format("{}_{}",this.getClass().getName(),this.hashCode()); switch (booleanConditionType) { case AND: - slot.setAndOrResult(resultKey, BooleanUtil.and(booleanArray)); + slot.setAndOrResult(resultKey, itemList.stream().allMatch(new AndOrConditionPredicate(slotIndex))); break; case OR: - slot.setAndOrResult(resultKey, BooleanUtil.or(booleanArray)); + slot.setAndOrResult(resultKey, itemList.stream().anyMatch(new AndOrConditionPredicate(slotIndex))); break; default: throw new AndOrConditionException("condition type must be 'AND' or 'OR'"); } } + private class AndOrConditionPredicate implements Predicate { + + private final Integer slotIndex; + + public AndOrConditionPredicate(Integer slotIndex) { + this.slotIndex = slotIndex; + } + + @Override + public boolean test(Executable condition) { + try { + condition.setCurrChainId(getCurrChainId()); + condition.execute(slotIndex); + return condition.getItemResultMetaValue(slotIndex); + } catch (Exception e) { + throw new AndOrConditionException(e.getMessage()); + } + } + + } + @Override @SuppressWarnings("unchecked") diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/BooleanOptELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/BooleanOptELSpringbootTest.java index 0e7eb64c1..8d3547961 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/BooleanOptELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/BooleanOptELSpringbootTest.java @@ -39,7 +39,7 @@ public class BooleanOptELSpringbootTest extends BaseTest { public void testBooleanOpt2() throws Exception { LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); Assertions.assertTrue(response.isSuccess()); - Assertions.assertEquals("x1==>x2==>x3==>a", response.getExecuteStepStr()); + Assertions.assertEquals("x1==>a", response.getExecuteStepStr()); } // IF情况下AND+NOT @@ -64,4 +64,13 @@ public class BooleanOptELSpringbootTest extends BaseTest { Assertions.assertTrue(response.isSuccess()); Assertions.assertEquals("w1==>w2==>a==>bk==>w1==>w2==>a==>bk==>w1==>w2==>a==>bk==>w1==>w2==>a==>bk", response.getExecuteStepStr()); } + + // AND + NOT 实现短路效果 + @Test + public void testBooleanOpt6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("x1==>b", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/booleanOpt/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/booleanOpt/flow.xml index 8898e2455..b215310ef 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/booleanOpt/flow.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/booleanOpt/flow.xml @@ -25,4 +25,9 @@ WHILE(AND(w1, NOT(w2))).DO(a).BREAK(bk); + + + IF(AND(NOT(x1), x2, x3), a, b); + + \ No newline at end of file From c18f46ac48ebb2683cdb8ef4f810d8b085c65c39 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Wed, 19 Jul 2023 18:45:47 +0800 Subject: [PATCH 09/18] =?UTF-8?q?enhancement=20#I7J1VJ=20=E5=B8=8C?= =?UTF-8?q?=E6=9C=9B=E9=92=88=E5=AF=B9=E8=8A=82=E7=82=B9=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E8=80=97=E6=97=B6=E7=9A=84=E6=89=93=E5=8D=B0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/yomahub/liteflow/core/NodeComponent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java index bf064af25..56d81ec4a 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java @@ -126,7 +126,7 @@ public abstract class NodeComponent { stopWatch.stop(); final long timeSpent = stopWatch.getTotalTimeMillis(); - LOG.debug("component[{}] finished in {} milliseconds", this.getDisplayName(), timeSpent); + LOG.info("component[{}] finished in {} milliseconds", this.getDisplayName(), timeSpent); // 往CmpStep中放入时间消耗信息 cmpStep.setTimeSpent(timeSpent); From b6eda40533403f6d9ba9df394d90207210d11518 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Tue, 18 Jul 2023 22:40:29 +0800 Subject: [PATCH 10/18] =?UTF-8?q?enhancement=20#I7KZCZ=20=E5=9C=A8?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=95=B0=E6=8D=AE=E5=BA=93=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E4=BD=BF=E7=94=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E4=B8=AD=E5=B7=B2=E7=BB=8F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=9A=84=E6=95=B0=E6=8D=AE=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.gitignore | 38 ++++++++ .../pom.xml | 86 +++++++++++++++++++ .../com/yomahub/liteflow/test/BaseTest.java | 27 ++++++ ...LWithXmlELMultiLanguageSpringbootTest.java | 34 ++++++++ .../test/sql/SQLWithXmlELSpringbootTest.java | 42 +++++++++ .../yomahub/liteflow/test/sql/cmp/ACmp.java | 22 +++++ .../yomahub/liteflow/test/sql/cmp/BCmp.java | 22 +++++ .../yomahub/liteflow/test/sql/cmp/CCmp.java | 22 +++++ ...ication-dynamic-data-source-xml.properties | 31 +++++++ .../src/test/resources/sql/data.sql | 14 +++ .../src/test/resources/sql/schema.sql | 20 +++++ .../src/test/resources/sql/second/data.sql | 27 ++++++ .../src/test/resources/sql/second/schema.sql | 20 +++++ ...LWithXmlELMultiLanguageSpringbootTest.java | 2 +- .../test/def/SQLWithXmlELSpringbootTest.java | 20 ++--- liteflow-testcase-el/pom.xml | 1 + 16 files changed, 413 insertions(+), 15 deletions(-) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/.gitignore create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/pom.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/BaseTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELMultiLanguageSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/application-dynamic-data-source-xml.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/data.sql create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/schema.sql create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/data.sql create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/schema.sql diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/.gitignore b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/.gitignore new file mode 100644 index 000000000..5ff6309b7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/pom.xml b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/pom.xml new file mode 100644 index 000000000..b7bd4c935 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/pom.xml @@ -0,0 +1,86 @@ + + + + liteflow-testcase-el + com.yomahub + ${revision} + ../pom.xml + + 4.0.0 + + liteflow-testcase-el-sql-springboot-dynamic + + + 2.1.214 + 2.6.8 + 4.1.2 + 2.7.13 + + + + + org.springframework.boot + spring-boot-starter + ${spring-boot.version} + + + org.springframework.boot + spring-boot-starter-web + ${spring-boot.version} + + + com.yomahub + liteflow-spring-boot-starter + ${revision} + + + + com.yomahub + liteflow-rule-sql + ${revision} + test + + + + org.springframework.boot + spring-boot-starter-test + + + + org.springframework.boot + spring-boot-starter-data-jpa + ${jpa.version} + test + + + + com.h2database + h2 + ${h2.version} + test + + + + com.yomahub + liteflow-script-groovy + ${revision} + test + + + + com.yomahub + liteflow-script-graaljs + ${revision} + test + + + + + com.baomidou + dynamic-datasource-spring-boot-starter + ${dynamic-datasource.version} + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/BaseTest.java new file mode 100644 index 000000000..eb7287357 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -0,0 +1,27 @@ +package com.yomahub.liteflow.test; + +import com.yomahub.liteflow.core.FlowInitHook; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner; +import com.yomahub.liteflow.spring.ComponentScanner; +import com.yomahub.liteflow.thread.ExecutorHelper; +import org.junit.jupiter.api.AfterAll; + +/** + * @author tangkc + * @since 2.8.6 + */ +public class BaseTest { + + @AfterAll + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELMultiLanguageSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELMultiLanguageSpringbootTest.java new file mode 100644 index 000000000..427351b64 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELMultiLanguageSpringbootTest.java @@ -0,0 +1,34 @@ +package com.yomahub.liteflow.test.sql; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; + +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/application-dynamic-data-source-xml.properties") +@SpringBootTest(classes = SQLWithXmlELMultiLanguageSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.sql.cmp"}) +public class SQLWithXmlELMultiLanguageSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMultiLanguage1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("x2[python脚本]==>x0[if 脚本]==>a==>b", response.getExecuteStepStrWithoutTime()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java new file mode 100644 index 000000000..d694f7bf8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java @@ -0,0 +1,42 @@ +package com.yomahub.liteflow.test.sql; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; + +/** + * @author tangkc + * @since 2.9.0 + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/application-dynamic-data-source-xml.properties") +@SpringBootTest(classes = SQLWithXmlELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.sql.cmp"}) +public class SQLWithXmlELSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + @Test + public void testSQLWithXml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertEquals("a==>b==>c", response.getExecuteStepStr()); + } + + @Test + public void testSQLWithScriptXml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("x0[if 脚本]==>a==>b", response.getExecuteStepStrWithoutTime()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/ACmp.java new file mode 100644 index 000000000..f263fa7d7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/ACmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.sql.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/BCmp.java new file mode 100644 index 000000000..c2ffd816c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/BCmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.sql.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/CCmp.java new file mode 100644 index 000000000..0d45928bb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/CCmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.sql.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/application-dynamic-data-source-xml.properties b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/application-dynamic-data-source-xml.properties new file mode 100644 index 000000000..8645c0b2e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/application-dynamic-data-source-xml.properties @@ -0,0 +1,31 @@ +liteflow.rule-source-ext-data={\ + "applicationName":"demo",\ + "chainTableName":"EL_TABLE",\ + "chainApplicationNameField":"application_name",\ + "chainNameField":"chain_name",\ + "elDataField":"EL_DATA",\ + "scriptTableName":"script_node_table",\ + "scriptApplicationNameField":"application_name",\ + "scriptIdField":"script_node_id",\ + "scriptNameField":"script_node_name",\ + "scriptDataField":"script_node_data",\ + "scriptLanguageField":"script_language",\ + "scriptTypeField":"script_node_type"\ + } +spring.profiles.active=test +spring.datasource.driver-class-name=org.h2.Driver +spring.datasource.dynamic.primary=h2-first +spring.datasource.dynamic.strict=false +spring.datasource.dynamic.datasource.h2-first.url=jdbc:h2:mem:test_db1 +spring.datasource.dynamic.datasource.h2-first.username=root1 +spring.datasource.dynamic.datasource.h2-first.password=123456 +spring.datasource.dynamic.datasource.h2-first.init.schema=classpath:/sql/schema.sql +spring.datasource.dynamic.datasource.h2-first.init.data=classpath:/sql/data.sql +spring.datasource.dynamic.datasource.h2-second.url=jdbc:h2:mem:test_db2 +spring.datasource.dynamic.datasource.h2-second.username=root2 +spring.datasource.dynamic.datasource.h2-second.password=123456 +spring.datasource.dynamic.datasource.h2-second.init.schema=classpath:/sql/second/schema.sql +spring.datasource.dynamic.datasource.h2-second.init.data=classpath:/sql/second/data.sql + + + diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/data.sql b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/data.sql new file mode 100644 index 000000000..dda527ee6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/data.sql @@ -0,0 +1,14 @@ +DELETE FROM EL_TABLE; + +INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain1','THEN(a, b, c);'); +INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain2','THEN(a, b, c);'); +INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain3','IF(x0, THEN(a, b));'); +INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','','IF(x0, THEN(a, b));'); +INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain4','IF(x2, IF(x0, THEN(a, b)));'); + +DELETE FROM SCRIPT_NODE_TABLE; + +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x0','if 脚本','if_script','return true','groovy'); +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x1','if 脚本','if_script','return false','groovy'); + +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x2','python脚本','if_script','return true','js'); diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/schema.sql b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/schema.sql new file mode 100644 index 000000000..fa60f098a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/schema.sql @@ -0,0 +1,20 @@ +create table IF NOT EXISTS `EL_TABLE` +( + `id` bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + `application_name` varchar(32) NOT NULL, + `chain_name` varchar(32) NOT NULL, + `el_data` varchar(1024) NOT NULL, + PRIMARY KEY (`id`) +); + +create table IF NOT EXISTS `script_node_table` +( + `id` bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + `application_name` varchar(32) NOT NULL, + `script_node_id` varchar(32) NOT NULL, + `script_node_name` varchar(32) NOT NULL, + `script_node_type` varchar(32) NOT NULL, + `script_node_data` varchar(1024) NOT NULL, + `script_language` varchar(1024) NOT NULL, + PRIMARY KEY (`id`) +); \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/data.sql b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/data.sql new file mode 100644 index 000000000..35412b6a8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/data.sql @@ -0,0 +1,27 @@ +DELETE +FROM EL_TABLE; + +INSERT INTO EL_TABLE (APPLICATION_NAME, CHAIN_NAME, EL_DATA) +values ('demo', 'chain11', 'THEN(a, b, c);'); +INSERT INTO EL_TABLE (APPLICATION_NAME, CHAIN_NAME, EL_DATA) +values ('demo', 'chain21', 'THEN(a, b, c);'); +INSERT INTO EL_TABLE (APPLICATION_NAME, CHAIN_NAME, EL_DATA) +values ('demo', 'chain31', 'IF(x0, THEN(a, b));'); +INSERT INTO EL_TABLE (APPLICATION_NAME, CHAIN_NAME, EL_DATA) +values ('demo', '', 'IF(x0, THEN(a, b));'); +INSERT INTO EL_TABLE (APPLICATION_NAME, CHAIN_NAME, EL_DATA) +values ('demo', 'chain41', 'IF(x2, IF(x0, THEN(a, b)));'); + +DELETE +FROM SCRIPT_NODE_TABLE; + +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME, SCRIPT_NODE_ID, SCRIPT_NODE_NAME, SCRIPT_NODE_TYPE, SCRIPT_NODE_DATA, + SCRIPT_LANGUAGE) +values ('demo', 'x01', 'if 脚本', 'if_script', 'return true', 'groovy'); +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME, SCRIPT_NODE_ID, SCRIPT_NODE_NAME, SCRIPT_NODE_TYPE, SCRIPT_NODE_DATA, + SCRIPT_LANGUAGE) +values ('demo', 'x11', 'if 脚本', 'if_script', 'return false', 'groovy'); + +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME, SCRIPT_NODE_ID, SCRIPT_NODE_NAME, SCRIPT_NODE_TYPE, SCRIPT_NODE_DATA, + SCRIPT_LANGUAGE) +values ('demo', 'x21', 'python脚本', 'if_script', 'return true', 'js'); diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/schema.sql b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/schema.sql new file mode 100644 index 000000000..fa60f098a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/schema.sql @@ -0,0 +1,20 @@ +create table IF NOT EXISTS `EL_TABLE` +( + `id` bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + `application_name` varchar(32) NOT NULL, + `chain_name` varchar(32) NOT NULL, + `el_data` varchar(1024) NOT NULL, + PRIMARY KEY (`id`) +); + +create table IF NOT EXISTS `script_node_table` +( + `id` bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + `application_name` varchar(32) NOT NULL, + `script_node_id` varchar(32) NOT NULL, + `script_node_name` varchar(32) NOT NULL, + `script_node_type` varchar(32) NOT NULL, + `script_node_data` varchar(1024) NOT NULL, + `script_language` varchar(1024) NOT NULL, + PRIMARY KEY (`id`) +); \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELMultiLanguageSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELMultiLanguageSpringbootTest.java index c573fd243..ee72f5f9a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELMultiLanguageSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELMultiLanguageSpringbootTest.java @@ -15,7 +15,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import javax.annotation.Resource; @ExtendWith(SpringExtension.class) -@TestPropertySource(value = "classpath:/application-xml.properties") +@TestPropertySource(value = "classpath:/application-data-source-xml.properties") @SpringBootTest(classes = SQLWithXmlELMultiLanguageSpringbootTest.class) @EnableAutoConfiguration @ComponentScan({"com.yomahub.liteflow.test.sql.cmp"}) diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java index 87edf48cd..9d9287230 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java @@ -3,11 +3,7 @@ package com.yomahub.liteflow.test.def; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.parser.sql.exception.ELSQLException; -import com.yomahub.liteflow.parser.sql.vo.SQLParserVO; -import com.yomahub.liteflow.property.LiteflowConfig; -import com.yomahub.liteflow.property.LiteflowConfigGetter; import com.yomahub.liteflow.test.BaseTest; -import com.yomahub.liteflow.util.JsonUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -18,8 +14,8 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; import javax.annotation.Resource; +import javax.sql.DataSource; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; @@ -28,7 +24,7 @@ import java.sql.Statement; * @since 2.9.0 */ @ExtendWith(SpringExtension.class) -@TestPropertySource(value = "classpath:/application-xml.properties") +@TestPropertySource(value = "classpath:/application-data-source-xml.properties") @SpringBootTest(classes = SQLWithXmlELSpringbootTest.class) @EnableAutoConfiguration @ComponentScan({"com.yomahub.liteflow.test.sql.cmp"}) @@ -36,6 +32,8 @@ public class SQLWithXmlELSpringbootTest extends BaseTest { @Resource private FlowExecutor flowExecutor; + @Resource + private DataSource dataSource; @Test public void testSQLWithXml() { @@ -67,12 +65,9 @@ public class SQLWithXmlELSpringbootTest extends BaseTest { * 修改数据库数据 */ private void changeData() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - SQLParserVO sqlParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), SQLParserVO.class); Connection connection; try { - connection = DriverManager.getConnection(sqlParserVO.getUrl(), sqlParserVO.getUsername(), - sqlParserVO.getPassword()); + connection = dataSource.getConnection(); Statement statement = connection.createStatement(); statement.executeUpdate("UPDATE EL_TABLE SET EL_DATA='THEN(a, c, b);' WHERE chain_name='chain1'"); } catch (SQLException e) { @@ -84,12 +79,9 @@ public class SQLWithXmlELSpringbootTest extends BaseTest { * 修改数据库数据 */ private void changeScriptData() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - SQLParserVO sqlParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), SQLParserVO.class); Connection connection; try { - connection = DriverManager.getConnection(sqlParserVO.getUrl(), sqlParserVO.getUsername(), - sqlParserVO.getPassword()); + connection = dataSource.getConnection(); Statement statement = connection.createStatement(); statement.executeUpdate( "UPDATE SCRIPT_NODE_TABLE SET SCRIPT_NODE_DATA='return false;' WHERE SCRIPT_NODE_ID='x0'"); diff --git a/liteflow-testcase-el/pom.xml b/liteflow-testcase-el/pom.xml index 2d53f3497..8f23e9e9f 100644 --- a/liteflow-testcase-el/pom.xml +++ b/liteflow-testcase-el/pom.xml @@ -34,6 +34,7 @@ liteflow-testcase-el-script-lua-springboot liteflow-testcase-el-script-multi-language-springboot liteflow-testcase-el-script-aviator-springboot + liteflow-testcase-el-sql-springboot-dynamic From 288899d3add137ce2366a22369ead68abb032c7e Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Fri, 21 Jul 2023 00:29:12 +0800 Subject: [PATCH 11/18] =?UTF-8?q?enhancement=20#I7KOPV=20=E7=B1=BB?= =?UTF-8?q?=E7=BA=A7=E5=88=AB=E5=A3=B0=E6=98=8E=E7=BB=84=E4=BB=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=BB=BA=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/annotation/LiteflowMethod.java | 8 ++++++- .../liteflow/core/proxy/ComponentProxy.java | 21 ++++++++++++++++++- .../com/yomahub/liteflow/flow/FlowBus.java | 2 +- .../spi/LiteflowComponentSupport.java | 2 +- .../local/LocalLiteflowComponentSupport.java | 2 +- .../solon/SolonLiteflowComponentSupport.java | 2 +- .../SpringLiteflowComponentSupport.java | 2 +- .../liteflow/test/base/cmp/CmpConfig.java | 2 +- 8 files changed, 33 insertions(+), 8 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java index 589cf4ee3..7eba135e7 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java @@ -18,10 +18,16 @@ public @interface LiteflowMethod { /** * 节点ID,用于区分节点 默认为空 则按照Spring模式下BeanName为准。 - * @return + * @return nodeId */ String nodeId() default ""; + /** + * 节点Name + * @return nodeName + */ + String nodeName() default ""; + /** * CMP类型定义 * @return AnnotationNodeTypeEnum diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java index 4ca355f87..5d6315946 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java @@ -13,6 +13,7 @@ import com.yomahub.liteflow.exception.LiteFlowException; import com.yomahub.liteflow.exception.ProxyException; import com.yomahub.liteflow.log.LFLog; import com.yomahub.liteflow.log.LFLoggerManager; +import com.yomahub.liteflow.spi.holder.LiteflowComponentSupportHolder; import com.yomahub.liteflow.util.LiteFlowProxyUtil; import com.yomahub.liteflow.util.SerialsUtil; import net.bytebuddy.ByteBuddy; @@ -28,6 +29,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Predicate; import java.util.stream.Collectors; /** @@ -94,8 +96,23 @@ public class ComponentProxy { boolean legal = classes.size() == 1; if (!legal) { throw new LiteFlowException("The cmpClass of the same nodeId must be the same,you declared nodeId:" - + activeNodeId + ",cmpClass:" + classes); + + activeNodeId + ",cmpClass:" + clazz); } + + + String activeNodeName; + if (isMethodCreate){ + // 获取process上的LiteflowMethod + LiteflowMethod mainliteflowMethod = methodList.stream().filter(liteflowMethod -> liteflowMethod.value().isMainMethod()).findFirst().orElse(null); + if (mainliteflowMethod == null){ + String errMsg = StrUtil.format("you have not defined @LiteFlowMethod on the processXXX method in class {}", clazz.getName()); + throw new LiteFlowException(errMsg); + } + activeNodeName = mainliteflowMethod.nodeName(); + }else{ + activeNodeName = LiteflowComponentSupportHolder.loadLiteflowComponentSupport().getCmpName(bean); + } + // 当前节点实际LiteflowRetry注解 AtomicReference liteflowRetryAtomicReference = new AtomicReference<>(null); // 相同nodeId只能有一个LiteflowRetry定义方法,且必须再Process方法上 @@ -151,6 +168,8 @@ public class ComponentProxy { NodeComponent nodeComponent = (NodeComponent) instance; // 重设nodeId nodeComponent.setNodeId(activeNodeId); + // 重设nodeName + nodeComponent.setName(activeNodeName); return nodeComponent; } catch (Exception e) { diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java index 2a82c62a5..1f8d1954d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java @@ -93,7 +93,7 @@ public class FlowBus { } nodeMap.put(nodeId, - new Node(ComponentInitializer.loadInstance().initComponent(nodeComponent, type, null, nodeId))); + new Node(ComponentInitializer.loadInstance().initComponent(nodeComponent, type, nodeComponent.getName(), nodeId))); } /** diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/LiteflowComponentSupport.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/LiteflowComponentSupport.java index da659f12a..710eb3921 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/LiteflowComponentSupport.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/LiteflowComponentSupport.java @@ -10,6 +10,6 @@ import com.yomahub.liteflow.core.NodeComponent; */ public interface LiteflowComponentSupport extends SpiPriority { - String getCmpName(NodeComponent nodeComponent); + String getCmpName(Object nodeComponent); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalLiteflowComponentSupport.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalLiteflowComponentSupport.java index 74426e82c..4303b47b8 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalLiteflowComponentSupport.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalLiteflowComponentSupport.java @@ -12,7 +12,7 @@ import com.yomahub.liteflow.spi.LiteflowComponentSupport; public class LocalLiteflowComponentSupport implements LiteflowComponentSupport { @Override - public String getCmpName(NodeComponent nodeComponent) { + public String getCmpName(Object nodeComponent) { return null; } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonLiteflowComponentSupport.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonLiteflowComponentSupport.java index 06b9de068..c25aa5220 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonLiteflowComponentSupport.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonLiteflowComponentSupport.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.spi.LiteflowComponentSupport; public class SolonLiteflowComponentSupport implements LiteflowComponentSupport { @Override - public String getCmpName(NodeComponent nodeComponent) { + public String getCmpName(Object nodeComponent) { // 判断NodeComponent是否是标识了@LiteflowComponent的标注 // 如果标注了,那么要从中取到name字段 LiteflowComponent liteflowComponent = nodeComponent.getClass().getAnnotation(LiteflowComponent.class); diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringLiteflowComponentSupport.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringLiteflowComponentSupport.java index a88fdb9e0..754ffcaa9 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringLiteflowComponentSupport.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringLiteflowComponentSupport.java @@ -15,7 +15,7 @@ import com.yomahub.liteflow.spi.LiteflowComponentSupport; public class SpringLiteflowComponentSupport implements LiteflowComponentSupport { @Override - public String getCmpName(NodeComponent nodeComponent) { + public String getCmpName(Object nodeComponent) { // 判断NodeComponent是否是标识了@LiteflowComponent的标注 // 如果标注了,那么要从中取到name字段 LiteflowComponent liteflowComponent = nodeComponent.getClass().getAnnotation(LiteflowComponent.class); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CmpConfig.java index 5689c278e..d5dab5786 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CmpConfig.java @@ -10,7 +10,7 @@ import javax.annotation.Resource; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a", nodeName = "A组件") public void processA(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } From ce810c4fee081dbb812d0073863cb80f4f53fa32 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Fri, 21 Jul 2023 13:56:00 +0800 Subject: [PATCH 12/18] =?UTF-8?q?=E4=BC=98=E5=8C=96monitorFile=E7=9A=84?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MonitorFileELDeclMultiSpringbootTest.java | 10 +++++++- .../MonitorFileELDeclSpringbootTest.java | 10 +++++++- .../monitorFile/LiteflowMonitorFileTest.java | 7 ++++++ .../MonitorFileSpringbootTest.java | 10 +++++++- .../MonitorFileELSpringbootTest.java | 23 +++++++++++-------- .../test/resources/monitorFile/flow.el.xml | 1 - 6 files changed, 48 insertions(+), 13 deletions(-) diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java index 8a88f4b16..9c4cf23f0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java @@ -6,6 +6,7 @@ import cn.hutool.core.util.CharsetUtil; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -32,13 +33,20 @@ public class MonitorFileELDeclMultiSpringbootTest extends BaseTest { @Test public void testMonitor() throws Exception { String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); String content = FileUtil.readUtf8String(absolutePath); String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(3000); + Thread.sleep(1000); LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); Assertions.assertEquals("a==>c==>b", response.getExecuteStepStr()); } + @AfterEach + public void afterEach(){ + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java index b264ef59d..98fc5169a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java @@ -6,6 +6,7 @@ import cn.hutool.core.util.CharsetUtil; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -32,12 +33,19 @@ public class MonitorFileELDeclSpringbootTest extends BaseTest { @Test public void testMonitor() throws Exception { String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); String content = FileUtil.readUtf8String(absolutePath); String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(3000); + Thread.sleep(1000); LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); Assertions.assertEquals("a==>c==>b", response.getExecuteStepStr()); } + @AfterEach + public void afterEach(){ + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/LiteflowMonitorFileTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/LiteflowMonitorFileTest.java index 07e4a7f1a..70c581ec1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/LiteflowMonitorFileTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/LiteflowMonitorFileTest.java @@ -8,6 +8,7 @@ import com.yomahub.liteflow.core.FlowExecutorHolder; import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.property.LiteflowConfig; import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -37,4 +38,10 @@ public class LiteflowMonitorFileTest extends BaseTest { Assertions.assertEquals("a==>c==>b", response.getExecuteStepStr()); } + @AfterEach + public void afterEach(){ + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileSpringbootTest.java index 8cb415647..047786ace 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileSpringbootTest.java @@ -6,6 +6,7 @@ import cn.hutool.core.util.CharsetUtil; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -25,12 +26,19 @@ public class MonitorFileSpringbootTest extends BaseTest { @Test public void testMonitor() throws Exception { String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.xml").getAbsolutePath(); + FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); String content = FileUtil.readUtf8String(absolutePath); String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(3000); + Thread.sleep(1000); LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); Assertions.assertEquals("a==>c==>b", response.getExecuteStepStr()); } + @AfterEach + public void afterEach(){ + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java index 9d7983d9f..52369a825 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java @@ -6,10 +6,7 @@ import cn.hutool.core.util.CharsetUtil; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.test.BaseTest; -import org.junit.jupiter.api.MethodOrderer; -import org.junit.jupiter.api.TestMethodOrder; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.ComponentScan; @@ -31,10 +28,11 @@ public class MonitorFileELSpringbootTest extends BaseTest { @Test public void testMonitor() throws Exception { String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); String content = FileUtil.readUtf8String(absolutePath); String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(3000); + Thread.sleep(1000); LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); Assertions.assertEquals("a==>c==>b", response.getExecuteStepStr()); } @@ -46,21 +44,28 @@ public class MonitorFileELSpringbootTest extends BaseTest { @Test public void testMonitorError() throws Exception { String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); String content = FileUtil.readUtf8String(absolutePath); // 错误规则配置 - String newContent = content.replace("THEN(a, c, b);", "THEN(c, b, ;"); + String newContent = content.replace("THEN(a, b, c);", "THEN(c, b, ;"); FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); Thread.sleep(3000); LiteflowResponse reloadFailedResponse = flowExecutor.execute2Resp("chain1", "arg"); - Assertions.assertEquals("a==>c==>b", reloadFailedResponse.getExecuteStepStr()); + Assertions.assertEquals("a==>b==>c", reloadFailedResponse.getExecuteStepStr()); // 再次变更正确 - newContent = content.replace("THEN(a, c, b);", "THEN(c, b, a);"); + newContent = content.replace("THEN(a, b, c);", "THEN(c, b, a);"); FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(3000); + Thread.sleep(1000); LiteflowResponse reloadSuccessResponse = flowExecutor.execute2Resp("chain1", "arg"); Assertions.assertEquals("c==>b==>a", reloadSuccessResponse.getExecuteStepStr()); } + @AfterEach + public void afterEach(){ + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/monitorFile/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/monitorFile/flow.el.xml index 98c3cbae6..049210cf4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/monitorFile/flow.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/monitorFile/flow.el.xml @@ -3,5 +3,4 @@ THEN(a, b, c); - \ No newline at end of file From 76563cf59680d9a665e7e1b4d7fa0b5d177bf358 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Fri, 21 Jul 2023 14:00:05 +0800 Subject: [PATCH 13/18] =?UTF-8?q?=E4=BC=98=E5=8C=96monitorFile=E7=9A=84?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java | 2 +- .../test/monitorFile/MonitorFileELDeclSpringbootTest.java | 2 +- .../liteflow/test/monitorFile/MonitorFileELSpringbootTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java index 9c4cf23f0..bf3639f2a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java @@ -37,7 +37,7 @@ public class MonitorFileELDeclMultiSpringbootTest extends BaseTest { String content = FileUtil.readUtf8String(absolutePath); String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(1000); + Thread.sleep(3000); LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); Assertions.assertEquals("a==>c==>b", response.getExecuteStepStr()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java index 98fc5169a..21b325a83 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java @@ -37,7 +37,7 @@ public class MonitorFileELDeclSpringbootTest extends BaseTest { String content = FileUtil.readUtf8String(absolutePath); String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(1000); + Thread.sleep(3000); LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); Assertions.assertEquals("a==>c==>b", response.getExecuteStepStr()); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java index 52369a825..17308d7e2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java @@ -57,7 +57,7 @@ public class MonitorFileELSpringbootTest extends BaseTest { // 再次变更正确 newContent = content.replace("THEN(a, b, c);", "THEN(c, b, a);"); FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(1000); + Thread.sleep(3000); LiteflowResponse reloadSuccessResponse = flowExecutor.execute2Resp("chain1", "arg"); Assertions.assertEquals("c==>b==>a", reloadSuccessResponse.getExecuteStepStr()); } From e5581f84f9f6cc2456059bc41e03a37af0f47a67 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Fri, 21 Jul 2023 14:43:42 +0800 Subject: [PATCH 14/18] =?UTF-8?q?=E4=BC=98=E5=8C=96monitorFile=E7=9A=84?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MonitorFileELDeclMultiSpringbootTest.java | 52 ------------------- .../test/monitorFile/cmp/CmpConfig.java | 28 ---------- .../monitorFile/application.properties | 2 - .../test/resources/monitorFile/flow.el.xml | 7 --- .../MonitorFileELDeclSpringbootTest.java | 51 ------------------ .../liteflow/test/monitorFile/cmp/ACmp.java | 25 --------- .../liteflow/test/monitorFile/cmp/BCmp.java | 25 --------- .../liteflow/test/monitorFile/cmp/CCmp.java | 25 --------- .../monitorFile/application.properties | 2 - .../test/resources/monitorFile/flow.el.xml | 7 --- .../monitorFile/LiteflowMonitorFileTest.java | 47 ----------------- .../liteflow/test/monitorFile/cmp/ACmp.java | 19 ------- .../liteflow/test/monitorFile/cmp/BCmp.java | 19 ------- .../liteflow/test/monitorFile/cmp/CCmp.java | 19 ------- .../MonitorFileSpringbootTest.java | 44 ---------------- .../liteflow/test/monitorFile/cmp/ACmp.java | 23 -------- .../liteflow/test/monitorFile/cmp/BCmp.java | 23 -------- .../liteflow/test/monitorFile/cmp/CCmp.java | 23 -------- .../monitorFile/application.properties | 2 - .../src/test/resources/monitorFile/flow.xml | 7 --- .../MonitorFileELSpringbootTest.java | 4 +- 21 files changed, 2 insertions(+), 452 deletions(-) delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CmpConfig.java delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitorFile/application.properties delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitorFile/flow.el.xml delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/monitorFile/application.properties delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/monitorFile/flow.el.xml delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/LiteflowMonitorFileTest.java delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileSpringbootTest.java delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/monitorFile/application.properties delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/monitorFile/flow.xml diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java deleted file mode 100644 index bf3639f2a..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.yomahub.liteflow.test.monitorFile; - -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.io.resource.ClassPathResource; -import cn.hutool.core.util.CharsetUtil; -import com.yomahub.liteflow.core.FlowExecutor; -import com.yomahub.liteflow.flow.LiteflowResponse; -import com.yomahub.liteflow.test.BaseTest; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.test.context.junit.jupiter.SpringExtension; -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; -import java.io.File; - -@ExtendWith(SpringExtension.class) -@TestPropertySource(value = "classpath:/monitorFile/application.properties") -@SpringBootTest(classes = MonitorFileELDeclMultiSpringbootTest.class) -@EnableAutoConfiguration -@ComponentScan({ "com.yomahub.liteflow.test.monitorFile.cmp" }) -public class MonitorFileELDeclMultiSpringbootTest extends BaseTest { - - @Resource - private FlowExecutor flowExecutor; - - @Test - public void testMonitor() throws Exception { - String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); - FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - String content = FileUtil.readUtf8String(absolutePath); - String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); - FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(3000); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assertions.assertEquals("a==>c==>b", response.getExecuteStepStr()); - - } - - @AfterEach - public void afterEach(){ - String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); - FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - } - -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CmpConfig.java deleted file mode 100644 index 198733537..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CmpConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.yomahub.liteflow.test.monitorFile.cmp; - -import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.annotation.LiteflowMethod; -import com.yomahub.liteflow.core.NodeComponent; -import com.yomahub.liteflow.enums.LiteFlowMethodEnum; - -import java.util.Random; - -@LiteflowComponent -public class CmpConfig { - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") - public void process(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } - -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitorFile/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitorFile/application.properties deleted file mode 100644 index 361f7e90e..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitorFile/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -liteflow.rule-source=monitorFile/flow.el.xml -liteflow.enable-monitor-file=true \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitorFile/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitorFile/flow.el.xml deleted file mode 100644 index 98c3cbae6..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitorFile/flow.el.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - THEN(a, b, c); - - - \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java deleted file mode 100644 index 21b325a83..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.yomahub.liteflow.test.monitorFile; - -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.io.resource.ClassPathResource; -import cn.hutool.core.util.CharsetUtil; -import com.yomahub.liteflow.core.FlowExecutor; -import com.yomahub.liteflow.flow.LiteflowResponse; -import com.yomahub.liteflow.test.BaseTest; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.test.context.junit.jupiter.SpringExtension; -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; -import java.io.File; - -@ExtendWith(SpringExtension.class) -@TestPropertySource(value = "classpath:/monitorFile/application.properties") -@SpringBootTest(classes = MonitorFileELDeclSpringbootTest.class) -@EnableAutoConfiguration -@ComponentScan({ "com.yomahub.liteflow.test.monitorFile.cmp" }) -public class MonitorFileELDeclSpringbootTest extends BaseTest { - - @Resource - private FlowExecutor flowExecutor; - - @Test - public void testMonitor() throws Exception { - String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); - FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - String content = FileUtil.readUtf8String(absolutePath); - String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); - FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(3000); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assertions.assertEquals("a==>c==>b", response.getExecuteStepStr()); - } - - @AfterEach - public void afterEach(){ - String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); - FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - } - -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java deleted file mode 100644 index 753f3d95d..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - *

Title: liteflow

- *

Description: 轻量级的组件式流程框架

- * @author Bryan.Zhang - * @email weenyc31@163.com - * @Date 2020/4/1 - */ -package com.yomahub.liteflow.test.monitorFile.cmp; - -import com.yomahub.liteflow.annotation.LiteflowMethod; -import com.yomahub.liteflow.core.NodeComponent; -import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -import org.springframework.stereotype.Component; - -import java.util.Random; - -@Component("a") -public class ACmp { - - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } - -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java deleted file mode 100644 index 2cf618339..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - *

Title: liteflow

- *

Description: 轻量级的组件式流程框架

- * @author Bryan.Zhang - * @email weenyc31@163.com - * @Date 2020/4/1 - */ -package com.yomahub.liteflow.test.monitorFile.cmp; - -import com.yomahub.liteflow.annotation.LiteflowMethod; -import com.yomahub.liteflow.core.NodeComponent; -import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -import org.springframework.stereotype.Component; - -import java.util.Random; - -@Component("b") -public class BCmp { - - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } - -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java deleted file mode 100644 index 697d5dabd..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - *

Title: liteflow

- *

Description: 轻量级的组件式流程框架

- * @author Bryan.Zhang - * @email weenyc31@163.com - * @Date 2020/4/1 - */ -package com.yomahub.liteflow.test.monitorFile.cmp; - -import com.yomahub.liteflow.annotation.LiteflowMethod; -import com.yomahub.liteflow.core.NodeComponent; -import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -import org.springframework.stereotype.Component; - -import java.util.Random; - -@Component("c") -public class CCmp { - - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } - -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/monitorFile/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/monitorFile/application.properties deleted file mode 100644 index 361f7e90e..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/monitorFile/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -liteflow.rule-source=monitorFile/flow.el.xml -liteflow.enable-monitor-file=true \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/monitorFile/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/monitorFile/flow.el.xml deleted file mode 100644 index 98c3cbae6..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/monitorFile/flow.el.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - THEN(a, b, c); - - - \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/LiteflowMonitorFileTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/LiteflowMonitorFileTest.java deleted file mode 100644 index 70c581ec1..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/LiteflowMonitorFileTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.yomahub.liteflow.test.monitorFile; - -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.io.resource.ClassPathResource; -import cn.hutool.core.util.CharsetUtil; -import com.yomahub.liteflow.core.FlowExecutor; -import com.yomahub.liteflow.core.FlowExecutorHolder; -import com.yomahub.liteflow.flow.LiteflowResponse; -import com.yomahub.liteflow.property.LiteflowConfig; -import com.yomahub.liteflow.test.BaseTest; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import java.io.File; - -public class LiteflowMonitorFileTest extends BaseTest { - - private static FlowExecutor flowExecutor; - - @BeforeAll - public static void init() { - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("monitorFile/flow.el.xml"); - config.setEnableMonitorFile(true); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } - - @Test - public void testMonitor() throws InterruptedException { - String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); - String content = FileUtil.readUtf8String(absolutePath); - String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); - FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(3000); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assertions.assertEquals("a==>c==>b", response.getExecuteStepStr()); - } - - @AfterEach - public void afterEach(){ - String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); - FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - } - -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java deleted file mode 100644 index d99aa2b97..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - *

Title: liteflow

- *

Description: 轻量级的组件式流程框架

- * @author Bryan.Zhang - * @email weenyc31@163.com - * @Date 2020/4/1 - */ -package com.yomahub.liteflow.test.monitorFile.cmp; - -import com.yomahub.liteflow.core.NodeComponent; - -public class ACmp extends NodeComponent { - - @Override - public void process() { - System.out.println("ACmp executed!"); - } - -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java deleted file mode 100644 index 8b108f065..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - *

Title: liteflow

- *

Description: 轻量级的组件式流程框架

- * @author Bryan.Zhang - * @email weenyc31@163.com - * @Date 2020/4/1 - */ -package com.yomahub.liteflow.test.monitorFile.cmp; - -import com.yomahub.liteflow.core.NodeComponent; - -public class BCmp extends NodeComponent { - - @Override - public void process() { - System.out.println("BCmp executed!"); - } - -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java deleted file mode 100644 index 6323f2318..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - *

Title: liteflow

- *

Description: 轻量级的组件式流程框架

- * @author Bryan.Zhang - * @email weenyc31@163.com - * @Date 2020/4/1 - */ -package com.yomahub.liteflow.test.monitorFile.cmp; - -import com.yomahub.liteflow.core.NodeComponent; - -public class CCmp extends NodeComponent { - - @Override - public void process() { - System.out.println("CCmp executed!"); - } - -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileSpringbootTest.java deleted file mode 100644 index 047786ace..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileSpringbootTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.yomahub.liteflow.test.monitorFile; - -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.io.resource.ClassPathResource; -import cn.hutool.core.util.CharsetUtil; -import com.yomahub.liteflow.core.FlowExecutor; -import com.yomahub.liteflow.flow.LiteflowResponse; -import com.yomahub.liteflow.test.BaseTest; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.noear.solon.annotation.Inject; -import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; - -import java.io.File; - -@ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/monitorFile/application.properties") -public class MonitorFileSpringbootTest extends BaseTest { - - @Inject - private FlowExecutor flowExecutor; - - @Test - public void testMonitor() throws Exception { - String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.xml").getAbsolutePath(); - FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - String content = FileUtil.readUtf8String(absolutePath); - String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); - FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(1000); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assertions.assertEquals("a==>c==>b", response.getExecuteStepStr()); - } - - @AfterEach - public void afterEach(){ - String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); - FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - } - -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java deleted file mode 100644 index 2bcc4b1ba..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - *

Title: liteflow

- *

Description: 轻量级的组件式流程框架

- * @author Bryan.Zhang - * @email weenyc31@163.com - * @Date 2020/4/1 - */ -package com.yomahub.liteflow.test.monitorFile.cmp; - -import com.yomahub.liteflow.core.NodeComponent; -import org.noear.solon.annotation.Component; - -import java.util.Random; - -@Component("a") -public class ACmp extends NodeComponent { - - @Override - public void process() { - System.out.println("ACmp executed!"); - } - -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java deleted file mode 100644 index 54437c018..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - *

Title: liteflow

- *

Description: 轻量级的组件式流程框架

- * @author Bryan.Zhang - * @email weenyc31@163.com - * @Date 2020/4/1 - */ -package com.yomahub.liteflow.test.monitorFile.cmp; - -import com.yomahub.liteflow.core.NodeComponent; -import org.noear.solon.annotation.Component; - -import java.util.Random; - -@Component("b") -public class BCmp extends NodeComponent { - - @Override - public void process() { - System.out.println("BCmp executed!"); - } - -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java deleted file mode 100644 index 346fdfde9..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - *

Title: liteflow

- *

Description: 轻量级的组件式流程框架

- * @author Bryan.Zhang - * @email weenyc31@163.com - * @Date 2020/4/1 - */ -package com.yomahub.liteflow.test.monitorFile.cmp; - -import com.yomahub.liteflow.core.NodeComponent; -import org.noear.solon.annotation.Component; - -import java.util.Random; - -@Component("c") -public class CCmp extends NodeComponent { - - @Override - public void process() { - System.out.println("CCmp executed!"); - } - -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/monitorFile/application.properties b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/monitorFile/application.properties deleted file mode 100644 index c1953bc13..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/monitorFile/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -liteflow.rule-source=monitorFile/flow.xml -liteflow.enable-monitor-file=true \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/monitorFile/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/monitorFile/flow.xml deleted file mode 100644 index 98c3cbae6..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/monitorFile/flow.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - THEN(a, b, c); - - - \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java index 17308d7e2..ecc1f9e91 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java @@ -31,8 +31,9 @@ public class MonitorFileELSpringbootTest extends BaseTest { FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); String content = FileUtil.readUtf8String(absolutePath); String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); + Thread.sleep(1000); FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(1000); + Thread.sleep(3000); LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); Assertions.assertEquals("a==>c==>b", response.getExecuteStepStr()); } @@ -44,7 +45,6 @@ public class MonitorFileELSpringbootTest extends BaseTest { @Test public void testMonitorError() throws Exception { String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); - FileUtil.writeString("THEN(a, b, c);", new File(absolutePath), CharsetUtil.CHARSET_UTF_8); String content = FileUtil.readUtf8String(absolutePath); // 错误规则配置 From 84143041455cb4fca17b1702edfa01b996d37889 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Fri, 21 Jul 2023 15:38:51 +0800 Subject: [PATCH 15/18] =?UTF-8?q?enhancement=20#I7KHE5=20=E5=85=B3?= =?UTF-8?q?=E4=BA=8E=E6=B3=A8=E8=A7=A3=E5=A3=B0=E6=98=8E=E5=BC=8F=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E5=9C=BA=E6=99=AFLiteFlowMethodEnum=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?getDisplayName=E7=AD=89=E9=9C=80=E6=B1=82=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/enums/LiteFlowMethodEnum.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/LiteFlowMethodEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/LiteFlowMethodEnum.java index dd49f0a85..62005e128 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/LiteFlowMethodEnum.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/LiteFlowMethodEnum.java @@ -2,14 +2,19 @@ package com.yomahub.liteflow.enums; public enum LiteFlowMethodEnum { - PROCESS("process", true), PROCESS_SWITCH("processSwitch", true), PROCESS_IF("processIf", true), - PROCESS_FOR("processFor", true), PROCESS_WHILE("processWhile", true), PROCESS_BREAK("processBreak", true), + PROCESS("process", true), + PROCESS_SWITCH("processSwitch", true), + PROCESS_IF("processIf", true), + PROCESS_FOR("processFor", true), + PROCESS_WHILE("processWhile", true), + PROCESS_BREAK("processBreak", true), PROCESS_ITERATOR("processIterator", true), IS_ACCESS("isAccess", false), - IS_END("isEnd", false), IS_CONTINUE_ON_ERROR("isContinueOnError", false), + IS_END("isEnd", false), + IS_CONTINUE_ON_ERROR("isContinueOnError", false), GET_NODE_EXECUTOR_CLASS("getNodeExecutorClass", false), @@ -19,7 +24,10 @@ public enum LiteFlowMethodEnum { BEFORE_PROCESS("beforeProcess", false), - AFTER_PROCESS("afterProcess", false); + AFTER_PROCESS("afterProcess", false), + + GET_DISPLAY_NAME("getDisplayName", false) + ; private String methodName; From be77a06b9b250190b713e2ed600ec7994e37e7f2 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Fri, 21 Jul 2023 16:29:23 +0800 Subject: [PATCH 16/18] =?UTF-8?q?=E6=9B=B4=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.zh-CN.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.zh-CN.md b/README.zh-CN.md index dd95c39b9..5216956f0 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -11,7 +11,7 @@ LiteFlow是一个轻量且强大的国产规则引擎框架,可用于复杂的 LiteFlow于2020年正式开源,2021年获得开源中国年度最受欢迎开源软件殊荣。于2022年获得Gitee最有价值开源项目(GVP)荣誉。是一个正处在高速发展中的开源项目。 -LiteFlow是一个由社区驱动的项目,我们非常重视社区建设,拥有一个2500多人的使用者社区,在使用中碰到任何问题或者建议都可以在社区中反应。 +LiteFlow是一个由社区驱动的项目,我们非常重视社区建设,拥有一个3000多人的使用者社区,在使用中碰到任何问题或者建议都可以在社区中反应。 你在官网中可以找到加入社区的方式! @@ -59,7 +59,7 @@ LiteFlow期待你的了解! **微信公众号** -由于社区群超过200人,需要邀请入群。关注公众号后点击`个人微信`加我,我可以拉你入群 +社区群需要邀请入群。关注公众号后点击`个人微信`加我,我可以拉你入群 ![offIical-wx](static/img/offical-wx.jpg) From 73392071f92ae2bad30ce63d51f29b8877f2559e Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Sat, 22 Jul 2023 16:25:53 +0800 Subject: [PATCH 17/18] =?UTF-8?q?=E8=BF=99=E9=87=8C=E4=B8=8D=E9=9C=80?= =?UTF-8?q?=E8=A6=81git=20ignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.gitignore | 38 ------------------- 1 file changed, 38 deletions(-) delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/.gitignore diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/.gitignore b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/.gitignore deleted file mode 100644 index 5ff6309b7..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/.gitignore +++ /dev/null @@ -1,38 +0,0 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file From 938afb6ad65640cdf669a4752dfd5355a7a2bc8e Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Sat, 22 Jul 2023 16:26:06 +0800 Subject: [PATCH 18/18] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=8C=96springboot?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow-testcase-el-sql-springboot-dynamic/pom.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/pom.xml b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/pom.xml index b7bd4c935..364966c49 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/pom.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/pom.xml @@ -16,19 +16,18 @@ 2.1.214 2.6.8 4.1.2 - 2.7.13 org.springframework.boot spring-boot-starter - ${spring-boot.version} + ${springboot.version} org.springframework.boot spring-boot-starter-web - ${spring-boot.version} + ${springboot.version} com.yomahub