You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by "llllkid (via GitHub)" <gi...@apache.org> on 2025/01/02 03:34:12 UTC

[PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

llllkid opened a new pull request, #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939

   
   <!--Thanks very much for contributing to Apache DolphinScheduler, we are happy that you want to help us improve DolphinScheduler! -->
   
   ## Purpose of the pull request
   
   <!--(For example: This pull request adds checkstyle plugin).-->
   Fix #16934 
   
   ## Brief change log
   
   <!--*(for example:)*
   - *Add maven-checkstyle-plugin to root pom.xml*
   -->
   
   ## Verify this pull request
   
   <!--*(Please pick either of the following options)*-->
   
   This pull request is code cleanup without any test coverage.
   
   *(or)*
   
   This pull request is already covered by existing tests, such as *(please describe tests)*.
   
   (or)
   
   This change added tests and can be verified as follows:
   
   <!--*(example:)*
   - *Added dolphinscheduler-dao tests for end-to-end.*
   - *Added CronUtilsTest to verify the change.*
   - *Manually verified the change by testing locally.* -->
   
   (or)
   
   ## Pull Request Notice
   [Pull Request Notice](https://github.com/apache/dolphinscheduler/blob/dev/docs/docs/en/contribute/join/pull-request.md)
   
   If your pull request contains incompatible change, you should also add it to `docs/docs/en/guide/upgrade/incompatible.md`
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "llllkid (via GitHub)" <gi...@apache.org>.
llllkid commented on code in PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#discussion_r1910022198


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java:
##########
@@ -2118,37 +2118,38 @@ protected void doBatchOperateWorkflowDefinition(User loginUser,
                 List<TaskDefinitionLog> taskDefinitionLogs =
                         taskDefinitionLogDao.queryTaskDefineLogList(workflowTaskRelations);
                 Map<Long, Long> taskCodeMap = new HashMap<>();
-                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                taskDefinitionLogs.forEach(taskDefinitionLog -> {
                     try {
-                        long taskCode = CodeGenerateUtils.genCode();
-                        taskCodeMap.put(taskDefinitionLog.getCode(), taskCode);
-                        taskDefinitionLog.setCode(taskCode);
-                        if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
-                            final String taskParams = taskDefinitionLog.getTaskParams();
-                            final SwitchParameters switchParameters =
-                                    JSONUtils.parseObject(taskParams, SwitchParameters.class);
-                            if (switchParameters == null) {
-                                throw new IllegalArgumentException(
-                                        "Switch task params: " + taskParams + " is invalid.");
-                            }
-                            SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
-                            switchResult.getDependTaskList().forEach(switchResultVo -> {
-                                switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
-                            });
-                            if (switchResult.getNextNode() != null) {
-                                switchResult.setNextNode(
-                                        taskCodeMap.get(switchResult.getNextNode()));
-                            }
-                            taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
-                        }
+                        taskCodeMap.put(taskDefinitionLog.getCode(), CodeGenerateUtils.genCode());
                     } catch (CodeGenerateException e) {
                         log.error("Generate task definition code error, projectCode:{}.", targetProjectCode, e);
                         putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS);
                         throw new ServiceException(Status.INTERNAL_SERVER_ERROR_ARGS);
                     }
+                });
+                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                    taskDefinitionLog.setCode(taskCodeMap.get(taskDefinitionLog.getCode()));
                     taskDefinitionLog.setProjectCode(targetProjectCode);
                     taskDefinitionLog.setVersion(0);
                     taskDefinitionLog.setName(taskDefinitionLog.getName());
+                    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
+                        final String taskParams = taskDefinitionLog.getTaskParams();
+                        final SwitchParameters switchParameters =
+                                JSONUtils.parseObject(taskParams, SwitchParameters.class);
+                        if (switchParameters == null) {
+                            throw new IllegalArgumentException(
+                                    "Switch task params: " + taskParams + " is invalid.");
+                        }
+                        SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
+                        switchResult.getDependTaskList().forEach(switchResultVo -> {
+                            switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
+                        });
+                        if (switchResult.getNextNode() != null) {
+                            switchResult.setNextNode(
+                                    taskCodeMap.get(switchResult.getNextNode()));
+                        }
+                        taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
+                    }

