Browse Source

bug #I40YVK 当主流程与子流程在不同的配置文件中时,会报错

bryan31 3 years ago
parent
commit
283abc3886

+ 8 - 5
liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java

@@ -31,6 +31,7 @@ import com.yomahub.liteflow.parser.XmlFlowParser;
 import com.yomahub.liteflow.parser.ZookeeperXmlFlowParser;
 
 import java.text.MessageFormat;
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -68,11 +69,12 @@ public class FlowExecutor {
         if (ObjectUtil.isNull(liteflowConfig) || StrUtil.isBlank(liteflowConfig.getRuleSource())) {
             throw new ConfigErrorException("config error, please check liteflow config property");
         }
-        List<String> rulePath = Lists.newArrayList(liteflowConfig.getRuleSource().split(",|;"));
+        List<String> sourceRulePathList = Lists.newArrayList(liteflowConfig.getRuleSource().split(",|;"));
 
         FlowParser parser = null;
         Set<String> parserNameSet = new HashSet<>();
-        for (String path : rulePath) {
+        List<String> rulePathList = new ArrayList<>();
+        for (String path : sourceRulePathList) {
             try {
                 FlowParserTypeEnum pattern = matchFormatConfig(path);
                 if (ObjectUtil.isNotNull(pattern)) {
@@ -95,6 +97,7 @@ public class FlowExecutor {
                             throw new ErrorSupportPathException(errorMsg);
                     }
                 }
+                rulePathList.add(path);
             } catch (Exception e) {
                 String errorMsg = StrUtil.format("init flow executor cause error,cannot find the parse for path {}", path);
                 LOG.error(errorMsg, e);
@@ -103,7 +106,7 @@ public class FlowExecutor {
         }
 
         //检查Parser是否只有一个,因为多个不同的parser会造成子流程的混乱
-        if (parserNameSet.size() != 1){
+        if (parserNameSet.size() > 1){
             String errorMsg = "cannot have multiple different parsers";
             LOG.error(errorMsg);
             throw new MultipleParsersException(errorMsg);
@@ -111,12 +114,12 @@ public class FlowExecutor {
 
         try{
             if (ObjectUtil.isNotNull(parser)) {
-                parser.parseMain(rulePath);
+                parser.parseMain(rulePathList);
             } else {
                 throw new ConfigErrorException("parse error, please check liteflow config property");
             }
         } catch (Exception e) {
-            String errorMsg = StrUtil.format("init flow executor cause error,can not parse rule file {}", rulePath);
+            String errorMsg = StrUtil.format("init flow executor cause error,can not parse rule file {}", rulePathList);
             LOG.error(errorMsg, e);
             throw new FlowExecutorNotInitException(errorMsg);
         }

+ 1 - 1
liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigTest.java

@@ -48,7 +48,7 @@ public class SubflowInDifferentConfigTest extends BaseTest {
     @Test(expected = MultipleParsersException.class)
     public void testExplicitSubFlow2() {
         LiteflowConfig config = context.getBean(LiteflowConfig.class);
-        config.setRuleSource("/subflow/application-subInDifferentConfig2.properties");
+        config.setRuleSource("subflow/flow-main.xml,subflow/flow-sub1.xml,subflow/flow-sub2.yml");
         flowExecutor.init();
     }
 }