Browse Source

[Feature][JsonSplit-api] replace projectName with projectCode for taskDefinition (#5815)

* fix processDefinitonController projectCode

* queryAllByProjectCode of processDefinition

* query taskNodeList of processDefinition

* replace projectName with projectCode for taskDefinition

Co-authored-by: JinyLeeChina <297062848@qq.com>
2.0.7-release
JinyLeeChina 3 years ago committed by GitHub
parent
commit
47de7cae7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 56
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java
  2. 36
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskDefinitionService.java
  3. 90
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java
  4. 81
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java

56
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java

@ -37,8 +37,6 @@ import org.apache.dolphinscheduler.dao.entity.User;
import java.util.Map; import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -62,11 +60,9 @@ import springfox.documentation.annotations.ApiIgnore;
*/ */
@Api(tags = "TASK_DEFINITION_TAG") @Api(tags = "TASK_DEFINITION_TAG")
@RestController @RestController
@RequestMapping("projects/{projectName}/task") @RequestMapping("projects/{projectCode}/task")
public class TaskDefinitionController extends BaseController { public class TaskDefinitionController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(TaskDefinitionController.class);
@Autowired @Autowired
private TaskDefinitionService taskDefinitionService; private TaskDefinitionService taskDefinitionService;
@ -74,7 +70,7 @@ public class TaskDefinitionController extends BaseController {
* create task definition * create task definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskDefinitionJson task definition json * @param taskDefinitionJson task definition json
* @return create result code * @return create result code
*/ */
@ -88,10 +84,9 @@ public class TaskDefinitionController extends BaseController {
@ApiException(CREATE_TASK_DEFINITION) @ApiException(CREATE_TASK_DEFINITION)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result createTaskDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result createTaskDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson) { @RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson) {
Map<String, Object> result = taskDefinitionService.createTaskDefinition(loginUser, projectCode, taskDefinitionJson);
Map<String, Object> result = taskDefinitionService.createTaskDefinition(loginUser, projectName, taskDefinitionJson);
return returnDataList(result); return returnDataList(result);
} }
@ -99,7 +94,7 @@ public class TaskDefinitionController extends BaseController {
* update task definition * update task definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskDefinitionCode task definition code * @param taskDefinitionCode task definition code
* @param taskDefinitionJson task definition json * @param taskDefinitionJson task definition json
* @return update result code * @return update result code
@ -115,10 +110,10 @@ public class TaskDefinitionController extends BaseController {
@ApiException(UPDATE_TASK_DEFINITION_ERROR) @ApiException(UPDATE_TASK_DEFINITION_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result updateTaskDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result updateTaskDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "taskDefinitionCode") long taskDefinitionCode, @RequestParam(value = "taskDefinitionCode") long taskDefinitionCode,
@RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson) { @RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson) {
Map<String, Object> result = taskDefinitionService.updateTaskDefinition(loginUser, projectName, taskDefinitionCode, taskDefinitionJson); Map<String, Object> result = taskDefinitionService.updateTaskDefinition(loginUser, projectCode, taskDefinitionCode, taskDefinitionJson);
return returnDataList(result); return returnDataList(result);
} }
@ -126,7 +121,7 @@ public class TaskDefinitionController extends BaseController {
* query task definition version paging list info * query task definition version paging list info
* *
* @param loginUser login user info * @param loginUser login user info
* @param projectName project name * @param projectCode project code
* @param pageNo the task definition version list current page number * @param pageNo the task definition version list current page number
* @param pageSize the task definition version list page size * @param pageSize the task definition version list page size
* @param taskDefinitionCode the task definition code * @param taskDefinitionCode the task definition code
@ -143,12 +138,11 @@ public class TaskDefinitionController extends BaseController {
@ApiException(QUERY_TASK_DEFINITION_VERSIONS_ERROR) @ApiException(QUERY_TASK_DEFINITION_VERSIONS_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryTaskDefinitionVersions(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryTaskDefinitionVersions(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "pageNo") int pageNo, @RequestParam(value = "pageNo") int pageNo,
@RequestParam(value = "pageSize") int pageSize, @RequestParam(value = "pageSize") int pageSize,
@RequestParam(value = "taskDefinitionCode") long taskDefinitionCode) { @RequestParam(value = "taskDefinitionCode") long taskDefinitionCode) {
Map<String, Object> result = taskDefinitionService.queryTaskDefinitionVersions(loginUser, Map<String, Object> result = taskDefinitionService.queryTaskDefinitionVersions(loginUser, projectCode, pageNo, pageSize, taskDefinitionCode);
projectName, pageNo, pageSize, taskDefinitionCode);
return returnDataList(result); return returnDataList(result);
} }
@ -156,7 +150,7 @@ public class TaskDefinitionController extends BaseController {
* switch task definition version * switch task definition version
* *
* @param loginUser login user info * @param loginUser login user info
* @param projectName project name * @param projectCode project code
* @param taskDefinitionCode the task definition code * @param taskDefinitionCode the task definition code
* @param version the version user want to switch * @param version the version user want to switch
* @return switch version result code * @return switch version result code
@ -171,10 +165,10 @@ public class TaskDefinitionController extends BaseController {
@ApiException(SWITCH_TASK_DEFINITION_VERSION_ERROR) @ApiException(SWITCH_TASK_DEFINITION_VERSION_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result switchTaskDefinitionVersion(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result switchTaskDefinitionVersion(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "taskDefinitionCode") long taskDefinitionCode, @RequestParam(value = "taskDefinitionCode") long taskDefinitionCode,
@RequestParam(value = "version") int version) { @RequestParam(value = "version") int version) {
Map<String, Object> result = taskDefinitionService.switchVersion(loginUser, projectName, taskDefinitionCode, version); Map<String, Object> result = taskDefinitionService.switchVersion(loginUser, projectCode, taskDefinitionCode, version);
return returnDataList(result); return returnDataList(result);
} }
@ -182,7 +176,7 @@ public class TaskDefinitionController extends BaseController {
* delete the certain task definition version by version and code * delete the certain task definition version by version and code
* *
* @param loginUser login user info * @param loginUser login user info
* @param projectName the task definition project name * @param projectCode project code
* @param taskDefinitionCode the task definition code * @param taskDefinitionCode the task definition code
* @param version the task definition version user want to delete * @param version the task definition version user want to delete
* @return delete version result code * @return delete version result code
@ -197,10 +191,10 @@ public class TaskDefinitionController extends BaseController {
@ApiException(DELETE_TASK_DEFINITION_VERSION_ERROR) @ApiException(DELETE_TASK_DEFINITION_VERSION_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result deleteTaskDefinitionVersion(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result deleteTaskDefinitionVersion(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "taskDefinitionCode") long taskDefinitionCode, @RequestParam(value = "taskDefinitionCode") long taskDefinitionCode,
@RequestParam(value = "version") int version) { @RequestParam(value = "version") int version) {
Map<String, Object> result = taskDefinitionService.deleteByCodeAndVersion(loginUser, projectName, taskDefinitionCode, version); Map<String, Object> result = taskDefinitionService.deleteByCodeAndVersion(loginUser, projectCode, taskDefinitionCode, version);
return returnDataList(result); return returnDataList(result);
} }
@ -208,7 +202,7 @@ public class TaskDefinitionController extends BaseController {
* delete task definition by code * delete task definition by code
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskDefinitionCode the task definition code * @param taskDefinitionCode the task definition code
* @return delete result code * @return delete result code
*/ */
@ -221,9 +215,9 @@ public class TaskDefinitionController extends BaseController {
@ApiException(DELETE_TASK_DEFINE_BY_CODE_ERROR) @ApiException(DELETE_TASK_DEFINE_BY_CODE_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result deleteTaskDefinitionByCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result deleteTaskDefinitionByCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "taskDefinitionCode") long taskDefinitionCode) { @RequestParam(value = "taskDefinitionCode") long taskDefinitionCode) {
Map<String, Object> result = taskDefinitionService.deleteTaskDefinitionByCode(loginUser, projectName, taskDefinitionCode); Map<String, Object> result = taskDefinitionService.deleteTaskDefinitionByCode(loginUser, projectCode, taskDefinitionCode);
return returnDataList(result); return returnDataList(result);
} }
@ -231,7 +225,7 @@ public class TaskDefinitionController extends BaseController {
* query detail of task definition by code * query detail of task definition by code
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskDefinitionCode the task definition code * @param taskDefinitionCode the task definition code
* @return task definition detail * @return task definition detail
*/ */
@ -244,9 +238,9 @@ public class TaskDefinitionController extends BaseController {
@ApiException(QUERY_DETAIL_OF_TASK_DEFINITION_ERROR) @ApiException(QUERY_DETAIL_OF_TASK_DEFINITION_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryTaskDefinitionDetail(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryTaskDefinitionDetail(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "taskDefinitionCode") long taskDefinitionCode) { @RequestParam(value = "taskDefinitionCode") long taskDefinitionCode) {
Map<String, Object> result = taskDefinitionService.queryTaskDefinitionDetail(loginUser, projectName, taskDefinitionCode); Map<String, Object> result = taskDefinitionService.queryTaskDefinitionDetail(loginUser, projectCode, taskDefinitionCode);
return returnDataList(result); return returnDataList(result);
} }
@ -254,7 +248,7 @@ public class TaskDefinitionController extends BaseController {
* query task definition list paging * query task definition list paging
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param searchVal search value * @param searchVal search value
* @param pageNo page number * @param pageNo page number
* @param pageSize page size * @param pageSize page size
@ -273,7 +267,7 @@ public class TaskDefinitionController extends BaseController {
@ApiException(QUERY_TASK_DEFINITION_LIST_PAGING_ERROR) @ApiException(QUERY_TASK_DEFINITION_LIST_PAGING_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryTaskDefinitionListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryTaskDefinitionListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam(value = "userId", required = false, defaultValue = "0") Integer userId, @RequestParam(value = "userId", required = false, defaultValue = "0") Integer userId,
@ -283,7 +277,7 @@ public class TaskDefinitionController extends BaseController {
return returnDataListPaging(result); return returnDataListPaging(result);
} }
searchVal = ParameterUtils.handleEscapes(searchVal); searchVal = ParameterUtils.handleEscapes(searchVal);
result = taskDefinitionService.queryTaskDefinitionListPaging(loginUser, projectName, searchVal, pageNo, pageSize, userId); result = taskDefinitionService.queryTaskDefinitionListPaging(loginUser, projectCode, searchVal, pageNo, pageSize, userId);
return returnDataListPaging(result); return returnDataListPaging(result);
} }
} }

36
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskDefinitionService.java

@ -30,45 +30,45 @@ public interface TaskDefinitionService {
* create task definition * create task definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskDefinitionJson task definition json * @param taskDefinitionJson task definition json
*/ */
Map<String, Object> createTaskDefinition(User loginUser, Map<String, Object> createTaskDefinition(User loginUser,
String projectName, long projectCode,
String taskDefinitionJson); String taskDefinitionJson);
/** /**
* query task definition * query task definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskName task name * @param taskName task name
*/ */
Map<String, Object> queryTaskDefinitionByName(User loginUser, Map<String, Object> queryTaskDefinitionByName(User loginUser,
String projectName, long projectCode,
String taskName); String taskName);
/** /**
* delete task definition * delete task definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskCode task code * @param taskCode task code
*/ */
Map<String, Object> deleteTaskDefinitionByCode(User loginUser, Map<String, Object> deleteTaskDefinitionByCode(User loginUser,
String projectName, long projectCode,
long taskCode); long taskCode);
/** /**
* update task definition * update task definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskCode task code * @param taskCode task code
* @param taskDefinitionJson task definition json * @param taskDefinitionJson task definition json
*/ */
Map<String, Object> updateTaskDefinition(User loginUser, Map<String, Object> updateTaskDefinition(User loginUser,
String projectName, long projectCode,
long taskCode, long taskCode,
String taskDefinitionJson); String taskDefinitionJson);
@ -76,12 +76,12 @@ public interface TaskDefinitionService {
* update task definition * update task definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskCode task code * @param taskCode task code
* @param version the version user want to switch * @param version the version user want to switch
*/ */
Map<String, Object> switchVersion(User loginUser, Map<String, Object> switchVersion(User loginUser,
String projectName, long projectCode,
long taskCode, long taskCode,
int version); int version);
@ -89,14 +89,14 @@ public interface TaskDefinitionService {
* query the pagination versions info by one certain task definition code * query the pagination versions info by one certain task definition code
* *
* @param loginUser login user info to check auth * @param loginUser login user info to check auth
* @param projectName project name * @param projectCode project code
* @param pageNo page number * @param pageNo page number
* @param pageSize page size * @param pageSize page size
* @param taskCode task definition code * @param taskCode task definition code
* @return the pagination task definition versions info of the certain task definition * @return the pagination task definition versions info of the certain task definition
*/ */
Map<String, Object> queryTaskDefinitionVersions(User loginUser, Map<String, Object> queryTaskDefinitionVersions(User loginUser,
String projectName, long projectCode,
int pageNo, int pageNo,
int pageSize, int pageSize,
long taskCode); long taskCode);
@ -105,13 +105,13 @@ public interface TaskDefinitionService {
* delete the certain task definition version by version and code * delete the certain task definition version by version and code
* *
* @param loginUser login user info * @param loginUser login user info
* @param projectName the task definition project name * @param projectCode project code
* @param taskCode the task definition code * @param taskCode the task definition code
* @param version the task definition version user want to delete * @param version the task definition version user want to delete
* @return delete version result code * @return delete version result code
*/ */
Map<String, Object> deleteByCodeAndVersion(User loginUser, Map<String, Object> deleteByCodeAndVersion(User loginUser,
String projectName, long projectCode,
long taskCode, long taskCode,
int version); int version);
@ -119,19 +119,19 @@ public interface TaskDefinitionService {
* query detail of task definition by code * query detail of task definition by code
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskCode the task definition code * @param taskCode the task definition code
* @return task definition detail * @return task definition detail
*/ */
Map<String, Object> queryTaskDefinitionDetail(User loginUser, Map<String, Object> queryTaskDefinitionDetail(User loginUser,
String projectName, long projectCode,
long taskCode); long taskCode);
/** /**
* query task definition list paging * query task definition list paging
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param searchVal search value * @param searchVal search value
* @param pageNo page number * @param pageNo page number
* @param pageSize page size * @param pageSize page size
@ -139,7 +139,7 @@ public interface TaskDefinitionService {
* @return task definition page * @return task definition page
*/ */
Map<String, Object> queryTaskDefinitionListPaging(User loginUser, Map<String, Object> queryTaskDefinitionListPaging(User loginUser,
String projectName, long projectCode,
String searchVal, String searchVal,
Integer pageNo, Integer pageNo,
Integer pageSize, Integer pageSize,

90
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java

@ -41,7 +41,6 @@ import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper;
import org.apache.dolphinscheduler.service.process.ProcessService; import org.apache.dolphinscheduler.service.process.ProcessService;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -83,22 +82,19 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
* create task definition * create task definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskDefinitionJson task definition json * @param taskDefinitionJson task definition json
*/ */
@Transactional(rollbackFor = RuntimeException.class) @Transactional(rollbackFor = RuntimeException.class)
@Override @Override
public Map<String, Object> createTaskDefinition(User loginUser, public Map<String, Object> createTaskDefinition(User loginUser,
String projectName, long projectCode,
String taskDefinitionJson) { String taskDefinitionJson) {
Project project = projectMapper.queryByCode(projectCode);
Map<String, Object> result = new HashMap<>(); //check user access for project
Project project = projectMapper.queryByName(projectName); Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
// check project auth if (result.get(Constants.STATUS) != Status.SUCCESS) {
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); return result;
Status resultStatus = (Status) checkResult.get(Constants.STATUS);
if (resultStatus != Status.SUCCESS) {
return checkResult;
} }
TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class);
@ -130,18 +126,16 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
* query task definition * query task definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskName task name * @param taskName task name
*/ */
@Override @Override
public Map<String, Object> queryTaskDefinitionByName(User loginUser, String projectName, String taskName) { public Map<String, Object> queryTaskDefinitionByName(User loginUser, long projectCode, String taskName) {
Map<String, Object> result = new HashMap<>(); Project project = projectMapper.queryByCode(projectCode);
Project project = projectMapper.queryByName(projectName); //check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); if (result.get(Constants.STATUS) != Status.SUCCESS) {
Status resultStatus = (Status) checkResult.get(Constants.STATUS); return result;
if (resultStatus != Status.SUCCESS) {
return checkResult;
} }
TaskDefinition taskDefinition = taskDefinitionMapper.queryByDefinitionName(project.getCode(), taskName); TaskDefinition taskDefinition = taskDefinitionMapper.queryByDefinitionName(project.getCode(), taskName);
@ -158,19 +152,17 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
* delete task definition * delete task definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskCode task code * @param taskCode task code
*/ */
@Transactional(rollbackFor = RuntimeException.class) @Transactional(rollbackFor = RuntimeException.class)
@Override @Override
public Map<String, Object> deleteTaskDefinitionByCode(User loginUser, String projectName, long taskCode) { public Map<String, Object> deleteTaskDefinitionByCode(User loginUser, long projectCode, long taskCode) {
Map<String, Object> result = new HashMap<>(5); Project project = projectMapper.queryByCode(projectCode);
Project project = projectMapper.queryByName(projectName); //check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); if (result.get(Constants.STATUS) != Status.SUCCESS) {
Status resultEnum = (Status) checkResult.get(Constants.STATUS); return result;
if (resultEnum != Status.SUCCESS) {
return checkResult;
} }
List<ProcessTaskRelation> processTaskRelationList = processTaskRelationMapper.queryByTaskCode(taskCode); List<ProcessTaskRelation> processTaskRelationList = processTaskRelationMapper.queryByTaskCode(taskCode);
if (!processTaskRelationList.isEmpty()) { if (!processTaskRelationList.isEmpty()) {
@ -194,20 +186,18 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
* update task definition * update task definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskCode task code * @param taskCode task code
* @param taskDefinitionJson task definition json * @param taskDefinitionJson task definition json
*/ */
@Transactional(rollbackFor = RuntimeException.class) @Transactional(rollbackFor = RuntimeException.class)
@Override @Override
public Map<String, Object> updateTaskDefinition(User loginUser, String projectName, long taskCode, String taskDefinitionJson) { public Map<String, Object> updateTaskDefinition(User loginUser, long projectCode, long taskCode, String taskDefinitionJson) {
Map<String, Object> result = new HashMap<>(5); Project project = projectMapper.queryByCode(projectCode);
Project project = projectMapper.queryByName(projectName); //check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); if (result.get(Constants.STATUS) != Status.SUCCESS) {
Status resultEnum = (Status) checkResult.get(Constants.STATUS); return result;
if (resultEnum != Status.SUCCESS) {
return checkResult;
} }
if (processService.isTaskOnline(taskCode)) { if (processService.isTaskOnline(taskCode)) {
putMsg(result, Status.PROCESS_DEFINE_STATE_ONLINE); putMsg(result, Status.PROCESS_DEFINE_STATE_ONLINE);
@ -246,19 +236,17 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
* update task definition * update task definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param taskCode task code * @param taskCode task code
* @param version the version user want to switch * @param version the version user want to switch
*/ */
@Override @Override
public Map<String, Object> switchVersion(User loginUser, String projectName, long taskCode, int version) { public Map<String, Object> switchVersion(User loginUser, long projectCode, long taskCode, int version) {
Map<String, Object> result = new HashMap<>(5); Project project = projectMapper.queryByCode(projectCode);
Project project = projectMapper.queryByName(projectName); //check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); if (result.get(Constants.STATUS) != Status.SUCCESS) {
Status resultEnum = (Status) checkResult.get(Constants.STATUS); return result;
if (resultEnum != Status.SUCCESS) {
return checkResult;
} }
if (processService.isTaskOnline(taskCode)) { if (processService.isTaskOnline(taskCode)) {
putMsg(result, Status.PROCESS_DEFINE_STATE_ONLINE); putMsg(result, Status.PROCESS_DEFINE_STATE_ONLINE);
@ -279,23 +267,23 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
} }
@Override @Override
public Map<String, Object> queryTaskDefinitionVersions(User loginUser, String projectName, int pageNo, int pageSize, long taskCode) { public Map<String, Object> queryTaskDefinitionVersions(User loginUser, long projectCode, int pageNo, int pageSize, long taskCode) {
return null; return null;
} }
@Override @Override
public Map<String, Object> deleteByCodeAndVersion(User loginUser, String projectName, long taskCode, int version) { public Map<String, Object> deleteByCodeAndVersion(User loginUser, long projectCode, long taskCode, int version) {
return null; return null;
} }
@Override @Override
public Map<String, Object> queryTaskDefinitionDetail(User loginUser, String projectName, long taskCode) { public Map<String, Object> queryTaskDefinitionDetail(User loginUser, long projectCode, long taskCode) {
return null; return null;
} }
@Override @Override
public Map<String, Object> queryTaskDefinitionListPaging(User loginUser, public Map<String, Object> queryTaskDefinitionListPaging(User loginUser,
String projectName, long projectCode,
String searchVal, String searchVal,
Integer pageNo, Integer pageNo,
Integer pageSize, Integer pageSize,

81
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java

@ -119,20 +119,18 @@ public class TaskDefinitionServiceImplTest {
@Test @Test
public void createTaskDefinition() { public void createTaskDefinition() {
String projectName = "project_test1"; long projectCode = 1L;
Project project = getProject(projectName); Project project = getProject(projectCode);
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
User loginUser = new User(); User loginUser = new User();
loginUser.setId(-1); loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
//project check auth fail
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class);
@ -143,7 +141,7 @@ public class TaskDefinitionServiceImplTest {
.thenReturn(1); .thenReturn(1);
Map<String, Object> relation = taskDefinitionService Map<String, Object> relation = taskDefinitionService
.createTaskDefinition(loginUser, projectName, taskDefinitionJson); .createTaskDefinition(loginUser, projectCode, taskDefinitionJson);
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS));
@ -151,20 +149,19 @@ public class TaskDefinitionServiceImplTest {
@Test @Test
public void queryTaskDefinitionByName() { public void queryTaskDefinitionByName() {
String projectName = "project_test1";
String taskName = "task"; String taskName = "task";
Project project = getProject(projectName); long projectCode = 1L;
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project);
Project project = getProject(projectCode);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
User loginUser = new User(); User loginUser = new User();
loginUser.setId(-1); loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
//project check auth fail
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class);
@ -172,27 +169,25 @@ public class TaskDefinitionServiceImplTest {
.thenReturn(new TaskDefinition()); .thenReturn(new TaskDefinition());
Map<String, Object> relation = taskDefinitionService Map<String, Object> relation = taskDefinitionService
.queryTaskDefinitionByName(loginUser, projectName, taskName); .queryTaskDefinitionByName(loginUser, projectCode, taskName);
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS));
} }
@Test @Test
public void deleteTaskDefinitionByCode() { public void deleteTaskDefinitionByCode() {
String projectName = "project_test1"; long projectCode = 1L;
Project project = getProject(projectName); Project project = getProject(projectCode);
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
User loginUser = new User(); User loginUser = new User();
loginUser.setId(-1); loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
//project check auth fail
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class);
@ -200,7 +195,7 @@ public class TaskDefinitionServiceImplTest {
.thenReturn(1); .thenReturn(1);
Map<String, Object> relation = taskDefinitionService Map<String, Object> relation = taskDefinitionService
.deleteTaskDefinitionByCode(loginUser, projectName, 11L); .deleteTaskDefinitionByCode(loginUser, projectCode, 11L);
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS));
@ -208,20 +203,18 @@ public class TaskDefinitionServiceImplTest {
@Test @Test
public void updateTaskDefinition() { public void updateTaskDefinition() {
String projectName = "project_test1"; long projectCode = 1L;
Project project = getProject(projectName); Project project = getProject(projectCode);
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
User loginUser = new User(); User loginUser = new User();
loginUser.setId(-1); loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
//project check auth fail
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class);
@ -235,28 +228,27 @@ public class TaskDefinitionServiceImplTest {
.thenReturn(new TaskDefinition()); .thenReturn(new TaskDefinition());
Map<String, Object> relation = taskDefinitionService Map<String, Object> relation = taskDefinitionService
.updateTaskDefinition(loginUser, projectName, 11L, taskDefinitionJson); .updateTaskDefinition(loginUser, projectCode, 11L, taskDefinitionJson);
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS));
} }
@Test @Test
public void switchVersion() { public void switchVersion() {
String projectName = "project_test1";
int version = 1; int version = 1;
Long taskCode = 11L; long taskCode = 11L;
Project project = getProject(projectName); long projectCode = 1L;
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project);
Project project = getProject(projectCode);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
User loginUser = new User(); User loginUser = new User();
loginUser.setId(-1); loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
//project check auth fail
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class); TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson, TaskNode.class);
@ -267,7 +259,7 @@ public class TaskDefinitionServiceImplTest {
.thenReturn(new TaskDefinition()); .thenReturn(new TaskDefinition());
Map<String, Object> relation = taskDefinitionService Map<String, Object> relation = taskDefinitionService
.switchVersion(loginUser, projectName, taskCode, version); .switchVersion(loginUser, projectCode, taskCode, version);
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS));
} }
@ -284,13 +276,14 @@ public class TaskDefinitionServiceImplTest {
/** /**
* get mock Project * get mock Project
* *
* @param projectName projectName * @param projectCode projectCode
* @return Project * @return Project
*/ */
private Project getProject(String projectName) { private Project getProject(long projectCode) {
Project project = new Project(); Project project = new Project();
project.setId(1); project.setId(1);
project.setName(projectName); project.setCode(projectCode);
project.setName("test");
project.setUserId(1); project.setUserId(1);
return project; return project;
} }

Loading…
Cancel
Save