Review Comment:
   > > The commit shows it's not a display issue. https://github.com/apache/dolphinscheduler/blob/48304f2a6c20de7471739b8889c2d02c41eef17d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java
   > 
   > I think I misunderstood your question. Do you want to ask me why I move this code after `taskDefinitionLog.setName`? Because for better readability:
   > 
   > ```
   >  taskDefinitionLog.setCode();
   >  taskDefinitionLog.setProjectCode();
   >  taskDefinitionLog.setVersion();
   >  taskDefinitionLog.setName();
   >  if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
   >  ...
   >       taskDefinitionLog.setTaskParams();
   >  ...
   >  }
   > ```
   > 
   > Is better than
   > 
   > ```
   >  taskDefinitionLog.setCode();
   >  if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
   >  ...
   >       taskDefinitionLog.setTaskParams();
   >  ...
   >  }
   >  taskDefinitionLog.setProjectCode();
   >  taskDefinitionLog.setVersion();
   >  taskDefinitionLog.setName();
   > ```
   
   Is that the question you want to ask? @SbloodyS 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "SbloodyS (via GitHub)" <gi...@apache.org>.
SbloodyS commented on code in PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#discussion_r1905107028


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java:
##########
@@ -2118,37 +2118,38 @@ protected void doBatchOperateWorkflowDefinition(User loginUser,
                 List<TaskDefinitionLog> taskDefinitionLogs =
                         taskDefinitionLogDao.queryTaskDefineLogList(workflowTaskRelations);
                 Map<Long, Long> taskCodeMap = new HashMap<>();
-                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                taskDefinitionLogs.forEach(taskDefinitionLog -> {
                     try {
-                        long taskCode = CodeGenerateUtils.genCode();
-                        taskCodeMap.put(taskDefinitionLog.getCode(), taskCode);
-                        taskDefinitionLog.setCode(taskCode);
-                        if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
-                            final String taskParams = taskDefinitionLog.getTaskParams();
-                            final SwitchParameters switchParameters =
-                                    JSONUtils.parseObject(taskParams, SwitchParameters.class);
-                            if (switchParameters == null) {
-                                throw new IllegalArgumentException(
-                                        "Switch task params: " + taskParams + " is invalid.");
-                            }
-                            SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
-                            switchResult.getDependTaskList().forEach(switchResultVo -> {
-                                switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
-                            });
-                            if (switchResult.getNextNode() != null) {
-                                switchResult.setNextNode(
-                                        taskCodeMap.get(switchResult.getNextNode()));
-                            }
-                            taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
-                        }
+                        taskCodeMap.put(taskDefinitionLog.getCode(), CodeGenerateUtils.genCode());
                     } catch (CodeGenerateException e) {
                         log.error("Generate task definition code error, projectCode:{}.", targetProjectCode, e);
                         putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS);
                         throw new ServiceException(Status.INTERNAL_SERVER_ERROR_ARGS);
                     }
+                });
+                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                    taskDefinitionLog.setCode(taskCodeMap.get(taskDefinitionLog.getCode()));
                     taskDefinitionLog.setProjectCode(targetProjectCode);
                     taskDefinitionLog.setVersion(0);
                     taskDefinitionLog.setName(taskDefinitionLog.getName());
+                    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
+                        final String taskParams = taskDefinitionLog.getTaskParams();
+                        final SwitchParameters switchParameters =
+                                JSONUtils.parseObject(taskParams, SwitchParameters.class);
+                        if (switchParameters == null) {
+                            throw new IllegalArgumentException(
+                                    "Switch task params: " + taskParams + " is invalid.");
+                        }
+                        SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
+                        switchResult.getDependTaskList().forEach(switchResultVo -> {
+                            switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
+                        });
+                        if (switchResult.getNextNode() != null) {
+                            switchResult.setNextNode(
+                                    taskCodeMap.get(switchResult.getNextNode()));
+                        }
+                        taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
+                    }

Review Comment:
   The commit shows it's not a display issue.
   https://github.com/apache/dolphinscheduler/blob/48304f2a6c20de7471739b8889c2d02c41eef17d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "SbloodyS (via GitHub)" <gi...@apache.org>.
