Browse Source

!295 enhancement #IAF4NJ liteflow-rule-sql 不支持 solon
Merge pull request !295 from 与或非/issues/IAF4NJ

铂赛东 9 tháng trước cách đây
mục cha
commit
e459f40537

+ 1 - 0
liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java

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

+ 1 - 1
liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowMainAutoConfiguration.java

@@ -18,7 +18,7 @@ import org.noear.solon.core.AppContext;
 @Configuration
 @Configuration
 public class LiteflowMainAutoConfiguration {
 public class LiteflowMainAutoConfiguration {
 
 
-	@Inject(value = "${liteflow.parseOnStart}", required = false)
+	@Inject(value = "${liteflow.parseOnStart:true}", required = false)
 	boolean parseOnStart;
 	boolean parseOnStart;
 
 
 	@Inject
 	@Inject

+ 16 - 0
liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java

@@ -4,6 +4,8 @@ import com.yomahub.liteflow.enums.ParseModeEnum;
 import org.noear.solon.annotation.Configuration;
 import org.noear.solon.annotation.Configuration;
 import org.noear.solon.annotation.Inject;
 import org.noear.solon.annotation.Inject;
 
 
+import java.util.Map;
+
 /**
 /**
  * 执行流程主要的参数类
  * 执行流程主要的参数类
  *
  *
@@ -24,6 +26,8 @@ public class LiteflowProperty {
 	// 流程资源扩展数据
 	// 流程资源扩展数据
 	private String ruleSourceExtData;
 	private String ruleSourceExtData;
 
 
+	private Map<String, String> ruleSourceExtDataMap;
+
 	// slot的数量
 	// slot的数量
 	private int slotSize;
 	private int slotSize;
 
 
@@ -251,4 +255,16 @@ public class LiteflowProperty {
 	public void setParseMode(ParseModeEnum parseMode) {
 	public void setParseMode(ParseModeEnum parseMode) {
 		this.parseMode = parseMode;
 		this.parseMode = parseMode;
 	}
 	}
+
+	public Map<String, String> getRuleSourceExtDataMap() {
+		return ruleSourceExtDataMap;
+	}
+
+	public void setRuleSourceExtDataMap(Map<String, String> ruleSourceExtDataMap) {
+		this.ruleSourceExtDataMap = ruleSourceExtDataMap;
+	}
+
+	public Boolean getFallbackCmpEnable() {
+		return fallbackCmpEnable;
+	}
 }
 }

+ 107 - 0
liteflow-testcase-el/liteflow-testcase-el-sql-solon/pom.xml

@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.yomahub</groupId>
+        <artifactId>liteflow-testcase-el</artifactId>
+        <version>2.12.2</version>
+    </parent>
+
+    <artifactId>liteflow-testcase-el-sql-solon</artifactId>
+
+    <properties>
+        <h2.version>2.1.214</h2.version>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>com.yomahub</groupId>
+            <artifactId>liteflow-rule-sql</artifactId>
+            <version>${revision}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.yomahub</groupId>
+            <artifactId>liteflow-core</artifactId>
+            <version>${revision}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+            <version>${h2.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.yomahub</groupId>
+            <artifactId>liteflow-script-groovy</artifactId>
+            <version>${revision}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.yomahub</groupId>
+            <artifactId>liteflow-script-graaljs</artifactId>
+            <version>${revision}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.yomahub</groupId>
+            <artifactId>liteflow-solon-plugin</artifactId>
+            <version>${revision}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.yomahub</groupId>
+            <artifactId>liteflow-el-builder</artifactId>
+            <version>${revision}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.noear</groupId>
+            <artifactId>solon-test-junit5</artifactId>
+            <version>${solon.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.aspectj</groupId>
+            <artifactId>aspectjweaver</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.curator</groupId>
+            <artifactId>curator-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.101tec</groupId>
+            <artifactId>zkclient</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.curator</groupId>
+            <artifactId>curator-framework</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.curator</groupId>
+            <artifactId>curator-recipes</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>8.0.31</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>

+ 21 - 0
liteflow-testcase-el/liteflow-testcase-el-sql-solon/src/test/java/com/yomahub/liteflow/test/BaseTest.java

@@ -0,0 +1,21 @@
+package com.yomahub.liteflow.test;
+
+import com.yomahub.liteflow.core.FlowInitHook;
+import com.yomahub.liteflow.flow.FlowBus;
+import com.yomahub.liteflow.property.LiteflowConfigGetter;
+import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
+import com.yomahub.liteflow.thread.ExecutorHelper;
+import org.junit.jupiter.api.AfterAll;
+
+public class BaseTest {
+
+    @AfterAll
+    public static void cleanScanCache() {
+        FlowBus.cleanCache();
+        ExecutorHelper.loadInstance().clearExecutorServiceMap();
+        SpiFactoryCleaner.clean();
+        LiteflowConfigGetter.clean();
+        FlowInitHook.cleanHook();
+        FlowBus.clearStat();
+    }
+}

+ 32 - 0
liteflow-testcase-el/liteflow-testcase-el-sql-solon/src/test/java/com/yomahub/liteflow/test/def/SQLWithXmlELSpringbootTest.java

@@ -0,0 +1,32 @@
+package com.yomahub.liteflow.test.def;
+
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.flow.LiteflowResponse;
+import com.yomahub.liteflow.test.BaseTest;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.noear.solon.annotation.Import;
+import org.noear.solon.annotation.Inject;
+import org.noear.solon.test.SolonJUnit5Extension;
+
+@ExtendWith(SolonJUnit5Extension.class)
+@Import(profiles = "classpath:/application.properties")
+public class SQLWithXmlELSpringbootTest extends BaseTest {
+
+    @Inject
+    private FlowExecutor flowExecutor;
+
+    @Test
+    public void testSQLWithXml() {
+        LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
+        Assertions.assertEquals("a==>b==>c", response.getExecuteStepStr());
+    }
+
+    @Test
+    public void testSQLWithScriptXml() {
+        LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
+        Assertions.assertTrue(response.isSuccess());
+        Assertions.assertEquals("x0[if 脚本]==>a==>b", response.getExecuteStepStrWithoutTime());
+    }
+}

+ 21 - 0
liteflow-testcase-el/liteflow-testcase-el-sql-solon/src/test/java/com/yomahub/liteflow/test/def/cmp/ACmp.java

@@ -0,0 +1,21 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.def.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.noear.solon.annotation.Component;
+
+@Component("a")
+public class ACmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("ACmp executed!");
+	}
+
+}

+ 21 - 0
liteflow-testcase-el/liteflow-testcase-el-sql-solon/src/test/java/com/yomahub/liteflow/test/def/cmp/BCmp.java

@@ -0,0 +1,21 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.def.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.noear.solon.annotation.Component;
+
+@Component("b")
+public class BCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("BCmp executed!");
+	}
+
+}

+ 21 - 0
liteflow-testcase-el/liteflow-testcase-el-sql-solon/src/test/java/com/yomahub/liteflow/test/def/cmp/CCmp.java

@@ -0,0 +1,21 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.def.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.noear.solon.annotation.Component;
+
+@Component("c")
+public class CCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("CCmp executed!");
+	}
+
+}

+ 21 - 0
liteflow-testcase-el/liteflow-testcase-el-sql-solon/src/test/resources/application.properties

@@ -0,0 +1,21 @@
+liteflow.rule-source-ext-data-map.url=jdbc:h2:mem:test_db;MODE=MySQL;INIT=RUNSCRIPT FROM 'classpath:sql/schema.sql'\\;RUNSCRIPT FROM 'classpath:sql/data.sql'
+liteflow.rule-source-ext-data-map.driverClassName=org.h2.Driver
+liteflow.rule-source-ext-data-map.username=root
+liteflow.rule-source-ext-data-map.password=123456
+liteflow.rule-source-ext-data-map.applicationName=demo
+liteflow.rule-source-ext-data-map.sqlLogEnabled=true
+liteflow.rule-source-ext-data-map.pollingEnabled=true
+liteflow.rule-source-ext-data-map.pollingIntervalSeconds=60
+liteflow.rule-source-ext-data-map.pollingStartSeconds=60
+liteflow.rule-source-ext-data-map.chainTableName=EL_TABLE
+liteflow.rule-source-ext-data-map.chainApplicationNameField=application_name
+liteflow.rule-source-ext-data-map.chainNameField=chain_name
+liteflow.rule-source-ext-data-map.elDataField=EL_DATA
+liteflow.rule-source-ext-data-map.namespaceField=namespace
+liteflow.rule-source-ext-data-map.scriptTableName=script_node_table
+liteflow.rule-source-ext-data-map.scriptApplicationNameField=application_name
+liteflow.rule-source-ext-data-map.scriptIdField=script_node_id
+liteflow.rule-source-ext-data-map.scriptNameField=script_node_name
+liteflow.rule-source-ext-data-map.scriptDataField=script_node_data
+liteflow.rule-source-ext-data-map.scriptTypeField=script_node_type
+liteflow.rule-source-ext-data-map.scriptLanguageField=script_language

+ 16 - 0
liteflow-testcase-el/liteflow-testcase-el-sql-solon/src/test/resources/sql/data.sql

@@ -0,0 +1,16 @@
+DELETE FROM EL_TABLE;
+
+INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain1','THEN(a, b, c);');
+INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain2','IF(x1, THEN(a, b));');
+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','<chain3>','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;
+
+INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x0','if 脚本','boolean_script','return true','groovy');
+INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x1','if 脚本','boolean_script','return true','groovy');
+
+INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x2','python脚本','boolean_script','return true','js');

+ 22 - 0
liteflow-testcase-el/liteflow-testcase-el-sql-solon/src/test/resources/sql/schema.sql

@@ -0,0 +1,22 @@
+create table IF NOT EXISTS `EL_TABLE`
+(
+    `id`         bigint        NOT NULL GENERATED BY DEFAULT AS IDENTITY,
+    `application_name` varchar(32) NOT NULL,
+    `chain_name` varchar(32)   NOT NULL,
+    `el_data`    varchar(1024) NOT NULL,
+    `route`     varchar(1024),
+    `namespace` varchar(32),
+    PRIMARY KEY (`id`)
+);
+
+create table IF NOT EXISTS `script_node_table`
+(
+    `id`                   bigint        NOT NULL GENERATED BY DEFAULT AS IDENTITY,
+    `application_name`     varchar(32)   NOT NULL,
+    `script_node_id`       varchar(32)   NOT NULL,
+    `script_node_name`     varchar(32)   NOT NULL,
+    `script_node_type`     varchar(32)   NOT NULL,
+    `script_node_data`     varchar(1024) NOT NULL,
+    `script_language`     varchar(1024) NOT NULL,
+    PRIMARY KEY (`id`)
+);

+ 1 - 0
liteflow-testcase-el/pom.xml

@@ -40,6 +40,7 @@
         <module>liteflow-testcase-el-builder</module>
         <module>liteflow-testcase-el-builder</module>
         <module>liteflow-testcase-el-routechain</module>
         <module>liteflow-testcase-el-routechain</module>
         <module>liteflow-testcase-el-script-kotlin-springboot</module>
         <module>liteflow-testcase-el-script-kotlin-springboot</module>
+        <module>liteflow-testcase-el-sql-solon</module>
     </modules>
     </modules>
 
 
     <build>
     <build>