From 252c81dd156dc9b4b8077d86dff8dcfe3a4ef770 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Fri, 19 Apr 2024 17:05:32 +0800 Subject: [PATCH 01/21] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yomahub/liteflow/parser/sql/read/SqlReadFactory.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/SqlReadFactory.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/SqlReadFactory.java index b08de78a..281f7798 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/SqlReadFactory.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/SqlReadFactory.java @@ -23,16 +23,16 @@ public class SqlReadFactory { private static final Map POLL_TASK_MAP = new HashMap<>(); public static void registerRead(SQLParserVO config) { - READ_MAP.put(ReadType.CHAIN, new ChainRead(config)); - READ_MAP.put(ReadType.SCRIPT, new ScriptRead(config)); + READ_MAP.putIfAbsent(ReadType.CHAIN, new ChainRead(config)); + READ_MAP.putIfAbsent(ReadType.SCRIPT, new ScriptRead(config)); } public static void registerSqlReadPollTask(ReadType readType) { SqlRead sqlRead = getSqlRead(readType); if (ReadType.CHAIN.equals(readType)) { - POLL_TASK_MAP.put(ReadType.CHAIN, new ChainReadPollTask(sqlRead)); + POLL_TASK_MAP.putIfAbsent(ReadType.CHAIN, new ChainReadPollTask(sqlRead)); } else if (ReadType.SCRIPT.equals(readType)) { - POLL_TASK_MAP.put(ReadType.SCRIPT, new ScriptReadPollTask(sqlRead)); + POLL_TASK_MAP.putIfAbsent(ReadType.SCRIPT, new ScriptReadPollTask(sqlRead)); } } From 3a25c35b628ae0db8fee868f1baab45c613c2610 Mon Sep 17 00:00:00 2001 From: rain <672378783@qq.com> Date: Wed, 24 Apr 2024 21:23:48 +0800 Subject: [PATCH 02/21] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwindows=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E4=B8=8B=E6=97=A0=E6=B3=95=E8=A7=A3=E6=9E=90=E6=A8=A1?= =?UTF-8?q?=E7=B3=8A=E8=B7=AF=E5=BE=84=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yomahub/liteflow/core/FlowExecutor.java | 4 ++-- .../AbsoluteConfigPathELDeclMultiSpringbootTest.java | 10 ++++++++++ .../AbsoluteConfigPathELDeclSpringbootTest.java | 10 ++++++++++ .../absoluteConfigPath/AbsoluteConfigPathTest.java | 10 ++++++++++ .../AbsoluteConfigPathELSpringbootTest.java | 10 ++++++++++ .../AbsoluteConfigPathELSpringbootTest.java | 10 ++++++++++ .../AbsoluteConfigPathELSpringTest.java | 10 ++++++++++ 7 files changed, 62 insertions(+), 2 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java index 56a5f5ac..a60c3222 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java @@ -136,8 +136,8 @@ public class FlowExecutor { // 查找对应的解析器 parser = FlowParserProvider.lookup(path); parserNameSet.add(parser.getClass().getName()); - // 替换掉前缀标识(如:xml:/json:),保留剩下的完整地址 - path = ReUtil.replaceAll(path, PREFIX_FORMAT_CONFIG_REGEX, ""); + // 替换掉前缀标识(如:xml:/json:),保留剩下的完整地址,并统一路径格式 + path = ReUtil.replaceAll(path, PREFIX_FORMAT_CONFIG_REGEX, "").replace("\\", "/"); rulePathList.add(path); // 支持多类型的配置文件,分别解析 diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java index ba135a61..30df1e19 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java @@ -63,6 +63,16 @@ public class AbsoluteConfigPathELDeclMultiSpringbootTest extends BaseTest { }); } + @Test + public void testAbsPath() throws Exception{ + Assertions.assertTrue(() -> { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource(StrUtil.format("{}\\sub\\**\\*.xml",rootDir)); + flowExecutor.reloadRule(); + return flowExecutor.execute2Resp("chain1", "arg").isSuccess(); + }); + } + @BeforeAll public static void createFiles() { rootDir = FileUtil.getAbsolutePath(ResourceUtil.getResource("").getPath()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java index ae2393ae..0e1a40e6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java @@ -65,6 +65,16 @@ public class AbsoluteConfigPathELDeclSpringbootTest extends BaseTest { }); } + @Test + public void testAbsPath() throws Exception{ + Assertions.assertTrue(() -> { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource(StrUtil.format("{}\\sub\\**\\*.xml",rootDir)); + flowExecutor.reloadRule(); + return flowExecutor.execute2Resp("chain1", "arg").isSuccess(); + }); + } + @BeforeAll public static void createFiles() { rootDir = FileUtil.getAbsolutePath(ResourceUtil.getResource("").getPath()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathTest.java index 06e20667..a536cede 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathTest.java @@ -50,6 +50,16 @@ public class AbsoluteConfigPathTest extends BaseTest { }); } + @Test + public void testAbsPath() throws Exception{ + Assertions.assertTrue(() -> { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource(StrUtil.format("{}\\sub\\**\\*.xml",rootDir)); + flowExecutor = FlowExecutorHolder.loadInstance(config); + return flowExecutor.execute2Resp("chain1", "arg").isSuccess(); + }); + } + @BeforeAll public static void createFiles() { rootDir = FileUtil.getAbsolutePath(ResourceUtil.getResource("").getPath()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java index 62812c80..2d3029b1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java @@ -56,6 +56,16 @@ public class AbsoluteConfigPathELSpringbootTest extends BaseTest { }); } + @Test + public void testAbsTest() throws Exception { + Assertions.assertTrue(() -> { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource(StrUtil.format("{}\\sub\\**\\*.xml",rootDir)); + flowExecutor.reloadRule(); + return flowExecutor.execute2Resp("chain1", "arg").isSuccess(); + }); + } + @BeforeAll public static void createFiles() { rootDir = FileUtil.getAbsolutePath(ResourceUtil.getResource("").getPath()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java index 97ac251c..8a2f4faf 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java @@ -70,6 +70,16 @@ public class AbsoluteConfigPathELSpringbootTest extends BaseTest { }); } + @Test + public void testAbsPath4() throws Exception{ + Assertions.assertTrue(() -> { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource(StrUtil.format("{}\\sub\\a\\*.xml,sub\\b\\*.xml",rootDir)); + flowExecutor.reloadRule(); + return flowExecutor.execute2Resp("chain2", "arg").isSuccess(); + }); + } + @BeforeAll public static void createFiles() { rootDir = FileUtil.getAbsolutePath(ResourceUtil.getResource("").getPath()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringTest.java index f44acb08..f82c89b7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringTest.java @@ -55,6 +55,16 @@ public class AbsoluteConfigPathELSpringTest extends BaseTest { }); } + @Test + public void testAbsPath() throws Exception{ + Assertions.assertTrue(() -> { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource(StrUtil.format("{}\\sub\\**\\*.xml",rootDir)); + flowExecutor.reloadRule(); + return flowExecutor.execute2Resp("chain1", "arg").isSuccess(); + }); + } + @BeforeAll public static void createFiles() { rootDir = FileUtil.getAbsolutePath(ResourceUtil.getResource("").getPath()); From 0a5d602a7a5ea18c74d6f012abe3e6eda99dabd3 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Thu, 2 May 2024 13:43:50 +0800 Subject: [PATCH 03/21] =?UTF-8?q?enhancement=20#I9LBTY=20=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=85=B3=E9=97=AD=20GPG=20=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index fe2b4d1d..8fdff57a 100644 --- a/pom.xml +++ b/pom.xml @@ -388,6 +388,10 @@ + + + true + From 33f05eb7cc23de57fb8ab7fac65d47b186488692 Mon Sep 17 00:00:00 2001 From: Dale Lee <1658850308@qq.com> Date: Thu, 2 May 2024 15:33:16 +0800 Subject: [PATCH 04/21] =?UTF-8?q?feature=20#I9H6GN=20=E6=94=AF=E6=8C=81=20?= =?UTF-8?q?kotlin=20=E8=84=9A=E6=9C=AC=E8=AF=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/enums/ScriptTypeEnum.java | 3 +- .../liteflow-script-kotlin/pom.xml | 29 ++++++ .../script/kotlin/KotlinScriptExecutor.java | 15 +++ ...com.yomahub.liteflow.script.ScriptExecutor | 2 + liteflow-script-plugin/pom.xml | 1 + .../pom.xml | 32 +++++++ .../liteflow/test/script/BaseTest.java | 24 +++++ .../liteflow/test/script/kotlin/T2.java | 93 +++++++++++++++++++ .../test/script/kotlin/TestKotlin.java | 49 ++++++++++ .../LiteFlowKotlinScriptCommonELTest.java | 68 ++++++++++++++ .../test/script/kotlin/common/cmp/ACmp.java | 21 +++++ .../test/script/kotlin/common/cmp/BCmp.java | 21 +++++ .../test/script/kotlin/common/cmp/CCmp.java | 21 +++++ .../resources/common/application.properties | 1 + .../src/test/resources/common/flow.xml | 72 ++++++++++++++ liteflow-testcase-el/pom.xml | 1 + 16 files changed, 452 insertions(+), 1 deletion(-) create mode 100644 liteflow-script-plugin/liteflow-script-kotlin/pom.xml create mode 100644 liteflow-script-plugin/liteflow-script-kotlin/src/main/java/com/yomahub/liteflow/script/kotlin/KotlinScriptExecutor.java create mode 100644 liteflow-script-plugin/liteflow-script-kotlin/src/main/resources/META-INF/services/com.yomahub.liteflow.script.ScriptExecutor create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/pom.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/BaseTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/T2.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/TestKotlin.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/LiteFlowKotlinScriptCommonELTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/flow.xml diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java index f350b416..c9a62570 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java @@ -8,7 +8,8 @@ public enum ScriptTypeEnum { PYTHON("python", "python"), LUA("luaj", "lua"), AVIATOR("AviatorScript", "aviator"), - JAVA("java", "java"); + JAVA("java", "java"), + KOTLIN("kotlin", "kotlin"); private String engineName; diff --git a/liteflow-script-plugin/liteflow-script-kotlin/pom.xml b/liteflow-script-plugin/liteflow-script-kotlin/pom.xml new file mode 100644 index 00000000..c89e6d79 --- /dev/null +++ b/liteflow-script-plugin/liteflow-script-kotlin/pom.xml @@ -0,0 +1,29 @@ + + + + liteflow-script-plugin + com.yomahub + ${revision} + ../pom.xml + + 4.0.0 + + liteflow-script-kotlin + + + + com.yomahub + liteflow-core + ${revision} + true + provided + + + org.jetbrains.kotlin + kotlin-scripting-jsr223 + 1.9.23 + + + \ No newline at end of file diff --git a/liteflow-script-plugin/liteflow-script-kotlin/src/main/java/com/yomahub/liteflow/script/kotlin/KotlinScriptExecutor.java b/liteflow-script-plugin/liteflow-script-kotlin/src/main/java/com/yomahub/liteflow/script/kotlin/KotlinScriptExecutor.java new file mode 100644 index 00000000..acdc490d --- /dev/null +++ b/liteflow-script-plugin/liteflow-script-kotlin/src/main/java/com/yomahub/liteflow/script/kotlin/KotlinScriptExecutor.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.script.kotlin; + +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.script.jsr223.JSR223ScriptExecutor; + +/** + * Kotlin脚本执行器 + * @author DaleLee + */ +public class KotlinScriptExecutor extends JSR223ScriptExecutor { + @Override + public ScriptTypeEnum scriptType() { + return ScriptTypeEnum.KOTLIN; + } +} diff --git a/liteflow-script-plugin/liteflow-script-kotlin/src/main/resources/META-INF/services/com.yomahub.liteflow.script.ScriptExecutor b/liteflow-script-plugin/liteflow-script-kotlin/src/main/resources/META-INF/services/com.yomahub.liteflow.script.ScriptExecutor new file mode 100644 index 00000000..ccce7e1f --- /dev/null +++ b/liteflow-script-plugin/liteflow-script-kotlin/src/main/resources/META-INF/services/com.yomahub.liteflow.script.ScriptExecutor @@ -0,0 +1,2 @@ +# Kotlin的实现 +com.yomahub.liteflow.script.kotlin.KotlinScriptExecutor \ No newline at end of file diff --git a/liteflow-script-plugin/pom.xml b/liteflow-script-plugin/pom.xml index 2c43fa16..a188cd04 100644 --- a/liteflow-script-plugin/pom.xml +++ b/liteflow-script-plugin/pom.xml @@ -23,6 +23,7 @@ liteflow-script-lua liteflow-script-aviator liteflow-script-java + liteflow-script-kotlin \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/pom.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/pom.xml new file mode 100644 index 00000000..e76dca32 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/pom.xml @@ -0,0 +1,32 @@ + + + + liteflow-testcase-el + com.yomahub + ${revision} + ../pom.xml + + 4.0.0 + + liteflow-testcase-el-script-kotlin-springboot + + + + com.yomahub + liteflow-spring-boot-starter + ${revision} + + + com.yomahub + liteflow-script-kotlin + 2.12.0 + test + + + org.springframework.boot + spring-boot-starter-test + + + diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/BaseTest.java new file mode 100644 index 00000000..6cb71ce8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/BaseTest.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.script; + +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; + +public class BaseTest { + + @AfterAll + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + FlowBus.clearStat(); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/T2.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/T2.java new file mode 100644 index 00000000..564cb33a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/T2.java @@ -0,0 +1,93 @@ +package com.yomahub.liteflow.test.script.kotlin; + +import com.yomahub.liteflow.slot.DefaultContext; +import org.junit.jupiter.api.Test; + +import javax.script.Bindings; +import javax.script.Compilable; +import javax.script.CompiledScript; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; +import javax.script.SimpleBindings; + +public class T2 { + @Test + public void test1() throws ScriptException { + // 初始化 ScriptEngineManager 和 Kotlin 脚本引擎 + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine engine = manager.getEngineByName("kotlin"); + + if (engine == null) { + throw new IllegalStateException("Kotlin script engine not found"); + } + + // 假设我们有以下Kotlin脚本,它期望一个名为'message'的外部参数 + String script = "fun greet(name: String) {\n" + + " println(\"Hello, $name!\")\n" + + " }\n" + + " println(bindings[\"message\"])"; + + + // 编译脚本为CompiledScript对象 + Compilable compilable = (Compilable) engine; + CompiledScript compiledScript = compilable.compile(script); + + // 准备脚本上下文,用于传递外部参数 + Bindings bindings = engine.createBindings(); + // 设置外部参数 + bindings.put("message", "User"); + + // 使用相同的上下文多次执行已编译的脚本 + for (int i = 0; i < 2; i++) { + compiledScript.eval(bindings); + } +// engine.put("message","User"); +// engine.eval(script); + //engine.eval(script,bindings); + } + + @Test + public void test2() throws ScriptException { + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine engine = manager.getEngineByName("kotlin"); + String script = "" + + "var defaultContext = bindings[\"defaultContext\"]\n" + + "println(defaultContext.getData(\"key\"))"; + // 编译脚本为CompiledScript对象 + Compilable compilable = (Compilable) engine; + CompiledScript compiledScript = compilable.compile(script); + + // 准备脚本上下文,用于传递外部参数 + Bindings bindings = new SimpleBindings(); + DefaultContext context = new DefaultContext(); + context.setData("key", "value"); + // 设置外部参数 + bindings.put("defaultContext", context); + compiledScript.eval(bindings); + } + + @Test + public void test3() throws ScriptException { + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine engine = manager.getEngineByName("kotlin"); + String script = + "fun getNum() = 15\n" + + "getNum()"; + + // 编译脚本为CompiledScript对象 + Compilable compilable = (Compilable) engine; + CompiledScript compiledScript = compilable.compile(script); + + // 准备脚本上下文,用于传递外部参数 +// Bindings bindings = new SimpleBindings(); +// DefaultContext context = new DefaultContext(); +// context.setData("key", "value"); +// // 设置外部参数 +// bindings.put("defaultContext", context); + /* Object res = compiledScript.eval(); + System.out.println(res);*/ + Object eval = engine.eval(script); + System.out.println(eval); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/TestKotlin.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/TestKotlin.java new file mode 100644 index 00000000..7ddd0a87 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/TestKotlin.java @@ -0,0 +1,49 @@ +package com.yomahub.liteflow.test.script.kotlin; + +import com.yomahub.liteflow.enums.ScriptTypeEnum; + +import javax.script.Compilable; +import javax.script.CompiledScript; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; + +public class TestKotlin { + public static void main(String[] args) throws ScriptException, NoSuchMethodException { + // 获取脚本引擎管理器 + ScriptEngineManager manager = new ScriptEngineManager(); + + // 获取Kotlin脚本引擎 + ScriptEngine engine = manager.getEngineByName(ScriptTypeEnum.KOTLIN.getEngineName()); // ".kts" 是Kotlin脚本文件的扩展名 + + // 检查是否找到了Kotlin脚本引擎 + if (engine == null) { + System.out.println("No Kotlin script engine found."); + return; + } + + System.out.println(engine instanceof Compilable); + + // 定义一个Kotlin脚本 + String script = "println(\"Hello, Kotlin JSR 223!\")"; + + Compilable compilable = (Compilable) engine; + CompiledScript compile = compilable.compile(script); + compile.eval(); + + + // 编译并执行脚本 + engine.eval(script); + + // 如果ScriptEngine也实现了Invocable接口,我们可以调用脚本中的函数 +// if (engine instanceof Invocable) { +// Invocable inv = (Invocable) engine; +// +// // 调用脚本中的greet函数 +// String greeting = (String) inv.invokeFunction("greet", "World"); +// System.out.println(greeting); // 输出: Hello, World! +// } else { +// System.out.println("The script engine does not support Invocable interface."); +// } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/LiteFlowKotlinScriptCommonELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/LiteFlowKotlinScriptCommonELTest.java new file mode 100644 index 00000000..49629ce3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/LiteFlowKotlinScriptCommonELTest.java @@ -0,0 +1,68 @@ +package com.yomahub.liteflow.test.script.kotlin.common; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.script.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:/common/application.properties") +@SpringBootTest(classes = LiteFlowKotlinScriptCommonELTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.script.kotlin.common.cmp"}) +public class LiteFlowKotlinScriptCommonELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testCommon1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(5), context.getData("s1")); + } + + @Test + public void testFor1() { + DefaultContext context = new DefaultContext(); + context.setData("k1", 1); + context.setData("k2", 2); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg", context); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("s2==>a==>a==>a",response.getExecuteStepStr()); + } + + @Test + public void testIf1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("s3==>b",response.getExecuteStepStr()); + } + + @Test + public void testIf2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("s4",response.getExecuteStepStr()); + } + + @Test + public void testSwitch1() { + DefaultContext context = new DefaultContext(); + context.setData("id", "c"); + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg", context); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("s5==>c",response.getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/ACmp.java new file mode 100644 index 00000000..895686f1 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.common.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/BCmp.java new file mode 100644 index 00000000..1c4eb649 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.common.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/CCmp.java new file mode 100644 index 00000000..661e979a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.common.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("c") +public class CCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/application.properties new file mode 100644 index 00000000..4c9c216b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=common/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/flow.xml new file mode 100644 index 00000000..35db6f00 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/flow.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + 1 + getBoolean1() + ]]> + + + + + + + + + + + THEN(a, b, c, s1); + + + + FOR(s2).DO(a); + + + + IF(s3, b); + + + + IF(s4, b); + + + + SWITCH(s5).TO(a, b, c); + + \ No newline at end of file diff --git a/liteflow-testcase-el/pom.xml b/liteflow-testcase-el/pom.xml index 7323492c..7c3ba26e 100644 --- a/liteflow-testcase-el/pom.xml +++ b/liteflow-testcase-el/pom.xml @@ -39,6 +39,7 @@ liteflow-testcase-el-script-java-springboot liteflow-testcase-el-builder liteflow-testcase-el-routechain + liteflow-testcase-el-script-kotlin-springboot From c3a64bd0f492dc4128390f96f31ef5648b4c7923 Mon Sep 17 00:00:00 2001 From: Dale Lee <1658850308@qq.com> Date: Thu, 2 May 2024 22:25:50 +0800 Subject: [PATCH 05/21] =?UTF-8?q?feature=20#I9H6GN=20=E5=AE=8C=E5=96=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 --- .../liteflow/test/script/kotlin/T2.java | 93 ------------ .../test/script/kotlin/TestKotlin.java | 49 ------- .../LiteFlowCmpDataKotlinScriptELTest.java | 36 +++++ .../test/script/kotlin/cmpdata/cmp/ACmp.java | 22 +++ .../LiteFlowKotlinScriptCommonELTest.java | 51 +++++-- ...LiteFlowScriptContextbeanKotlinELTest.java | 57 ++++++++ .../kotlin/contextbean/bean/CheckContext.java | 28 ++++ .../contextbean/bean/Order2Context.java | 37 +++++ .../kotlin/contextbean/bean/OrderContext.java | 40 ++++++ .../script/kotlin/contextbean/cmp/ACmp.java | 21 +++ .../script/kotlin/contextbean/cmp/BCmp.java | 21 +++ .../script/kotlin/contextbean/cmp/CCmp.java | 21 +++ .../meta/LiteflowKotlinScriptMetaELTest.java | 37 +++++ .../test/script/kotlin/meta/cmp/ACmp.java | 21 +++ .../test/script/kotlin/meta/cmp/BCmp.java | 21 +++ .../test/script/kotlin/meta/cmp/CCmp.java | 21 +++ .../LiteflowKotlinScriptRefreshELTest.java | 48 +++++++ .../test/script/kotlin/refresh/cmp/ACmp.java | 21 +++ .../test/script/kotlin/refresh/cmp/BCmp.java | 21 +++ .../test/script/kotlin/refresh/cmp/CCmp.java | 21 +++ .../test/script/kotlin/refresh/cmp/DCmp.java | 24 ++++ .../LiteFlowKotlinScriptRemoveELTest.java | 114 +++++++++++++++ .../LiteFlowScriptScriptbeanKotlinELTest.java | 103 ++++++++++++++ .../kotlin/scriptbean/bean/DemoBean1.java | 23 +++ .../kotlin/scriptbean/bean/DemoBean2.java | 12 ++ .../kotlin/scriptbean/bean/DemoBean3.java | 22 +++ .../kotlin/scriptbean/bean/DemoBean4.java | 22 +++ .../kotlin/scriptbean/bean/DemoBean5.java | 24 ++++ .../script/kotlin/scriptbean/cmp/ACmp.java | 21 +++ .../script/kotlin/scriptbean/cmp/BCmp.java | 21 +++ .../script/kotlin/scriptbean/cmp/CCmp.java | 21 +++ ...iteFlowScriptScriptMethodKotlinELTest.java | 45 ++++++ .../kotlin/scriptmethod/bean/DemoBean1.java | 24 ++++ .../kotlin/scriptmethod/bean/DemoBean2.java | 12 ++ .../script/kotlin/scriptmethod/cmp/ACmp.java | 21 +++ .../script/kotlin/scriptmethod/cmp/BCmp.java | 21 +++ .../script/kotlin/scriptmethod/cmp/CCmp.java | 21 +++ .../kotlin/throwException/TestException.java | 15 ++ .../ThrowExceptionScriptKotlinELTest.java | 37 +++++ .../kotlin/throwException/cmp/ACmp.java | 21 +++ .../ValidateKotlinScriptComponentTest.java | 26 ++++ .../resources/cmpdata/application.properties | 1 + .../src/test/resources/cmpdata/flow.xml | 27 ++++ .../src/test/resources/common/flow.xml | 41 +++++- .../contextbean/application.properties | 1 + .../src/test/resources/contextbean/flow.xml | 45 ++++++ .../resources/meta/application.properties | 1 + .../src/test/resources/meta/flow.xml | 24 ++++ .../resources/refresh/application.properties | 1 + .../src/test/resources/refresh/flow.xml | 27 ++++ .../test/resources/refresh/flow_update.xml | 36 +++++ .../resources/remove/application.properties | 1 + .../src/test/resources/remove/flow.xml | 34 +++++ .../src/test/resources/script-file/s7.kts | 6 + .../scriptbean/application.properties | 1 + .../src/test/resources/scriptbean/flow.xml | 134 ++++++++++++++++++ .../scriptmethod/application.properties | 1 + .../src/test/resources/scriptmethod/flow.xml | 37 +++++ .../throwException/application.properties | 1 + .../test/resources/throwException/flow.xml | 17 +++ 60 files changed, 1610 insertions(+), 163 deletions(-) delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/T2.java delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/TestKotlin.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/cmpdata/LiteFlowCmpDataKotlinScriptELTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/cmpdata/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/LiteFlowScriptContextbeanKotlinELTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/CheckContext.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/Order2Context.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/OrderContext.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/LiteflowKotlinScriptMetaELTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/LiteflowKotlinScriptRefreshELTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/DCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/remove/LiteFlowKotlinScriptRemoveELTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/LiteFlowScriptScriptbeanKotlinELTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean1.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean2.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean3.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean4.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean5.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/LiteFlowScriptScriptMethodKotlinELTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/bean/DemoBean1.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/bean/DemoBean2.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/TestException.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/ThrowExceptionScriptKotlinELTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/validate/ValidateKotlinScriptComponentTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/flow.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/contextbean/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/contextbean/flow.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/flow.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/flow.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/flow_update.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/remove/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/remove/flow.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/script-file/s7.kts create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptbean/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptbean/flow.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptmethod/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptmethod/flow.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/throwException/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/throwException/flow.xml diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/T2.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/T2.java deleted file mode 100644 index 564cb33a..00000000 --- a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/T2.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.yomahub.liteflow.test.script.kotlin; - -import com.yomahub.liteflow.slot.DefaultContext; -import org.junit.jupiter.api.Test; - -import javax.script.Bindings; -import javax.script.Compilable; -import javax.script.CompiledScript; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; -import javax.script.SimpleBindings; - -public class T2 { - @Test - public void test1() throws ScriptException { - // 初始化 ScriptEngineManager 和 Kotlin 脚本引擎 - ScriptEngineManager manager = new ScriptEngineManager(); - ScriptEngine engine = manager.getEngineByName("kotlin"); - - if (engine == null) { - throw new IllegalStateException("Kotlin script engine not found"); - } - - // 假设我们有以下Kotlin脚本,它期望一个名为'message'的外部参数 - String script = "fun greet(name: String) {\n" + - " println(\"Hello, $name!\")\n" + - " }\n" + - " println(bindings[\"message\"])"; - - - // 编译脚本为CompiledScript对象 - Compilable compilable = (Compilable) engine; - CompiledScript compiledScript = compilable.compile(script); - - // 准备脚本上下文,用于传递外部参数 - Bindings bindings = engine.createBindings(); - // 设置外部参数 - bindings.put("message", "User"); - - // 使用相同的上下文多次执行已编译的脚本 - for (int i = 0; i < 2; i++) { - compiledScript.eval(bindings); - } -// engine.put("message","User"); -// engine.eval(script); - //engine.eval(script,bindings); - } - - @Test - public void test2() throws ScriptException { - ScriptEngineManager manager = new ScriptEngineManager(); - ScriptEngine engine = manager.getEngineByName("kotlin"); - String script = "" + - "var defaultContext = bindings[\"defaultContext\"]\n" + - "println(defaultContext.getData(\"key\"))"; - // 编译脚本为CompiledScript对象 - Compilable compilable = (Compilable) engine; - CompiledScript compiledScript = compilable.compile(script); - - // 准备脚本上下文,用于传递外部参数 - Bindings bindings = new SimpleBindings(); - DefaultContext context = new DefaultContext(); - context.setData("key", "value"); - // 设置外部参数 - bindings.put("defaultContext", context); - compiledScript.eval(bindings); - } - - @Test - public void test3() throws ScriptException { - ScriptEngineManager manager = new ScriptEngineManager(); - ScriptEngine engine = manager.getEngineByName("kotlin"); - String script = - "fun getNum() = 15\n" + - "getNum()"; - - // 编译脚本为CompiledScript对象 - Compilable compilable = (Compilable) engine; - CompiledScript compiledScript = compilable.compile(script); - - // 准备脚本上下文,用于传递外部参数 -// Bindings bindings = new SimpleBindings(); -// DefaultContext context = new DefaultContext(); -// context.setData("key", "value"); -// // 设置外部参数 -// bindings.put("defaultContext", context); - /* Object res = compiledScript.eval(); - System.out.println(res);*/ - Object eval = engine.eval(script); - System.out.println(eval); - } -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/TestKotlin.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/TestKotlin.java deleted file mode 100644 index 7ddd0a87..00000000 --- a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/TestKotlin.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.yomahub.liteflow.test.script.kotlin; - -import com.yomahub.liteflow.enums.ScriptTypeEnum; - -import javax.script.Compilable; -import javax.script.CompiledScript; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; - -public class TestKotlin { - public static void main(String[] args) throws ScriptException, NoSuchMethodException { - // 获取脚本引擎管理器 - ScriptEngineManager manager = new ScriptEngineManager(); - - // 获取Kotlin脚本引擎 - ScriptEngine engine = manager.getEngineByName(ScriptTypeEnum.KOTLIN.getEngineName()); // ".kts" 是Kotlin脚本文件的扩展名 - - // 检查是否找到了Kotlin脚本引擎 - if (engine == null) { - System.out.println("No Kotlin script engine found."); - return; - } - - System.out.println(engine instanceof Compilable); - - // 定义一个Kotlin脚本 - String script = "println(\"Hello, Kotlin JSR 223!\")"; - - Compilable compilable = (Compilable) engine; - CompiledScript compile = compilable.compile(script); - compile.eval(); - - - // 编译并执行脚本 - engine.eval(script); - - // 如果ScriptEngine也实现了Invocable接口,我们可以调用脚本中的函数 -// if (engine instanceof Invocable) { -// Invocable inv = (Invocable) engine; -// -// // 调用脚本中的greet函数 -// String greeting = (String) inv.invokeFunction("greet", "World"); -// System.out.println(greeting); // 输出: Hello, World! -// } else { -// System.out.println("The script engine does not support Invocable interface."); -// } - } -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/cmpdata/LiteFlowCmpDataKotlinScriptELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/cmpdata/LiteFlowCmpDataKotlinScriptELTest.java new file mode 100644 index 00000000..c950c67d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/cmpdata/LiteFlowCmpDataKotlinScriptELTest.java @@ -0,0 +1,36 @@ +package com.yomahub.liteflow.test.script.kotlin.cmpdata; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.script.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:/cmpdata/application.properties") +@SpringBootTest(classes = LiteFlowCmpDataKotlinScriptELTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.script.kotlin.cmpdata.cmp" }) +public class LiteFlowCmpDataKotlinScriptELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testCmpData1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("1995-10-01", context.getData("s1")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/cmpdata/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/cmpdata/cmp/ACmp.java new file mode 100644 index 00000000..1de2ccb9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/cmpdata/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.script.kotlin.cmpdata.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(this.getCmpData(String.class)); + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/LiteFlowKotlinScriptCommonELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/LiteFlowKotlinScriptCommonELTest.java index 49629ce3..17b61966 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/LiteFlowKotlinScriptCommonELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/common/LiteFlowKotlinScriptCommonELTest.java @@ -15,6 +15,12 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import javax.annotation.Resource; +/** + * Kotlin 脚本测试 + * + * @author DaleLee + */ + @ExtendWith(SpringExtension.class) @TestPropertySource(value = "classpath:/common/application.properties") @SpringBootTest(classes = LiteFlowKotlinScriptCommonELTest.class) @@ -26,43 +32,60 @@ public class LiteFlowKotlinScriptCommonELTest extends BaseTest { private FlowExecutor flowExecutor; @Test - public void testCommon1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + public void testCommonScript1() { + LiteflowResponse response = flowExecutor.execute2Resp("testCommonScript1", "arg"); Assertions.assertTrue(response.isSuccess()); DefaultContext context = response.getFirstContextBean(); Assertions.assertEquals(Integer.valueOf(5), context.getData("s1")); } @Test - public void testFor1() { + public void testForScript1() { DefaultContext context = new DefaultContext(); context.setData("k1", 1); context.setData("k2", 2); - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg", context); + LiteflowResponse response = flowExecutor.execute2Resp("testForScript1", "arg", context); Assertions.assertTrue(response.isSuccess()); - Assertions.assertEquals("s2==>a==>a==>a",response.getExecuteStepStr()); + Assertions.assertEquals("s2==>a==>a==>a", response.getExecuteStepStr()); } @Test - public void testIf1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + public void testBooleanScript1() { + LiteflowResponse response = flowExecutor.execute2Resp("testBooleanScript1", "arg"); Assertions.assertTrue(response.isSuccess()); - Assertions.assertEquals("s3==>b",response.getExecuteStepStr()); + Assertions.assertEquals("s3==>b", response.getExecuteStepStr()); } @Test - public void testIf2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + public void testBooleanScript2() { + LiteflowResponse response = flowExecutor.execute2Resp("testBooleanScript2", "arg"); Assertions.assertTrue(response.isSuccess()); - Assertions.assertEquals("s4",response.getExecuteStepStr()); + Assertions.assertEquals("s4", response.getExecuteStepStr()); } @Test - public void testSwitch1() { + public void testBooleanScript3() { + DefaultContext context = new DefaultContext(); + context.setData("count", 2); + LiteflowResponse response = flowExecutor.execute2Resp("testBooleanScript3", "arg", context); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("s3==>b==>s6==>s3==>b==>s6==>s3==>b==>s6",response.getExecuteStepStr()); + } + + @Test + public void testSwitchScript1() { DefaultContext context = new DefaultContext(); context.setData("id", "c"); - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg", context); + LiteflowResponse response = flowExecutor.execute2Resp("testSwitchScript1", "arg", context); Assertions.assertTrue(response.isSuccess()); - Assertions.assertEquals("s5==>c",response.getExecuteStepStr()); + Assertions.assertEquals("s5==>c", response.getExecuteStepStr()); + } + + @Test + public void testFileScript1() { + LiteflowResponse response = flowExecutor.execute2Resp("testFileScript1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(6), context.getData("s7")); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/LiteFlowScriptContextbeanKotlinELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/LiteFlowScriptContextbeanKotlinELTest.java new file mode 100644 index 00000000..d0bdba39 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/LiteFlowScriptContextbeanKotlinELTest.java @@ -0,0 +1,57 @@ +package com.yomahub.liteflow.test.script.kotlin.contextbean; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.script.BaseTest; +import com.yomahub.liteflow.test.script.kotlin.contextbean.bean.CheckContext; +import com.yomahub.liteflow.test.script.kotlin.contextbean.bean.Order2Context; +import com.yomahub.liteflow.test.script.kotlin.contextbean.bean.OrderContext; +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:/contextbean/application.properties") +@SpringBootTest(classes = LiteFlowScriptContextbeanKotlinELTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.script.kotlin.contextbean.cmp", + "com.yomahub.liteflow.test.script.kotlin.contextbean.bean" }) +public class LiteFlowScriptContextbeanKotlinELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testContextBean1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, + Order2Context.class); + Assertions.assertTrue(response.isSuccess()); + OrderContext orderContext = response.getContextBean(OrderContext.class); + CheckContext checkContext = response.getContextBean(CheckContext.class); + Order2Context order2Context = response.getContextBean(Order2Context.class); + Assertions.assertEquals("order1", orderContext.getOrderNo()); + Assertions.assertEquals("sign1", checkContext.getSign()); + Assertions.assertEquals("order2", order2Context.getOrderNo()); + } + + @Test + public void testContextBean2() throws Exception { + OrderContext orderContext = new OrderContext(); + orderContext.setOrderNo("order1"); + CheckContext checkContext = new CheckContext(); + checkContext.setSign("sign1"); + Order2Context orderContext2 = new Order2Context(); + orderContext2.setOrderNo("order2"); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, + orderContext2); + Assertions.assertTrue(response.isSuccess()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/CheckContext.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/CheckContext.java new file mode 100644 index 00000000..9b385913 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/CheckContext.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.script.kotlin.contextbean.bean; + +import com.yomahub.liteflow.context.ContextBean; + +@ContextBean +public class CheckContext { + + private String sign; + + private int randomId; + + public String getSign() { + return sign; + } + + public void setSign(String sign) { + this.sign = sign; + } + + public int getRandomId() { + return randomId; + } + + public void setRandomId(int randomId) { + this.randomId = randomId; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/Order2Context.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/Order2Context.java new file mode 100644 index 00000000..325548ef --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/Order2Context.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.test.script.kotlin.contextbean.bean; + +import java.util.Date; + +public class Order2Context { + + private String orderNo; + + private int orderType; + + private Date createTime; + + public String getOrderNo() { + return orderNo; + } + + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } + + public int getOrderType() { + return orderType; + } + + public void setOrderType(int orderType) { + this.orderType = orderType; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/OrderContext.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/OrderContext.java new file mode 100644 index 00000000..31fcae99 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/bean/OrderContext.java @@ -0,0 +1,40 @@ +package com.yomahub.liteflow.test.script.kotlin.contextbean.bean; + +import com.yomahub.liteflow.context.ContextBean; + +import java.util.Date; + +@ContextBean("order") +public class OrderContext { + + private String orderNo; + + private int orderType; + + private Date createTime; + + public String getOrderNo() { + return orderNo; + } + + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } + + public int getOrderType() { + return orderType; + } + + public void setOrderType(int orderType) { + this.orderType = orderType; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/ACmp.java new file mode 100644 index 00000000..811c8988 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.contextbean.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-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/BCmp.java new file mode 100644 index 00000000..608f172b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.contextbean.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-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/CCmp.java new file mode 100644 index 00000000..a63216cb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/contextbean/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.contextbean.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-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/LiteflowKotlinScriptMetaELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/LiteflowKotlinScriptMetaELTest.java new file mode 100644 index 00000000..c941b00a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/LiteflowKotlinScriptMetaELTest.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.test.script.kotlin.meta; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.script.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:/meta/application.properties") +@SpringBootTest(classes = LiteflowKotlinScriptMetaELTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.script.kotlin.meta.cmp"}) +public class LiteflowKotlinScriptMetaELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMeta() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("chain1", context.getData("currChainId")); + Assertions.assertEquals("arg", context.getData("requestData")); + Assertions.assertEquals("s1", context.getData("nodeId")); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/ACmp.java new file mode 100644 index 00000000..baadb1aa --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.meta.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/BCmp.java new file mode 100644 index 00000000..c101ba3b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.meta.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/CCmp.java new file mode 100644 index 00000000..c02ae6b2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/meta/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.meta.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("c") +public class CCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/LiteflowKotlinScriptRefreshELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/LiteflowKotlinScriptRefreshELTest.java new file mode 100644 index 00000000..af0cd54e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/LiteflowKotlinScriptRefreshELTest.java @@ -0,0 +1,48 @@ +package com.yomahub.liteflow.test.script.kotlin.refresh; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.enums.FlowParserTypeEnum; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.script.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:/refresh/application.properties") +@SpringBootTest(classes = LiteflowKotlinScriptRefreshELTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.script.kotlin.refresh.cmp" }) +public class LiteflowKotlinScriptRefreshELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // 测试脚本的热重载 + @Test + public void testRefresh1() throws Exception { + // 根据配置,加载的应该是flow.xml,执行原来的规则 + LiteflowResponse responseOld = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(responseOld.isSuccess()); + Assertions.assertEquals("d==>s1[选择脚本]==>a", responseOld.getExecuteStepStr()); + // 更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 + String newContent = ResourceUtil.readUtf8Str("classpath: /refresh/flow_update.xml"); + // 进行刷新 + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); + + // 重新执行chain2这个链路,结果会变 + LiteflowResponse responseNew = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(responseNew.isSuccess()); + Assertions.assertEquals("d==>s1[选择脚本_改]==>b==>s2[普通脚本_新增]", responseNew.getExecuteStepStr()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/ACmp.java new file mode 100644 index 00000000..80182dad --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.refresh.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/BCmp.java new file mode 100644 index 00000000..ad4d47c8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.refresh.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/CCmp.java new file mode 100644 index 00000000..aa4b3795 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.refresh.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("c") +public class CCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/DCmp.java new file mode 100644 index 00000000..2062df4d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/refresh/cmp/DCmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.refresh.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +@LiteflowComponent("d") +public class DCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("count", 198); + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/remove/LiteFlowKotlinScriptRemoveELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/remove/LiteFlowKotlinScriptRemoveELTest.java new file mode 100644 index 00000000..3249d3a2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/remove/LiteFlowKotlinScriptRemoveELTest.java @@ -0,0 +1,114 @@ +package com.yomahub.liteflow.test.script.kotlin.remove; + +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.exception.ELParseException; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.script.ScriptExecutor; +import com.yomahub.liteflow.script.ScriptExecutorFactory; +import com.yomahub.liteflow.script.exception.ScriptLoadException; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.script.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.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 测试脚本的卸载和重载功能 + * + * @author DaleLee + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/remove/application.properties") +@SpringBootTest(classes = LiteFlowKotlinScriptRemoveELTest.class) +@EnableAutoConfiguration +public class LiteFlowKotlinScriptRemoveELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + private ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance() + .getScriptExecutor(ScriptTypeEnum.KOTLIN.getDisplayName()); + + // 仅卸载脚本 + @Test + public void testUnload() { + flowExecutor.reloadRule(); + + // 获取节点id + List nodeIds = scriptExecutor.getNodeIds(); + Assertions.assertEquals(2, nodeIds.size()); + Assertions.assertTrue(nodeIds.contains("s1")); + Assertions.assertTrue(nodeIds.contains("s2")); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(6), context.getData("s1")); + + // 卸载脚本 + scriptExecutor.unLoad("s1"); + response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + Assertions.assertEquals("script for node[s1] is not loaded", response.getMessage()); + + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1")); + } + + // 卸载节点和脚本 + @Test + public void testRemove() { + flowExecutor.reloadRule(); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(5), context.getData("s2")); + + // 卸载节点 + FlowBus.unloadScriptNode("s2"); + + // 旧 chain 报脚本加载错误 + response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + + // 新 chian 会找不到节点 + Assertions.assertThrows(ELParseException.class, + () -> LiteFlowChainELBuilder.createChain() + .setChainId("chain3") + .setEL("THEN(s2)") + .build()); + + // 节点已卸载 + Assertions.assertFalse(FlowBus.containNode("s2")); + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2")); + } + + // 重载脚本 + @Test + public void testReloadScript() { + flowExecutor.reloadRule(); + String script = "(bindings[\"defaultContext\"] as? DefaultContext)?.setData(\"s1\", \"abc\")"; + FlowBus.reloadScript("s1", script); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + // 执行结果变更 + Assertions.assertEquals("abc", context.getData("s1")); + // 脚本变更 + Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/LiteFlowScriptScriptbeanKotlinELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/LiteFlowScriptScriptbeanKotlinELTest.java new file mode 100644 index 00000000..20fc01ef --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/LiteFlowScriptScriptbeanKotlinELTest.java @@ -0,0 +1,103 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptbean; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.exception.ScriptBeanMethodInvokeException; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.script.ScriptBeanManager; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.script.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; +import java.util.HashMap; +import java.util.Map; + +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/scriptbean/application.properties") +@SpringBootTest(classes = LiteFlowScriptScriptbeanKotlinELTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.script.kotlin.scriptbean.cmp", + "com.yomahub.liteflow.test.script.kotlin.scriptbean.bean" }) +public class LiteFlowScriptScriptbeanKotlinELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testScriptBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals("hello", context.getData("demo")); + } + + @Test + public void testScriptBean2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals("hello,kobe", context.getData("demo")); + } + + // 测试scriptBean includeMethodName配置包含情况下 + @Test + public void testScriptBean3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals("hello,kobe", context.getData("demo")); + } + + // 测试scriptBean includeMethodName配置不包含情况下 + @Test + public void testScriptBean4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals(ScriptBeanMethodInvokeException.class, response.getCause().getClass()); + } + + // 测试scriptBean excludeMethodName配置不包含情况下 + @Test + public void testScriptBean5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals("hello,kobe", context.getData("demo")); + } + + // 测试scriptBean excludeMethodName配置包含情况下 + @Test + public void testScriptBean6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals(ScriptBeanMethodInvokeException.class, response.getCause().getClass()); + } + + // 测试在ScriptBeanManager里放入上下文,实现自定义脚本引用名称 + @Test + public void testScriptBean7() throws Exception { + Map map = new HashMap<>(); + ScriptBeanManager.addScriptBean("abcCx", map); + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg", map); + Assertions.assertTrue(response.isSuccess()); + Map context = response.getFirstContextBean(); + 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-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean1.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean1.java new file mode 100644 index 00000000..8e650f77 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean1.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptbean.bean; + +import com.yomahub.liteflow.script.annotation.ScriptBean; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component +@ScriptBean("demo") +public class DemoBean1 { + + @Resource + private 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-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean2.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean2.java new file mode 100644 index 00000000..a074ad4a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean2.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptbean.bean; + +import org.springframework.stereotype.Component; + +@Component +public class DemoBean2 { + + public String getDemoStr2(String name) { + return "hello," + name; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean3.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean3.java new file mode 100644 index 00000000..4e31d7b8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean3.java @@ -0,0 +1,22 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptbean.bean; + +import com.yomahub.liteflow.script.annotation.ScriptBean; +import org.springframework.stereotype.Component; + +@Component +@ScriptBean(name = "demo3", includeMethodName = { "test1", "test2" }) +public class DemoBean3 { + + public String test1(String name) { + return "hello," + name; + } + + public String test2(String name) { + return "hello," + name; + } + + public String test3(String name) { + return "hello," + name; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean4.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean4.java new file mode 100644 index 00000000..d473f716 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean4.java @@ -0,0 +1,22 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptbean.bean; + +import com.yomahub.liteflow.script.annotation.ScriptBean; +import org.springframework.stereotype.Component; + +@Component +@ScriptBean(name = "demo4", excludeMethodName = { "test2", "test3" }) +public class DemoBean4 { + + public String test1(String name) { + return "hello," + name; + } + + public String test2(String name) { + return "hello," + name; + } + + public String test3(String name) { + return "hello," + name; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean5.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean5.java new file mode 100644 index 00000000..7f64ba0c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/bean/DemoBean5.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptbean.bean; + +import com.yomahub.liteflow.script.annotation.ScriptBean; +import org.springframework.stereotype.Component; + +@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-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/ACmp.java new file mode 100644 index 00000000..a1531df6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.scriptbean.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-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/BCmp.java new file mode 100644 index 00000000..eac2a2db --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.scriptbean.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-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/CCmp.java new file mode 100644 index 00000000..8c244ff4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptbean/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.scriptbean.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-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/LiteFlowScriptScriptMethodKotlinELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/LiteFlowScriptScriptMethodKotlinELTest.java new file mode 100644 index 00000000..651796fb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/LiteFlowScriptScriptMethodKotlinELTest.java @@ -0,0 +1,45 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptmethod; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.script.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:/scriptmethod/application.properties") +@SpringBootTest(classes = LiteFlowScriptScriptMethodKotlinELTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.script.kotlin.scriptmethod.cmp", + "com.yomahub.liteflow.test.script.kotlin.scriptmethod.bean" }) +public class LiteFlowScriptScriptMethodKotlinELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testScriptBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals("hello", context.getData("demo")); + } + + @Test + public void testScriptBean2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals("hello,kobe", context.getData("demo")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/bean/DemoBean1.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/bean/DemoBean1.java new file mode 100644 index 00000000..640ef677 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/bean/DemoBean1.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptmethod.bean; + +import com.yomahub.liteflow.script.annotation.ScriptMethod; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component +public class DemoBean1 { + + @Resource + private DemoBean2 demoBean2; + + @ScriptMethod("demo") + public String getDemoStr1() { + return "hello"; + } + + @ScriptMethod("demo2") + public String getDemoStr2(String name) { + return demoBean2.getDemoStr2(name); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/bean/DemoBean2.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/bean/DemoBean2.java new file mode 100644 index 00000000..db6a06dc --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/bean/DemoBean2.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.script.kotlin.scriptmethod.bean; + +import org.springframework.stereotype.Component; + +@Component +public class DemoBean2 { + + public String getDemoStr2(String name) { + return "hello," + name; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/ACmp.java new file mode 100644 index 00000000..fe678737 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.scriptmethod.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-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/BCmp.java new file mode 100644 index 00000000..af4217e6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.scriptmethod.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-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/CCmp.java new file mode 100644 index 00000000..ea5401aa --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/scriptmethod/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.scriptmethod.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-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/TestException.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/TestException.java new file mode 100644 index 00000000..c4f2be49 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/TestException.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.test.script.kotlin.throwException; + +import com.yomahub.liteflow.exception.LiteFlowException; + +public class TestException extends LiteFlowException { + + public TestException(String message) { + super(message); + } + + public TestException(String code, String message) { + super(code, message); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/ThrowExceptionScriptKotlinELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/ThrowExceptionScriptKotlinELTest.java new file mode 100644 index 00000000..2dd09ccc --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/ThrowExceptionScriptKotlinELTest.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.test.script.kotlin.throwException; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.script.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; + +/** + * 测试 springboot下的 Kotlin 脚本抛错 + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/throwException/application.properties") +@SpringBootTest(classes = ThrowExceptionScriptKotlinELTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.script.kotlin.throwException.cmp" }) +public class ThrowExceptionScriptKotlinELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void test1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("T01", response.getCode()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/cmp/ACmp.java new file mode 100644 index 00000000..7c41ce79 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/throwException/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.kotlin.throwException.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/validate/ValidateKotlinScriptComponentTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/validate/ValidateKotlinScriptComponentTest.java new file mode 100644 index 00000000..727b2641 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/validate/ValidateKotlinScriptComponentTest.java @@ -0,0 +1,26 @@ +package com.yomahub.liteflow.test.script.kotlin.validate; + +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.script.validator.ScriptValidator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = ValidateKotlinScriptComponentTest.class) +@EnableAutoConfiguration +public class ValidateKotlinScriptComponentTest { + @Test + public void testGroovyScriptComponentValidateFunction(){ + // 编译错误,字符串不能直接赋值给Int + String wrongScript = "val number: Int = \"123\""; + // 使用转换函数 + String correctScript = "val number: Int = \"123\".toInt()"; + + Assertions.assertTrue(ScriptValidator.validate(correctScript)); + Assertions.assertFalse(ScriptValidator.validate(wrongScript)); + + Assertions.assertTrue(ScriptValidator.validate(correctScript, ScriptTypeEnum.KOTLIN)); + Assertions.assertFalse(ScriptValidator.validate(correctScript, ScriptTypeEnum.JS)); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/application.properties new file mode 100644 index 00000000..4cc9f322 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=cmpdata/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/flow.xml new file mode 100644 index 00000000..4d333a05 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/flow.xml @@ -0,0 +1,27 @@ + + + + + + + println(_meta) + var cmpData = _meta["cmpData"] as Map + var context = bindings["defaultContext"] as DefaultContext + context.setData("s1", cmpData["birth"]) + ]]> + + + + + cmpData = '{"name":"jack","age":27,"birth":"1995-10-01"}'; + + THEN( + s1.data(cmpData), + a + ); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/flow.xml index 35db6f00..47d5e480 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/flow.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/common/flow.xml @@ -8,6 +8,7 @@ fun sum(a: Int, b: Int) = a + b var a = 2 var b = 3 + // 从 bindings 中获取上下文 val defaultContext = bindings["defaultContext"] as DefaultContext defaultContext.setData("s1", sum(a, b)) println("Hello Kotlin!") @@ -15,20 +16,22 @@ 1 + // 函数名可以自定义,但必须返回 Boolean getBoolean1() ]]> @@ -45,28 +48,52 @@ fun getId(ctx: DefaultContext) : String { return ctx.getData("id") as String } + // 函数名可以自定义,但必须返回 String getId(bindings["defaultContext"] as DefaultContext) ]]> + + + + - + THEN(a, b, c, s1); - + FOR(s2).DO(a); - + IF(s3, b); - + IF(s4, b); - + + WHILE(s3).DO(b).BREAK(s6); + + + SWITCH(s5).TO(a, b, c); + + + THEN(s7); + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/contextbean/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/contextbean/application.properties new file mode 100644 index 00000000..25ff2335 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/contextbean/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=contextbean/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/contextbean/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/contextbean/flow.xml new file mode 100644 index 00000000..a7a290a7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/contextbean/flow.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + THEN(a,b,c,d); + + + + THEN(a,b,c,e); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/application.properties new file mode 100644 index 00000000..8d005372 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=meta/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/flow.xml new file mode 100644 index 00000000..01afbc11 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/flow.xml @@ -0,0 +1,24 @@ + + + + + + var nodeId = _meta["nodeId"] + var currChainId = _meta["currChainId"] + var requestData = _meta["requestData"] + + var context = bindings["defaultContext"] as DefaultContext + context.setData("nodeId",nodeId) + context.setData("currChainId",currChainId) + context.setData("requestData",requestData) + ]]> + + + + + THEN(a, b, c, s1); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/application.properties new file mode 100644 index 00000000..52bc92b9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=refresh/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/flow.xml new file mode 100644 index 00000000..b74f49ba --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/flow.xml @@ -0,0 +1,27 @@ + + + + + 100) { + return "a"; + } else { + return "b"; + } + } + getId() + ]]> + + + + + + THEN(d, SWITCH(s1).to(a,b)); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/flow_update.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/flow_update.xml new file mode 100644 index 00000000..94eebfa5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/refresh/flow_update.xml @@ -0,0 +1,36 @@ + + + + + 100) { + return "b"; + } else { + return "a"; + } + } + getId() + ]]> + + + + + + + + + THEN(d, SWITCH(s1).to(a,b), s2); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/remove/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/remove/application.properties new file mode 100644 index 00000000..21b59625 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/remove/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=remove/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/remove/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/remove/flow.xml new file mode 100644 index 00000000..84c3a55c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/remove/flow.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + THEN(s1); + + + + THEN(s2); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/script-file/s7.kts b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/script-file/s7.kts new file mode 100644 index 00000000..0b610789 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/script-file/s7.kts @@ -0,0 +1,6 @@ +import com.yomahub.liteflow.slot.DefaultContext + +var a = 2 +var b = 3 +val defaultContext = bindings["defaultContext"] as DefaultContext +defaultContext.setData("s7", a * b) \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptbean/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptbean/application.properties new file mode 100644 index 00000000..8c26b5e8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptbean/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=scriptbean/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptbean/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptbean/flow.xml new file mode 100644 index 00000000..0edabf7a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptbean/flow.xml @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + abcCx.put("demo", str) + ]]> + + + + + + + + + THEN(a,b,c,d); + + + + THEN(a,b,c,e); + + + + THEN(a,b,c,s1); + + + + THEN(a,b,c,s2); + + + + THEN(a,b,c,s3); + + + + THEN(a,b,c,s4); + + + + THEN(a,b,c,s5); + + + + THEN(a,b,c,f); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptmethod/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptmethod/application.properties new file mode 100644 index 00000000..1f247a58 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptmethod/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=scriptmethod/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptmethod/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptmethod/flow.xml new file mode 100644 index 00000000..22f069ff --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/scriptmethod/flow.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + THEN(a,b,c,d); + + + + THEN(a,b,c,e); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/throwException/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/throwException/application.properties new file mode 100644 index 00000000..c30228a4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/throwException/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=throwException/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/throwException/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/throwException/flow.xml new file mode 100644 index 00000000..b215e766 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/throwException/flow.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + THEN(a, s1); + + \ No newline at end of file From 90ed04e5b9a55b5435e89c7774cc1defbc98f452 Mon Sep 17 00:00:00 2001 From: Dale Lee <1658850308@qq.com> Date: Sat, 4 May 2024 14:36:50 +0800 Subject: [PATCH 06/21] =?UTF-8?q?feature=20#I9H6GN=20=E8=AE=BE=E7=BD=AE=20?= =?UTF-8?q?koltin=20=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow-script-kotlin/pom.xml | 1 - .../pom.xml | 2 +- .../ValidateKotlinScriptComponentTest.java | 22 ++++++++++++++++++- .../src/test/resources/cmpdata/flow.xml | 2 -- .../src/test/resources/meta/flow.xml | 2 +- pom.xml | 6 +++++ 6 files changed, 29 insertions(+), 6 deletions(-) diff --git a/liteflow-script-plugin/liteflow-script-kotlin/pom.xml b/liteflow-script-plugin/liteflow-script-kotlin/pom.xml index c89e6d79..df3bed9d 100644 --- a/liteflow-script-plugin/liteflow-script-kotlin/pom.xml +++ b/liteflow-script-plugin/liteflow-script-kotlin/pom.xml @@ -23,7 +23,6 @@ org.jetbrains.kotlin kotlin-scripting-jsr223 - 1.9.23 \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/pom.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/pom.xml index e76dca32..0563cb2d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/pom.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/pom.xml @@ -21,7 +21,7 @@ com.yomahub liteflow-script-kotlin - 2.12.0 + ${revision} test diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/validate/ValidateKotlinScriptComponentTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/validate/ValidateKotlinScriptComponentTest.java index 727b2641..9c9e1885 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/validate/ValidateKotlinScriptComponentTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/validate/ValidateKotlinScriptComponentTest.java @@ -1,21 +1,41 @@ package com.yomahub.liteflow.test.script.kotlin.validate; import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.script.ScriptExecutor; +import com.yomahub.liteflow.script.ScriptExecutorFactory; import com.yomahub.liteflow.script.validator.ScriptValidator; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; +import javax.script.Compilable; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; + @SpringBootTest(classes = ValidateKotlinScriptComponentTest.class) @EnableAutoConfiguration public class ValidateKotlinScriptComponentTest { @Test - public void testGroovyScriptComponentValidateFunction(){ + public void testScriptComponentValidateFunction() throws Exception { // 编译错误,字符串不能直接赋值给Int String wrongScript = "val number: Int = \"123\""; // 使用转换函数 String correctScript = "val number: Int = \"123\".toInt()"; +// ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); +// ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("kotlin"); +// Compilable compilable = (Compilable) scriptEngine; +// compilable.compile(correctScript); + +// try { +// ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance() +// .getScriptExecutor(ScriptTypeEnum.KOTLIN.getDisplayName()); +// scriptExecutor.compile(wrongScript); +// } catch (Exception e) { +// +// } + Assertions.assertTrue(ScriptValidator.validate(correctScript)); Assertions.assertFalse(ScriptValidator.validate(wrongScript)); diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/flow.xml index 4d333a05..889ae01e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/flow.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/cmpdata/flow.xml @@ -4,11 +4,9 @@ - println(_meta) var cmpData = _meta["cmpData"] as Map var context = bindings["defaultContext"] as DefaultContext context.setData("s1", cmpData["birth"]) diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/flow.xml index 01afbc11..ff49ec51 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/flow.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/resources/meta/flow.xml @@ -5,7 +5,7 @@ + var _meta = bindings["_meta"] as Map var nodeId = _meta["nodeId"] var currChainId = _meta["currChainId"] var requestData = _meta["requestData"] diff --git a/pom.xml b/pom.xml index fe2b4d1d..793082b5 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,7 @@ 1.3.5 3.21.0 3.1.11 + 1.9.23 @@ -314,6 +315,11 @@ redisson ${redisson.version} + + org.jetbrains.kotlin + kotlin-scripting-jsr223 + ${kotlin.version} + From 621790896b41a059dc9931cf720c692a759a8127 Mon Sep 17 00:00:00 2001 From: Dale Lee <1658850308@qq.com> Date: Sat, 4 May 2024 15:33:03 +0800 Subject: [PATCH 07/21] =?UTF-8?q?feature=20#I9H6GN=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../validate/ValidateKotlinScriptComponentTest.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/validate/ValidateKotlinScriptComponentTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/validate/ValidateKotlinScriptComponentTest.java index 9c9e1885..841d5933 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/validate/ValidateKotlinScriptComponentTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-kotlin-springboot/src/test/java/com/yomahub/liteflow/test/script/kotlin/validate/ValidateKotlinScriptComponentTest.java @@ -23,19 +23,6 @@ public class ValidateKotlinScriptComponentTest { String wrongScript = "val number: Int = \"123\""; // 使用转换函数 String correctScript = "val number: Int = \"123\".toInt()"; -// ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); -// ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("kotlin"); -// Compilable compilable = (Compilable) scriptEngine; -// compilable.compile(correctScript); - -// try { -// ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance() -// .getScriptExecutor(ScriptTypeEnum.KOTLIN.getDisplayName()); -// scriptExecutor.compile(wrongScript); -// } catch (Exception e) { -// -// } - Assertions.assertTrue(ScriptValidator.validate(correctScript)); Assertions.assertFalse(ScriptValidator.validate(wrongScript)); From 65240fb2b577096797774f0f4940fa41684d3e63 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Tue, 7 May 2024 19:06:58 +0800 Subject: [PATCH 08/21] =?UTF-8?q?bug=20#I9N5K8=20=E5=9C=A8=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E7=BB=84=E4=BB=B6=E5=90=8E=EF=BC=8C=E9=80=9A?= =?UTF-8?q?=E8=BF=87getCmpData=20=E8=8E=B7=E5=8F=96data=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E4=BD=93=E5=AF=B9=E8=B1=A1=EF=BC=8Cdata=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E4=B8=8E=E5=AE=9E=E4=BD=93=E7=B1=BB=E4=B8=8D=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E6=98=AF=E4=BC=9A=E6=8A=9B=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/yomahub/liteflow/util/JsonUtil.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/JsonUtil.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/JsonUtil.java index eafa3142..c3944948 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/JsonUtil.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/JsonUtil.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.util; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.yomahub.liteflow.exception.JsonProcessException; @@ -27,6 +28,7 @@ public class JsonUtil { static { objectMapper.setTimeZone(TimeZone.getDefault()); + objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); } public static String toJsonString(Object object) { @@ -71,5 +73,4 @@ public class JsonUtil { throw new JsonProcessException(errMsg); } } - } From 09aa29329d299f060b06d36a23407deb51e7b277 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Wed, 8 May 2024 16:15:43 +0800 Subject: [PATCH 09/21] =?UTF-8?q?=E4=BF=AE=E5=A4=8Djson=E6=A0=BC=E5=BC=8Fp?= =?UTF-8?q?arser=E6=B2=A1=E6=9C=89=E5=AF=B9language=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yomahub/liteflow/parser/helper/ParserHelper.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 40a64b29..ab0fb928 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 @@ -205,7 +205,7 @@ public class ParserHelper { // 当存在节点定义时,解析node节点 if (flowJsonNode.get(FLOW).has(NODES)) { Iterator nodeIterator = flowJsonNode.get(FLOW).get(NODES).get(NODE).elements(); - String id, name, clazz, script, type, file; + String id, name, clazz, script, type, file, language; while ((nodeIterator.hasNext())) { JsonNode nodeObject = nodeIterator.next(); id = nodeObject.get(ID).textValue(); @@ -214,6 +214,7 @@ public class ParserHelper { type = nodeObject.hasNonNull(TYPE) ? nodeObject.get(TYPE).textValue() : null; script = nodeObject.hasNonNull(VALUE) ? nodeObject.get(VALUE).textValue() : ""; file = nodeObject.hasNonNull(FILE) ? nodeObject.get(FILE).textValue() : ""; + language = nodeObject.hasNonNull(LANGUAGE) ? nodeObject.get(LANGUAGE).textValue() : ""; // 如果是禁用的,就不编译了 if (!getEnableByJsonNode(nodeObject)) { @@ -226,7 +227,8 @@ public class ParserHelper { .setClazz(clazz) .setScript(script) .setType(type) - .setFile(file); + .setFile(file) + .setLanguage(language); ParserHelper.buildNode(nodePropBean); } From 295bc0e2c6eb052e6ac21da69811a52bdafe458a Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Sat, 11 May 2024 16:42:15 +0800 Subject: [PATCH 10/21] =?UTF-8?q?feature=20#I9K14C=20=E4=B8=BAprocess?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E6=8F=90=E4=BE=9B=E6=B3=A8=E5=85=A5=E5=9E=8B?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=89=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/annotation/LiteflowFact.java | 12 +++ .../core/proxy/DeclComponentProxy.java | 79 +++++++++++++-- .../liteflow/core/proxy/MethodWrapBean.java | 14 ++- .../core/proxy/ParameterWrapBean.java | 47 +++++++++ .../exception/ParameterFactException.java | 26 +++++ .../spi/spring/SpringDeclComponentParser.java | 22 ++++- .../ProcessFactELDeclMultiSpringbootTest.java | 97 +++++++++++++++++++ .../test/processFact/cmp/CmpConfig.java | 43 ++++++++ .../test/processFact/context/Company.java | 40 ++++++++ .../processFact/context/Demo1Context.java | 24 +++++ .../processFact/context/Demo2Context.java | 29 ++++++ .../processFact/context/Demo3Context.java | 32 ++++++ .../test/processFact/context/TestContext.java | 29 ++++++ .../test/processFact/context/User.java | 53 ++++++++++ .../processFact/application.properties | 1 + .../src/test/resources/processFact/flow.xml | 18 ++++ .../ProcessFactELDeclSpringbootTest.java | 97 +++++++++++++++++++ .../liteflow/test/processFact/cmp/ACmp.java | 28 ++++++ .../liteflow/test/processFact/cmp/BCmp.java | 28 ++++++ .../liteflow/test/processFact/cmp/CCmp.java | 27 ++++++ .../liteflow/test/processFact/cmp/DCmp.java | 27 ++++++ .../test/processFact/context/Company.java | 40 ++++++++ .../processFact/context/Demo1Context.java | 24 +++++ .../processFact/context/Demo2Context.java | 29 ++++++ .../processFact/context/Demo3Context.java | 32 ++++++ .../test/processFact/context/TestContext.java | 29 ++++++ .../test/processFact/context/User.java | 53 ++++++++++ .../processFact/application.properties | 1 + .../src/test/resources/processFact/flow.xml | 18 ++++ 29 files changed, 987 insertions(+), 12 deletions(-) create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowFact.java create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ParameterWrapBean.java create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/exception/ParameterFactException.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/ProcessFactELDeclMultiSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/CmpConfig.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Company.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo1Context.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo2Context.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo3Context.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/TestContext.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/User.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/processFact/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/processFact/flow.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/ProcessFactELDeclSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/DCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Company.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo1Context.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo2Context.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo3Context.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/TestContext.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/User.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/processFact/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/processFact/flow.xml diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowFact.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowFact.java new file mode 100644 index 00000000..6461c8cb --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowFact.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.annotation; + +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.PARAMETER}) +@Documented +@Inherited +public @interface LiteflowFact { + + String value(); +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/DeclComponentProxy.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/DeclComponentProxy.java index cbf2aa1e..5345fffa 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/DeclComponentProxy.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/DeclComponentProxy.java @@ -1,17 +1,24 @@ package com.yomahub.liteflow.core.proxy; import cn.hutool.core.exceptions.InvocationTargetRuntimeException; +import cn.hutool.core.lang.Tuple; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; +import com.ql.util.express.DefaultContext; +import com.ql.util.express.ExpressRunner; +import com.ql.util.express.InstructionSet; import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.annotation.LiteflowRetry; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.exception.ComponentMethodDefineErrorException; import com.yomahub.liteflow.exception.LiteFlowException; +import com.yomahub.liteflow.exception.ParameterFactException; import com.yomahub.liteflow.exception.ProxyException; +import com.yomahub.liteflow.flow.element.Node; import com.yomahub.liteflow.log.LFLog; import com.yomahub.liteflow.log.LFLoggerManager; +import com.yomahub.liteflow.slot.DataBus; import com.yomahub.liteflow.util.SerialsUtil; import net.bytebuddy.ByteBuddy; import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; @@ -21,7 +28,12 @@ import java.lang.annotation.Annotation; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Map; +import java.util.function.Consumer; import java.util.function.Function; import java.util.stream.Collectors; @@ -112,6 +124,10 @@ public class DeclComponentProxy { .findFirst() .orElse(null); + if (currentMethodWrapBean == null){ + throw new ProxyException("currentMethodWrapBean is null"); + } + // 如果被代理的对象里有此标注标的方法,则调用此被代理的对象里的方法,如果没有,则调用父类里的方法 // 进行检查,检查被代理的bean里是否第一个参数为NodeComponent这个类型的 boolean checkFlag = currentMethodWrapBean.getMethod().getParameterTypes().length > 0 @@ -124,13 +140,13 @@ public class DeclComponentProxy { throw new ComponentMethodDefineErrorException(errMsg); } + + // 这里是针对于参数的处理 + // 首先需要保证第一个参数是NodeComponent + // 其次需要针对于@LiteflowFact做处理 try { - if (args != null && args.length > 0){ - Object[] wrapArgs = ArrayUtil.insert(args, 0, proxy); - return ReflectUtil.invoke(declWarpBean.getRawBean(), currentMethodWrapBean.getMethod(), wrapArgs); - }else{ - return ReflectUtil.invoke(declWarpBean.getRawBean(), currentMethodWrapBean.getMethod(), proxy); - } + Object[] realArgs = loadMethodParameter(proxy, currentMethodWrapBean); + return ReflectUtil.invoke(declWarpBean.getRawBean(), currentMethodWrapBean.getMethod(), realArgs); }catch (InvocationTargetRuntimeException e) { InvocationTargetException targetEx = (InvocationTargetException) e.getCause(); throw targetEx.getTargetException(); @@ -138,4 +154,55 @@ public class DeclComponentProxy { } } + + private final ExpressRunner expressRunner = new ExpressRunner(); + + private Object[] loadMethodParameter(Object proxy, MethodWrapBean methodWrapBean){ + NodeComponent thisNodeComponent = (NodeComponent) proxy; + + return methodWrapBean.getParameterWrapBeanList().stream().map(parameterWrapBean -> { + // 如果参数是NodeComponent,那就返回proxy本身 + if (parameterWrapBean.getParameterType().isAssignableFrom(NodeComponent.class)) { + return proxy; + } + + // 如果没有@LiteflowFact标注,那么不处理,直接赋值null + if (parameterWrapBean.getFact() == null) { + return null; + } + + // 把上下文数据转换成map形式的,key为别名,value为上下文 + Map contextMap = DataBus.getSlot(thisNodeComponent.getSlotIndex()).getContextBeanList().stream().collect( + Collectors.toMap(tuple -> tuple.get(0), tuple -> tuple.get(1)) + ); + + List errorList = new ArrayList<>(); + + Object result = null; + // 根据表达式去上下文里搜索相匹配的数据 + for(Map.Entry entry : contextMap.entrySet()){ + try{ + InstructionSet instructionSet = expressRunner.getInstructionSetFromLocalCache(entry.getKey() + "." + parameterWrapBean.getFact().value()); + DefaultContext context = new DefaultContext<>(); + context.put(entry.getKey(), entry.getValue()); + result = expressRunner.execute(instructionSet, context, errorList, false, false); + if (result != null){ + break; + } + }catch (Exception ignore){} + } + + if (result == null){ + try{ + // 如果没有搜到,那么尝试推断表达式是指定的上下文,按照指定上下文的方式去再获取 + InstructionSet instructionSet = expressRunner.getInstructionSetFromLocalCache("contextMap." + parameterWrapBean.getFact().value()); + DefaultContext context = new DefaultContext<>(); + context.put("contextMap", contextMap); + result = expressRunner.execute(instructionSet, context, errorList, false, false); + }catch (Exception ignore){} + } + + return result; + }).toArray(); + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/MethodWrapBean.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/MethodWrapBean.java index ab099334..156de8e7 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/MethodWrapBean.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/MethodWrapBean.java @@ -4,6 +4,7 @@ import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.annotation.LiteflowRetry; import java.lang.reflect.Method; +import java.util.List; /** * LiteflowMethod的包装类 @@ -18,10 +19,13 @@ public class MethodWrapBean { private LiteflowRetry liteflowRetry; - public MethodWrapBean(Method method, LiteflowMethod liteflowMethod, LiteflowRetry liteflowRetry) { + private List parameterWrapBeanList; + + public MethodWrapBean(Method method, LiteflowMethod liteflowMethod, LiteflowRetry liteflowRetry, List parameterWrapBeanList) { this.method = method; this.liteflowMethod = liteflowMethod; this.liteflowRetry = liteflowRetry; + this.parameterWrapBeanList = parameterWrapBeanList; } public Method getMethod() { @@ -47,4 +51,12 @@ public class MethodWrapBean { public void setLiteflowRetry(LiteflowRetry liteflowRetry) { this.liteflowRetry = liteflowRetry; } + + public List getParameterWrapBeanList() { + return parameterWrapBeanList; + } + + public void setParameterWrapBeanList(List parameterWrapBeanList) { + this.parameterWrapBeanList = parameterWrapBeanList; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ParameterWrapBean.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ParameterWrapBean.java new file mode 100644 index 00000000..18c362c0 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ParameterWrapBean.java @@ -0,0 +1,47 @@ +package com.yomahub.liteflow.core.proxy; + +import com.yomahub.liteflow.annotation.LiteflowFact; + +/** + * 声明式的包装类 + * @author Bryan.Zhang + * @since 2.12.1 + */ +public class ParameterWrapBean { + + private Class parameterType; + + private LiteflowFact fact; + + private int index; + + public ParameterWrapBean(Class parameterType, LiteflowFact fact, int index) { + this.parameterType = parameterType; + this.fact = fact; + this.index = index; + } + + public Class getParameterType() { + return parameterType; + } + + public void setParameterType(Class parameterType) { + this.parameterType = parameterType; + } + + public LiteflowFact getFact() { + return fact; + } + + public void setFact(LiteflowFact fact) { + this.fact = fact; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ParameterFactException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ParameterFactException.java new file mode 100644 index 00000000..366635b1 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ParameterFactException.java @@ -0,0 +1,26 @@ +package com.yomahub.liteflow.exception; + +/** + * @author Bryan.Zhang + */ +public class ParameterFactException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** 异常信息 */ + private String message; + + public ParameterFactException(String message) { + this.message = message; + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + +} diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringDeclComponentParser.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringDeclComponentParser.java index 312076f4..333c6a87 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringDeclComponentParser.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringDeclComponentParser.java @@ -1,24 +1,27 @@ package com.yomahub.liteflow.spi.spring; import cn.hutool.core.annotation.AnnotationUtil; +import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; -import com.yomahub.liteflow.annotation.LiteflowCmpDefine; -import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.annotation.LiteflowMethod; -import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.annotation.*; import com.yomahub.liteflow.annotation.util.AnnoUtil; import com.yomahub.liteflow.core.proxy.DeclWarpBean; import com.yomahub.liteflow.core.proxy.MethodWrapBean; +import com.yomahub.liteflow.core.proxy.ParameterWrapBean; import com.yomahub.liteflow.enums.NodeTypeEnum; import com.yomahub.liteflow.exception.CmpDefinitionException; import com.yomahub.liteflow.spi.DeclComponentParser; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.stereotype.Component; + +import java.lang.reflect.Parameter; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.IntStream; /** * Spring环境声明式组件解析器实现 @@ -73,7 +76,16 @@ public class SpringDeclComponentParser implements DeclComponentParser { nodeType = liteflowMethod.nodeType(); } - return new DeclInfo(currNodeId, currNodeName, nodeType, method.getDeclaringClass(), new MethodWrapBean(method, liteflowMethod, liteflowRetry)); + + Parameter[] parameters = method.getParameters(); + List parameterList = IntStream.range(0, parameters.length).boxed().map(index -> { + Parameter parameter = parameters[index]; + return new ParameterWrapBean(parameter.getType(), AnnotationUtil.getAnnotation(parameter, LiteflowFact.class), index); + }).collect(Collectors.toList()); + + + + return new DeclInfo(currNodeId, currNodeName, nodeType, method.getDeclaringClass(), new MethodWrapBean(method, liteflowMethod, liteflowRetry, parameterList)); }).filter(declInfo -> StrUtil.isNotBlank(declInfo.getNodeId())).collect(Collectors.groupingBy(DeclInfo::getNodeId)); return definitionMap.entrySet().stream().map(entry -> { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/ProcessFactELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/ProcessFactELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..8421fa3f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/ProcessFactELDeclMultiSpringbootTest.java @@ -0,0 +1,97 @@ +package com.yomahub.liteflow.test.processFact; + +import cn.hutool.core.date.DateUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.processFact.context.*; +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; + +/** + * process方法上的fact映射参数测试 + * @author Bryan.Zhang + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/processFact/application.properties") +@SpringBootTest(classes = ProcessFactELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.processFact.cmp"}) +public class ProcessFactELDeclMultiSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // 最基本的情况 + @Test + public void testFact1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", createContext()); + Assertions.assertTrue(response.isSuccess()); + TestContext context = response.getContextBean(TestContext.class); + Assertions.assertEquals("jack", context.getUser().getName()); + } + + // 多上下文自动搜寻 + @Test + public void testFact2() throws Exception { + TestContext testContext = createContext(); + Demo1Context demo1Context = new Demo1Context(); + demo1Context.setData1("xxxx"); + demo1Context.setData2(99); + + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg", demo1Context, testContext); + Assertions.assertTrue(response.isSuccess()); + TestContext context = response.getContextBean(TestContext.class); + Assertions.assertEquals(20, context.getUser().getCompany().getHeadCount()); + } + + // 多上下文都有user,指定上下文中的user + @Test + public void testFact3() throws Exception { + TestContext testContext = createContext(); + Demo2Context demo2Context = createDemo2Context(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg", testContext, demo2Context); + Assertions.assertTrue(response.isSuccess()); + Demo2Context context = response.getContextBean(Demo2Context.class); + Assertions.assertEquals("rose", context.getUser().getName()); + } + + // 多上下文都有user,指定上下文中的user + @Test + public void testFact4() throws Exception { + Demo3Context demo3Context = createDemo3Context(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg", demo3Context); + Assertions.assertTrue(response.isSuccess()); + Demo3Context context = response.getContextBean(Demo3Context.class); + Assertions.assertEquals("jelly", context.getUser().getName()); + } + + private TestContext createContext(){ + Company company = new Company("XXX有限公司", "黄河路34号303室", 400); + User user = new User("张三", 18, DateUtil.parseDate("1990-08-20"), company); + return new TestContext(user, "this is data"); + } + + private Demo2Context createDemo2Context(){ + Company company = new Company("XXX有限公司", "和平路12号101室", 600); + User user = new User("李四", 28, DateUtil.parseDate("1990-06-01"), company); + return new Demo2Context("xxx", user); + } + + private Demo3Context createDemo3Context(){ + Company company = new Company("XXX有限公司", "和平路12号101室", 600); + User user = new User("王五", 28, DateUtil.parseDate("1990-06-01"), company); + return new Demo3Context("xxx", user); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/CmpConfig.java new file mode 100644 index 00000000..efc1e5d3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/CmpConfig.java @@ -0,0 +1,43 @@ +package com.yomahub.liteflow.test.processFact.cmp; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowFact; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.processFact.context.Company; +import com.yomahub.liteflow.test.processFact.context.User; +import org.springframework.stereotype.Component; + +@LiteflowComponent +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeType = NodeTypeEnum.COMMON, nodeId = "a") + public void processA(NodeComponent bindCmp, + @LiteflowFact("user") User user, + @LiteflowFact("user.company.address") String address) { + user.setName("jack"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeType = NodeTypeEnum.COMMON, nodeId = "b") + public void processB(NodeComponent bindCmp, + @LiteflowFact("user.company") Company company, + @LiteflowFact("data2") Integer data) { + company.setHeadCount(20); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeType = NodeTypeEnum.COMMON, nodeId = "c") + public void processC(NodeComponent bindCmp, + @LiteflowFact("demo2Context.user") User user) { + user.setName("rose"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeType = NodeTypeEnum.COMMON, nodeId = "d") + public void processD(NodeComponent bindCmp, + @LiteflowFact("ctx.user") User user) { + user.setName("jelly"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Company.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Company.java new file mode 100644 index 00000000..024db737 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Company.java @@ -0,0 +1,40 @@ +package com.yomahub.liteflow.test.processFact.context; + +public class Company { + + private String name; + + private String address; + + private int headCount; + + public Company(String name, String address, int headCount) { + this.name = name; + this.address = address; + this.headCount = headCount; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public int getHeadCount() { + return headCount; + } + + public void setHeadCount(int headCount) { + this.headCount = headCount; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo1Context.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo1Context.java new file mode 100644 index 00000000..e86e6cec --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo1Context.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.processFact.context; + +public class Demo1Context { + + private String data1; + + private Integer data2; + + public String getData1() { + return data1; + } + + public void setData1(String data1) { + this.data1 = data1; + } + + public Integer getData2() { + return data2; + } + + public void setData2(Integer data2) { + this.data2 = data2; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo2Context.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo2Context.java new file mode 100644 index 00000000..df4a356f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo2Context.java @@ -0,0 +1,29 @@ +package com.yomahub.liteflow.test.processFact.context; + +public class Demo2Context { + + private String data1; + + private User user; + + public Demo2Context(String data1, User user) { + this.data1 = data1; + this.user = user; + } + + public String getData1() { + return data1; + } + + public void setData1(String data1) { + this.data1 = data1; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo3Context.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo3Context.java new file mode 100644 index 00000000..bedbe5b7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo3Context.java @@ -0,0 +1,32 @@ +package com.yomahub.liteflow.test.processFact.context; + +import com.yomahub.liteflow.context.ContextBean; + +@ContextBean("ctx") +public class Demo3Context { + + private String data1; + + private User user; + + public Demo3Context(String data1, User user) { + this.data1 = data1; + this.user = user; + } + + public String getData1() { + return data1; + } + + public void setData1(String data1) { + this.data1 = data1; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/TestContext.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/TestContext.java new file mode 100644 index 00000000..8b96a319 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/TestContext.java @@ -0,0 +1,29 @@ +package com.yomahub.liteflow.test.processFact.context; + +public class TestContext { + + private User user; + + private String data1; + + public TestContext(User user, String data1) { + this.user = user; + this.data1 = data1; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public String getData1() { + return data1; + } + + public void setData1(String data1) { + this.data1 = data1; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/User.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/User.java new file mode 100644 index 00000000..c3e2fc59 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/User.java @@ -0,0 +1,53 @@ +package com.yomahub.liteflow.test.processFact.context; + +import java.util.Date; + +public class User { + + private String name; + + private int age; + + private Date birthday; + + private Company company; + + public User(String name, int age, Date birthday, Company company) { + this.name = name; + this.age = age; + this.birthday = birthday; + this.company = company; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public Company getCompany() { + return company; + } + + public void setCompany(Company company) { + this.company = company; + } + + public Date getBirthday() { + return birthday; + } + + public void setBirthday(Date birthday) { + this.birthday = birthday; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/processFact/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/processFact/application.properties new file mode 100644 index 00000000..7bf5b573 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/processFact/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=processFact/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/processFact/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/processFact/flow.xml new file mode 100644 index 00000000..a92b50eb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/processFact/flow.xml @@ -0,0 +1,18 @@ + + + + THEN(a); + + + + THEN(b); + + + + THEN(c); + + + + THEN(d); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/ProcessFactELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/ProcessFactELDeclSpringbootTest.java new file mode 100644 index 00000000..730bfde6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/ProcessFactELDeclSpringbootTest.java @@ -0,0 +1,97 @@ +package com.yomahub.liteflow.test.processFact; + +import cn.hutool.core.date.DateUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.processFact.context.*; +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; + +/** + * process方法上的fact映射参数测试 + * @author Bryan.Zhang + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/processFact/application.properties") +@SpringBootTest(classes = ProcessFactELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.processFact.cmp"}) +public class ProcessFactELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // 最基本的情况 + @Test + public void testFact1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", createContext()); + Assertions.assertTrue(response.isSuccess()); + TestContext context = response.getContextBean(TestContext.class); + Assertions.assertEquals("jack", context.getUser().getName()); + } + + // 多上下文自动搜寻 + @Test + public void testFact2() throws Exception { + TestContext testContext = createContext(); + Demo1Context demo1Context = new Demo1Context(); + demo1Context.setData1("xxxx"); + demo1Context.setData2(99); + + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg", demo1Context, testContext); + Assertions.assertTrue(response.isSuccess()); + TestContext context = response.getContextBean(TestContext.class); + Assertions.assertEquals(20, context.getUser().getCompany().getHeadCount()); + } + + // 多上下文都有user,指定上下文中的user + @Test + public void testFact3() throws Exception { + TestContext testContext = createContext(); + Demo2Context demo2Context = createDemo2Context(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg", testContext, demo2Context); + Assertions.assertTrue(response.isSuccess()); + Demo2Context context = response.getContextBean(Demo2Context.class); + Assertions.assertEquals("rose", context.getUser().getName()); + } + + // 多上下文都有user,指定上下文中的user + @Test + public void testFact4() throws Exception { + Demo3Context demo3Context = createDemo3Context(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg", demo3Context); + Assertions.assertTrue(response.isSuccess()); + Demo3Context context = response.getContextBean(Demo3Context.class); + Assertions.assertEquals("jelly", context.getUser().getName()); + } + + private TestContext createContext(){ + Company company = new Company("XXX有限公司", "黄河路34号303室", 400); + User user = new User("张三", 18, DateUtil.parseDate("1990-08-20"), company); + return new TestContext(user, "this is data"); + } + + private Demo2Context createDemo2Context(){ + Company company = new Company("XXX有限公司", "和平路12号101室", 600); + User user = new User("李四", 28, DateUtil.parseDate("1990-06-01"), company); + return new Demo2Context("xxx", user); + } + + private Demo3Context createDemo3Context(){ + Company company = new Company("XXX有限公司", "和平路12号101室", 600); + User user = new User("王五", 28, DateUtil.parseDate("1990-06-01"), company); + return new Demo3Context("xxx", user); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/ACmp.java new file mode 100644 index 00000000..05b2e285 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/ACmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.processFact.cmp; + +import com.yomahub.liteflow.annotation.LiteflowFact; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.test.processFact.context.User; +import org.springframework.stereotype.Component; + + +@Component("a") +public class ACmp { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeType = NodeTypeEnum.COMMON) + public void process(NodeComponent bindCmp, + @LiteflowFact("user") User user, + @LiteflowFact("user.company.address") String address) { + user.setName("jack"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/BCmp.java new file mode 100644 index 00000000..a3886a0c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/BCmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.processFact.cmp; + +import com.yomahub.liteflow.annotation.LiteflowFact; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.test.processFact.context.Company; +import org.springframework.stereotype.Component; + +@Component("b") +public class BCmp { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeType = NodeTypeEnum.COMMON) + public void process(NodeComponent bindCmp, + @LiteflowFact("user.company") Company company, + @LiteflowFact("data2") Integer data) { + company.setHeadCount(20); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/CCmp.java new file mode 100644 index 00000000..3849f3e8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/CCmp.java @@ -0,0 +1,27 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.processFact.cmp; + +import com.yomahub.liteflow.annotation.LiteflowFact; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.test.processFact.context.User; +import org.springframework.stereotype.Component; + +@Component("c") +public class CCmp { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeType = NodeTypeEnum.COMMON) + public void process(NodeComponent bindCmp, + @LiteflowFact("demo2Context.user") User user) { + user.setName("rose"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/DCmp.java new file mode 100644 index 00000000..b3ec1b2b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/cmp/DCmp.java @@ -0,0 +1,27 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.processFact.cmp; + +import com.yomahub.liteflow.annotation.LiteflowFact; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.test.processFact.context.User; +import org.springframework.stereotype.Component; + +@Component("d") +public class DCmp { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeType = NodeTypeEnum.COMMON) + public void process(NodeComponent bindCmp, + @LiteflowFact("ctx.user") User user) { + user.setName("jelly"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Company.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Company.java new file mode 100644 index 00000000..024db737 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Company.java @@ -0,0 +1,40 @@ +package com.yomahub.liteflow.test.processFact.context; + +public class Company { + + private String name; + + private String address; + + private int headCount; + + public Company(String name, String address, int headCount) { + this.name = name; + this.address = address; + this.headCount = headCount; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public int getHeadCount() { + return headCount; + } + + public void setHeadCount(int headCount) { + this.headCount = headCount; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo1Context.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo1Context.java new file mode 100644 index 00000000..e86e6cec --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo1Context.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.processFact.context; + +public class Demo1Context { + + private String data1; + + private Integer data2; + + public String getData1() { + return data1; + } + + public void setData1(String data1) { + this.data1 = data1; + } + + public Integer getData2() { + return data2; + } + + public void setData2(Integer data2) { + this.data2 = data2; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo2Context.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo2Context.java new file mode 100644 index 00000000..df4a356f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo2Context.java @@ -0,0 +1,29 @@ +package com.yomahub.liteflow.test.processFact.context; + +public class Demo2Context { + + private String data1; + + private User user; + + public Demo2Context(String data1, User user) { + this.data1 = data1; + this.user = user; + } + + public String getData1() { + return data1; + } + + public void setData1(String data1) { + this.data1 = data1; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo3Context.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo3Context.java new file mode 100644 index 00000000..bedbe5b7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/Demo3Context.java @@ -0,0 +1,32 @@ +package com.yomahub.liteflow.test.processFact.context; + +import com.yomahub.liteflow.context.ContextBean; + +@ContextBean("ctx") +public class Demo3Context { + + private String data1; + + private User user; + + public Demo3Context(String data1, User user) { + this.data1 = data1; + this.user = user; + } + + public String getData1() { + return data1; + } + + public void setData1(String data1) { + this.data1 = data1; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/TestContext.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/TestContext.java new file mode 100644 index 00000000..8b96a319 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/TestContext.java @@ -0,0 +1,29 @@ +package com.yomahub.liteflow.test.processFact.context; + +public class TestContext { + + private User user; + + private String data1; + + public TestContext(User user, String data1) { + this.user = user; + this.data1 = data1; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public String getData1() { + return data1; + } + + public void setData1(String data1) { + this.data1 = data1; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/User.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/User.java new file mode 100644 index 00000000..c3e2fc59 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/processFact/context/User.java @@ -0,0 +1,53 @@ +package com.yomahub.liteflow.test.processFact.context; + +import java.util.Date; + +public class User { + + private String name; + + private int age; + + private Date birthday; + + private Company company; + + public User(String name, int age, Date birthday, Company company) { + this.name = name; + this.age = age; + this.birthday = birthday; + this.company = company; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public Company getCompany() { + return company; + } + + public void setCompany(Company company) { + this.company = company; + } + + public Date getBirthday() { + return birthday; + } + + public void setBirthday(Date birthday) { + this.birthday = birthday; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/processFact/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/processFact/application.properties new file mode 100644 index 00000000..7bf5b573 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/processFact/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=processFact/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/processFact/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/processFact/flow.xml new file mode 100644 index 00000000..a92b50eb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/processFact/flow.xml @@ -0,0 +1,18 @@ + + + + THEN(a); + + + + THEN(b); + + + + THEN(c); + + + + THEN(d); + + \ No newline at end of file From d3ef608a425ed2e7ea9117f77f27aa91f0d27aa3 Mon Sep 17 00:00:00 2001 From: rain <672378783@qq.com> Date: Mon, 13 May 2024 19:59:51 +0800 Subject: [PATCH 11/21] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BB=9D=E5=AF=B9?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E6=A8=A1=E7=B3=8A=E5=8C=B9=E9=85=8D=E7=9A=84?= =?UTF-8?q?BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/spi/solon/SolonPathContentParser.java | 6 ++++-- ...bsoluteConfigPathELDeclMultiSpringbootTest.java | 14 ++++++++++++++ .../AbsoluteConfigPathELDeclSpringbootTest.java | 14 ++++++++++++++ .../absoluteConfigPath/AbsoluteConfigPathTest.java | 14 ++++++++++++++ .../AbsoluteConfigPathELSpringbootTest.java | 14 ++++++++++++++ .../AbsoluteConfigPathELSpringbootTest.java | 14 ++++++++++++++ .../AbsoluteConfigPathELSpringTest.java | 14 ++++++++++++++ 7 files changed, 88 insertions(+), 2 deletions(-) diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java index e1ea3f71..522f553d 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java @@ -8,6 +8,7 @@ import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.exception.ConfigErrorException; import com.yomahub.liteflow.spi.PathContentParser; +import com.yomahub.liteflow.util.PathMatchUtil; import org.noear.solon.Utils; import java.io.File; @@ -47,9 +48,10 @@ public class SolonPathContentParser implements PathContentParser { if (CollectionUtil.isEmpty(pathList)) { throw new ConfigErrorException("rule source must not be null"); } - + List absolutePathList = PathMatchUtil.searchAbsolutePath(pathList); List allResource = new ArrayList<>(); - for (String path : pathList) { + + for (String path : absolutePathList) { // 如果 path 是绝对路径且这个文件存在时,我们认为这是一个本地文件路径,而并非classpath路径 if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)) { allResource.add(new File(path).toURI().toURL()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java index 30df1e19..4551da5d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java @@ -13,6 +13,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIf; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.slf4j.Logger; @@ -64,6 +65,7 @@ public class AbsoluteConfigPathELDeclMultiSpringbootTest extends BaseTest { } @Test + @DisabledIf("isWindows") public void testAbsPath() throws Exception{ Assertions.assertTrue(() -> { LiteflowConfig config = LiteflowConfigGetter.get(); @@ -73,6 +75,18 @@ public class AbsoluteConfigPathELDeclMultiSpringbootTest extends BaseTest { }); } + public static boolean isWindows() { + try { + String osName = System.getProperty("os.name"); + if (osName.isEmpty()) return false; + else { + return osName.contains("windows"); + } + } catch (Exception e) { + return false; + } + } + @BeforeAll public static void createFiles() { rootDir = FileUtil.getAbsolutePath(ResourceUtil.getResource("").getPath()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java index 0e1a40e6..d603e03c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java @@ -15,6 +15,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIf; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.slf4j.Logger; @@ -66,6 +67,7 @@ public class AbsoluteConfigPathELDeclSpringbootTest extends BaseTest { } @Test + @DisabledIf("isWindows") public void testAbsPath() throws Exception{ Assertions.assertTrue(() -> { LiteflowConfig config = LiteflowConfigGetter.get(); @@ -75,6 +77,18 @@ public class AbsoluteConfigPathELDeclSpringbootTest extends BaseTest { }); } + public static boolean isWindows() { + try { + String osName = System.getProperty("os.name"); + if (osName.isEmpty()) return false; + else { + return osName.contains("windows"); + } + } catch (Exception e) { + return false; + } + } + @BeforeAll public static void createFiles() { rootDir = FileUtil.getAbsolutePath(ResourceUtil.getResource("").getPath()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathTest.java index a536cede..f6709326 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathTest.java @@ -14,6 +14,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIf; import java.util.Objects; @@ -51,6 +52,7 @@ public class AbsoluteConfigPathTest extends BaseTest { } @Test + @DisabledIf("isWindows") public void testAbsPath() throws Exception{ Assertions.assertTrue(() -> { LiteflowConfig config = new LiteflowConfig(); @@ -60,6 +62,18 @@ public class AbsoluteConfigPathTest extends BaseTest { }); } + public static boolean isWindows() { + try { + String osName = System.getProperty("os.name"); + if (osName.isEmpty()) return false; + else { + return osName.contains("windows"); + } + } catch (Exception e) { + return false; + } + } + @BeforeAll public static void createFiles() { rootDir = FileUtil.getAbsolutePath(ResourceUtil.getResource("").getPath()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java index 2d3029b1..a418038f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java @@ -13,6 +13,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIf; import org.junit.jupiter.api.extension.ExtendWith; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; @@ -57,6 +58,7 @@ public class AbsoluteConfigPathELSpringbootTest extends BaseTest { } @Test + @DisabledIf("isWindows") public void testAbsTest() throws Exception { Assertions.assertTrue(() -> { LiteflowConfig config = LiteflowConfigGetter.get(); @@ -66,6 +68,18 @@ public class AbsoluteConfigPathELSpringbootTest extends BaseTest { }); } + public static boolean isWindows() { + try { + String osName = System.getProperty("os.name"); + if (osName.isEmpty()) return false; + else { + return osName.contains("windows"); + } + } catch (Exception e) { + return false; + } + } + @BeforeAll public static void createFiles() { rootDir = FileUtil.getAbsolutePath(ResourceUtil.getResource("").getPath()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java index 8a2f4faf..b5cb1563 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java @@ -13,6 +13,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIf; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -71,6 +72,7 @@ public class AbsoluteConfigPathELSpringbootTest extends BaseTest { } @Test + @DisabledIf("isWindows") public void testAbsPath4() throws Exception{ Assertions.assertTrue(() -> { LiteflowConfig config = LiteflowConfigGetter.get(); @@ -80,6 +82,18 @@ public class AbsoluteConfigPathELSpringbootTest extends BaseTest { }); } + public static boolean isWindows() { + try { + String osName = System.getProperty("os.name"); + if (osName.isEmpty()) return false; + else { + return osName.contains("windows"); + } + } catch (Exception e) { + return false; + } + } + @BeforeAll public static void createFiles() { rootDir = FileUtil.getAbsolutePath(ResourceUtil.getResource("").getPath()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringTest.java index f82c89b7..097bf03e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringTest.java @@ -13,6 +13,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIf; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -56,6 +57,7 @@ public class AbsoluteConfigPathELSpringTest extends BaseTest { } @Test + @DisabledIf("isWindows") public void testAbsPath() throws Exception{ Assertions.assertTrue(() -> { LiteflowConfig config = LiteflowConfigGetter.get(); @@ -65,6 +67,18 @@ public class AbsoluteConfigPathELSpringTest extends BaseTest { }); } + public static boolean isWindows() { + try { + String osName = System.getProperty("os.name"); + if (osName.isEmpty()) return false; + else { + return osName.contains("windows"); + } + } catch (Exception e) { + return false; + } + } + @BeforeAll public static void createFiles() { rootDir = FileUtil.getAbsolutePath(ResourceUtil.getResource("").getPath()); From c8062d6585d028973cca043b0bbaf377b589d161 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Thu, 16 May 2024 17:21:45 +0800 Subject: [PATCH 12/21] =?UTF-8?q?feature=20#I9PVQ7=20=E5=86=B3=E7=AD=96?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E4=B8=AD=E5=A2=9E=E5=8A=A0namespace=EF=BC=8C?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E6=89=A7=E8=A1=8C=E6=8C=87=E5=AE=9A=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E7=A9=BA=E9=97=B4=E7=9A=84=E5=86=B3=E7=AD=96=E8=B7=AF?= =?UTF-8?q?=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builder/el/LiteFlowChainELBuilder.java | 5 ++ .../liteflow/common/ChainConstant.java | 4 ++ .../yomahub/liteflow/core/FlowExecutor.java | 49 ++++++++++---- .../yomahub/liteflow/flow/element/Chain.java | 10 +++ .../liteflow/parser/helper/ParserHelper.java | 11 +++- .../src/main/resources/dtd/liteflow.dtd | 3 + .../RouteSpringbootNamespaceTest.java | 66 +++++++++++++++++++ .../liteflow/test/namespace/cmp/ACmp.java | 20 ++++++ .../liteflow/test/namespace/cmp/BCmp.java | 21 ++++++ .../liteflow/test/namespace/cmp/R1.java | 13 ++++ .../liteflow/test/namespace/cmp/R2.java | 13 ++++ .../namespace/application.properties | 1 + .../src/test/resources/namespace/flow.el.xml | 30 +++++++++ 13 files changed, 232 insertions(+), 14 deletions(-) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/RouteSpringbootNamespaceTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/cmp/R1.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/cmp/R2.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/resources/namespace/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/resources/namespace/flow.el.xml diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java index ea1b80e5..26071666 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java @@ -233,6 +233,11 @@ public class LiteFlowChainELBuilder { } } + public LiteFlowChainELBuilder setNamespace(String nameSpace){ + this.chain.setNamespace(nameSpace); + return this; + } + /** * EL表达式校验 * @param elStr EL表达式 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java b/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java index ad64b36e..e54c6af2 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java @@ -32,6 +32,10 @@ public interface ChainConstant { String LANGUAGE = "language"; + String NAMESPACE = "namespace"; + + String DEFAULT_NAMESPACE = "default"; + String VALUE = "value"; String ANY = "any"; diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java index a60c3222..bee3fa8b 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java @@ -13,6 +13,7 @@ import cn.hutool.core.collection.ListUtil; import cn.hutool.core.lang.Tuple; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.*; +import com.yomahub.liteflow.common.ChainConstant; import com.yomahub.liteflow.enums.ChainExecuteModeEnum; import com.yomahub.liteflow.enums.InnerChainTypeEnum; import com.yomahub.liteflow.enums.ParseModeEnum; @@ -283,7 +284,11 @@ public class FlowExecutor { } public List executeRouteChain(Object param, Class... contextBeanClazzArray){ - return this.executeWithRoute(param, null, contextBeanClazzArray, null); + return this.executeWithRoute(null, param, null, contextBeanClazzArray, null); + } + + public List executeRouteChain(String namespace, Object param, Class... contextBeanClazzArray){ + return this.executeWithRoute(namespace, param, null, contextBeanClazzArray, null); } public LiteflowResponse execute2Resp(String chainId, Object param, Object... contextBeanArray) { @@ -291,23 +296,35 @@ public class FlowExecutor { } public List executeRouteChain(Object param, Object... contextBeanArray){ - return this.executeWithRoute(param, null, null, contextBeanArray); + return this.executeWithRoute(null, param, null, null, contextBeanArray); + } + + public List executeRouteChain(String namespace, Object param, Object... contextBeanArray){ + return this.executeWithRoute(namespace, param, null, null, contextBeanArray); } public LiteflowResponse execute2RespWithRid(String chainId, Object param, String requestId, Class... contextBeanClazzArray) { return this.execute2Resp(chainId, param, requestId, contextBeanClazzArray, null); } - public List executeRouteChainWithRid(String chainId, Object param, String requestId, Class... contextBeanClazzArray) { - return this.executeWithRoute(param, requestId, contextBeanClazzArray, null); + public List executeRouteChainWithRid(Object param, String requestId, Class... contextBeanClazzArray) { + return this.executeWithRoute(null, param, requestId, contextBeanClazzArray, null); + } + + public List executeRouteChainWithRid(String namespace, Object param, String requestId, Class... contextBeanClazzArray) { + return this.executeWithRoute(namespace, param, requestId, contextBeanClazzArray, null); } public LiteflowResponse execute2RespWithRid(String chainId, Object param, String requestId, Object... contextBeanArray) { return this.execute2Resp(chainId, param, requestId, null, contextBeanArray); } - public List executeRouteChainWithRid(String chainId, Object param, String requestId, Object... contextBeanArray) { - return this.executeWithRoute(param, requestId, null, contextBeanArray); + public List executeRouteChainWithRid(Object param, String requestId, Object... contextBeanArray) { + return this.executeWithRoute(null, param, requestId, null, contextBeanArray); + } + + public List executeRouteChainWithRid(String namespace, Object param, String requestId, Object... contextBeanArray) { + return this.executeWithRoute(namespace, param, requestId, null, contextBeanArray); } // 调用一个流程并返回Future,允许多上下文的传入 @@ -353,8 +370,8 @@ public class FlowExecutor { return LiteflowResponse.newMainResponse(slot); } - private List executeWithRoute(Object param, String requestId, Class[] contextBeanClazzArray, Object[] contextBeanArray){ - List slotList = doExecuteWithRoute(param, requestId, contextBeanClazzArray, contextBeanArray); + private List executeWithRoute(String namespace, Object param, String requestId, Class[] contextBeanClazzArray, Object[] contextBeanArray){ + List slotList = doExecuteWithRoute(namespace, param, requestId, contextBeanClazzArray, contextBeanArray); return slotList.stream().map(LiteflowResponse::newMainResponse).collect(Collectors.toList()); } @@ -522,15 +539,23 @@ public class FlowExecutor { MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath); } - private List doExecuteWithRoute(Object param, String requestId, Class[] contextBeanClazzArray, Object[] contextBeanArray){ + private List doExecuteWithRoute(String namespace, Object param, String requestId, Class[] contextBeanClazzArray, Object[] contextBeanArray){ if (FlowBus.needInit()) { init(true); } - List routeChainList = FlowBus.getChainMap().values().stream().filter(chain -> chain.getRouteItem() != null).collect(Collectors.toList()); + if (StrUtil.isBlank(namespace)){ + namespace = ChainConstant.DEFAULT_NAMESPACE; + } + + String finalNamespace = namespace; + List routeChainList = FlowBus.getChainMap().values().stream() + .filter(chain -> chain.getNamespace().equals(finalNamespace)) + .filter(chain -> chain.getRouteItem() != null).collect(Collectors.toList()); if (CollUtil.isEmpty(routeChainList)){ - throw new RouteChainNotFoundException("cannot find any route chain"); + String errorMsg = StrUtil.format("no route found for namespace[{}]", finalNamespace); + throw new RouteChainNotFoundException(errorMsg); } String finalRequestId; @@ -601,7 +626,7 @@ public class FlowExecutor { } }).filter(Objects::nonNull).collect(Collectors.toList()); - LOG.info("There are {} chains that matched the route.", resultSlotList.size()); + LOG.info("chain namespace:[{}], total size:[{}], matched size:[{}]", namespace, routeChainList.size(), resultSlotList.size()); return resultSlotList; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java index f381be1c..fef1c651 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java @@ -40,6 +40,8 @@ public class Chain implements Executable{ private boolean isCompiled = true; + private String namespace; + public Chain(String chainName) { this.chainId = chainName; } @@ -195,4 +197,12 @@ public class Chain implements Executable{ public void setCompiled(boolean compiled) { isCompiled = compiled; } + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } } 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 ab0fb928..9c3df120 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 @@ -1,5 +1,6 @@ package com.yomahub.liteflow.parser.helper; +import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.fasterxml.jackson.databind.JsonNode; @@ -24,6 +25,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.function.Consumer; +import java.util.function.Function; import static com.yomahub.liteflow.common.ChainConstant.*; @@ -310,9 +312,11 @@ public class ParserHelper { // 构建chainBuilder String chainId = Optional.ofNullable(chainNode.get(ID)).orElse(chainNode.get(NAME)).textValue(); + String namespace = chainNode.get(NAMESPACE) == null? DEFAULT_NAMESPACE : chainNode.get(NAMESPACE).textValue(); + JsonNode routeJsonNode = chainNode.get(ROUTE); - LiteFlowChainELBuilder builder = LiteFlowChainELBuilder.createChain().setChainId(chainId); + LiteFlowChainELBuilder builder = LiteFlowChainELBuilder.createChain().setChainId(chainId).setNamespace(namespace); // 如果有route这个标签,说明是决策表chain // 决策表链路必须有route和body这两个标签 @@ -339,9 +343,11 @@ public class ParserHelper { // 构建chainBuilder String chainId = Optional.ofNullable(e.attributeValue(ID)).orElse(e.attributeValue(NAME)); + String namespace = StrUtil.blankToDefault(e.attributeValue(NAMESPACE), DEFAULT_NAMESPACE); + Element routeElement = e.element(ROUTE); - LiteFlowChainELBuilder builder = LiteFlowChainELBuilder.createChain().setChainId(chainId); + LiteFlowChainELBuilder builder = LiteFlowChainELBuilder.createChain().setChainId(chainId).setNamespace(namespace); // 如果有route这个标签,说明是决策表chain // 决策表链路必须有route和body这两个标签 @@ -364,6 +370,7 @@ public class ParserHelper { } } + builder.build(); } diff --git a/liteflow-core/src/main/resources/dtd/liteflow.dtd b/liteflow-core/src/main/resources/dtd/liteflow.dtd index 8698963e..334cee79 100644 --- a/liteflow-core/src/main/resources/dtd/liteflow.dtd +++ b/liteflow-core/src/main/resources/dtd/liteflow.dtd @@ -14,9 +14,12 @@ class CDATA #IMPLIED file CDATA #IMPLIED language (qlexpress|groovy|js|python|lua|aviator|java) #IMPLIED + enable (true|false) #IMPLIED > \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/RouteSpringbootNamespaceTest.java b/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/RouteSpringbootNamespaceTest.java new file mode 100644 index 00000000..762db6a4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/RouteSpringbootNamespaceTest.java @@ -0,0 +1,66 @@ +package com.yomahub.liteflow.test.namespace; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.exception.NoMatchedRouteChainException; +import com.yomahub.liteflow.exception.RouteChainNotFoundException; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; +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 javax.annotation.Resource; +import java.util.List; + +/** + * springboot环境EL常规的例子测试 + * + * @author Bryan.Zhang + */ +@TestPropertySource(value = "classpath:/namespace/application.properties") +@SpringBootTest(classes = RouteSpringbootNamespaceTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.namespace.cmp" }) +public class RouteSpringbootNamespaceTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // n1 space中的两个链路都能匹配 + @Test + public void testNamespaceRoute1() throws Exception { + List responseList = flowExecutor.executeRouteChain("n1", 15, DefaultContext.class); + LiteflowResponse response1 = responseList.stream().filter( + liteflowResponse -> liteflowResponse.getChainId().equals("r_chain1") + ).findFirst().orElse(null); + + assert response1 != null; + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertEquals("b==>a", response1.getExecuteStepStr()); + + LiteflowResponse response2 = responseList.stream().filter( + liteflowResponse -> liteflowResponse.getChainId().equals("r_chain2") + ).findFirst().orElse(null); + + assert response2 != null; + Assertions.assertTrue(response2.isSuccess()); + Assertions.assertEquals("a==>b", response2.getExecuteStepStr()); + } + + // n1这个namespace中没有规则被匹配上 + @Test + public void testNamespaceRoute2() throws Exception { + Assertions.assertThrows(NoMatchedRouteChainException.class, () -> flowExecutor.executeRouteChain("n1", 8, DefaultContext.class)); + } + + // 没有n3这个namespace + @Test + public void testNamespaceRoute3() throws Exception { + Assertions.assertThrows(RouteChainNotFoundException.class, () -> flowExecutor.executeRouteChain("n3", 8, DefaultContext.class)); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/cmp/ACmp.java new file mode 100644 index 00000000..f2e91ff4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/cmp/ACmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.namespace.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-routechain/src/test/java/com/yomahub/liteflow/test/namespace/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/cmp/BCmp.java new file mode 100644 index 00000000..36455d7c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.namespace.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-routechain/src/test/java/com/yomahub/liteflow/test/namespace/cmp/R1.java b/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/cmp/R1.java new file mode 100644 index 00000000..f18471f9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/cmp/R1.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.namespace.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; + +@LiteflowComponent("r1") +public class R1 extends NodeBooleanComponent { + @Override + public boolean processBoolean() throws Exception { + int testInt = this.getRequestData(); + return testInt >= 10 && testInt <= 20; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/cmp/R2.java b/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/cmp/R2.java new file mode 100644 index 00000000..b0fcf95f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/java/com/yomahub/liteflow/test/namespace/cmp/R2.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.namespace.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; + +@LiteflowComponent("r2") +public class R2 extends NodeBooleanComponent { + @Override + public boolean processBoolean() throws Exception { + int testInt = this.getRequestData(); + return testInt > 100; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/resources/namespace/application.properties b/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/resources/namespace/application.properties new file mode 100644 index 00000000..850ec86f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/resources/namespace/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=namespace/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/resources/namespace/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/resources/namespace/flow.el.xml new file mode 100644 index 00000000..8a2aeaa6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-routechain/src/test/resources/namespace/flow.el.xml @@ -0,0 +1,30 @@ + + + + + + r1 + + + THEN(b,a); + + + + + + OR(r1,r2) + + + THEN(a,b); + + + + + + r2 + + + THEN(b,b); + + + \ No newline at end of file From 46c974eead24f5cd16b225185e1f8d21d45ad3c2 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Fri, 17 May 2024 17:20:49 +0800 Subject: [PATCH 13/21] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/contextBean/ContextBeanSpringbootTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/contextBean/ContextBeanSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/contextBean/ContextBeanSpringbootTest.java index 55567ea7..1daf1541 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/contextBean/ContextBeanSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/contextBean/ContextBeanSpringbootTest.java @@ -35,4 +35,13 @@ public class ContextBeanSpringbootTest extends BaseTest { TestContext context = response.getContextBean("skuContext"); Assertions.assertEquals("J001", context.getSkuCode()); } + + // new一个上下文的情况 + @Test + public void testContextBean2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", new TestContext("J001", "test")); + Assertions.assertTrue(response.isSuccess()); + TestContext context = response.getContextBean("skuContext"); + Assertions.assertEquals("J001", context.getSkuCode()); + } } From 6c25e26f2525ebd3c191d67dd4c12d688cd5a170 Mon Sep 17 00:00:00 2001 From: rain <672378783@qq.com> Date: Sat, 18 May 2024 10:37:19 +0800 Subject: [PATCH 14/21] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbsoluteConfigPathELDeclMultiSpringbootTest.java | 6 +++--- .../AbsoluteConfigPathELDeclSpringbootTest.java | 6 +++--- .../test/absoluteConfigPath/AbsoluteConfigPathTest.java | 6 +++--- .../AbsoluteConfigPathELSpringbootTest.java | 6 +++--- .../AbsoluteConfigPathELSpringbootTest.java | 6 +++--- .../absoluteConfigPath/AbsoluteConfigPathELSpringTest.java | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java index 4551da5d..7600850d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java @@ -13,7 +13,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledIf; +import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.slf4j.Logger; @@ -65,7 +65,7 @@ public class AbsoluteConfigPathELDeclMultiSpringbootTest extends BaseTest { } @Test - @DisabledIf("isWindows") + @EnabledIf("isWindows") public void testAbsPath() throws Exception{ Assertions.assertTrue(() -> { LiteflowConfig config = LiteflowConfigGetter.get(); @@ -80,7 +80,7 @@ public class AbsoluteConfigPathELDeclMultiSpringbootTest extends BaseTest { String osName = System.getProperty("os.name"); if (osName.isEmpty()) return false; else { - return osName.contains("windows"); + return osName.contains("Windows"); } } catch (Exception e) { return false; diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java index d603e03c..f4b0650d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java @@ -15,7 +15,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledIf; +import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.slf4j.Logger; @@ -67,7 +67,7 @@ public class AbsoluteConfigPathELDeclSpringbootTest extends BaseTest { } @Test - @DisabledIf("isWindows") + @EnabledIf("isWindows") public void testAbsPath() throws Exception{ Assertions.assertTrue(() -> { LiteflowConfig config = LiteflowConfigGetter.get(); @@ -82,7 +82,7 @@ public class AbsoluteConfigPathELDeclSpringbootTest extends BaseTest { String osName = System.getProperty("os.name"); if (osName.isEmpty()) return false; else { - return osName.contains("windows"); + return osName.contains("Windows"); } } catch (Exception e) { return false; diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathTest.java index f6709326..ce14a2cd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathTest.java @@ -14,7 +14,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledIf; +import org.junit.jupiter.api.condition.EnabledIf; import java.util.Objects; @@ -52,7 +52,7 @@ public class AbsoluteConfigPathTest extends BaseTest { } @Test - @DisabledIf("isWindows") + @EnabledIf("isWindows") public void testAbsPath() throws Exception{ Assertions.assertTrue(() -> { LiteflowConfig config = new LiteflowConfig(); @@ -67,7 +67,7 @@ public class AbsoluteConfigPathTest extends BaseTest { String osName = System.getProperty("os.name"); if (osName.isEmpty()) return false; else { - return osName.contains("windows"); + return osName.contains("Windows"); } } catch (Exception e) { return false; diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java index a418038f..a8e85596 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java @@ -13,7 +13,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledIf; +import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.api.extension.ExtendWith; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; @@ -58,7 +58,7 @@ public class AbsoluteConfigPathELSpringbootTest extends BaseTest { } @Test - @DisabledIf("isWindows") + @EnabledIf("isWindows") public void testAbsTest() throws Exception { Assertions.assertTrue(() -> { LiteflowConfig config = LiteflowConfigGetter.get(); @@ -73,7 +73,7 @@ public class AbsoluteConfigPathELSpringbootTest extends BaseTest { String osName = System.getProperty("os.name"); if (osName.isEmpty()) return false; else { - return osName.contains("windows"); + return osName.contains("Windows"); } } catch (Exception e) { return false; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java index b5cb1563..4bf4bd97 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java @@ -13,7 +13,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledIf; +import org.junit.jupiter.api.condition.EnabledIf; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -72,7 +72,7 @@ public class AbsoluteConfigPathELSpringbootTest extends BaseTest { } @Test - @DisabledIf("isWindows") + @EnabledIf("isWindows") public void testAbsPath4() throws Exception{ Assertions.assertTrue(() -> { LiteflowConfig config = LiteflowConfigGetter.get(); @@ -87,7 +87,7 @@ public class AbsoluteConfigPathELSpringbootTest extends BaseTest { String osName = System.getProperty("os.name"); if (osName.isEmpty()) return false; else { - return osName.contains("windows"); + return osName.contains("Windows"); } } catch (Exception e) { return false; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringTest.java index 097bf03e..d0b1d143 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringTest.java @@ -13,7 +13,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledIf; +import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -57,7 +57,7 @@ public class AbsoluteConfigPathELSpringTest extends BaseTest { } @Test - @DisabledIf("isWindows") + @EnabledIf("isWindows") public void testAbsPath() throws Exception{ Assertions.assertTrue(() -> { LiteflowConfig config = LiteflowConfigGetter.get(); @@ -72,7 +72,7 @@ public class AbsoluteConfigPathELSpringTest extends BaseTest { String osName = System.getProperty("os.name"); if (osName.isEmpty()) return false; else { - return osName.contains("windows"); + return osName.contains("Windows"); } } catch (Exception e) { return false; From 18cf5af50249fc500ee7836dae0ebf709c396fa9 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Thu, 23 May 2024 19:28:21 +0800 Subject: [PATCH 15/21] =?UTF-8?q?feature=20#I9RPBK=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=8F=92=E4=BB=B6=E6=94=AF=E6=8C=81=E5=86=B3=E7=AD=96?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E7=89=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builder/el/LiteFlowChainELBuilder.java | 3 +- .../parser/helper/NodeConvertHelper.java | 23 ------- .../parser/constant/SqlReadConstant.java | 2 +- .../sql/polling/AbstractSqlReadPollTask.java | 61 +++++++++++------- .../parser/sql/polling/SqlReadPollTask.java | 6 +- .../sql/polling/impl/ChainReadPollTask.java | 36 ++++++++--- .../sql/polling/impl/ScriptReadPollTask.java | 44 +++++++++---- .../parser/sql/read/AbstractSqlRead.java | 21 +++--- .../liteflow/parser/sql/read/SqlRead.java | 5 +- .../parser/sql/read/SqlReadFactory.java | 20 +++--- .../parser/sql/read/impl/ChainRead.java | 31 ++++----- .../parser/sql/read/impl/ScriptRead.java | 54 ++++------------ .../liteflow/parser/sql/read/vo/ChainVO.java | 44 +++++++++++++ .../liteflow/parser/sql/read/vo/ScriptVO.java | 64 +++++++++++++++++++ .../liteflow/parser/sql/util/JDBCHelper.java | 32 ++++++---- .../liteflow/parser/sql/vo/SQLParserVO.java | 26 ++++++++ 16 files changed, 306 insertions(+), 166 deletions(-) create mode 100644 liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/vo/ChainVO.java create mode 100644 liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/vo/ScriptVO.java diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java index 26071666..c8e6ef6e 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java @@ -136,8 +136,7 @@ public class LiteFlowChainELBuilder { public LiteFlowChainELBuilder setRoute(String routeEl){ if (StrUtil.isBlank(routeEl)) { - String errMsg = StrUtil.format("You have defined the label but there is no el in the chain route[{}].", chain.getChainId()); - throw new FlowSystemException(errMsg); + return this; } List errorList = new ArrayList<>(); try { diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/NodeConvertHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/NodeConvertHelper.java index 7b5d9105..c834425b 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/NodeConvertHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/NodeConvertHelper.java @@ -15,29 +15,6 @@ import java.util.List; */ public class NodeConvertHelper { - /*script节点的修改/添加*/ - public static void changeScriptNode(NodeSimpleVO nodeSimpleVO, String newValue) { - // 有语言类型 - if (StrUtil.isNotBlank(nodeSimpleVO.getLanguage())) { - LiteFlowNodeBuilder.createScriptNode() - .setId(nodeSimpleVO.getNodeId()) - .setType(NodeTypeEnum.getEnumByCode(nodeSimpleVO.getType())) - .setName(nodeSimpleVO.getName()) - .setScript(newValue) - .setLanguage(nodeSimpleVO.getLanguage()) - .build(); - } - // 没有语言类型 - else { - LiteFlowNodeBuilder.createScriptNode() - .setId(nodeSimpleVO.getNodeId()) - .setType(NodeTypeEnum.getEnumByCode(nodeSimpleVO.getType())) - .setName(nodeSimpleVO.getName()) - .setScript(newValue) - .build(); - } - } - public static NodeSimpleVO convert(String scriptKey){ // 不需要去理解这串正则,就是一个匹配冒号的 // 一定得是a:b,或是a:b:c...这种完整类型的字符串的 diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/constant/SqlReadConstant.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/constant/SqlReadConstant.java index 1161493d..6cc4015d 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/constant/SqlReadConstant.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/constant/SqlReadConstant.java @@ -16,7 +16,7 @@ public class SqlReadConstant { public static final String SCRIPT_SQL_PATTERN = "SELECT * FROM {} WHERE {}=?"; - public static final String CHAIN_XML_PATTERN = ""; + public static final String CHAIN_XML_PATTERN = ""; public static final String NODE_XML_PATTERN = "{}"; diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/polling/AbstractSqlReadPollTask.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/polling/AbstractSqlReadPollTask.java index d4049a4c..9d464839 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/polling/AbstractSqlReadPollTask.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/polling/AbstractSqlReadPollTask.java @@ -11,6 +11,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; /** * sql 轮询任务抽象类,维护公共方法 @@ -19,11 +21,11 @@ import java.util.Set; * @author houxinyu * @since 2.11.1 */ -public abstract class AbstractSqlReadPollTask implements SqlReadPollTask { +public abstract class AbstractSqlReadPollTask implements SqlReadPollTask { private final Map DATA_SHA_MAP = new HashMap<>(); - private final SqlRead read; + private final SqlRead read; - public AbstractSqlReadPollTask(SqlRead read) { + public AbstractSqlReadPollTask(SqlRead read) { this.read = read; if (!read.type().equals(type())) { @@ -33,35 +35,34 @@ public abstract class AbstractSqlReadPollTask implements SqlReadPollTask { @Override public void execute() { - Map newData = read.read(); + List dataList = read.read(); // 新增或者更新的元素 - Map saveElementMap = new HashMap<>(); + List saveElementList = new ArrayList<>(); // 删除的元素 - List deleteElementIds = new ArrayList<>(); + List deleteElementIds; - for (Map.Entry entry : newData.entrySet()) { - String id = entry.getKey(); - String element = entry.getValue(); - String newSHA = DigestUtil.sha1Hex(element); + for (T data : dataList) { + String id = getKey(data); + String newSHA = getNeedSha1Value(data); // 新增 // 如果封装的SHAMap中不存在该chain, 表示该元素为新增 if (!DATA_SHA_MAP.containsKey(id)) { - saveElementMap.put(id, element); + saveElementList.add(data); DATA_SHA_MAP.put(id, newSHA); } // 修改 // SHA值发生变化,表示该元素的值已被修改,重新拉取变化的chain else if (!StrUtil.equals(newSHA, DATA_SHA_MAP.get(id))) { - saveElementMap.put(id, element); + saveElementList.add(data); DATA_SHA_MAP.put(id, newSHA); } } Set oldIdList = DATA_SHA_MAP.keySet(); // 旧的 id 列表 - Set newIdList = newData.keySet(); // 新的 id 列表 + Set newIdList = dataList.stream().map(this::getKey).collect(Collectors.toSet()); // 新的 id 列表 // 计算单差集 // 计算集合的单差集,即只返回【oldIdList】中有,但是【newIdList】中没有的元素,例如: // subtractToList([1,2,3,4],[2,3,4,5]) -》 [1] @@ -71,8 +72,8 @@ public abstract class AbstractSqlReadPollTask implements SqlReadPollTask { DATA_SHA_MAP.remove(id); } - if (CollUtil.isNotEmpty(saveElementMap)) { - doSave(saveElementMap); + if (CollUtil.isNotEmpty(saveElementList)) { + doSave(saveElementList); } if (CollUtil.isNotEmpty(deleteElementIds)) { @@ -81,20 +82,34 @@ public abstract class AbstractSqlReadPollTask implements SqlReadPollTask { } @Override - public void initData(Map dataMap) { - DATA_SHA_MAP.putAll(shaMapValue(dataMap)); + public void initData(List dataList) { + DATA_SHA_MAP.putAll(shaValue(dataList)); } - public abstract void doSave(Map saveElementMap); + public abstract void doSave(List saveElementList); public abstract void doDelete(List deleteElementId); - private Map shaMapValue(Map dataMap) { + private Map shaValue(List dataList) { Map result = new HashMap<>(); - dataMap.forEach((k, v) -> { - result.put(k, DigestUtil.sha1Hex(v)); - }); - + dataList.forEach(t -> result.put(getKey(t), DigestUtil.sha1Hex(getNeedSha1Value(t)))); return result; } + + private String getNeedSha1Value(T data) { + if (StrUtil.isBlank(getExtValue(data))) { + return DigestUtil.sha1Hex(getValue(data)); + }else{ + return DigestUtil.sha1Hex(getValue(data) + "|||" + getExtValue(data)); + } + } + + // 如果是chain,那就是返回chain的id,如果是script,那就返回script的id + protected abstract String getKey(T t); + + // 如果是chain,那就返回EL,如果是script,那就返回脚本数据 + protected abstract String getValue(T t); + + // 如果是chain,那就返回route el,如果是script,这个不返回,因为script没有扩展value + protected abstract String getExtValue(T t); } diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/polling/SqlReadPollTask.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/polling/SqlReadPollTask.java index 8c491e9a..7d8ac7e9 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/polling/SqlReadPollTask.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/polling/SqlReadPollTask.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.parser.sql.polling; import com.yomahub.liteflow.parser.constant.ReadType; +import java.util.List; import java.util.Map; /** @@ -11,7 +12,7 @@ import java.util.Map; * @author houxinyu * @since 2.11.1 */ -public interface SqlReadPollTask { +public interface SqlReadPollTask { /** * 执行 @@ -21,9 +22,8 @@ public interface SqlReadPollTask { /** * 初始化数据 * - * @param dataMap 数据 */ - void initData(Map dataMap); + void initData(List dataList); /** * 类型 diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/polling/impl/ChainReadPollTask.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/polling/impl/ChainReadPollTask.java index 717ebc10..b2d10b44 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/polling/impl/ChainReadPollTask.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/polling/impl/ChainReadPollTask.java @@ -1,13 +1,16 @@ package com.yomahub.liteflow.parser.sql.polling.impl; +import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; import com.yomahub.liteflow.flow.FlowBus; import com.yomahub.liteflow.parser.constant.ReadType; import com.yomahub.liteflow.parser.sql.polling.AbstractSqlReadPollTask; import com.yomahub.liteflow.parser.sql.read.SqlRead; +import com.yomahub.liteflow.parser.sql.read.vo.ChainVO; import java.util.List; import java.util.Map; +import java.util.function.Consumer; /** * chain 读取任务 @@ -16,20 +19,20 @@ import java.util.Map; * @author houxinyu * @since 2.11.1 */ -public class ChainReadPollTask extends AbstractSqlReadPollTask { +public class ChainReadPollTask extends AbstractSqlReadPollTask { - public ChainReadPollTask(SqlRead read) { + public ChainReadPollTask(SqlRead read) { super(read); } @Override - public void doSave(Map saveElementMap) { - for (Map.Entry entry : saveElementMap.entrySet()) { - String chainName = entry.getKey(); - String newData = entry.getValue(); - - LiteFlowChainELBuilder.createChain().setChainId(chainName).setEL(newData).build(); - } + public void doSave(List saveElementList) { + saveElementList.forEach(chainVO -> + LiteFlowChainELBuilder.createChain().setChainId(chainVO.getChainId()) + .setRoute(chainVO.getRoute()) + .setNamespace(chainVO.getNamespace()) + .setEL(chainVO.getBody()) + .build()); } @Override @@ -39,6 +42,21 @@ public class ChainReadPollTask extends AbstractSqlReadPollTask { } } + @Override + protected String getKey(ChainVO chainVO) { + return chainVO.getChainId(); + } + + @Override + protected String getValue(ChainVO chainVO) { + return chainVO.getBody(); + } + + @Override + protected String getExtValue(ChainVO chainVO) { + return chainVO.getRoute(); + } + @Override public ReadType type() { return ReadType.CHAIN; diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/polling/impl/ScriptReadPollTask.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/polling/impl/ScriptReadPollTask.java index 38bbd621..ddfff6da 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/polling/impl/ScriptReadPollTask.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/polling/impl/ScriptReadPollTask.java @@ -1,13 +1,18 @@ package com.yomahub.liteflow.parser.sql.polling.impl; +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.builder.LiteFlowNodeBuilder; +import com.yomahub.liteflow.enums.NodeTypeEnum; import com.yomahub.liteflow.flow.FlowBus; import com.yomahub.liteflow.parser.constant.ReadType; import com.yomahub.liteflow.parser.helper.NodeConvertHelper; import com.yomahub.liteflow.parser.sql.polling.AbstractSqlReadPollTask; import com.yomahub.liteflow.parser.sql.read.SqlRead; +import com.yomahub.liteflow.parser.sql.read.vo.ScriptVO; import java.util.List; import java.util.Map; +import java.util.function.Consumer; /** * 脚本轮询任务 @@ -16,32 +21,45 @@ import java.util.Map; * @author houxinyu * @since 2.11.1 */ -public class ScriptReadPollTask extends AbstractSqlReadPollTask { - public ScriptReadPollTask(SqlRead read) { +public class ScriptReadPollTask extends AbstractSqlReadPollTask { + public ScriptReadPollTask(SqlRead read) { super(read); } @Override - public void doSave(Map saveElementMap) { - for (Map.Entry entry : saveElementMap.entrySet()) { - String scriptKey = entry.getKey(); - String newData = entry.getValue(); - - NodeConvertHelper.NodeSimpleVO scriptVO = NodeConvertHelper.convert(scriptKey); - NodeConvertHelper.changeScriptNode(scriptVO, newData); - } + public void doSave(List saveElementList) { + saveElementList.forEach(scriptVO -> LiteFlowNodeBuilder.createScriptNode() + .setId(scriptVO.getNodeId()) + .setType(NodeTypeEnum.getEnumByCode(scriptVO.getType())) + .setName(scriptVO.getName()) + .setScript(scriptVO.getScript()) + .setLanguage(scriptVO.getLanguage()) + .build()); } @Override public void doDelete(List deleteElementId) { for (String id : deleteElementId) { - NodeConvertHelper.NodeSimpleVO scriptVO = NodeConvertHelper.convert(id); - // 删除script - FlowBus.unloadScriptNode(scriptVO.getNodeId()); + FlowBus.unloadScriptNode(id); } } + @Override + protected String getKey(ScriptVO scriptVO) { + return scriptVO.getNodeId(); + } + + @Override + protected String getValue(ScriptVO scriptVO) { + return scriptVO.getScript(); + } + + @Override + protected String getExtValue(ScriptVO scriptVO) { + return StrUtil.EMPTY; + } + @Override public ReadType type() { return ReadType.SCRIPT; diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/AbstractSqlRead.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/AbstractSqlRead.java index bb2f7cbe..5d611f4e 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/AbstractSqlRead.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/AbstractSqlRead.java @@ -9,7 +9,9 @@ import com.yomahub.liteflow.parser.sql.util.LiteFlowJdbcUtil; import com.yomahub.liteflow.parser.sql.vo.SQLParserVO; import java.sql.*; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -20,7 +22,7 @@ import java.util.Map; * @author Bryan.Zhang * @since 2.11.1 */ -public abstract class AbstractSqlRead implements SqlRead { +public abstract class AbstractSqlRead implements SqlRead { public final SQLParserVO config; private static LFLog LOG = LFLoggerManager.getLogger(AbstractSqlRead.class); @@ -29,10 +31,10 @@ public abstract class AbstractSqlRead implements SqlRead { } @Override - public Map read() { + public List read() { // 如果不需要读取直接返回 if (!needRead()) { - return new HashMap<>(); + return new ArrayList<>(); } checkConfig(); @@ -40,7 +42,7 @@ public abstract class AbstractSqlRead implements SqlRead { // 如果允许,就打印 sql 语句 logSqlIfEnable(sqlCmd); - Map result = new HashMap<>(); + List result = new ArrayList<>(); Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; @@ -54,9 +56,6 @@ public abstract class AbstractSqlRead implements SqlRead { rs = stmt.executeQuery(); while (rs.next()) { - String xml = buildXmlElement(rs); - String uniqueKey = buildXmlElementUniqueKey(rs); - if (hasEnableFiled()){ boolean enable = getEnableFiledValue(rs); // 如果停用,直接跳过 @@ -64,7 +63,7 @@ public abstract class AbstractSqlRead implements SqlRead { continue; } } - result.put(uniqueKey, xml); + result.add(parse(rs)); } } catch (Exception e) { throw new ELSQLException(e.getMessage()); @@ -76,6 +75,8 @@ public abstract class AbstractSqlRead implements SqlRead { return result; } + protected abstract T parse(ResultSet rs) throws SQLException; + /** * 是否包含启停字段 */ @@ -88,10 +89,6 @@ public abstract class AbstractSqlRead implements SqlRead { public abstract String buildQuerySql(); - public abstract String buildXmlElement(ResultSet rs) throws SQLException; - - public abstract String buildXmlElementUniqueKey(ResultSet rs) throws SQLException; - public abstract void checkConfig(); /** diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/SqlRead.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/SqlRead.java index af003f8e..e6c8c96f 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/SqlRead.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/SqlRead.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.parser.sql.read; import com.yomahub.liteflow.parser.constant.ReadType; +import java.util.List; import java.util.Map; /** @@ -11,14 +12,14 @@ import java.util.Map; * @author houxinyu * @since 2.11.1 */ -public interface SqlRead { +public interface SqlRead { /** * 读取 * * @return 返回读取到的数据 */ - Map read(); + List read(); /** * 类型 diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/SqlReadFactory.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/SqlReadFactory.java index 281f7798..f22f3657 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/SqlReadFactory.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/SqlReadFactory.java @@ -19,8 +19,8 @@ import java.util.Map; * @since 2.11.1 */ public class SqlReadFactory { - private static final Map READ_MAP = new HashMap<>(); - private static final Map POLL_TASK_MAP = new HashMap<>(); + private static final Map> READ_MAP = new HashMap<>(); + private static final Map> POLL_TASK_MAP = new HashMap<>(); public static void registerRead(SQLParserVO config) { READ_MAP.putIfAbsent(ReadType.CHAIN, new ChainRead(config)); @@ -28,19 +28,21 @@ public class SqlReadFactory { } public static void registerSqlReadPollTask(ReadType readType) { - SqlRead sqlRead = getSqlRead(readType); + SqlRead sqlRead = getSqlRead(readType); if (ReadType.CHAIN.equals(readType)) { - POLL_TASK_MAP.putIfAbsent(ReadType.CHAIN, new ChainReadPollTask(sqlRead)); + POLL_TASK_MAP.putIfAbsent(ReadType.CHAIN, new ChainReadPollTask((ChainRead)sqlRead)); } else if (ReadType.SCRIPT.equals(readType)) { - POLL_TASK_MAP.putIfAbsent(ReadType.SCRIPT, new ScriptReadPollTask(sqlRead)); + POLL_TASK_MAP.putIfAbsent(ReadType.SCRIPT, new ScriptReadPollTask((ScriptRead)sqlRead)); } } - public static SqlRead getSqlRead(ReadType readType) { - return READ_MAP.get(readType); + @SuppressWarnings("unchecked") + public static SqlRead getSqlRead(ReadType readType) { + return (SqlRead)READ_MAP.get(readType); } - public static SqlReadPollTask getSqlReadPollTask(ReadType readType) { - return POLL_TASK_MAP.get(readType); + @SuppressWarnings("unchecked") + public static SqlReadPollTask getSqlReadPollTask(ReadType readType) { + return (SqlReadPollTask)POLL_TASK_MAP.get(readType); } } diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/impl/ChainRead.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/impl/ChainRead.java index c7048a8b..b7ce9ef9 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/impl/ChainRead.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/impl/ChainRead.java @@ -5,6 +5,7 @@ import com.yomahub.liteflow.parser.constant.ReadType; import com.yomahub.liteflow.parser.constant.SqlReadConstant; import com.yomahub.liteflow.parser.sql.exception.ELSQLException; import com.yomahub.liteflow.parser.sql.read.AbstractSqlRead; +import com.yomahub.liteflow.parser.sql.read.vo.ChainVO; import com.yomahub.liteflow.parser.sql.vo.SQLParserVO; import java.sql.ResultSet; @@ -17,12 +18,26 @@ import java.sql.SQLException; * @author houxinyu * @since 2.11.1 */ -public class ChainRead extends AbstractSqlRead { +public class ChainRead extends AbstractSqlRead { public ChainRead(SQLParserVO config) { super(config); } + @Override + protected ChainVO parse(ResultSet rs) throws SQLException { + ChainVO chainVO = new ChainVO(); + chainVO.setChainId(getStringFromRsWithCheck(rs, super.config.getChainNameField())); + chainVO.setBody(getStringFromRsWithCheck(rs, super.config.getElDataField())); + if (StrUtil.isNotBlank(super.config.getNamespaceField())){ + chainVO.setNamespace(getStringFromRs(rs, super.config.getNamespaceField())); + } + if (StrUtil.isNotBlank(super.config.getRouteField())){ + chainVO.setRoute(getStringFromRs(rs, super.config.getRouteField())); + } + return chainVO; + } + @Override public boolean hasEnableFiled() { String chainEnableField = super.config.getChainEnableField(); @@ -70,20 +85,6 @@ public class ChainRead extends AbstractSqlRead { } } - @Override - public String buildXmlElement(ResultSet rs) throws SQLException { - String elDataField = super.config.getElDataField(); - - return getStringFromRs(rs, elDataField); - } - - @Override - public String buildXmlElementUniqueKey(ResultSet rs) throws SQLException { - String chainNameField = super.config.getChainNameField(); - - return getStringFromRsWithCheck(rs, chainNameField); - } - @Override public ReadType type() { return ReadType.CHAIN; diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/impl/ScriptRead.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/impl/ScriptRead.java index 3b2fd264..fa10a616 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/impl/ScriptRead.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/impl/ScriptRead.java @@ -8,6 +8,7 @@ import com.yomahub.liteflow.parser.constant.ReadType; import com.yomahub.liteflow.parser.constant.SqlReadConstant; import com.yomahub.liteflow.parser.sql.exception.ELSQLException; import com.yomahub.liteflow.parser.sql.read.AbstractSqlRead; +import com.yomahub.liteflow.parser.sql.read.vo.ScriptVO; import com.yomahub.liteflow.parser.sql.util.LiteFlowJdbcUtil; import com.yomahub.liteflow.parser.sql.vo.SQLParserVO; @@ -24,12 +25,23 @@ import java.util.Objects; * @author houxinyu * @since 2.11.1 */ -public class ScriptRead extends AbstractSqlRead { +public class ScriptRead extends AbstractSqlRead { public ScriptRead(SQLParserVO config) { super(config); } + @Override + protected ScriptVO parse(ResultSet rs) throws SQLException { + ScriptVO scriptVO = new ScriptVO(); + scriptVO.setNodeId(getStringFromRsWithCheck(rs, super.config.getScriptIdField())); + scriptVO.setName(getStringFromRs(rs, super.config.getScriptNameField())); + scriptVO.setType(getStringFromRsWithCheck(rs, super.config.getScriptTypeField())); + scriptVO.setLanguage(getStringFromRs(rs, super.config.getScriptLanguageField())); + scriptVO.setScript(getStringFromRsWithCheck(rs, super.config.getScriptDataField())); + return scriptVO; + } + @Override public boolean hasEnableFiled() { String scriptEnableField = super.config.getScriptEnableField(); @@ -80,46 +92,6 @@ public class ScriptRead extends AbstractSqlRead { } } - @Override - public String buildXmlElement(ResultSet rs) throws SQLException { - String scriptDataField = super.config.getScriptDataField(); - - return getStringFromRs(rs, scriptDataField); - - } - - @Override - public String buildXmlElementUniqueKey(ResultSet rs) throws SQLException { - String scriptIdField = super.config.getScriptIdField(); - String scriptNameField = super.config.getScriptNameField(); - String scriptTypeField = super.config.getScriptTypeField(); - String scriptLanguageField = super.config.getScriptLanguageField(); - - String id = getStringFromRsWithCheck(rs, scriptIdField); - String name = getStringFromRsWithCheck(rs, scriptNameField); - String type = getStringFromRsWithCheck(rs, scriptTypeField); - String language = withLanguage() ? getStringFromRs(rs, scriptLanguageField) : null; - - 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 (withLanguage() && !ScriptTypeEnum.checkScriptType(language)) { - throw new ELSQLException(StrUtil.format("The language value[{}] is invalid", language)); - } - List keys = CollUtil.newArrayList(id, type, name); - if (StrUtil.isNotBlank(language)) { - keys.add(language); - } - - return StrUtil.join(StrUtil.COLON, keys); - } - @Override public boolean needRead() { if (StrUtil.isBlank(super.config.getScriptTableName())) { diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/vo/ChainVO.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/vo/ChainVO.java new file mode 100644 index 00000000..61710e20 --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/vo/ChainVO.java @@ -0,0 +1,44 @@ +package com.yomahub.liteflow.parser.sql.read.vo; + +public class ChainVO { + + private String chainId; + + private String route; + + private String namespace; + + private String body; + + public String getChainId() { + return chainId; + } + + public void setChainId(String chainId) { + this.chainId = chainId; + } + + public String getRoute() { + return route; + } + + public void setRoute(String route) { + this.route = route; + } + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } +} diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/vo/ScriptVO.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/vo/ScriptVO.java new file mode 100644 index 00000000..5c4f3fb1 --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/vo/ScriptVO.java @@ -0,0 +1,64 @@ +package com.yomahub.liteflow.parser.sql.read.vo; + +public class ScriptVO { + + private String nodeId; + + private String type; + + private String name; + + private String language; + + private Boolean enable; + + private String script; + + public String getNodeId() { + return nodeId; + } + + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public Boolean getEnable() { + return enable; + } + + public void setEnable(Boolean enable) { + this.enable = enable; + } + + public String getScript() { + return script; + } + + public void setScript(String script) { + this.script = script; + } +} 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 4c5b91d7..714644a3 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 @@ -11,9 +11,12 @@ import com.yomahub.liteflow.parser.constant.ReadType; import com.yomahub.liteflow.parser.helper.NodeConvertHelper; import com.yomahub.liteflow.parser.sql.exception.ELSQLException; +import com.yomahub.liteflow.parser.sql.polling.SqlReadPollTask; import com.yomahub.liteflow.parser.sql.read.AbstractSqlRead; import com.yomahub.liteflow.parser.sql.read.SqlRead; import com.yomahub.liteflow.parser.sql.read.SqlReadFactory; +import com.yomahub.liteflow.parser.sql.read.vo.ChainVO; +import com.yomahub.liteflow.parser.sql.read.vo.ScriptVO; import com.yomahub.liteflow.parser.sql.vo.SQLParserVO; import org.apache.commons.lang.StringUtils; @@ -87,30 +90,30 @@ public class JDBCHelper { * @return 数据内容 */ public String getContent() { - SqlRead chainRead = SqlReadFactory.getSqlRead(ReadType.CHAIN); - SqlRead scriptRead = SqlReadFactory.getSqlRead(ReadType.SCRIPT); + SqlRead chainRead = SqlReadFactory.getSqlRead(ReadType.CHAIN); + SqlRead scriptRead = SqlReadFactory.getSqlRead(ReadType.SCRIPT); // 获取 chain 数据 - Map chainMap = chainRead.read(); + List chainVOList = chainRead.read(); List chainList = new ArrayList<>(); - chainMap.entrySet().stream() - .filter(entry -> StrUtil.isNotBlank(entry.getValue())) - .forEach( - entry -> chainList.add(StrUtil.format(CHAIN_XML_PATTERN, XmlUtil.escape(entry.getKey()), entry.getValue())) - ); + chainVOList.forEach( + chainVO -> chainList.add(StrUtil.format(CHAIN_XML_PATTERN, XmlUtil.escape(chainVO.getChainId()), StrUtil.emptyIfNull(chainVO.getNamespace()), StrUtil.emptyIfNull(chainVO.getRoute()), chainVO.getBody())) + ); + String chainsContent = CollUtil.join(chainList, StrUtil.EMPTY); // 获取脚本数据 - Map scriptMap = scriptRead.read(); + List scriptVOList = scriptRead.read(); List scriptList = new ArrayList<>(); - scriptMap.forEach((scriptKey, elData) -> { - NodeConvertHelper.NodeSimpleVO scriptVO = NodeConvertHelper.convert(scriptKey); + + scriptVOList.forEach(scriptVO -> { String id = scriptVO.getNodeId(); String name = scriptVO.getName(); String type = scriptVO.getType(); String language = scriptVO.getLanguage(); + String elData = scriptVO.getScript(); if (StringUtils.isNotBlank(scriptVO.getLanguage())) { scriptList.add(StrUtil.format(NODE_ITEM_WITH_LANGUAGE_XML_PATTERN, XmlUtil.escape(id), XmlUtil.escape(name), type, language, elData)); @@ -118,11 +121,14 @@ public class JDBCHelper { scriptList.add(StrUtil.format(NODE_ITEM_XML_PATTERN, XmlUtil.escape(id), XmlUtil.escape(name), type, elData)); } }); + String nodesContent = StrUtil.format(NODE_XML_PATTERN, CollUtil.join(scriptList, StrUtil.EMPTY)); // 初始化轮询任务 - SqlReadFactory.getSqlReadPollTask(ReadType.CHAIN).initData(chainMap); - SqlReadFactory.getSqlReadPollTask(ReadType.SCRIPT).initData(scriptMap); + SqlReadPollTask sqlReadPollTask4Chain = SqlReadFactory.getSqlReadPollTask(ReadType.CHAIN); + sqlReadPollTask4Chain.initData(chainVOList); + SqlReadPollTask sqlReadPollTask4Script = SqlReadFactory.getSqlReadPollTask(ReadType.SCRIPT); + sqlReadPollTask4Script.initData(scriptVOList); return StrUtil.format(XML_PATTERN, nodesContent, chainsContent); } 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 535f1856..c654df2a 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 @@ -56,6 +56,16 @@ public class SQLParserVO { */ private String elDataField = "el_data"; + /** + * 决策路由字段 + */ + private String routeField; + + /** + * 命名空间字段 + */ + private String namespaceField; + /** * 是否启动某一条chain */ @@ -310,4 +320,20 @@ public class SQLParserVO { public boolean hasEnableField() { return StrUtil.isNotBlank(chainEnableField) || StrUtil.isNotBlank(scriptEnableField); } + + public String getRouteField() { + return routeField; + } + + public void setRouteField(String routeField) { + this.routeField = routeField; + } + + public String getNamespaceField() { + return namespaceField; + } + + public void setNamespaceField(String namespaceField) { + this.namespaceField = namespaceField; + } } From be4daeb188bd35a129ca4b7aacd1429ec672ea23 Mon Sep 17 00:00:00 2001 From: joewulf Date: Thu, 23 May 2024 15:10:14 +0000 Subject: [PATCH 16/21] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E8=84=9A=E6=9C=AC=E8=AF=AD=E8=A8=80=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=20=E5=A2=9E=E5=8A=A0CUSTOM=E7=B1=BB=E5=9E=8B=E6=9E=9A?= =?UTF-8?q?=E4=B8=BE=EF=BC=8C=E5=85=B7=E4=BD=93=E7=9A=84ScriptExecutor?= =?UTF-8?q?=E7=94=B1=E7=94=A8=E6=88=B7=E8=87=AA=E8=A1=8C=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: joewulf --- .../src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java | 1 + 1 file changed, 1 insertion(+) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java index c9a62570..a3bedba7 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.enums; public enum ScriptTypeEnum { + CUSTOM("custom", "custom"), GROOVY("groovy", "groovy"), QLEXPRESS("qlexpress", "qlexpress"), JS("javascript", "js"), From 30cda75daaa4ebab4c196966de92fae09fc44dbe Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Fri, 24 May 2024 15:32:38 +0800 Subject: [PATCH 17/21] =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=94=B9=E6=88=902.12.?= =?UTF-8?q?1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 439f5668..63ab879e 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ - 2.12.0 + 2.12.1 UTF-8 UTF-8 8 From ff88db092a4d54b62bc28938c50834507aad1ac3 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Mon, 27 May 2024 22:00:31 +0800 Subject: [PATCH 18/21] =?UTF-8?q?feature=20#I9PVQ7=20=E5=86=B3=E7=AD=96?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E4=B8=AD=E5=A2=9E=E5=8A=A0namespace=EF=BC=8C?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E6=89=A7=E8=A1=8C=E6=8C=87=E5=AE=9A=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E7=A9=BA=E9=97=B4=E7=9A=84=E5=86=B3=E7=AD=96=E8=B7=AF?= =?UTF-8?q?=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java index c8e6ef6e..802be989 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java @@ -233,6 +233,9 @@ public class LiteFlowChainELBuilder { } public LiteFlowChainELBuilder setNamespace(String nameSpace){ + if (StrUtil.isBlank(nameSpace)) { + nameSpace = ChainConstant.DEFAULT_NAMESPACE; + } this.chain.setNamespace(nameSpace); return this; } From 3e3ab505d9113cc13911b10b305dc7a3063d360f Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Wed, 29 May 2024 17:56:22 +0800 Subject: [PATCH 19/21] =?UTF-8?q?feature=20#I9PVQ7=20=E5=86=B3=E7=AD=96?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E4=B8=AD=E5=A2=9E=E5=8A=A0namespace=EF=BC=8C?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E6=89=A7=E8=A1=8C=E6=8C=87=E5=AE=9A=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E7=A9=BA=E9=97=B4=E7=9A=84=E5=86=B3=E7=AD=96=E8=B7=AF?= =?UTF-8?q?=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/sqlroute/SQLRouteSpringbootTest.java | 56 +++++++++++++++++++ .../liteflow/test/sqlroute/cmp/ACmp.java | 21 +++++++ .../liteflow/test/sqlroute/cmp/BCmp.java | 21 +++++++ .../liteflow/test/sqlroute/cmp/CCmp.java | 21 +++++++ .../liteflow/test/sqlroute/cmp/R1.java | 13 +++++ .../liteflow/test/sqlroute/cmp/R2.java | 13 +++++ .../resources/application-route.properties | 28 ++++++++++ .../src/test/resources/sql/data.sql | 2 + .../src/test/resources/sql/schema.sql | 2 + 9 files changed, 177 insertions(+) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/SQLRouteSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/R1.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/R2.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-route.properties diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/SQLRouteSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/SQLRouteSpringbootTest.java new file mode 100644 index 00000000..48334315 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/SQLRouteSpringbootTest.java @@ -0,0 +1,56 @@ +package com.yomahub.liteflow.test.sqlroute; + +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.slot.DefaultContext; +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; +import java.util.List; +import java.util.function.Predicate; + +/** + * @author tangkc + * @since 2.9.0 + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/application-route.properties") +@SpringBootTest(classes = SQLRouteSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.sqlroute.cmp" }) +public class SQLRouteSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testRoute1() { + List responseList = flowExecutor.executeRouteChain("ns", 15, DefaultContext.class); + LiteflowResponse response1 = responseList.stream().filter(liteflowResponse -> liteflowResponse.getChainId().equals("r_chain1")).findFirst().orElse(null); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertEquals("a==>b==>c", response1.getExecuteStepStr()); + LiteflowResponse response2 = responseList.stream().filter(liteflowResponse -> liteflowResponse.getChainId().equals("r_chain2")).findFirst().orElse(null); + Assertions.assertTrue(response2.isSuccess()); + Assertions.assertEquals("c==>b==>a", response2.getExecuteStepStr()); + } + + + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/ACmp.java new file mode 100644 index 00000000..7391a4aa --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.sqlroute.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/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/BCmp.java new file mode 100644 index 00000000..e7a99db2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.sqlroute.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/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/CCmp.java new file mode 100644 index 00000000..9c6d33cf --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.sqlroute.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/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/R1.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/R1.java new file mode 100644 index 00000000..f7307d1b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/R1.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.sqlroute.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; + +@LiteflowComponent("r1") +public class R1 extends NodeBooleanComponent { + @Override + public boolean processBoolean() throws Exception { + int testInt = this.getRequestData(); + return testInt >= 10 && testInt <= 20; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/R2.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/R2.java new file mode 100644 index 00000000..c15f0123 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sqlroute/cmp/R2.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.sqlroute.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; + +@LiteflowComponent("r2") +public class R2 extends NodeBooleanComponent { + @Override + public boolean processBoolean() throws Exception { + int testInt = this.getRequestData(); + return testInt > 100; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-route.properties b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-route.properties new file mode 100644 index 00000000..6a01b558 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-route.properties @@ -0,0 +1,28 @@ +liteflow.rule-source-ext-data={\ + "url":"jdbc:h2:mem:test_db;MODE=MySQL",\ + "driverClassName":"org.h2.Driver",\ + "username":"root",\ + "password":"123456",\ + "applicationName":"demo",\ + "chainTableName":"EL_TABLE",\ + "chainApplicationNameField":"application_name",\ + "chainNameField":"chain_name",\ + "elDataField":"EL_DATA",\ + "routeField":"route",\ + "namespaceField":"namespace",\ + "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 diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/data.sql b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/data.sql index 5453c149..e885458b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/data.sql +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/data.sql @@ -5,6 +5,8 @@ INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain 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)));'); +INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA,ROUTE,NAMESPACE) values ('demo','r_chain1','THEN(a,b,c);','r1','ns'); +INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA,ROUTE,NAMESPACE) values ('demo','r_chain2','THEN(c,b,a);','OR(r1,r2)','ns'); DELETE FROM SCRIPT_NODE_TABLE; diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/schema.sql b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/schema.sql index fa60f098..4e4efcfc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/schema.sql +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/schema.sql @@ -4,6 +4,8 @@ create table IF NOT EXISTS `EL_TABLE` `application_name` varchar(32) NOT NULL, `chain_name` varchar(32) NOT NULL, `el_data` varchar(1024) NOT NULL, + `route` varchar(1024), + `namespace` varchar(32), PRIMARY KEY (`id`) ); From ce2a9c854e205904081c6ef1275a11e240e970f3 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Wed, 29 May 2024 21:19:58 +0800 Subject: [PATCH 20/21] =?UTF-8?q?feature=20#I9PVQ7=20=E5=86=B3=E7=AD=96?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E4=B8=AD=E5=A2=9E=E5=8A=A0namespace=EF=BC=8C?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E6=89=A7=E8=A1=8C=E6=8C=87=E5=AE=9A=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E7=A9=BA=E9=97=B4=E7=9A=84=E5=86=B3=E7=AD=96=E8=B7=AF?= =?UTF-8?q?=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yomahub/liteflow/parser/sql/read/SqlReadFactory.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/SqlReadFactory.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/SqlReadFactory.java index f22f3657..a49b33d3 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/SqlReadFactory.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/read/SqlReadFactory.java @@ -23,16 +23,16 @@ public class SqlReadFactory { private static final Map> POLL_TASK_MAP = new HashMap<>(); public static void registerRead(SQLParserVO config) { - READ_MAP.putIfAbsent(ReadType.CHAIN, new ChainRead(config)); - READ_MAP.putIfAbsent(ReadType.SCRIPT, new ScriptRead(config)); + READ_MAP.put(ReadType.CHAIN, new ChainRead(config)); + READ_MAP.put(ReadType.SCRIPT, new ScriptRead(config)); } public static void registerSqlReadPollTask(ReadType readType) { SqlRead sqlRead = getSqlRead(readType); if (ReadType.CHAIN.equals(readType)) { - POLL_TASK_MAP.putIfAbsent(ReadType.CHAIN, new ChainReadPollTask((ChainRead)sqlRead)); + POLL_TASK_MAP.put(ReadType.CHAIN, new ChainReadPollTask((ChainRead)sqlRead)); } else if (ReadType.SCRIPT.equals(readType)) { - POLL_TASK_MAP.putIfAbsent(ReadType.SCRIPT, new ScriptReadPollTask((ScriptRead)sqlRead)); + POLL_TASK_MAP.put(ReadType.SCRIPT, new ScriptReadPollTask((ScriptRead)sqlRead)); } } From 350f7bf5fba70d31a4b5408e3f4993e44420d280 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Thu, 30 May 2024 21:25:28 +0800 Subject: [PATCH 21/21] =?UTF-8?q?dtd=E4=B8=AD=E5=8A=A0=E5=85=A5kotlin?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteflow-core/src/main/resources/dtd/liteflow.dtd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liteflow-core/src/main/resources/dtd/liteflow.dtd b/liteflow-core/src/main/resources/dtd/liteflow.dtd index 334cee79..324f17cb 100644 --- a/liteflow-core/src/main/resources/dtd/liteflow.dtd +++ b/liteflow-core/src/main/resources/dtd/liteflow.dtd @@ -13,7 +13,7 @@ type (script|boolean_script|switch_script|for_script) #IMPLIED class CDATA #IMPLIED file CDATA #IMPLIED - language (qlexpress|groovy|js|python|lua|aviator|java) #IMPLIED + language (qlexpress|groovy|js|python|lua|aviator|java|kotlin) #IMPLIED enable (true|false) #IMPLIED >