SbloodyS merged PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "llllkid (via GitHub)" <gi...@apache.org>.
llllkid commented on code in PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#discussion_r1903949379


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java:
##########
@@ -2118,37 +2118,38 @@ protected void doBatchOperateWorkflowDefinition(User loginUser,
                 List<TaskDefinitionLog> taskDefinitionLogs =
                         taskDefinitionLogDao.queryTaskDefineLogList(workflowTaskRelations);
                 Map<Long, Long> taskCodeMap = new HashMap<>();
-                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                taskDefinitionLogs.forEach(taskDefinitionLog -> {
                     try {
-                        long taskCode = CodeGenerateUtils.genCode();
-                        taskCodeMap.put(taskDefinitionLog.getCode(), taskCode);
-                        taskDefinitionLog.setCode(taskCode);
-                        if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
-                            final String taskParams = taskDefinitionLog.getTaskParams();
-                            final SwitchParameters switchParameters =
-                                    JSONUtils.parseObject(taskParams, SwitchParameters.class);
-                            if (switchParameters == null) {
-                                throw new IllegalArgumentException(
-                                        "Switch task params: " + taskParams + " is invalid.");
-                            }
-                            SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
-                            switchResult.getDependTaskList().forEach(switchResultVo -> {
-                                switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
-                            });
-                            if (switchResult.getNextNode() != null) {
-                                switchResult.setNextNode(
-                                        taskCodeMap.get(switchResult.getNextNode()));
-                            }
-                            taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
-                        }
+                        taskCodeMap.put(taskDefinitionLog.getCode(), CodeGenerateUtils.genCode());
                     } catch (CodeGenerateException e) {
                         log.error("Generate task definition code error, projectCode:{}.", targetProjectCode, e);
                         putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS);
                         throw new ServiceException(Status.INTERNAL_SERVER_ERROR_ARGS);
                     }
+                });
+                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                    taskDefinitionLog.setCode(taskCodeMap.get(taskDefinitionLog.getCode()));
                     taskDefinitionLog.setProjectCode(targetProjectCode);
                     taskDefinitionLog.setVersion(0);
                     taskDefinitionLog.setName(taskDefinitionLog.getName());
+                    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
+                        final String taskParams = taskDefinitionLog.getTaskParams();
+                        final SwitchParameters switchParameters =
+                                JSONUtils.parseObject(taskParams, SwitchParameters.class);
+                        if (switchParameters == null) {
+                            throw new IllegalArgumentException(
+                                    "Switch task params: " + taskParams + " is invalid.");
+                        }
+                        SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
+                        switchResult.getDependTaskList().forEach(switchResultVo -> {
+                            switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
+                        });
+                        if (switchResult.getNextNode() != null) {
+                            switchResult.setNextNode(
+                                    taskCodeMap.get(switchResult.getNextNode()));
+                        }
+                        taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
+                    }

Review Comment:
   > Why move this code to here?
   
   I think this is git's display problem, 
   I don't move this code to here, 
   I added `taskDefinitionLogs.forEach` before `for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs)`, because we need put all taskDefinitionLog's new code into taskCodeMap before `taskDefinitionLog.setTaskParams`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "SbloodyS (via GitHub)" <gi...@apache.org>.
SbloodyS commented on code in PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#discussion_r1903684158


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java:
##########
@@ -2118,37 +2118,38 @@ protected void doBatchOperateWorkflowDefinition(User loginUser,
                 List<TaskDefinitionLog> taskDefinitionLogs =
                         taskDefinitionLogDao.queryTaskDefineLogList(workflowTaskRelations);
                 Map<Long, Long> taskCodeMap = new HashMap<>();
-                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                taskDefinitionLogs.forEach(taskDefinitionLog -> {
                     try {
-                        long taskCode = CodeGenerateUtils.genCode();
-                        taskCodeMap.put(taskDefinitionLog.getCode(), taskCode);
-                        taskDefinitionLog.setCode(taskCode);
-                        if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
-                            final String taskParams = taskDefinitionLog.getTaskParams();
-                            final SwitchParameters switchParameters =
-                                    JSONUtils.parseObject(taskParams, SwitchParameters.class);
-                            if (switchParameters == null) {
-                                throw new IllegalArgumentException(
-                                        "Switch task params: " + taskParams + " is invalid.");
-                            }
-                            SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
-                            switchResult.getDependTaskList().forEach(switchResultVo -> {
-                                switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
-                            });
-                            if (switchResult.getNextNode() != null) {
-                                switchResult.setNextNode(
-                                        taskCodeMap.get(switchResult.getNextNode()));
-                            }
-                            taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
-                        }
+                        taskCodeMap.put(taskDefinitionLog.getCode(), CodeGenerateUtils.genCode());
                     } catch (CodeGenerateException e) {
                         log.error("Generate task definition code error, projectCode:{}.", targetProjectCode, e);
                         putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS);
                         throw new ServiceException(Status.INTERNAL_SERVER_ERROR_ARGS);
                     }
+                });
+                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                    taskDefinitionLog.setCode(taskCodeMap.get(taskDefinitionLog.getCode()));
                     taskDefinitionLog.setProjectCode(targetProjectCode);
                     taskDefinitionLog.setVersion(0);
                     taskDefinitionLog.setName(taskDefinitionLog.getName());
