From 80ef7568b8f830039800e662400cf09ad64be85e Mon Sep 17 00:00:00 2001 From: JinyLeeChina <42576980+JinyLeeChina@users.noreply.github.com> Date: Mon, 9 Aug 2021 10:09:58 +0800 Subject: [PATCH] [Feature][JsonSplit-api] refactor of ProjectService.checkProjectAndAuth (#5961) * refactor of ProjectService.checkProjectAndAuth * fix ut * fix ut Co-authored-by: JinyLeeChina <297062848@qq.com> --- .../api/controller/ProjectController.java | 2 +- .../service/ProcessTaskRelationService.java | 40 ------- .../api/service/ProjectService.java | 6 +- .../service/impl/DataAnalysisServiceImpl.java | 4 +- .../api/service/impl/ExecutorServiceImpl.java | 47 +++----- .../impl/ProcessDefinitionServiceImpl.java | 36 +++--- .../impl/ProcessInstanceServiceImpl.java | 16 +-- .../impl/ProcessTaskRelationServiceImpl.java | 78 ------------- .../api/service/impl/ProjectServiceImpl.java | 16 ++- .../service/impl/SchedulerServiceImpl.java | 2 +- .../impl/TaskDefinitionServiceImpl.java | 10 +- .../service/impl/TaskInstanceServiceImpl.java | 4 +- .../api/service/DataAnalysisServiceTest.java | 17 +-- .../api/service/ExecutorServiceTest.java | 2 +- .../service/ProcessDefinitionServiceTest.java | 62 +++++----- .../service/ProcessInstanceServiceTest.java | 32 +++--- .../ProcessTaskRelationServiceImplTest.java | 107 ------------------ .../api/service/ProjectServiceTest.java | 28 ++--- .../TaskDefinitionServiceImplTest.java | 10 +- .../api/service/TaskInstanceServiceTest.java | 16 +-- 20 files changed, 137 insertions(+), 398 deletions(-) delete mode 100644 dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationService.java delete mode 100644 dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessTaskRelationServiceImpl.java delete mode 100644 dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationServiceImplTest.java diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java index ca7e081a58..14de0984f2 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java @@ -133,7 +133,7 @@ public class ProjectController extends BaseController { @ApiException(QUERY_PROJECT_DETAILS_BY_CODE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryProjectByCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam("projectCode") Long projectCode) { + @RequestParam("projectCode") long projectCode) { Map result = projectService.queryByCode(loginUser, projectCode); return returnDataList(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationService.java deleted file mode 100644 index 76b6389c46..0000000000 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationService.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.api.service; - -import org.apache.dolphinscheduler.dao.entity.User; - -import java.util.Map; - -/** - * process task relation service - */ -public interface ProcessTaskRelationService { - - /** - * query process task relation - * - * @param loginUser login user - * @param projectName project name - * @param processDefinitionCode process definition code - */ - Map queryProcessTaskRelation(User loginUser, - String projectName, - Long processDefinitionCode); -} - diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java index 5e3f40a067..7c79dc61e5 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java @@ -43,17 +43,17 @@ public interface ProjectService { * @param projectCode project code * @return project detail information */ - Map queryByCode(User loginUser, Long projectCode); + Map queryByCode(User loginUser, long projectCode); /** * check project and authorization * * @param loginUser login user * @param project project - * @param projectName project name + * @param projectCode project code * @return true if the login user have permission to see the project */ - Map checkProjectAndAuth(User loginUser, Project project, String projectName); + Map checkProjectAndAuth(User loginUser, Project project, long projectCode); boolean hasProjectAndPerm(User loginUser, Project project, Map result); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java index 2377439ba8..98bae2ad5a 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java @@ -136,7 +136,7 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal if (projectCode != 0) { Project project = projectMapper.queryByCode(projectCode); - result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -180,7 +180,7 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal if (projectCode != 0) { Project project = projectMapper.queryByCode(projectCode); - result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java index c3b422f65b..76a5bc16fa 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java @@ -90,11 +90,6 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ @Autowired private MonitorService monitorService; - - @Autowired - private ProcessInstanceMapper processInstanceMapper; - - @Autowired private ProcessService processService; @@ -126,17 +121,17 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ RunMode runMode, Priority processInstancePriority, String workerGroup, Integer timeout, Map startParams) { - Map result = new HashMap<>(); + Project project = projectMapper.queryByCode(projectCode); + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; + } // timeout is invalid if (timeout <= 0 || timeout > MAX_TASK_TIMEOUT) { putMsg(result, Status.TASK_TIMEOUT_PARAMS_ERROR); return result; } - Project project = projectMapper.queryByCode(projectCode); - Map checkResultAndAuth = checkResultAndAuth(loginUser, project.getName(), project); - if (checkResultAndAuth != null) { - return checkResultAndAuth; - } // check process define release state ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(processDefinitionCode); @@ -225,12 +220,11 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ */ @Override public Map execute(User loginUser, long projectCode, Integer processInstanceId, ExecuteType executeType) { - Map result = new HashMap<>(); Project project = projectMapper.queryByCode(projectCode); - - Map checkResult = checkResultAndAuth(loginUser, project.getName(), project); - if (checkResult != null) { - return checkResult; + //check user access for project + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } // check master exists @@ -253,10 +247,9 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ } } - checkResult = checkExecuteType(processInstance, executeType); - Status status = (Status) checkResult.get(Constants.STATUS); - if (status != Status.SUCCESS) { - return checkResult; + result = checkExecuteType(processInstance, executeType); + if (result.get(Constants.STATUS) != Status.SUCCESS) { + return result; } if (!checkTenantSuitable(processDefinition)) { logger.error("there is not any valid tenant for the process definition: id:{},name:{}, ", @@ -589,18 +582,4 @@ public class ExecutorServiceImpl extends BaseServiceImpl implements ExecutorServ return 0; } - - /** - * check result and auth - */ - private Map checkResultAndAuth(User loginUser, String projectName, Project project) { - // check project auth - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - Status status = (Status) checkResult.get(Constants.STATUS); - if (status != Status.SUCCESS) { - return checkResult; - } - return null; - } - } 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 49975a7739..b957e5d82f 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 @@ -189,7 +189,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro String taskRelationJson) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -288,7 +288,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro public Map queryProcessDefinitionList(User loginUser, long projectCode) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -314,7 +314,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro public Map queryProcessDefinitionListPaging(User loginUser, long projectCode, String searchVal, Integer pageNo, Integer pageSize, Integer userId) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -352,7 +352,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro public Map queryProcessDefinitionByCode(User loginUser, long projectCode, long code) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -372,7 +372,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro public Map queryProcessDefinitionByName(User loginUser, long projectCode, String processDefinitionName) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -416,7 +416,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro String taskRelationJson) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -490,7 +490,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro public Map verifyProcessDefinitionName(User loginUser, long projectCode, String name) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -516,7 +516,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro public Map deleteProcessDefinitionById(User loginUser, long projectCode, Integer processDefinitionId) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -589,7 +589,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro public Map releaseProcessDefinition(User loginUser, long projectCode, long code, ReleaseState releaseState) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -655,7 +655,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro } Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return; } @@ -926,7 +926,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro public Map getTaskNodeListByDefinitionCode(User loginUser, long projectCode, long defineCode) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -955,7 +955,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro public Map getNodeListMapByDefinitionCodes(User loginUser, long projectCode, String defineCodes) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -991,7 +991,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro public Map queryAllProcessDefinitionByProjectCode(User loginUser, long projectCode) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -1200,7 +1200,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro long targetProjectCode) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -1213,7 +1213,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro if (projectCode != targetProjectCode) { Project targetProject = projectMapper.queryByCode(targetProjectCode); //check user access for project - Map targetResult = projectService.checkProjectAndAuth(loginUser, targetProject, targetProject.getName()); + Map targetResult = projectService.checkProjectAndAuth(loginUser, targetProject, targetProjectCode); if (targetResult.get(Constants.STATUS) != Status.SUCCESS) { return targetResult; } @@ -1263,7 +1263,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro public Map switchProcessDefinitionVersion(User loginUser, long projectCode, int processDefinitionId, int version) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -1340,7 +1340,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro Project project = projectMapper.queryByCode(projectCode); //check user access for project - result.putAll(projectService.checkProjectAndAuth(loginUser, project, project.getName())); + result.putAll(projectService.checkProjectAndAuth(loginUser, project, projectCode)); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -1374,7 +1374,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro public Map deleteByProcessDefinitionIdAndVersion(User loginUser, long projectCode, int processDefinitionId, int version) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java index b5679ed5b4..4b41ecb064 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java @@ -142,7 +142,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce public Map queryTopNLongestRunningProcessInstance(User loginUser, long projectCode, int size, String startTime, String endTime) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -188,7 +188,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce public Map queryProcessInstanceById(User loginUser, long projectCode, Integer processId) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -239,7 +239,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce Integer pageSize) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -296,7 +296,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce public Map queryTaskListByProcessId(User loginUser, long projectCode, Integer processId) throws IOException { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -370,7 +370,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce public Map querySubProcessInstanceByTaskId(User loginUser, long projectCode, Integer taskId) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -421,7 +421,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce String locations, int timeout, String tenantCode) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -508,7 +508,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce public Map queryParentInstanceBySubId(User loginUser, long projectCode, Integer subId) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -548,7 +548,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce public Map deleteProcessInstanceById(User loginUser, long projectCode, Integer processInstanceId) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessTaskRelationServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessTaskRelationServiceImpl.java deleted file mode 100644 index 488c60cd22..0000000000 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessTaskRelationServiceImpl.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.api.service.impl; - -import org.apache.dolphinscheduler.api.enums.Status; -import org.apache.dolphinscheduler.api.service.ProcessTaskRelationService; -import org.apache.dolphinscheduler.api.service.ProjectService; -import org.apache.dolphinscheduler.common.Constants; -import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation; -import org.apache.dolphinscheduler.dao.entity.Project; -import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; -import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** - * task definition service impl - */ -@Service -public class ProcessTaskRelationServiceImpl extends BaseServiceImpl implements - ProcessTaskRelationService { - - private static final Logger logger = LoggerFactory.getLogger(ProcessTaskRelationServiceImpl.class); - - @Autowired - private ProjectMapper projectMapper; - - @Autowired - private ProjectService projectService; - - @Autowired - private ProcessTaskRelationMapper processTaskRelationMapper; - - /** - * query process task relation - * - * @param loginUser login user - * @param projectName project name - * @param processDefinitionCode process definition code - */ - @Override - public Map queryProcessTaskRelation(User loginUser, String projectName, Long processDefinitionCode) { - Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); - // check project auth - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); - if (checkResult.get(Constants.STATUS) != Status.SUCCESS) { - return checkResult; - } - List processTaskRelationList = processTaskRelationMapper.queryByProcessCode(project.getCode(), processDefinitionCode); - result.put(Constants.DATA_LIST, processTaskRelationList); - putMsg(result, Status.SUCCESS); - return result; - } -} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java index 1125336d41..6aed8da8a5 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java @@ -124,7 +124,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic * @return project detail information */ @Override - public Map queryByCode(User loginUser, Long projectCode) { + public Map queryByCode(User loginUser, long projectCode) { Map result = new HashMap<>(); Project project = projectMapper.queryByCode(projectCode); boolean hasProjectAndPerm = hasProjectAndPerm(loginUser, project, result); @@ -140,21 +140,20 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic /** * check project and authorization - * // TODO projectCode will be instead of projectName * * @param loginUser login user * @param project project - * @param projectName project name + * @param projectCode project code * @return true if the login user have permission to see the project */ @Override - public Map checkProjectAndAuth(User loginUser, Project project, String projectName) { + public Map checkProjectAndAuth(User loginUser, Project project, long projectCode) { Map result = new HashMap<>(); if (project == null) { - putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); + putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); } else if (!checkReadPermission(loginUser, project)) { // check read permission - putMsg(result, Status.USER_NO_OPERATION_PROJECT_PERM, loginUser.getUserName(), projectName); + putMsg(result, Status.USER_NO_OPERATION_PROJECT_PERM, loginUser.getUserName(), projectCode); } else { putMsg(result, Status.SUCCESS); } @@ -167,7 +166,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic if (project == null) { putMsg(result, Status.PROJECT_NOT_FOUNT, ""); } else if (!checkReadPermission(loginUser, project)) { - putMsg(result, Status.USER_NO_OPERATION_PROJECT_PERM, loginUser.getUserName(), project.getName()); + putMsg(result, Status.USER_NO_OPERATION_PROJECT_PERM, loginUser.getUserName(), project.getCode()); } else { checkResult = true; } @@ -252,8 +251,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic * @return check result */ private Map getCheckResult(User loginUser, Project project) { - String projectName = project == null ? null : project.getName(); - Map checkResult = checkProjectAndAuth(loginUser, project, projectName); + Map checkResult = checkProjectAndAuth(loginUser, project, project == null ? 0L : project.getCode()); Status status = (Status) checkResult.get(Constants.STATUS); if (status != Status.SUCCESS) { return checkResult; 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 edc7074fdb..92e58668d2 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 @@ -526,7 +526,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe Map result = new HashMap<>(); Project project = projectMapper.queryByCode(projectCode); - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectCode); Status resultEnum = (Status) checkResult.get(Constants.STATUS); if (resultEnum != Status.SUCCESS) { return checkResult; 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 2f8ec20cc7..545cb817f8 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 @@ -95,7 +95,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe String taskDefinitionJson) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -156,7 +156,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe public Map queryTaskDefinitionByName(User loginUser, long projectCode, String taskName) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -183,7 +183,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe public Map deleteTaskDefinitionByCode(User loginUser, long projectCode, long taskCode) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -218,7 +218,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe public Map updateTaskDefinition(User loginUser, long projectCode, long taskCode, String taskDefinitionJson) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -291,7 +291,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe public Map switchVersion(User loginUser, long projectCode, long taskCode, int version) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java index 1a4cb3f982..1bb6367313 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java @@ -102,7 +102,7 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst Integer pageSize) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } @@ -158,7 +158,7 @@ public class TaskInstanceServiceImpl extends BaseServiceImpl implements TaskInst public Map forceTaskSuccess(User loginUser, long projectCode, Integer taskInstanceId) { Project project = projectMapper.queryByCode(projectCode); //check user access for project - Map result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); + Map result = projectService.checkProjectAndAuth(loginUser, project, projectCode); if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java index aade722362..4f1ce76db0 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java @@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.api.service; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; import org.apache.dolphinscheduler.api.dto.CommandStateCount; import org.apache.dolphinscheduler.api.enums.Status; @@ -125,7 +126,7 @@ public class DataAnalysisServiceTest { Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, null); - Mockito.when(projectService.checkProjectAndAuth(any(), any(), any())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(result); Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); // SUCCESS @@ -144,7 +145,7 @@ public class DataAnalysisServiceTest { // checkProject false Map failResult = new HashMap<>(); putMsg(failResult, Status.PROJECT_NOT_FOUNT, 1); - Mockito.when(projectService.checkProjectAndAuth(any(), any(), any())).thenReturn(failResult); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(failResult); failResult = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, startDate, endDate); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, failResult.get(Constants.STATUS)); } @@ -153,7 +154,7 @@ public class DataAnalysisServiceTest { public void testCountTaskStateByProject_paramValid() { Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, null); - Mockito.when(projectService.checkProjectAndAuth(any(), any(), any())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(result); Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); // when date in illegal format then return error message @@ -179,7 +180,7 @@ public class DataAnalysisServiceTest { public void testCountTaskStateByProject_allCountZero() { Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, null); - Mockito.when(projectService.checkProjectAndAuth(any(), any(), any())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(result); Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); // when general user doesn't have any task then return all count are 0 @@ -198,7 +199,7 @@ public class DataAnalysisServiceTest { public void testCountTaskStateByProject_noData() { Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, null); - Mockito.when(projectService.checkProjectAndAuth(any(), any(), any())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(result); Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); // when instanceStateCounter return null, then return nothing @@ -218,13 +219,13 @@ public class DataAnalysisServiceTest { //checkProject false Map failResult = new HashMap<>(); putMsg(failResult, Status.PROJECT_NOT_FOUNT, 1); - Mockito.when(projectService.checkProjectAndAuth(any(), any(), any())).thenReturn(failResult); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(failResult); failResult = dataAnalysisServiceImpl.countProcessInstanceStateByProject(user, 1, startDate, endDate); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, failResult.get(Constants.STATUS)); Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, null); - Mockito.when(projectService.checkProjectAndAuth(any(), any(), any())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(result); //SUCCESS Mockito.when(processInstanceMapper.countInstanceStateByUser(DateUtils.getScheduleDate(startDate), @@ -241,7 +242,7 @@ public class DataAnalysisServiceTest { Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, null); - Mockito.when(projectService.checkProjectAndAuth(any(), any(), any())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(result); Mockito.when(processDefinitionMapper.countDefinitionGroupByUser(Mockito.anyInt(), Mockito.any(Long[].class), Mockito.anyBoolean())).thenReturn(new ArrayList()); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java index 2cae0513b0..4c1b3e4c63 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java @@ -137,7 +137,7 @@ public class ExecutorServiceTest { // mock Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(checkProjectAndAuth()); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(checkProjectAndAuth()); Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(processDefinition); Mockito.when(processService.getTenantForProcess(tenantId, userId)).thenReturn(new Tenant()); Mockito.when(processService.createCommand(any(Command.class))).thenReturn(1); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java index 1fd4e0aa90..c38e811847 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java @@ -110,13 +110,13 @@ public class ProcessDefinitionServiceTest { putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); //project not found - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map map = processDefinitionService.queryProcessDefinitionList(loginUser, projectCode); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); //project check auth success putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); List resourceList = new ArrayList<>(); resourceList.add(getProcessDefinition()); Mockito.when(processDefineMapper.queryAllDefinitionList(project.getCode())).thenReturn(resourceList); @@ -140,13 +140,13 @@ public class ProcessDefinitionServiceTest { putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); //project not found - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map map = processDefinitionService.queryProcessDefinitionListPaging(loginUser, projectCode, "", 1, 5, 0); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); putMsg(result, Status.SUCCESS, projectCode); loginUser.setId(1); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Page page = new Page<>(1, 10); page.setTotal(30); Mockito.when(processDefineMapper.queryDefineListPaging( @@ -177,13 +177,13 @@ public class ProcessDefinitionServiceTest { putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); //project check auth fail - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map map = processDefinitionService.queryProcessDefinitionByCode(loginUser, 1L, 1L); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); //project check auth success, instance not exist putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); DagData dagData = new DagData(getProcessDefinition(), null, null); Mockito.when(processService.genDagData(Mockito.any())).thenReturn(dagData); @@ -193,7 +193,7 @@ public class ProcessDefinitionServiceTest { //instance exit Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(getProcessDefinition()); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map successRes = processDefinitionService.queryProcessDefinitionByCode(loginUser, projectCode, 46L); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); } @@ -213,13 +213,13 @@ public class ProcessDefinitionServiceTest { putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); //project check auth fail - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map map = processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, "test_def"); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); //project check auth success, instance not exist putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Mockito.when(processDefineMapper.queryByDefineName(project.getCode(), "test_def")).thenReturn(null); Map instanceNotExitRes = processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, "test_def"); @@ -228,7 +228,7 @@ public class ProcessDefinitionServiceTest { //instance exit Mockito.when(processDefineMapper.queryByDefineName(project.getCode(), "test")).thenReturn(getProcessDefinition()); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map successRes = processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, "test"); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); } @@ -243,7 +243,7 @@ public class ProcessDefinitionServiceTest { Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); // copy project definition ids empty test Map map = processDefinitionService.batchCopyProcessDefinition(loginUser, projectCode, StringUtils.EMPTY, 2L); @@ -252,7 +252,7 @@ public class ProcessDefinitionServiceTest { // project check auth fail putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map map1 = processDefinitionService.batchCopyProcessDefinition( loginUser, projectCode, String.valueOf(project.getId()), 2L); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map1.get(Constants.STATUS)); @@ -261,7 +261,7 @@ public class ProcessDefinitionServiceTest { projectCode = 2L; Project project1 = getProject(projectCode); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project1); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); putMsg(result, Status.SUCCESS, projectCode); ProcessDefinition definition = getProcessDefinition(); @@ -292,8 +292,8 @@ public class ProcessDefinitionServiceTest { Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project1, project1.getName())).thenReturn(result); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project2, project2.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project1, projectCode)).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project2, projectCode2)).thenReturn(result); ProcessDefinition definition = getProcessDefinition(); List processDefinitionList = new ArrayList<>(); @@ -321,20 +321,20 @@ public class ProcessDefinitionServiceTest { //project check auth fail Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map map = processDefinitionService.deleteProcessDefinitionById(loginUser, projectCode, 6); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); //project check auth success, instance not exist putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Mockito.when(processDefineMapper.selectById(1)).thenReturn(null); Map instanceNotExitRes = processDefinitionService.deleteProcessDefinitionById(loginUser, projectCode, 1); Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotExitRes.get(Constants.STATUS)); ProcessDefinition processDefinition = getProcessDefinition(); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); //user no auth loginUser.setUserType(UserType.GENERAL_USER); Mockito.when(processDefineMapper.selectById(46)).thenReturn(processDefinition); @@ -344,7 +344,7 @@ public class ProcessDefinitionServiceTest { //process definition online loginUser.setUserType(UserType.ADMIN_USER); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); processDefinition.setReleaseState(ReleaseState.ONLINE); Mockito.when(processDefineMapper.selectById(46)).thenReturn(processDefinition); Map dfOnlineRes = processDefinitionService.deleteProcessDefinitionById(loginUser, projectCode, 46); @@ -354,7 +354,7 @@ public class ProcessDefinitionServiceTest { processDefinition.setReleaseState(ReleaseState.OFFLINE); Mockito.when(processDefineMapper.selectById(46)).thenReturn(processDefinition); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); List schedules = new ArrayList<>(); schedules.add(getSchedule()); schedules.add(getSchedule()); @@ -368,7 +368,7 @@ public class ProcessDefinitionServiceTest { schedule.setReleaseState(ReleaseState.ONLINE); schedules.add(schedule); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Mockito.when(scheduleMapper.queryByProcessDefinitionCode(46)).thenReturn(schedules); Map schedulerOnlineRes = processDefinitionService.deleteProcessDefinitionById(loginUser, projectCode, 46); Assert.assertEquals(Status.SCHEDULE_CRON_STATE_ONLINE, schedulerOnlineRes.get(Constants.STATUS)); @@ -378,7 +378,7 @@ public class ProcessDefinitionServiceTest { schedule.setReleaseState(ReleaseState.OFFLINE); schedules.add(schedule); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Mockito.when(scheduleMapper.queryByProcessDefinitionCode(46)).thenReturn(schedules); Mockito.when(processDefineMapper.deleteById(46)).thenReturn(0); Map deleteFail = processDefinitionService.deleteProcessDefinitionById(loginUser, projectCode, 46); @@ -387,7 +387,7 @@ public class ProcessDefinitionServiceTest { //delete success Mockito.when(processDefineMapper.deleteById(46)).thenReturn(1); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map deleteSuccess = processDefinitionService.deleteProcessDefinitionById(loginUser, projectCode, 46); Assert.assertEquals(Status.SUCCESS, deleteSuccess.get(Constants.STATUS)); } @@ -405,7 +405,7 @@ public class ProcessDefinitionServiceTest { //project check auth fail Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map map = processDefinitionService.releaseProcessDefinition(loginUser, projectCode, 6, ReleaseState.OFFLINE); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); @@ -444,7 +444,7 @@ public class ProcessDefinitionServiceTest { //project check auth fail Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map map = processDefinitionService.verifyProcessDefinitionName(loginUser, projectCode, "test_pdf"); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); @@ -485,7 +485,7 @@ public class ProcessDefinitionServiceTest { //project check auth fail Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); //process definition not exist Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(null); Map processDefinitionNullRes = processDefinitionService.getTaskNodeListByDefinitionCode(loginUser, projectCode, 46L); @@ -513,7 +513,7 @@ public class ProcessDefinitionServiceTest { //project check auth fail Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); //process definition not exist String defineCodes = "46"; Set defineCodeSet = Lists.newArrayList(defineCodes.split(Constants.COMMA)).stream().map(Long::parseLong).collect(Collectors.toSet()); @@ -542,7 +542,7 @@ public class ProcessDefinitionServiceTest { Project project = getProject(projectCode); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); ProcessDefinition processDefinition = getProcessDefinition(); List processDefinitionList = new ArrayList<>(); processDefinitionList.add(processDefinition); @@ -590,7 +590,7 @@ public class ProcessDefinitionServiceTest { long projectCode = 1L; Project project = getProject(projectCode); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map updateResult = processDefinitionService.updateProcessDefinition(loginUser, projectCode, "test", 1, "", "", "", 0, "root", null); @@ -611,7 +611,7 @@ public class ProcessDefinitionServiceTest { Map result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); processDefinitionService.batchExportProcessDefinitionByCodes( loginUser, projectCode, "1", null); @@ -621,7 +621,7 @@ public class ProcessDefinitionServiceTest { Map checkResult = new HashMap<>(); checkResult.put(Constants.STATUS, Status.SUCCESS); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(checkResult); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(checkResult); HttpServletResponse response = mock(HttpServletResponse.class); DagData dagData = new DagData(getProcessDefinition(), null, null); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java index f8b9ab7d9f..d6a7aa82cd 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java @@ -126,7 +126,7 @@ public class ProcessInstanceServiceTest { //project auth fail when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, "project_test1")).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map proejctAuthFailRes = processInstanceService.queryProcessInstanceList(loginUser, projectCode, 46, "2020-01-01 00:00:00", "2020-01-02 00:00:00", "", "test_user", ExecutionStatus.SUBMITTED_SUCCESS, "192.168.xx.xx", 1, 10); @@ -143,7 +143,7 @@ public class ProcessInstanceServiceTest { // data parameter check putMsg(result, Status.SUCCESS, projectCode); when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(processDefineMapper.selectById(Mockito.anyInt())).thenReturn(getProcessDefinition()); when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class) , Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), @@ -158,7 +158,7 @@ public class ProcessInstanceServiceTest { putMsg(result, Status.SUCCESS, projectCode); when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId()); when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1L), eq(""), eq(-1), Mockito.any(), @@ -210,7 +210,7 @@ public class ProcessInstanceServiceTest { //project auth fail when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map proejctAuthFailRes = processInstanceService.queryTopNLongestRunningProcessInstance(loginUser, projectCode, size, startTime, endTime); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); @@ -218,7 +218,7 @@ public class ProcessInstanceServiceTest { putMsg(result, Status.SUCCESS, projectCode); ProcessInstance processInstance = getProcessInstance(); when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId()); when(usersService.queryUser(processInstance.getExecutorId())).thenReturn(loginUser); @@ -237,7 +237,7 @@ public class ProcessInstanceServiceTest { //project auth fail when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map proejctAuthFailRes = processInstanceService.queryProcessInstanceById(loginUser, projectCode, 1); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); @@ -246,7 +246,7 @@ public class ProcessInstanceServiceTest { putMsg(result, Status.SUCCESS, projectCode); ProcessDefinition processDefinition = getProcessDefinition(); when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(processService.findProcessInstanceDetailById(processInstance.getId())).thenReturn(processInstance); when(processService.findProcessDefinition(processInstance.getProcessDefinitionCode(), processInstance.getProcessDefinitionVersion())).thenReturn(processDefinition); @@ -273,7 +273,7 @@ public class ProcessInstanceServiceTest { //project auth fail when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map proejctAuthFailRes = processInstanceService.queryTaskListByProcessId(loginUser, projectCode, 1); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); @@ -289,7 +289,7 @@ public class ProcessInstanceServiceTest { res.setCode(Status.SUCCESS.ordinal()); res.setData("xxx"); when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(processService.findProcessInstanceDetailById(processInstance.getId())).thenReturn(processInstance); when(processService.findValidTaskListByProcessId(processInstance.getId())).thenReturn(taskInstanceList); when(loggerService.queryLog(taskInstance.getId(), 0, 4098)).thenReturn(res); @@ -319,14 +319,14 @@ public class ProcessInstanceServiceTest { //project auth fail when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map proejctAuthFailRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectCode, 1); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); //task null putMsg(result, Status.SUCCESS, projectCode); when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(processService.findTaskInstanceById(1)).thenReturn(null); Map taskNullRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectCode, 1); Assert.assertEquals(Status.TASK_INSTANCE_NOT_EXISTS, taskNullRes.get(Constants.STATUS)); @@ -368,7 +368,7 @@ public class ProcessInstanceServiceTest { //project auth fail when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map proejctAuthFailRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1, shellJson, "2020-02-21 00:00:00", true, Flag.YES, "", "", 0, ""); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); @@ -377,7 +377,7 @@ public class ProcessInstanceServiceTest { putMsg(result, Status.SUCCESS, projectCode); ProcessInstance processInstance = getProcessInstance(); when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(processService.findProcessInstanceDetailById(1)).thenReturn(null); Map processInstanceNullRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1, shellJson, "2020-02-21 00:00:00", true, Flag.YES, "", "", 0, ""); @@ -430,14 +430,14 @@ public class ProcessInstanceServiceTest { //project auth fail when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map proejctAuthFailRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); //process instance null putMsg(result, Status.SUCCESS, projectCode); when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(processService.findProcessInstanceDetailById(1)).thenReturn(null); Map processInstanceNullRes = processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1); Assert.assertEquals(Status.PROCESS_INSTANCE_NOT_EXIST, processInstanceNullRes.get(Constants.STATUS)); @@ -474,7 +474,7 @@ public class ProcessInstanceServiceTest { //process instance null putMsg(result, Status.SUCCESS, projectCode); when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(processService.findProcessInstanceDetailById(1)).thenReturn(null); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationServiceImplTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationServiceImplTest.java deleted file mode 100644 index b1b20a7e5e..0000000000 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessTaskRelationServiceImplTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.api.service; - -import org.apache.dolphinscheduler.api.enums.Status; -import org.apache.dolphinscheduler.api.service.impl.ProcessTaskRelationServiceImpl; -import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; -import org.apache.dolphinscheduler.common.Constants; -import org.apache.dolphinscheduler.common.enums.UserType; -import org.apache.dolphinscheduler.dao.entity.Project; -import org.apache.dolphinscheduler.dao.entity.User; -import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; -import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; -import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; - -import java.text.MessageFormat; -import java.util.HashMap; -import java.util.Map; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; - -@RunWith(MockitoJUnitRunner.class) -public class ProcessTaskRelationServiceImplTest { - @InjectMocks - private ProcessTaskRelationServiceImpl processTaskRelationService; - - @Mock - private ProcessDefinitionMapper processDefineMapper; - - @Mock - private ProcessTaskRelationMapper processTaskRelationMapper; - - @Mock - private ProjectMapper projectMapper; - - @Mock - private ProjectServiceImpl projectService; - - @Test - public void queryProcessTaskRelationTest() { - String projectName = "project_test1"; - - Project project = getProject(projectName); - Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); - - User loginUser = new User(); - loginUser.setId(-1); - loginUser.setUserType(UserType.GENERAL_USER); - - Map result = new HashMap<>(); - putMsg(result, Status.SUCCESS, projectName); - - //project check auth fail - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); - - Map relation = processTaskRelationService - .queryProcessTaskRelation(loginUser, projectName, 11L); - - Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); - } - - private void putMsg(Map 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()); - } - } - - /** - * get mock Project - * - * @param projectName projectName - * @return Project - */ - private Project getProject(String projectName) { - Project project = new Project(); - project.setCode(11L); - project.setId(1); - project.setName(projectName); - project.setUserId(1); - return project; - } - -} diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java index 86d641cfe6..92cc663450 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java @@ -101,28 +101,14 @@ public class ProjectServiceTest { } - @Test - public void testQueryById() { - User loginUser = getLoginUser(); - //not exist - Map result = projectService.queryByCode(loginUser, Long.MAX_VALUE); - Assert.assertEquals(Status.PROJECT_NOT_FOUNT, result.get(Constants.STATUS)); - logger.info(result.toString()); - - //success - Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject()); - result = projectService.queryByCode(loginUser,1L); - logger.info(result.toString()); - Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - } - @Test public void testCheckProjectAndAuth() { + long projectCode = 1L; Mockito.when(projectUserMapper.queryProjectRelation(1, 1)).thenReturn(getProjectUser()); User loginUser = getLoginUser(); - Map result = projectService.checkProjectAndAuth(loginUser, null, projectName); + Map result = projectService.checkProjectAndAuth(loginUser, null, projectCode); logger.info(result.toString()); Status status = (Status) result.get(Constants.STATUS); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, result.get(Constants.STATUS)); @@ -130,30 +116,30 @@ public class ProjectServiceTest { Project project = getProject(); //USER_NO_OPERATION_PROJECT_PERM project.setUserId(2); - result = projectService.checkProjectAndAuth(loginUser, project, projectName); + result = projectService.checkProjectAndAuth(loginUser, project, projectCode); logger.info(result.toString()); Assert.assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM, result.get(Constants.STATUS)); //success project.setUserId(1); - result = projectService.checkProjectAndAuth(loginUser, project, projectName); + result = projectService.checkProjectAndAuth(loginUser, project, projectCode); logger.info(result.toString()); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); Map result2 = new HashMap<>(); - result2 = projectService.checkProjectAndAuth(loginUser, null, projectName); + result2 = projectService.checkProjectAndAuth(loginUser, null, projectCode); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, result2.get(Constants.STATUS)); Project project1 = getProject(); // USER_NO_OPERATION_PROJECT_PERM project1.setUserId(2); - result2 = projectService.checkProjectAndAuth(loginUser, project1, projectName); + result2 = projectService.checkProjectAndAuth(loginUser, project1, projectCode); Assert.assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM, result2.get(Constants.STATUS)); //success project1.setUserId(1); - projectService.checkProjectAndAuth(loginUser, project1, projectName); + projectService.checkProjectAndAuth(loginUser, project1, projectCode); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java index 9f51ab7998..c66fbac94c 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java @@ -130,7 +130,7 @@ public class TaskDefinitionServiceImplTest { Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); String createTaskDefinitionJson = "[{\n" + "\"name\": \"test12111\",\n" @@ -195,7 +195,7 @@ public class TaskDefinitionServiceImplTest { Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Mockito.when(processService.isTaskOnline(taskCode)).thenReturn(Boolean.FALSE); Mockito.when(taskDefinitionMapper.queryByDefinitionCode(taskCode)).thenReturn(new TaskDefinition()); @@ -219,7 +219,7 @@ public class TaskDefinitionServiceImplTest { Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); @@ -245,7 +245,7 @@ public class TaskDefinitionServiceImplTest { Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); @@ -274,7 +274,7 @@ public class TaskDefinitionServiceImplTest { Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, projectCode); - Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java index 09145a189f..a39cc1e1d2 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java @@ -90,7 +90,7 @@ public class TaskInstanceServiceTest { //project auth fail when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, "project_test1")).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map projectAuthFailRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 0, "", "", "test_user", "2019-02-26 19:48:00", "2019-02-26 19:48:22", "", null, "", 1, 20); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, projectAuthFailRes.get(Constants.STATUS)); @@ -98,7 +98,7 @@ public class TaskInstanceServiceTest { // data parameter check putMsg(result, Status.SUCCESS, projectCode); when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); Map dataParameterRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", "test_user", "20200101 00:00:00", "2020-01-02 00:00:00", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, dataParameterRes.get(Constants.STATUS)); @@ -114,7 +114,7 @@ public class TaskInstanceServiceTest { taskInstanceList.add(taskInstance); pageReturn.setRecords(taskInstanceList); when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId()); when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""), @@ -240,12 +240,12 @@ public class TaskInstanceServiceTest { // user auth failed Map mockFailure = new HashMap<>(5); putMsg(mockFailure, Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectCode); - when(projectService.checkProjectAndAuth(user, project, project.getName())).thenReturn(mockFailure); + when(projectService.checkProjectAndAuth(user, project, projectCode)).thenReturn(mockFailure); Map authFailRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId); Assert.assertNotSame(Status.SUCCESS, authFailRes.get(Constants.STATUS)); // test task not found - when(projectService.checkProjectAndAuth(user, project, project.getName())).thenReturn(mockSuccess); + when(projectService.checkProjectAndAuth(user, project, projectCode)).thenReturn(mockSuccess); when(taskInstanceMapper.selectById(Mockito.anyInt())).thenReturn(null); Map taskNotFoundRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId); Assert.assertEquals(Status.TASK_INSTANCE_NOT_FOUND, taskNotFoundRes.get(Constants.STATUS)); @@ -256,7 +256,7 @@ public class TaskInstanceServiceTest { Map result = new HashMap<>(); putMsg(result, Status.SUCCESS, projectCode); when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(user, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(user, project, projectCode)).thenReturn(result); Map taskStateErrorRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId); Assert.assertEquals(Status.TASK_INSTANCE_STATE_OPERATION_ERROR, taskStateErrorRes.get(Constants.STATUS)); @@ -265,7 +265,7 @@ public class TaskInstanceServiceTest { when(taskInstanceMapper.updateById(task)).thenReturn(0); putMsg(result, Status.SUCCESS, projectCode); when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(user, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(user, project, projectCode)).thenReturn(result); Map errorRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId); Assert.assertEquals(Status.FORCE_TASK_SUCCESS_ERROR, errorRes.get(Constants.STATUS)); @@ -274,7 +274,7 @@ public class TaskInstanceServiceTest { when(taskInstanceMapper.updateById(task)).thenReturn(1); putMsg(result, Status.SUCCESS, projectCode); when(projectMapper.queryByCode(projectCode)).thenReturn(project); - when(projectService.checkProjectAndAuth(user, project, project.getName())).thenReturn(result); + when(projectService.checkProjectAndAuth(user, project, projectCode)).thenReturn(result); Map successRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); }