From c590ad43d7826a2c441801d71ee07ba284cfb042 Mon Sep 17 00:00:00 2001 From: calvin Date: Thu, 24 Feb 2022 08:50:03 +0800 Subject: [PATCH] fix this issue (#8509) --- .../impl/TaskDefinitionServiceImpl.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java index e722210688..f5ba6296ba 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java @@ -202,6 +202,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe return result; } } + List processTaskRelationLogList = Lists.newArrayList(); if (StringUtils.isNotBlank(upstreamCodes)) { Set upstreamTaskCodes = Arrays.stream(upstreamCodes.split(Constants.COMMA)).map(Long::parseLong).collect(Collectors.toSet()); List upstreamTaskDefinitionList = taskDefinitionMapper.queryByCodeList(upstreamTaskCodes); @@ -212,7 +213,6 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe putMsg(result, Status.TASK_DEFINE_NOT_EXIST, StringUtils.join(diffCode, Constants.COMMA)); return result; } - List processTaskRelationLogList = Lists.newArrayList(); for (TaskDefinition upstreamTask : upstreamTaskDefinitionList) { ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(); processTaskRelationLog.setPreTaskCode(upstreamTask.getCode()); @@ -227,13 +227,23 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe if (!processTaskRelationList.isEmpty()) { processTaskRelationLogList.addAll(processTaskRelationList.stream().map(ProcessTaskRelationLog::new).collect(Collectors.toList())); } - int insertResult = processService.saveTaskRelation(loginUser, projectCode, processDefinition.getCode(), processDefinition.getVersion(), - processTaskRelationLogList, Lists.newArrayList(), Boolean.TRUE); - if (insertResult != Constants.EXIT_CODE_SUCCESS) { - putMsg(result, Status.CREATE_PROCESS_TASK_RELATION_ERROR); - throw new ServiceException(Status.CREATE_PROCESS_TASK_RELATION_ERROR); - } + } else { + ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(); + processTaskRelationLog.setPreTaskCode(0); + processTaskRelationLog.setPreTaskVersion(0); + processTaskRelationLog.setPostTaskCode(taskCode); + processTaskRelationLog.setPostTaskVersion(Constants.VERSION_FIRST); + processTaskRelationLog.setConditionType(ConditionType.NONE); + processTaskRelationLog.setConditionParams("{}"); + processTaskRelationLogList.add(processTaskRelationLog); + } + int insertResult = processService.saveTaskRelation(loginUser, projectCode, processDefinition.getCode(), processDefinition.getVersion(), + processTaskRelationLogList, Lists.newArrayList(), Boolean.TRUE); + if (insertResult != Constants.EXIT_CODE_SUCCESS) { + putMsg(result, Status.CREATE_PROCESS_TASK_RELATION_ERROR); + throw new ServiceException(Status.CREATE_PROCESS_TASK_RELATION_ERROR); } + int saveTaskResult = processService.saveTaskDefine(loginUser, projectCode, Lists.newArrayList(taskDefinition), Boolean.TRUE); if (saveTaskResult == Constants.DEFINITION_FAILURE) { putMsg(result, Status.CREATE_TASK_DEFINITION_ERROR);