+                    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
+                        final String taskParams = taskDefinitionLog.getTaskParams();
+                        final SwitchParameters switchParameters =
+                                JSONUtils.parseObject(taskParams, SwitchParameters.class);
+                        if (switchParameters == null) {
+                            throw new IllegalArgumentException(
+                                    "Switch task params: " + taskParams + " is invalid.");
+                        }
+                        SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
+                        switchResult.getDependTaskList().forEach(switchResultVo -> {
+                            switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
+                        });
+                        if (switchResult.getNextNode() != null) {
+                            switchResult.setNextNode(
+                                    taskCodeMap.get(switchResult.getNextNode()));
+                        }
+                        taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
+                    }

Review Comment:
   Why move this code to here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#issuecomment-2597542265

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=16939) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [73.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=16939&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=16939&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=16939)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#issuecomment-2567324677

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=16939) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [73.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=16939&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=16939&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=16939)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "llllkid (via GitHub)" <gi...@apache.org>.
llllkid commented on code in PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#discussion_r1905155817


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java:
##########
@@ -2118,37 +2118,38 @@ protected void doBatchOperateWorkflowDefinition(User loginUser,
                 List<TaskDefinitionLog> taskDefinitionLogs =
                         taskDefinitionLogDao.queryTaskDefineLogList(workflowTaskRelations);
                 Map<Long, Long> taskCodeMap = new HashMap<>();
-                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                taskDefinitionLogs.forEach(taskDefinitionLog -> {
                     try {
-                        long taskCode = CodeGenerateUtils.genCode();
-                        taskCodeMap.put(taskDefinitionLog.getCode(), taskCode);
-                        taskDefinitionLog.setCode(taskCode);
-                        if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
-                            final String taskParams = taskDefinitionLog.getTaskParams();
-                            final SwitchParameters switchParameters =
-                                    JSONUtils.parseObject(taskParams, SwitchParameters.class);
-                            if (switchParameters == null) {
-                                throw new IllegalArgumentException(
-                                        "Switch task params: " + taskParams + " is invalid.");
-                            }
-                            SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
-                            switchResult.getDependTaskList().forEach(switchResultVo -> {
-                                switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
-                            });
-                            if (switchResult.getNextNode() != null) {
-                                switchResult.setNextNode(
-                                        taskCodeMap.get(switchResult.getNextNode()));
-                            }
-                            taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
-                        }
+                        taskCodeMap.put(taskDefinitionLog.getCode(), CodeGenerateUtils.genCode());
                     } catch (CodeGenerateException e) {
                         log.error("Generate task definition code error, projectCode:{}.", targetProjectCode, e);
                         putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS);
                         throw new ServiceException(Status.INTERNAL_SERVER_ERROR_ARGS);
                     }
+                });
+                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                    taskDefinitionLog.setCode(taskCodeMap.get(taskDefinitionLog.getCode()));
                     taskDefinitionLog.setProjectCode(targetProjectCode);
                     taskDefinitionLog.setVersion(0);
                     taskDefinitionLog.setName(taskDefinitionLog.getName());
+                    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
+                        final String taskParams = taskDefinitionLog.getTaskParams();
+                        final SwitchParameters switchParameters =
+                                JSONUtils.parseObject(taskParams, SwitchParameters.class);
+                        if (switchParameters == null) {
+                            throw new IllegalArgumentException(
+                                    "Switch task params: " + taskParams + " is invalid.");
+                        }
+                        SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
+                        switchResult.getDependTaskList().forEach(switchResultVo -> {
+                            switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
+                        });
+                        if (switchResult.getNextNode() != null) {
+                            switchResult.setNextNode(
+                                    taskCodeMap.get(switchResult.getNextNode()));
+                        }
+                        taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
+                    }

