This is an automated email from the ASF dual-hosted git repository.

wenhemin pushed a commit to branch json_split_two
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/json_split_two by this push:
     new d382a7b  [Fix-5509]: createSchedule interface, process definition id 
-> process definition code (#5756)
d382a7b is described below

commit d382a7ba8c454b41944958c6e42692843a765234
Author: wen-hemin <[email protected]>
AuthorDate: Wed Jul 7 14:01:02 2021 +0800

    [Fix-5509]: createSchedule interface, process definition id -> process 
definition code (#5756)
    
    * fix: createSchedule interface, process definition id -> process 
definition code
    
    * fix: add junit
    
    * fix junit
    
    * fix: projectName -> projectCode
    
    * fix UT
    
    * Optimize variable type
    
    Co-authored-by: wen-hemin <[email protected]>
---
 .../api/controller/SchedulerController.java        | 14 +++++------
 .../api/service/SchedulerService.java              | 11 +++++----
 .../api/service/impl/SchedulerServiceImpl.java     | 17 +++++++-------
 .../api/controller/AbstractControllerTest.java     | 14 ++++++++++-
 .../api/controller/SchedulerControllerTest.java    | 27 ++++++++++++++++++----
 .../controller/WorkFlowLineageControllerTest.java  |  9 --------
 .../pages/definition/pages/list/_source/timing.vue |  2 +-
 .../pages/projects/pages/list/_source/list.vue     |  4 +++-
 .../src/js/conf/home/router/index.js               |  2 ++
 .../src/js/conf/home/store/dag/actions.js          |  2 +-
 .../src/js/conf/home/store/dag/mutations.js        |  3 +++
 .../src/js/conf/home/store/dag/state.js            |  3 +++
 12 files changed, 71 insertions(+), 37 deletions(-)

diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java
index 20b668a..5732027 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java
@@ -65,7 +65,7 @@ import springfox.documentation.annotations.ApiIgnore;
  */
 @Api(tags = "SCHEDULER_TAG")
 @RestController
-@RequestMapping("/projects/{projectName}/schedule")
+@RequestMapping("/projects/{projectCode}/schedule")
 public class SchedulerController extends BaseController {
 
     public static final String DEFAULT_WARNING_TYPE = "NONE";
@@ -81,8 +81,8 @@ public class SchedulerController extends BaseController {
      * create schedule
      *
      * @param loginUser login user
-     * @param projectName project name
-     * @param processDefinitionId process definition id
+     * @param projectCode project code
+     * @param processDefinitionCode process definition code
      * @param schedule scheduler
      * @param warningType warning type
      * @param warningGroupId warning group id
@@ -93,7 +93,7 @@ public class SchedulerController extends BaseController {
      */
     @ApiOperation(value = "createSchedule", notes = "CREATE_SCHEDULE_NOTES")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "processDefinitionId", value = 
"PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"),
+            @ApiImplicitParam(name = "processDefinitionCode", value = 
"PROCESS_DEFINITION_CODE", required = true, dataType = "Long", example = "100"),
             @ApiImplicitParam(name = "schedule", value = "SCHEDULE", dataType 
= "String",
                     example = "{'startTime':'2019-06-10 
00:00:00','endTime':'2019-06-13 
00:00:00','timezoneId':'America/Phoenix','crontab':'0 0 3/6 * * ? *'}"),
             @ApiImplicitParam(name = "warningType", value = "WARNING_TYPE", 
type = "WarningType"),
@@ -107,15 +107,15 @@ public class SchedulerController extends BaseController {
     @ApiException(CREATE_SCHEDULE_ERROR)
     @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
     public Result createSchedule(@ApiIgnore @RequestAttribute(value = 
SESSION_USER) User loginUser,
-                                 @ApiParam(name = "projectName", value = 
"PROJECT_NAME", required = true) @PathVariable String projectName,
-                                 @RequestParam(value = "processDefinitionId") 
Integer processDefinitionId,
+                                 @ApiParam(name = "projectCode", value = 
"PROJECT_CODE", required = true) @PathVariable long projectCode,
+                                 @RequestParam(value = 
"processDefinitionCode") long processDefinitionCode,
                                  @RequestParam(value = "schedule") String 
schedule,
                                  @RequestParam(value = "warningType", required 
= false, defaultValue = DEFAULT_WARNING_TYPE) WarningType warningType,
                                  @RequestParam(value = "warningGroupId", 
required = false, defaultValue = DEFAULT_NOTIFY_GROUP_ID) int warningGroupId,
                                  @RequestParam(value = "failureStrategy", 
required = false, defaultValue = DEFAULT_FAILURE_POLICY) FailureStrategy 
failureStrategy,
                                  @RequestParam(value = "workerGroup", required 
= false, defaultValue = "default") String workerGroup,
                                  @RequestParam(value = 
"processInstancePriority", required = false, defaultValue = 
DEFAULT_PROCESS_INSTANCE_PRIORITY) Priority processInstancePriority) {
-        Map<String, Object> result = 
schedulerService.insertSchedule(loginUser, projectName, processDefinitionId, 
schedule,
+        Map<String, Object> result = 
schedulerService.insertSchedule(loginUser, projectCode, processDefinitionCode, 
schedule,
                 warningType, warningGroupId, failureStrategy, 
processInstancePriority, workerGroup);
 
         return returnDataList(result);
diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java
index 18f3ebf..7b743c4 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java
@@ -34,8 +34,8 @@ public interface SchedulerService {
      * save schedule
      *
      * @param loginUser login user
-     * @param projectName project name
-     * @param processDefineId process definition id
+     * @param projectCode project code
+     * @param processDefineCode process definition code
      * @param schedule scheduler
      * @param warningType warning type
      * @param warningGroupId warning group id
@@ -44,8 +44,9 @@ public interface SchedulerService {
      * @param workerGroup worker group
      * @return create result code
      */
-    Map<String, Object> insertSchedule(User loginUser, String projectName,
-                                       Integer processDefineId,
+    Map<String, Object> insertSchedule(User loginUser,
+                                       long projectCode,
+                                       long processDefineCode,
                                        String schedule,
                                        WarningType warningType,
                                        int warningGroupId,
@@ -144,4 +145,4 @@ public interface SchedulerService {
      * @return the next five fire time
      */
     Map<String, Object> previewSchedule(User loginUser, String projectName, 
String schedule);
-}
\ No newline at end of file
+}
diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java
index d83682f..ef383e5 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java
@@ -97,8 +97,8 @@ public class SchedulerServiceImpl extends BaseServiceImpl 
implements SchedulerSe
      * save schedule
      *
      * @param loginUser login user
-     * @param projectName project name
-     * @param processDefineId process definition id
+     * @param projectCode project name
+     * @param processDefineCode process definition code
      * @param schedule scheduler
      * @param warningType warning type
      * @param warningGroupId warning group id
@@ -109,8 +109,9 @@ public class SchedulerServiceImpl extends BaseServiceImpl 
implements SchedulerSe
      */
     @Override
     @Transactional(rollbackFor = RuntimeException.class)
-    public Map<String, Object> insertSchedule(User loginUser, String 
projectName,
-                                              Integer processDefineId,
+    public Map<String, Object> insertSchedule(User loginUser,
+                                              long projectCode,
+                                              long processDefineCode,
                                               String schedule,
                                               WarningType warningType,
                                               int warningGroupId,
@@ -120,7 +121,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl 
implements SchedulerSe
 
         Map<String, Object> result = new HashMap<>();
 
-        Project project = projectMapper.queryByName(projectName);
+        Project project = projectMapper.queryByCode(projectCode);
 
         // check project auth
         boolean hasProjectAndPerm = 
projectService.hasProjectAndPerm(loginUser, project, result);
@@ -129,8 +130,8 @@ public class SchedulerServiceImpl extends BaseServiceImpl 
implements SchedulerSe
         }
 
         // check work flow define release state
-        ProcessDefinition processDefinition = 
processService.findProcessDefineById(processDefineId);
-        result = 
executorService.checkProcessDefinitionValid(processDefinition, processDefineId);
+        ProcessDefinition processDefinition = 
processDefinitionMapper.queryByCode(processDefineCode);
+        result = 
executorService.checkProcessDefinitionValid(processDefinition, 
processDefineCode);
         if (result.get(Constants.STATUS) != Status.SUCCESS) {
             return result;
         }
@@ -138,7 +139,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl 
implements SchedulerSe
         Schedule scheduleObj = new Schedule();
         Date now = new Date();
 
-        scheduleObj.setProjectName(projectName);
+        scheduleObj.setProjectName(project.getName());
         scheduleObj.setProcessDefinitionId(processDefinition.getId());
         scheduleObj.setProcessDefinitionName(processDefinition.getName());
 
diff --git 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AbstractControllerTest.java
 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AbstractControllerTest.java
index b0c9616..83d1ae8 100644
--- 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AbstractControllerTest.java
+++ 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AbstractControllerTest.java
@@ -19,13 +19,17 @@ package org.apache.dolphinscheduler.api.controller;
 
 import static org.mockito.Mockito.doNothing;
 
+import java.text.MessageFormat;
+import java.util.Map;
+
 import org.apache.dolphinscheduler.api.ApiApplicationServer;
+import org.apache.dolphinscheduler.api.enums.Status;
 import org.apache.dolphinscheduler.api.service.SessionService;
+import org.apache.dolphinscheduler.common.Constants;
 import org.apache.dolphinscheduler.common.enums.UserType;
 import org.apache.dolphinscheduler.common.utils.StringUtils;
 import org.apache.dolphinscheduler.dao.entity.User;
 import org.apache.dolphinscheduler.service.registry.RegistryClient;
-
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -87,6 +91,14 @@ public class AbstractControllerTest {
         sessionId = session;
 
         Assert.assertTrue(StringUtils.isNotEmpty(session));
+    }
 
+    public void putMsg(Map<String, Object> result, Status status, Object... 
statusParams) {
+        result.put(Constants.STATUS, status);
+        if (statusParams != null && statusParams.length > 0) {
+            result.put(Constants.MSG, MessageFormat.format(status.getMsg(), 
statusParams));
+        } else {
+            result.put(Constants.MSG, status.getMsg());
+        }
     }
 }
diff --git 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java
 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java
index 6122c1a..d37f106 100644
--- 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java
+++ 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java
@@ -17,22 +17,30 @@
 
 package org.apache.dolphinscheduler.api.controller;
 
+import static org.mockito.ArgumentMatchers.isA;
 import static 
org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
 import static 
org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
 import static 
org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
 import static 
org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.dolphinscheduler.api.enums.Status;
+import org.apache.dolphinscheduler.api.service.SchedulerService;
 import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.Constants;
 import org.apache.dolphinscheduler.common.enums.FailureStrategy;
 import org.apache.dolphinscheduler.common.enums.Priority;
 import org.apache.dolphinscheduler.common.enums.WarningType;
 import org.apache.dolphinscheduler.common.utils.JSONUtils;
-
+import org.apache.dolphinscheduler.dao.entity.User;
 import org.junit.Assert;
 import org.junit.Test;
+import org.mockito.Mockito;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.boot.test.mock.mockito.MockBean;
 import org.springframework.http.MediaType;
 import org.springframework.test.web.servlet.MvcResult;
 import org.springframework.util.LinkedMultiValueMap;
@@ -41,14 +49,17 @@ import org.springframework.util.MultiValueMap;
 /**
  * scheduler controller test
  */
-public class SchedulerControllerTest extends AbstractControllerTest{
+public class SchedulerControllerTest extends AbstractControllerTest {
 
     private static Logger logger = 
LoggerFactory.getLogger(SchedulerControllerTest.class);
 
+    @MockBean
+    private SchedulerService schedulerService;
+
     @Test
     public void testCreateSchedule() throws Exception {
         MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
-        paramsMap.add("processDefinitionId","40");
+        paramsMap.add("processDefinitionCode","40");
         paramsMap.add("schedule","{'startTime':'2019-12-16 
00:00:00','endTime':'2019-12-17 00:00:00','crontab':'0 0 6 * * ? *'}");
         paramsMap.add("warningType",String.valueOf(WarningType.NONE));
         paramsMap.add("warningGroupId","1");
@@ -58,7 +69,15 @@ public class SchedulerControllerTest extends 
AbstractControllerTest{
         paramsMap.add("workerGroupId","1");
         paramsMap.add("processInstancePriority",String.valueOf(Priority.HIGH));
 
-        MvcResult mvcResult = 
mockMvc.perform(post("/projects/{projectName}/schedule/create","cxc_1113")
+        Map<String, Object> serviceResult = new HashMap<>();
+        putMsg(serviceResult, Status.SUCCESS);
+        serviceResult.put(Constants.DATA_LIST, 1);
+
+        Mockito.when(schedulerService.insertSchedule(isA(User.class), 
isA(Long.class), isA(Long.class),
+                isA(String.class), isA(WarningType.class), isA(int.class), 
isA(FailureStrategy.class),
+                isA(Priority.class), 
isA(String.class))).thenReturn(serviceResult);
+
+        MvcResult mvcResult = 
mockMvc.perform(post("/projects/{projectCode}/schedule/create",123)
                 .header(SESSION_ID, sessionId)
                 .params(paramsMap))
                 .andExpect(status().isCreated())
diff --git 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageControllerTest.java
 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageControllerTest.java
index 4666150..4fa6ef7 100644
--- 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageControllerTest.java
+++ 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageControllerTest.java
@@ -76,15 +76,6 @@ public class WorkFlowLineageControllerTest extends 
AbstractControllerTest {
         Assert.assertEquals(Status.SUCCESS.getCode(), 
response.getCode().intValue());
     }
 
-    private void putMsg(Map<String, Object> result, Status status, Object... 
statusParams) {
-        result.put(Constants.STATUS, status);
-        if (statusParams != null && statusParams.length > 0) {
-            result.put(Constants.MSG, MessageFormat.format(status.getMsg(), 
statusParams));
-        } else {
-            result.put(Constants.MSG, status.getMsg());
-        }
-    }
-
     @Test
     public  void testQueryWorkFlowLineageByIds() {
         int projectId = 1;
diff --git 
a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/timing.vue
 
b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/timing.vue
index 08e06cd..c8a3caf 100644
--- 
a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/timing.vue
+++ 
b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/timing.vue
@@ -240,7 +240,7 @@
             msg = `${i18n.$t('Edit')}${i18n.$t('Success')},${i18n.$t('Please 
go online')}`
           } else {
             api = 'dag/createSchedule'
-            searchParams.processDefinitionId = this.timingData.item.id
+            searchParams.processDefinitionCode = this.timingData.item.code
             msg = `${i18n.$t('Create')}${i18n.$t('Success')}`
           }
 
diff --git 
a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/list/_source/list.vue
 
b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/list/_source/list.vue
index 06ecfb0..fe5086f 100644
--- 
a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/list/_source/list.vue
+++ 
b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/list/_source/list.vue
@@ -89,11 +89,13 @@
     },
     methods: {
       ...mapActions('projects', ['deleteProjects']),
-      ...mapMutations('dag', ['setProjectId', 'setProjectName']),
+      ...mapMutations('dag', ['setProjectId', 'setProjectCode', 
'setProjectName']),
       _switchProjects (item) {
         this.setProjectId(item.id)
+        this.setProjectCode(item.code)
         this.setProjectName(item.name)
         localStore.setItem('projectId', item.id)
+        localStore.setItem('projectCode', item.code)
         localStore.setItem('projectName', item.name)
         this.$router.push({ path: `/projects/${item.id}/index` })
       },
diff --git a/dolphinscheduler-ui/src/js/conf/home/router/index.js 
b/dolphinscheduler-ui/src/js/conf/home/router/index.js
index 3660852..35cb943 100644
--- a/dolphinscheduler-ui/src/js/conf/home/router/index.js
+++ b/dolphinscheduler-ui/src/js/conf/home/router/index.js
@@ -59,8 +59,10 @@ const router = new Router({
             projectId: to.params.projectId
           }).then(res => {
             store.commit('dag/setProjectId', res.id)
+            store.commit('dag/setProjectCode', res.code)
             store.commit('dag/setProjectName', res.name)
             localStore.setItem('projectId', res.id)
+            localStore.setItem('projectCode', res.code)
             localStore.setItem('projectName', res.name)
             next()
           }).catch(e => {
diff --git a/dolphinscheduler-ui/src/js/conf/home/store/dag/actions.js 
b/dolphinscheduler-ui/src/js/conf/home/store/dag/actions.js
index 3cda9e3..4166c1d 100644
--- a/dolphinscheduler-ui/src/js/conf/home/store/dag/actions.js
+++ b/dolphinscheduler-ui/src/js/conf/home/store/dag/actions.js
@@ -555,7 +555,7 @@ export default {
    */
   createSchedule ({ state }, payload) {
     return new Promise((resolve, reject) => {
-      io.post(`projects/${state.projectName}/schedule/create`, payload, res => 
{
+      io.post(`projects/${state.projectCode}/schedule/create`, payload, res => 
{
         resolve(res)
       }).catch(e => {
         reject(e)
diff --git a/dolphinscheduler-ui/src/js/conf/home/store/dag/mutations.js 
b/dolphinscheduler-ui/src/js/conf/home/store/dag/mutations.js
index 1a6dd2c..010a860 100755
--- a/dolphinscheduler-ui/src/js/conf/home/store/dag/mutations.js
+++ b/dolphinscheduler-ui/src/js/conf/home/store/dag/mutations.js
@@ -21,6 +21,9 @@ export default {
   setProjectId (state, payload) {
     state.projectId = payload
   },
+  setProjectCode (state, payload) {
+    state.projectCode = payload
+  },
   setProjectName (state, payload) {
     state.projectName = payload
   },
diff --git a/dolphinscheduler-ui/src/js/conf/home/store/dag/state.js 
b/dolphinscheduler-ui/src/js/conf/home/store/dag/state.js
index 8bbbda8..4843ad9 100644
--- a/dolphinscheduler-ui/src/js/conf/home/store/dag/state.js
+++ b/dolphinscheduler-ui/src/js/conf/home/store/dag/state.js
@@ -19,6 +19,7 @@ import localStore from '@/module/util/localStorage'
 
 // Get the project currently clicked
 const projectId = localStore.getItem('projectId')
+const projectCode = localStore.getItem('projectCode')
 const projectName = localStore.getItem('projectName')
 
 export default {
@@ -50,6 +51,8 @@ export default {
   isEditDag: false,
   // Current project id
   projectId: projectId,
+  // Current project code
+  projectCode: projectCode,
   // Current project name
   projectName: projectName || '',
   // Whether to go online the process definition

Reply via email to