simon824 commented on a change in pull request #4654:
URL: 
https://github.com/apache/incubator-dolphinscheduler/pull/4654#discussion_r568455134



##########
File path: 
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java
##########
@@ -204,5 +211,188 @@ private String getResourceIds(TaskDefinition 
taskDefinition) {
         return result;
     }
 
+    /**
+     * delete task definition
+     *
+     * @param loginUser login user
+     * @param projectName project name
+     * @param taskCode task code
+     */
+    @Transactional(rollbackFor = RuntimeException.class)
+    @Override
+    public Map<String, Object> deleteTaskDefinitionByCode(User loginUser, 
String projectName, Long taskCode) {
+        Map<String, Object> result = new HashMap<>(5);
+        Project project = projectMapper.queryByName(projectName);
+
+        Map<String, Object> checkResult = 
projectService.checkProjectAndAuth(loginUser, project, projectName);
+        Status resultEnum = (Status) checkResult.get(Constants.STATUS);
+        if (resultEnum != Status.SUCCESS) {
+            return checkResult;
+        }
+        checkTaskRelation(result, taskCode);
+        resultEnum = (Status) result.get(Constants.STATUS);
+        if (resultEnum != Status.SUCCESS) {
+            return result;
+        }
+        int delete = taskDefinitionMapper.deleteByCode(taskCode);
+        if (delete > 0) {
+            putMsg(result, Status.SUCCESS);
+        } else {
+            putMsg(result, Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR);
+        }
+        return result;
+    }
+
+    /**
+     * update task definition
+     *
+     * @param loginUser login user
+     * @param projectName project name
+     * @param taskCode task code
+     * @param taskDefinitionJson task definition json
+     */
+    @Override
+    public Map<String, Object> updateTaskDefinition(User loginUser, String 
projectName, Long taskCode, String taskDefinitionJson) {
+        Map<String, Object> result = new HashMap<>(5);
+        Project project = projectMapper.queryByName(projectName);
+
+        Map<String, Object> checkResult = 
projectService.checkProjectAndAuth(loginUser, project, projectName);
+        Status resultEnum = (Status) checkResult.get(Constants.STATUS);
+        if (resultEnum != Status.SUCCESS) {
+            return checkResult;
+        }
+        checkTaskRelation(result, taskCode);
+        if (result.get(Constants.STATUS) != Status.SUCCESS) {
+            return result;
+        }
+        TaskDefinition taskDefinition = 
taskDefinitionMapper.queryByDefinitionCode(taskCode);
+        if (taskDefinition == null) {
+            putMsg(result, Status.TASK_DEFINE_NOT_EXIST, taskCode);
+            return result;
+        }
+        TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, 
TaskNode.class);
+        checkTaskNode(result, taskNode, taskDefinitionJson);
+        if (result.get(Constants.STATUS) != Status.SUCCESS) {
+            return result;
+        }
+
+        List<TaskDefinitionLog> taskDefinitionLogs = 
taskDefinitionLogMapper.queryByDefinitionCode(taskCode);
+        int version = taskDefinitionLogs
+                .stream()
+                .map(TaskDefinitionLog::getVersion)
+                .max((x, y) -> x > y ? x : y)
+                .orElse(0) + 1;
+        Date now = new Date();
+        taskDefinition.setVersion(version);
+        taskDefinition.setCode(taskCode);
+        taskDefinition.setName(taskNode.getName());
+        taskDefinition.setDescription(taskNode.getDesc());
+        taskDefinition.setProjectCode(project.getCode());
+        taskDefinition.setUserId(loginUser.getId());
+        taskDefinition.setTaskType(TaskType.of(taskNode.getType()));
+        taskDefinition.setTaskParams(taskNode.getParams());
+        taskDefinition.setFlag(taskNode.isForbidden() ? Flag.NO : Flag.YES);
+        taskDefinition.setTaskPriority(taskNode.getTaskInstancePriority());
+        taskDefinition.setWorkerGroup(taskNode.getWorkerGroup());
+        taskDefinition.setFailRetryTimes(taskNode.getMaxRetryTimes());
+        taskDefinition.setFailRetryInterval(taskNode.getRetryInterval());
+        
taskDefinition.setTimeoutFlag(taskNode.getTaskTimeoutParameter().getEnable() ? 
TimeoutFlag.OPEN : TimeoutFlag.CLOSE);
+        
taskDefinition.setTaskTimeoutStrategy(taskNode.getTaskTimeoutParameter().getStrategy());
+        
taskDefinition.setTimeout(taskNode.getTaskTimeoutParameter().getInterval());
+        taskDefinition.setUpdateTime(now);
+        taskDefinition.setResourceIds(getResourceIds(taskDefinition));
+        taskDefinitionMapper.updateById(taskDefinition);

Review comment:
       missing setId or updateByCode 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