Review Comment:
   > The commit shows it's not a display issue. https://github.com/apache/dolphinscheduler/blob/48304f2a6c20de7471739b8889c2d02c41eef17d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java
   
   I think I misunderstood your question.  
   Do you want to ask me why I move this code after `taskDefinitionLog.setName`?
   Because for better readability:
   ```
    taskDefinitionLog.setCode();
    taskDefinitionLog.setProjectCode();
    taskDefinitionLog.setVersion();
    taskDefinitionLog.setName(taskDefinitionLog.getName());
    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
   ...
         taskDefinitionLog.setTaskParams();
   ...
    }
   ```
   Is better than
   ```
    taskDefinitionLog.setCode();
    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
    ...
         taskDefinitionLog.setTaskParams();
    ...
    }
    taskDefinitionLog.setProjectCode();
    taskDefinitionLog.setVersion();
    taskDefinitionLog.setName(taskDefinitionLog.getName());
   
   ```
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#issuecomment-2597381403

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=16939) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [73.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=16939&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=16939&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=16939)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "llllkid (via GitHub)" <gi...@apache.org>.
llllkid commented on PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#issuecomment-2594958960

   @SbloodyS @caishunfeng @ruanwenjun PTAL


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "llllkid (via GitHub)" <gi...@apache.org>.
llllkid commented on PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#issuecomment-2568813930

   @SbloodyS @caishunfeng PTAL


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "SbloodyS (via GitHub)" <gi...@apache.org>.
SbloodyS commented on code in PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#discussion_r1919499909


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java:
##########
@@ -2118,37 +2118,38 @@ protected void doBatchOperateWorkflowDefinition(User loginUser,
                 List<TaskDefinitionLog> taskDefinitionLogs =
                         taskDefinitionLogDao.queryTaskDefineLogList(workflowTaskRelations);
                 Map<Long, Long> taskCodeMap = new HashMap<>();
-                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                taskDefinitionLogs.forEach(taskDefinitionLog -> {
                     try {
-                        long taskCode = CodeGenerateUtils.genCode();
-                        taskCodeMap.put(taskDefinitionLog.getCode(), taskCode);
-                        taskDefinitionLog.setCode(taskCode);
-                        if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
-                            final String taskParams = taskDefinitionLog.getTaskParams();
-                            final SwitchParameters switchParameters =
-                                    JSONUtils.parseObject(taskParams, SwitchParameters.class);
-                            if (switchParameters == null) {
-                                throw new IllegalArgumentException(
-                                        "Switch task params: " + taskParams + " is invalid.");
-                            }
-                            SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
-                            switchResult.getDependTaskList().forEach(switchResultVo -> {
-                                switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
-                            });
-                            if (switchResult.getNextNode() != null) {
-                                switchResult.setNextNode(
-                                        taskCodeMap.get(switchResult.getNextNode()));
-                            }
-                            taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
-                        }
+                        taskCodeMap.put(taskDefinitionLog.getCode(), CodeGenerateUtils.genCode());
                     } catch (CodeGenerateException e) {
                         log.error("Generate task definition code error, projectCode:{}.", targetProjectCode, e);
                         putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS);
                         throw new ServiceException(Status.INTERNAL_SERVER_ERROR_ARGS);
                     }
+                });
+                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                    taskDefinitionLog.setCode(taskCodeMap.get(taskDefinitionLog.getCode()));
                     taskDefinitionLog.setProjectCode(targetProjectCode);
                     taskDefinitionLog.setVersion(0);
                     taskDefinitionLog.setName(taskDefinitionLog.getName());
+                    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
+                        final String taskParams = taskDefinitionLog.getTaskParams();
+                        final SwitchParameters switchParameters =
+                                JSONUtils.parseObject(taskParams, SwitchParameters.class);
+                        if (switchParameters == null) {
+                            throw new IllegalArgumentException(
+                                    "Switch task params: " + taskParams + " is invalid.");
+                        }
+                        SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
+                        switchResult.getDependTaskList().forEach(switchResultVo -> {
+                            switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
+                        });
+                        if (switchResult.getNextNode() != null) {
+                            switchResult.setNextNode(
+                                    taskCodeMap.get(switchResult.getNextNode()));
+                        }
+                        taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
+                    }

Review Comment:
   Thanks for clarification.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "llllkid (via GitHub)" <gi...@apache.org>.
llllkid commented on code in PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#discussion_r1903949379


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java:
##########
@@ -2118,37 +2118,38 @@ protected void doBatchOperateWorkflowDefinition(User loginUser,
                 List<TaskDefinitionLog> taskDefinitionLogs =
                         taskDefinitionLogDao.queryTaskDefineLogList(workflowTaskRelations);
                 Map<Long, Long> taskCodeMap = new HashMap<>();
-                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                taskDefinitionLogs.forEach(taskDefinitionLog -> {
                     try {
-                        long taskCode = CodeGenerateUtils.genCode();
-                        taskCodeMap.put(taskDefinitionLog.getCode(), taskCode);
-                        taskDefinitionLog.setCode(taskCode);
-                        if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
-                            final String taskParams = taskDefinitionLog.getTaskParams();
-                            final SwitchParameters switchParameters =
-                                    JSONUtils.parseObject(taskParams, SwitchParameters.class);
-                            if (switchParameters == null) {
-                                throw new IllegalArgumentException(
-                                        "Switch task params: " + taskParams + " is invalid.");
-                            }
-                            SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
-                            switchResult.getDependTaskList().forEach(switchResultVo -> {
-                                switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
-                            });
-                            if (switchResult.getNextNode() != null) {
-                                switchResult.setNextNode(
-                                        taskCodeMap.get(switchResult.getNextNode()));
-                            }
-                            taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
-                        }
+                        taskCodeMap.put(taskDefinitionLog.getCode(), CodeGenerateUtils.genCode());
                     } catch (CodeGenerateException e) {
                         log.error("Generate task definition code error, projectCode:{}.", targetProjectCode, e);
                         putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS);
                         throw new ServiceException(Status.INTERNAL_SERVER_ERROR_ARGS);
                     }
+                });
+                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                    taskDefinitionLog.setCode(taskCodeMap.get(taskDefinitionLog.getCode()));
                     taskDefinitionLog.setProjectCode(targetProjectCode);
                     taskDefinitionLog.setVersion(0);
                     taskDefinitionLog.setName(taskDefinitionLog.getName());
