lenboo commented on a change in pull request #4555:
URL: 
https://github.com/apache/incubator-dolphinscheduler/pull/4555#discussion_r564364051



##########
File path: 
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java
##########
@@ -1990,4 +1992,57 @@ public String formatTaskAppId(TaskInstance taskInstance) 
{
             taskInstance.getId());
     }
 
+    /**
+     * solve the branch rename bug
+     *
+     * @param processData
+     * @param oldProcessData
+     * @return String
+     */
+    public String changeJson(ProcessData processData, ProcessData 
oldProcessData) {
+        HashMap<String, String> oldNameTaskId = new HashMap<>();
+        List<TaskNode> oldTasks = oldProcessData.getTasks();
+        for (int i = 0; i < oldTasks.size(); i++) {
+            TaskNode taskNode = oldTasks.get(i);
+            String oldName = taskNode.getName();
+            String oldId = taskNode.getId();
+            oldNameTaskId.put(oldName, oldId);
+        }
+
+        // take the processdefinitionjson saved this time, and then save the 
taskid and name
+        HashMap<String, String> newNameTaskId = new HashMap<>();
+        List<TaskNode> newTasks = processData.getTasks();
+        for (int i = 0; i < newTasks.size(); i++) {
+            TaskNode taskNode = newTasks.get(i);
+            String newId = taskNode.getId();
+            String newName = taskNode.getName();
+            newNameTaskId.put(newId, newName);
+        }
+
+        // replace the previous conditionresult with a new one
+        List<TaskNode> tasks = processData.getTasks();
+        for (int i = 0; i < tasks.size(); i++) {
+            TaskNode taskNode = newTasks.get(i);
+            String type = taskNode.getType().toLowerCase();
+            if (TaskType.CONDITIONS.getDescp().equals(type)) {
+                ConditionsParameters conditionsParameters = 
JSONUtils.parseObject(taskNode.getConditionResult(), 
ConditionsParameters.class);
+                String oldSuccessNodeName = 
conditionsParameters.getSuccessNode().get(0);
+                String oldFailedNodeName = 
conditionsParameters.getFailedNode().get(0);
+                String newSuccessNodeName = 
newNameTaskId.getOrDefault(oldNameTaskId.get(oldSuccessNodeName), "");
+                String newFailedNodeName = 
newNameTaskId.getOrDefault(oldNameTaskId.get(oldFailedNodeName), "");
+                if (!"".equals(newSuccessNodeName) || 
!"".equals(newFailedNodeName)) {
+                    ArrayList<String> successNode = new ArrayList<>();
+                    successNode.add("\"" + newSuccessNodeName + "\"");

Review comment:
       i think it do not need "\"" here

##########
File path: 
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java
##########
@@ -1990,4 +1992,57 @@ public String formatTaskAppId(TaskInstance taskInstance) 
{
             taskInstance.getId());
     }
 
+    /**
+     * solve the branch rename bug
+     *
+     * @param processData
+     * @param oldProcessData
+     * @return String
+     */
+    public String changeJson(ProcessData processData, ProcessData 
oldProcessData) {
+        HashMap<String, String> oldNameTaskId = new HashMap<>();
+        List<TaskNode> oldTasks = oldProcessData.getTasks();
+        for (int i = 0; i < oldTasks.size(); i++) {
+            TaskNode taskNode = oldTasks.get(i);
+            String oldName = taskNode.getName();
+            String oldId = taskNode.getId();
+            oldNameTaskId.put(oldName, oldId);
+        }
+
+        // take the processdefinitionjson saved this time, and then save the 
taskid and name
+        HashMap<String, String> newNameTaskId = new HashMap<>();
+        List<TaskNode> newTasks = processData.getTasks();
+        for (int i = 0; i < newTasks.size(); i++) {
+            TaskNode taskNode = newTasks.get(i);
+            String newId = taskNode.getId();
+            String newName = taskNode.getName();
+            newNameTaskId.put(newId, newName);
+        }
+
+        // replace the previous conditionresult with a new one
+        List<TaskNode> tasks = processData.getTasks();
+        for (int i = 0; i < tasks.size(); i++) {
+            TaskNode taskNode = newTasks.get(i);
+            String type = taskNode.getType().toLowerCase();
+            if (TaskType.CONDITIONS.getDescp().equals(type)) {
+                ConditionsParameters conditionsParameters = 
JSONUtils.parseObject(taskNode.getConditionResult(), 
ConditionsParameters.class);
+                String oldSuccessNodeName = 
conditionsParameters.getSuccessNode().get(0);
+                String oldFailedNodeName = 
conditionsParameters.getFailedNode().get(0);
+                String newSuccessNodeName = 
newNameTaskId.getOrDefault(oldNameTaskId.get(oldSuccessNodeName), "");
+                String newFailedNodeName = 
newNameTaskId.getOrDefault(oldNameTaskId.get(oldFailedNodeName), "");
+                if (!"".equals(newSuccessNodeName) || 
!"".equals(newFailedNodeName)) {
+                    ArrayList<String> successNode = new ArrayList<>();
+                    successNode.add("\"" + newSuccessNodeName + "\"");

Review comment:
       i think it do not need '"\""' 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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to