From 0963640ea7a96b3fb4274ad702332fe50f1b3a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=92=E5=B9=B4?= <1043706593@qq.com> Date: Tue, 19 Jan 2021 23:03:13 +0800 Subject: [PATCH] [Improvement-#4481][API] ProcessDefinitionController save API optimization Co-authored-by: lei.zou --- .../impl/ProcessDefinitionServiceImpl.java | 42 ++----------------- .../ProcessDefinitionControllerTest.java | 2 +- 2 files changed, 4 insertions(+), 40 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java index 245d33bb19..52385dd00f 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java @@ -221,9 +221,8 @@ public class ProcessDefinitionServiceImpl extends BaseService implements processDefineMapper.updateVersionByProcessDefinitionId(processDefine.getId(), version); // return processDefinition object with ID - result.put(Constants.DATA_LIST, processDefineMapper.selectById(processDefine.getId())); + result.put(Constants.DATA_LIST, processDefine.getId()); putMsg(result, Status.SUCCESS); - result.put(PROCESSDEFINITIONID, processDefine.getId()); return result; } @@ -888,8 +887,8 @@ public class ProcessDefinitionServiceImpl extends BaseService implements //create process definition Integer processDefinitionId = - Objects.isNull(createProcessResult.get(PROCESSDEFINITIONID)) - ? null : Integer.parseInt(createProcessResult.get(PROCESSDEFINITIONID).toString()); + Objects.isNull(createProcessResult.get(Constants.DATA_LIST)) + ? null : Integer.parseInt(createProcessResult.get(Constants.DATA_LIST).toString()); //scheduler param return getImportProcessScheduleResult(loginUser, @@ -1516,41 +1515,6 @@ public class ProcessDefinitionServiceImpl extends BaseService implements } } - /** - * copy process definition - * - * @param loginUser login user - * @param projectName project name - * @param processId process definition id - * @return copy result code - */ - public Map copyProcessDefinition(User loginUser, String projectName, Integer processId) { - - Map result = new HashMap<>(5); - Project project = projectMapper.queryByName(projectName); - - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status resultStatus = (Status) checkResult.get(Constants.STATUS); - if (resultStatus != Status.SUCCESS) { - return checkResult; - } - - ProcessDefinition processDefinition = processDefineMapper.selectById(processId); - if (processDefinition == null) { - putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processId); - return result; - } else { - return createProcessDefinition( - loginUser, - projectName, - processDefinition.getName() + "_copy_" + System.currentTimeMillis(), - processDefinition.getProcessDefinitionJson(), - processDefinition.getDescription(), - processDefinition.getLocations(), - processDefinition.getConnects()); - } - } - /** * batch copy process definition * diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java index a13afecb0d..662c45d7ac 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java @@ -94,7 +94,7 @@ public class ProcessDefinitionControllerTest { String connects = "[]"; Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); - result.put("processDefinitionId", 1); + result.put(Constants.DATA_LIST, 1); Mockito.when(processDefinitionService.createProcessDefinition(user, projectName, name, json, description, locations, connects)).thenReturn(result);