+                    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
+                        final String taskParams = taskDefinitionLog.getTaskParams();
+                        final SwitchParameters switchParameters =
+                                JSONUtils.parseObject(taskParams, SwitchParameters.class);
+                        if (switchParameters == null) {
+                            throw new IllegalArgumentException(
+                                    "Switch task params: " + taskParams + " is invalid.");
+                        }
+                        SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
+                        switchResult.getDependTaskList().forEach(switchResultVo -> {
+                            switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
+                        });
+                        if (switchResult.getNextNode() != null) {
+                            switchResult.setNextNode(
+                                    taskCodeMap.get(switchResult.getNextNode()));
+                        }
+                        taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
+                    }

Review Comment:
   > Why move this code to here?
   
   I think this is git's display problem, 
   I don't move this code to here, 
   I added `taskDefinitionLogs.forEach` before `for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs)`, because we need put all new code into taskCodeMap before `taskDefinitionLog.setTaskParams`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#issuecomment-2567325000

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=16939) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [73.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=16939&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=16939&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=16939)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#issuecomment-2572243280

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=16939) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [73.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=16939&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=16939&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=16939)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "llllkid (via GitHub)" <gi...@apache.org>.
llllkid commented on code in PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#discussion_r1905155817


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java:
##########
@@ -2118,37 +2118,38 @@ protected void doBatchOperateWorkflowDefinition(User loginUser,
                 List<TaskDefinitionLog> taskDefinitionLogs =
                         taskDefinitionLogDao.queryTaskDefineLogList(workflowTaskRelations);
                 Map<Long, Long> taskCodeMap = new HashMap<>();
-                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                taskDefinitionLogs.forEach(taskDefinitionLog -> {
                     try {
-                        long taskCode = CodeGenerateUtils.genCode();
-                        taskCodeMap.put(taskDefinitionLog.getCode(), taskCode);
-                        taskDefinitionLog.setCode(taskCode);
-                        if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
-                            final String taskParams = taskDefinitionLog.getTaskParams();
-                            final SwitchParameters switchParameters =
-                                    JSONUtils.parseObject(taskParams, SwitchParameters.class);
-                            if (switchParameters == null) {
-                                throw new IllegalArgumentException(
-                                        "Switch task params: " + taskParams + " is invalid.");
-                            }
-                            SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
-                            switchResult.getDependTaskList().forEach(switchResultVo -> {
-                                switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
-                            });
-                            if (switchResult.getNextNode() != null) {
-                                switchResult.setNextNode(
-                                        taskCodeMap.get(switchResult.getNextNode()));
-                            }
-                            taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
-                        }
+                        taskCodeMap.put(taskDefinitionLog.getCode(), CodeGenerateUtils.genCode());
                     } catch (CodeGenerateException e) {
                         log.error("Generate task definition code error, projectCode:{}.", targetProjectCode, e);
                         putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS);
                         throw new ServiceException(Status.INTERNAL_SERVER_ERROR_ARGS);
                     }
+                });
+                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                    taskDefinitionLog.setCode(taskCodeMap.get(taskDefinitionLog.getCode()));
                     taskDefinitionLog.setProjectCode(targetProjectCode);
                     taskDefinitionLog.setVersion(0);
                     taskDefinitionLog.setName(taskDefinitionLog.getName());
