ruanwenjun commented on code in PR #13023:
URL: 
https://github.com/apache/dolphinscheduler/pull/13023#discussion_r1036621194


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java:
##########
@@ -812,78 +811,89 @@ public Map<String, Object> updateTaskWithUpstream(User 
loginUser, long projectCo
         if (result.get(Constants.STATUS) != Status.SUCCESS && 
taskDefinitionToUpdate == null) {
             return result;
         }
+        // get sourceUpstreamTaskCodeSet
         List<ProcessTaskRelation> upstreamTaskRelations =
                 processTaskRelationMapper.queryUpstreamByCode(projectCode, 
taskCode);
-        Set<Long> upstreamCodeSet =
+        Set<Long> sourceUpstreamCodeSet =
                 
upstreamTaskRelations.stream().map(ProcessTaskRelation::getPreTaskCode).collect(Collectors.toSet());
-        Set<Long> upstreamTaskCodes = Collections.emptySet();
-        if (StringUtils.isNotEmpty(upstreamCodes)) {
-            upstreamTaskCodes = 
Arrays.stream(upstreamCodes.split(Constants.COMMA)).map(Long::parseLong)
-                    .collect(Collectors.toSet());
-        }
-        if (CollectionUtils.isEqualCollection(upstreamCodeSet, 
upstreamTaskCodes) && taskDefinitionToUpdate == null) {
+        // get updateUpstreamTaskCodeSet
+        Set<Long> updateUpstreamTaskCodeSet = getTaskCodeSet(upstreamCodes, 
result);
+
+        if (CollectionUtils.isEqualCollection(sourceUpstreamCodeSet, 
updateUpstreamTaskCodeSet)
+                && taskDefinitionToUpdate == null) {
             putMsg(result, Status.SUCCESS);
             return result;
-        } else {
-            if (taskDefinitionToUpdate == null) {
-                taskDefinitionToUpdate = 
JSONUtils.parseObject(taskDefinitionJsonObj, TaskDefinitionLog.class);
-            }
+        } else if (taskDefinitionToUpdate == null) {
+            taskDefinitionToUpdate = 
JSONUtils.parseObject(taskDefinitionJsonObj, TaskDefinitionLog.class);
         }
-        Map<Long, TaskDefinition> queryUpStreamTaskCodeMap;
-        if (CollectionUtils.isNotEmpty(upstreamTaskCodes)) {
-            List<TaskDefinition> upstreamTaskDefinitionList = 
taskDefinitionMapper.queryByCodeList(upstreamTaskCodes);
-            queryUpStreamTaskCodeMap = upstreamTaskDefinitionList.stream()
-                    .collect(Collectors.toMap(TaskDefinition::getCode, 
taskDefinition -> taskDefinition));
-            // upstreamTaskCodes - queryUpStreamTaskCodeMap.keySet
-            upstreamTaskCodes.removeAll(queryUpStreamTaskCodeMap.keySet());
-            if (CollectionUtils.isNotEmpty(upstreamTaskCodes)) {
-                String notExistTaskCodes = StringUtils.join(upstreamTaskCodes, 
Constants.COMMA);
-                logger.error("Some task definitions in parameter 
upstreamTaskCodes do not exist, notExistTaskCodes:{}.",
-                        notExistTaskCodes);
-                putMsg(result, Status.TASK_DEFINE_NOT_EXIST, 
notExistTaskCodes);
-                return result;
-            }
-        } else {
-            queryUpStreamTaskCodeMap = new HashMap<>();
+        // get survive updateUpstreamTask
+        getUpdateUpstreamTaskCodeMap(updateUpstreamTaskCodeSet, result);
+        if (result.get(Constants.STATUS) != Status.SUCCESS) {
+            return result;
         }
-        if (CollectionUtils.isNotEmpty(upstreamTaskCodes)) {
+        // update log
+        if (CollectionUtils.isNotEmpty(updateUpstreamTaskCodeSet)) {
             ProcessTaskRelation taskRelation = upstreamTaskRelations.get(0);
             List<ProcessTaskRelation> processTaskRelations =
                     processTaskRelationMapper.queryByProcessCode(projectCode, 
taskRelation.getProcessDefinitionCode());
-            List<ProcessTaskRelation> processTaskRelationList = 
Lists.newArrayList(processTaskRelations);

Review Comment:
   It has been used in below `for loop`.



-- 
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: [email protected]

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

Reply via email to