+                    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
+                        final String taskParams = taskDefinitionLog.getTaskParams();
+                        final SwitchParameters switchParameters =
+                                JSONUtils.parseObject(taskParams, SwitchParameters.class);
+                        if (switchParameters == null) {
+                            throw new IllegalArgumentException(
+                                    "Switch task params: " + taskParams + " is invalid.");
+                        }
+                        SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
+                        switchResult.getDependTaskList().forEach(switchResultVo -> {
+                            switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
+                        });
+                        if (switchResult.getNextNode() != null) {
+                            switchResult.setNextNode(
+                                    taskCodeMap.get(switchResult.getNextNode()));
+                        }
+                        taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
+                    }

Review Comment:
   > The commit shows it's not a display issue. https://github.com/apache/dolphinscheduler/blob/48304f2a6c20de7471739b8889c2d02c41eef17d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java
   
   I think I misunderstood your question.  
   Do you want to ask me why I move this code after `taskDefinitionLog.setName`?
   Because for better readability:
   ```
    taskDefinitionLog.setCode();
    taskDefinitionLog.setProjectCode();
    taskDefinitionLog.setVersion();
    taskDefinitionLog.setName(taskDefinitionLog.getName());
    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
    ...
         taskDefinitionLog.setTaskParams();
    ...
    }
   ```
   Is better than
   ```
    taskDefinitionLog.setCode();
    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
    ...
         taskDefinitionLog.setTaskParams();
    ...
    }
    taskDefinitionLog.setProjectCode();
    taskDefinitionLog.setVersion();
    taskDefinitionLog.setName(taskDefinitionLog.getName());
   
   ```
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "llllkid (via GitHub)" <gi...@apache.org>.
llllkid commented on code in PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#discussion_r1905155817


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java:
##########
@@ -2118,37 +2118,38 @@ protected void doBatchOperateWorkflowDefinition(User loginUser,
                 List<TaskDefinitionLog> taskDefinitionLogs =
                         taskDefinitionLogDao.queryTaskDefineLogList(workflowTaskRelations);
                 Map<Long, Long> taskCodeMap = new HashMap<>();
-                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                taskDefinitionLogs.forEach(taskDefinitionLog -> {
                     try {
-                        long taskCode = CodeGenerateUtils.genCode();
-                        taskCodeMap.put(taskDefinitionLog.getCode(), taskCode);
-                        taskDefinitionLog.setCode(taskCode);
-                        if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
-                            final String taskParams = taskDefinitionLog.getTaskParams();
-                            final SwitchParameters switchParameters =
-                                    JSONUtils.parseObject(taskParams, SwitchParameters.class);
-                            if (switchParameters == null) {
-                                throw new IllegalArgumentException(
-                                        "Switch task params: " + taskParams + " is invalid.");
-                            }
-                            SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
-                            switchResult.getDependTaskList().forEach(switchResultVo -> {
-                                switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
-                            });
-                            if (switchResult.getNextNode() != null) {
-                                switchResult.setNextNode(
-                                        taskCodeMap.get(switchResult.getNextNode()));
-                            }
-                            taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
-                        }
+                        taskCodeMap.put(taskDefinitionLog.getCode(), CodeGenerateUtils.genCode());
                     } catch (CodeGenerateException e) {
                         log.error("Generate task definition code error, projectCode:{}.", targetProjectCode, e);
                         putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS);
                         throw new ServiceException(Status.INTERNAL_SERVER_ERROR_ARGS);
                     }
+                });
+                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                    taskDefinitionLog.setCode(taskCodeMap.get(taskDefinitionLog.getCode()));
                     taskDefinitionLog.setProjectCode(targetProjectCode);
                     taskDefinitionLog.setVersion(0);
                     taskDefinitionLog.setName(taskDefinitionLog.getName());
+                    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
+                        final String taskParams = taskDefinitionLog.getTaskParams();
+                        final SwitchParameters switchParameters =
+                                JSONUtils.parseObject(taskParams, SwitchParameters.class);
+                        if (switchParameters == null) {
+                            throw new IllegalArgumentException(
+                                    "Switch task params: " + taskParams + " is invalid.");
+                        }
+                        SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
+                        switchResult.getDependTaskList().forEach(switchResultVo -> {
+                            switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
+                        });
+                        if (switchResult.getNextNode() != null) {
+                            switchResult.setNextNode(
+                                    taskCodeMap.get(switchResult.getNextNode()));
+                        }
+                        taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
+                    }

Review Comment:
   > The commit shows it's not a display issue. https://github.com/apache/dolphinscheduler/blob/48304f2a6c20de7471739b8889c2d02c41eef17d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java
   
   I think I misunderstood your question.  
   Do you want to ask me why I move this code after `taskDefinitionLog.setName`?
   Because for better readability:
   ```
    taskDefinitionLog.setCode();
    taskDefinitionLog.setProjectCode();
    taskDefinitionLog.setVersion();
    taskDefinitionLog.setName();
    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
    ...
         taskDefinitionLog.setTaskParams();
    ...
    }
   ```
   Is better than
   ```
    taskDefinitionLog.setCode();
    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
    ...
         taskDefinitionLog.setTaskParams();
    ...
    }
    taskDefinitionLog.setProjectCode();
    taskDefinitionLog.setVersion();
    taskDefinitionLog.setName(taskDefinitionLog.getName());
   
   ```
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "llllkid (via GitHub)" <gi...@apache.org>.
llllkid commented on code in PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#discussion_r1905155817


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java:
##########
@@ -2118,37 +2118,38 @@ protected void doBatchOperateWorkflowDefinition(User loginUser,
                 List<TaskDefinitionLog> taskDefinitionLogs =
                         taskDefinitionLogDao.queryTaskDefineLogList(workflowTaskRelations);
                 Map<Long, Long> taskCodeMap = new HashMap<>();
-                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                taskDefinitionLogs.forEach(taskDefinitionLog -> {
                     try {
-                        long taskCode = CodeGenerateUtils.genCode();
-                        taskCodeMap.put(taskDefinitionLog.getCode(), taskCode);
-                        taskDefinitionLog.setCode(taskCode);
-                        if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
-                            final String taskParams = taskDefinitionLog.getTaskParams();
-                            final SwitchParameters switchParameters =
-                                    JSONUtils.parseObject(taskParams, SwitchParameters.class);
-                            if (switchParameters == null) {
-                                throw new IllegalArgumentException(
-                                        "Switch task params: " + taskParams + " is invalid.");
-                            }
-                            SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
-                            switchResult.getDependTaskList().forEach(switchResultVo -> {
-                                switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
-                            });
-                            if (switchResult.getNextNode() != null) {
-                                switchResult.setNextNode(
-                                        taskCodeMap.get(switchResult.getNextNode()));
-                            }
-                            taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
-                        }
+                        taskCodeMap.put(taskDefinitionLog.getCode(), CodeGenerateUtils.genCode());
                     } catch (CodeGenerateException e) {
                         log.error("Generate task definition code error, projectCode:{}.", targetProjectCode, e);
                         putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS);
                         throw new ServiceException(Status.INTERNAL_SERVER_ERROR_ARGS);
                     }
+                });
+                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) {
+                    taskDefinitionLog.setCode(taskCodeMap.get(taskDefinitionLog.getCode()));
                     taskDefinitionLog.setProjectCode(targetProjectCode);
                     taskDefinitionLog.setVersion(0);
                     taskDefinitionLog.setName(taskDefinitionLog.getName());
+                    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
+                        final String taskParams = taskDefinitionLog.getTaskParams();
+                        final SwitchParameters switchParameters =
+                                JSONUtils.parseObject(taskParams, SwitchParameters.class);
+                        if (switchParameters == null) {
+                            throw new IllegalArgumentException(
+                                    "Switch task params: " + taskParams + " is invalid.");
+                        }
+                        SwitchParameters.SwitchResult switchResult = switchParameters.getSwitchResult();
+                        switchResult.getDependTaskList().forEach(switchResultVo -> {
+                            switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
+                        });
+                        if (switchResult.getNextNode() != null) {
+                            switchResult.setNextNode(
+                                    taskCodeMap.get(switchResult.getNextNode()));
+                        }
+                        taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
+                    }

Review Comment:
   > The commit shows it's not a display issue. https://github.com/apache/dolphinscheduler/blob/48304f2a6c20de7471739b8889c2d02c41eef17d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java
   
   I think I misunderstood your question.  
   Do you want to ask me why I move this code after `taskDefinitionLog.setName`?
   Because for better readability:
   ```
    taskDefinitionLog.setCode();
    taskDefinitionLog.setProjectCode();
    taskDefinitionLog.setVersion();
    taskDefinitionLog.setName();
    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
    ...
         taskDefinitionLog.setTaskParams();
    ...
    }
   ```
   Is better than
   ```
    taskDefinitionLog.setCode();
    if (TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
    ...
         taskDefinitionLog.setTaskParams();
    ...
    }
    taskDefinitionLog.setProjectCode();
    taskDefinitionLog.setVersion();
    taskDefinitionLog.setName();
   
   ```
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix-16934][api] When creating workflows containing switch nodes in different orders, the copied workflows may lose associations. [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #16939:
URL: https://github.com/apache/dolphinscheduler/pull/16939#issuecomment-2572243190

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=16939) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=16939&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [73.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=16939&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=16939&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=16939)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org