CalvinKirs
3 years ago
68 changed files with 3761 additions and 582 deletions
@ -0,0 +1,297 @@ |
|||||||
|
/* |
||||||
|
* 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.controller; |
||||||
|
|
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.CREATE_PROCESS_TASK_RELATION_ERROR; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.DATA_IS_NOT_VALID; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.DELETE_EDGE_ERROR; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.DELETE_TASK_PROCESS_RELATION_ERROR; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.MOVE_PROCESS_TASK_RELATION_ERROR; |
||||||
|
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_PROCESS_RELATION_ERROR; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; |
||||||
|
import org.apache.dolphinscheduler.api.exceptions.ApiException; |
||||||
|
import org.apache.dolphinscheduler.api.service.ProcessTaskRelationService; |
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.common.Constants; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.User; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.http.HttpStatus; |
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestAttribute; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiImplicitParam; |
||||||
|
import io.swagger.annotations.ApiImplicitParams; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import io.swagger.annotations.ApiParam; |
||||||
|
import springfox.documentation.annotations.ApiIgnore; |
||||||
|
|
||||||
|
/** |
||||||
|
* process task relation controller |
||||||
|
*/ |
||||||
|
@Api(tags = "PROCESS_TASK_RELATION_TAG") |
||||||
|
@RestController |
||||||
|
@RequestMapping("projects/{projectCode}/process-task-relation") |
||||||
|
public class ProcessTaskRelationController extends BaseController { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ProcessTaskRelationService processTaskRelationService; |
||||||
|
|
||||||
|
/** |
||||||
|
* create process task relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param processDefinitionCode processDefinitionCode |
||||||
|
* @param preTaskCode preTaskCode |
||||||
|
* @param postTaskCode postTaskCode |
||||||
|
* @return create result code |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "save", notes = "CREATE_PROCESS_TASK_RELATION_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", required = true, type = "Long"), |
||||||
|
@ApiImplicitParam(name = "processDefinitionCode", value = "PROCESS_DEFINITION_CODE", required = true, type = "Long"), |
||||||
|
@ApiImplicitParam(name = "preTaskCode", value = "PRE_TASK_CODE", required = true, type = "Long"), |
||||||
|
@ApiImplicitParam(name = "postTaskCode", value = "POST_TASK_CODE", required = true, type = "Long") |
||||||
|
}) |
||||||
|
@PostMapping() |
||||||
|
@ResponseStatus(HttpStatus.CREATED) |
||||||
|
@ApiException(CREATE_PROCESS_TASK_RELATION_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result createProcessTaskRelation(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, |
||||||
|
@RequestParam(name = "processDefinitionCode", required = true) long processDefinitionCode, |
||||||
|
@RequestParam(name = "preTaskCode", required = true) long preTaskCode, |
||||||
|
@RequestParam(name = "postTaskCode", required = true) long postTaskCode) { |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
if (postTaskCode == 0L) { |
||||||
|
putMsg(result, DATA_IS_NOT_VALID, "postTaskCode"); |
||||||
|
} else if (processDefinitionCode == 0L) { |
||||||
|
putMsg(result, DATA_IS_NOT_VALID, "processDefinitionCode"); |
||||||
|
} else { |
||||||
|
result = processTaskRelationService.createProcessTaskRelation(loginUser, projectCode, processDefinitionCode, preTaskCode, postTaskCode); |
||||||
|
} |
||||||
|
return returnDataList(result); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* move task to other processDefinition |
||||||
|
* |
||||||
|
* @param loginUser login user info |
||||||
|
* @param projectCode project code |
||||||
|
* @param processDefinitionCode process definition code |
||||||
|
* @param targetProcessDefinitionCode target process definition code |
||||||
|
* @param taskCode the current task code (the post task code) |
||||||
|
* @return move result code |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "moveRelation", notes = "MOVE_TASK_TO_OTHER_PROCESS_DEFINITION_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", required = true, type = "Long"), |
||||||
|
@ApiImplicitParam(name = "processDefinitionCode", value = "PROCESS_DEFINITION_CODE", required = true, type = "Long"), |
||||||
|
@ApiImplicitParam(name = "targetProcessDefinitionCode", value = "TARGET_PROCESS_DEFINITION_CODE", required = true, type = "Long"), |
||||||
|
@ApiImplicitParam(name = "taskCode", value = "TASK_CODE", required = true, type = "Long") |
||||||
|
}) |
||||||
|
@PostMapping(value = "/move") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(MOVE_PROCESS_TASK_RELATION_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result moveTaskProcessRelation(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, |
||||||
|
@RequestParam(name = "processDefinitionCode", required = true) long processDefinitionCode, |
||||||
|
@RequestParam(name = "targetProcessDefinitionCode", required = true) long targetProcessDefinitionCode, |
||||||
|
@RequestParam(name = "taskCode", required = true) long taskCode) { |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
if (processDefinitionCode == 0L) { |
||||||
|
putMsg(result, DATA_IS_NOT_VALID, "processDefinitionCode"); |
||||||
|
} else if (targetProcessDefinitionCode == 0L) { |
||||||
|
putMsg(result, DATA_IS_NOT_VALID, "targetProcessDefinitionCode"); |
||||||
|
} else if (taskCode == 0L) { |
||||||
|
putMsg(result, DATA_IS_NOT_VALID, "taskCode"); |
||||||
|
} else { |
||||||
|
result = processTaskRelationService.moveTaskProcessRelation(loginUser, projectCode, processDefinitionCode, |
||||||
|
targetProcessDefinitionCode, taskCode); |
||||||
|
} |
||||||
|
return returnDataList(result); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete process task relation (delete task from workflow) |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param processDefinitionCode process definition code |
||||||
|
* @param taskCode the post task code |
||||||
|
* @return delete result code |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "deleteRelation", notes = "DELETE_PROCESS_TASK_RELATION_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", required = true, type = "Long"), |
||||||
|
@ApiImplicitParam(name = "processDefinitionCode", value = "PROCESS_DEFINITION_CODE", required = true, type = "Long"), |
||||||
|
@ApiImplicitParam(name = "taskCode", value = "TASK_CODE", required = true, type = "Long") |
||||||
|
}) |
||||||
|
@DeleteMapping(value = "/{taskCode}") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(DELETE_TASK_PROCESS_RELATION_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result deleteTaskProcessRelation(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, |
||||||
|
@RequestParam(name = "processDefinitionCode", required = true) long processDefinitionCode, |
||||||
|
@PathVariable("taskCode") long taskCode) { |
||||||
|
return returnDataList(processTaskRelationService.deleteTaskProcessRelation(loginUser, projectCode, processDefinitionCode, taskCode)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete task upstream relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param preTaskCodes the pre task codes, sep ',' |
||||||
|
* @param taskCode the post task code |
||||||
|
* @return delete result code |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "deleteUpstreamRelation", notes = "DELETE_UPSTREAM_RELATION_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", required = true, type = "Long"), |
||||||
|
@ApiImplicitParam(name = "preTaskCodes", value = "PRE_TASK_CODES", required = true, type = "String", example = "3,4"), |
||||||
|
@ApiImplicitParam(name = "taskCode", value = "TASK_CODE", required = true, type = "Long") |
||||||
|
}) |
||||||
|
@DeleteMapping(value = "/{taskCode}/upstream") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(DELETE_TASK_PROCESS_RELATION_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result deleteUpstreamRelation(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, |
||||||
|
@RequestParam(name = "preTaskCodes", required = true) String preTaskCodes, |
||||||
|
@PathVariable("taskCode") long taskCode) { |
||||||
|
return returnDataList(processTaskRelationService.deleteUpstreamRelation(loginUser, projectCode, preTaskCodes, taskCode)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete task downstream relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param postTaskCodes the post task codes, sep ',' |
||||||
|
* @param taskCode the pre task code |
||||||
|
* @return delete result code |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "deleteDownstreamRelation", notes = "DELETE_DOWNSTREAM_RELATION_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", required = true, type = "Long"), |
||||||
|
@ApiImplicitParam(name = "postTaskCodes", value = "POST_TASK_CODES", required = true, type = "String", example = "3,4"), |
||||||
|
@ApiImplicitParam(name = "taskCode", value = "TASK_CODE", required = true, type = "Long") |
||||||
|
}) |
||||||
|
@DeleteMapping(value = "/{taskCode}/downstream") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(DELETE_TASK_PROCESS_RELATION_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result deleteDownstreamRelation(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, |
||||||
|
@RequestParam(name = "postTaskCodes", required = true) String postTaskCodes, |
||||||
|
@PathVariable("taskCode") long taskCode) { |
||||||
|
return returnDataList(processTaskRelationService.deleteDownstreamRelation(loginUser, projectCode, postTaskCodes, taskCode)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query task upstream relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param taskCode current task code (post task code) |
||||||
|
* @return process task relation list |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "queryUpstreamRelation", notes = "QUERY_UPSTREAM_RELATION_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", required = true, type = "Long"), |
||||||
|
@ApiImplicitParam(name = "taskCode", value = "TASK_CODE", required = true, type = "Long") |
||||||
|
}) |
||||||
|
@GetMapping(value = "/{taskCode}/upstream") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(QUERY_TASK_PROCESS_RELATION_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result queryUpstreamRelation(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, |
||||||
|
@PathVariable("taskCode") long taskCode) { |
||||||
|
return returnDataList(processTaskRelationService.queryUpstreamRelation(loginUser, projectCode, taskCode)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query task downstream relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param taskCode pre task code |
||||||
|
* @return process task relation list |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "queryDownstreamRelation", notes = "QUERY_DOWNSTREAM_RELATION_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", required = true, type = "Long"), |
||||||
|
@ApiImplicitParam(name = "taskCode", value = "TASK_CODE", required = true, type = "Long") |
||||||
|
}) |
||||||
|
@GetMapping(value = "/{taskCode}/downstream") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(QUERY_TASK_PROCESS_RELATION_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result queryDownstreamRelation(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, |
||||||
|
@PathVariable("taskCode") long taskCode) { |
||||||
|
return returnDataList(processTaskRelationService.queryDownstreamRelation(loginUser, projectCode, taskCode)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete edge |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param processDefinitionCode process definition code |
||||||
|
* @param preTaskCode pre task code |
||||||
|
* @param postTaskCode post task code |
||||||
|
* @return delete result code |
||||||
|
*/ |
||||||
|
@ApiOperation(value = "deleteEdge", notes = "DELETE_EDGE_NOTES") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", required = true, type = "Long"), |
||||||
|
@ApiImplicitParam(name = "processDefinitionCode", value = "PROCESS_DEFINITION_CODE", required = true, type = "Long"), |
||||||
|
@ApiImplicitParam(name = "preTaskCode", value = "PRE_TASK_CODE", required = true, type = "Long"), |
||||||
|
@ApiImplicitParam(name = "postTaskCode", value = "POST_TASK_CODE", required = true, type = "Long") |
||||||
|
}) |
||||||
|
@DeleteMapping(value = "/{processDefinitionCode}/{preTaskCode}/{postTaskCode}") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
@ApiException(DELETE_EDGE_ERROR) |
||||||
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") |
||||||
|
public Result deleteEdge(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) |
||||||
|
@PathVariable long projectCode, |
||||||
|
@PathVariable long processDefinitionCode, |
||||||
|
@PathVariable long preTaskCode, |
||||||
|
@PathVariable long postTaskCode) { |
||||||
|
return returnDataList(processTaskRelationService.deleteEdge(loginUser, projectCode, processDefinitionCode, preTaskCode, postTaskCode)); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,138 @@ |
|||||||
|
/* |
||||||
|
* 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 { |
||||||
|
|
||||||
|
/** |
||||||
|
* create process task relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param processDefinitionCode processDefinitionCode |
||||||
|
* @param preTaskCode preTaskCode |
||||||
|
* @param postTaskCode postTaskCode |
||||||
|
* @return create result code |
||||||
|
*/ |
||||||
|
Map<String, Object> createProcessTaskRelation(User loginUser, |
||||||
|
long projectCode, |
||||||
|
long processDefinitionCode, |
||||||
|
long preTaskCode, |
||||||
|
long postTaskCode); |
||||||
|
|
||||||
|
/** |
||||||
|
* move task to other processDefinition |
||||||
|
* |
||||||
|
* @param loginUser login user info |
||||||
|
* @param projectCode project code |
||||||
|
* @param processDefinitionCode process definition code |
||||||
|
* @param targetProcessDefinitionCode target process definition code |
||||||
|
* @param taskCode the current task code (the post task code) |
||||||
|
* @return move result code |
||||||
|
*/ |
||||||
|
Map<String, Object> moveTaskProcessRelation(User loginUser, |
||||||
|
long projectCode, |
||||||
|
long processDefinitionCode, |
||||||
|
long targetProcessDefinitionCode, |
||||||
|
long taskCode); |
||||||
|
|
||||||
|
/** |
||||||
|
* delete process task relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param processDefinitionCode process definition code |
||||||
|
* @param taskCode the post task code |
||||||
|
* @return delete result code |
||||||
|
*/ |
||||||
|
Map<String, Object> deleteTaskProcessRelation(User loginUser, |
||||||
|
long projectCode, |
||||||
|
long processDefinitionCode, |
||||||
|
long taskCode); |
||||||
|
|
||||||
|
/** |
||||||
|
* delete task upstream relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param preTaskCodes the pre task codes, sep ',' |
||||||
|
* @param taskCode the post task code |
||||||
|
* @return delete result code |
||||||
|
*/ |
||||||
|
Map<String, Object> deleteUpstreamRelation(User loginUser, |
||||||
|
long projectCode, |
||||||
|
String preTaskCodes, |
||||||
|
long taskCode); |
||||||
|
|
||||||
|
/** |
||||||
|
* delete task downstream relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param postTaskCodes the post task codes, sep ',' |
||||||
|
* @param taskCode the pre task code |
||||||
|
* @return delete result code |
||||||
|
*/ |
||||||
|
Map<String, Object> deleteDownstreamRelation(User loginUser, |
||||||
|
long projectCode, |
||||||
|
String postTaskCodes, |
||||||
|
long taskCode); |
||||||
|
|
||||||
|
/** |
||||||
|
* query task upstream relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param taskCode current task code (post task code) |
||||||
|
* @return process task relation list |
||||||
|
*/ |
||||||
|
Map<String, Object> queryUpstreamRelation(User loginUser, |
||||||
|
long projectCode, |
||||||
|
long taskCode); |
||||||
|
|
||||||
|
/** |
||||||
|
* query task downstream relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param taskCode pre task code |
||||||
|
* @return process task relation list |
||||||
|
*/ |
||||||
|
Map<String, Object> queryDownstreamRelation(User loginUser, |
||||||
|
long projectCode, |
||||||
|
long taskCode); |
||||||
|
|
||||||
|
/** |
||||||
|
* delete edge |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param processDefinitionCode process definition code |
||||||
|
* @param preTaskCode pre task code |
||||||
|
* @param postTaskCode post task code |
||||||
|
* @return delete result code |
||||||
|
*/ |
||||||
|
Map<String, Object> deleteEdge(User loginUser, long projectCode, long processDefinitionCode, long preTaskCode, long postTaskCode); |
||||||
|
} |
@ -0,0 +1,653 @@ |
|||||||
|
/* |
||||||
|
* 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 static org.apache.dolphinscheduler.api.enums.Status.DATA_IS_NOT_VALID; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.enums.Status; |
||||||
|
import org.apache.dolphinscheduler.api.exceptions.ServiceException; |
||||||
|
import org.apache.dolphinscheduler.api.service.ProcessTaskRelationService; |
||||||
|
import org.apache.dolphinscheduler.api.service.ProjectService; |
||||||
|
import org.apache.dolphinscheduler.common.Constants; |
||||||
|
import org.apache.dolphinscheduler.common.enums.ConditionType; |
||||||
|
import org.apache.dolphinscheduler.common.enums.TaskType; |
||||||
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.Project; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.TaskDefinition; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.User; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationLogMapper; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; |
||||||
|
import org.apache.dolphinscheduler.spi.utils.StringUtils; |
||||||
|
|
||||||
|
import org.apache.commons.collections.CollectionUtils; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.HashSet; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Objects; |
||||||
|
import java.util.Set; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import org.springframework.transaction.annotation.Transactional; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode; |
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode; |
||||||
|
import com.google.common.collect.Lists; |
||||||
|
|
||||||
|
/** |
||||||
|
* process task relation service impl |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class ProcessTaskRelationServiceImpl extends BaseServiceImpl implements ProcessTaskRelationService { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ProjectMapper projectMapper; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ProjectService projectService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ProcessTaskRelationMapper processTaskRelationMapper; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ProcessTaskRelationLogMapper processTaskRelationLogMapper; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private TaskDefinitionLogMapper taskDefinitionLogMapper; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private TaskDefinitionMapper taskDefinitionMapper; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ProcessDefinitionMapper processDefinitionMapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* create process task relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param processDefinitionCode processDefinitionCode |
||||||
|
* @param preTaskCode preTaskCode |
||||||
|
* @param postTaskCode postTaskCode |
||||||
|
* @return create result code |
||||||
|
*/ |
||||||
|
@Transactional(rollbackFor = RuntimeException.class) |
||||||
|
@Override |
||||||
|
public Map<String, Object> createProcessTaskRelation(User loginUser, long projectCode, long processDefinitionCode, long preTaskCode, long postTaskCode) { |
||||||
|
Project project = projectMapper.queryByCode(projectCode); |
||||||
|
//check user access for project
|
||||||
|
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, projectCode); |
||||||
|
if (result.get(Constants.STATUS) != Status.SUCCESS) { |
||||||
|
return result; |
||||||
|
} |
||||||
|
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(processDefinitionCode); |
||||||
|
if (processDefinition == null) { |
||||||
|
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionCode); |
||||||
|
return result; |
||||||
|
} |
||||||
|
if (processDefinition.getProjectCode() != projectCode) { |
||||||
|
putMsg(result, Status.PROJECT_PROCESS_NOT_MATCH); |
||||||
|
return result; |
||||||
|
} |
||||||
|
List<ProcessTaskRelation> processTaskRelations = processTaskRelationMapper.queryByCode(projectCode, processDefinitionCode, 0L, postTaskCode); |
||||||
|
if (!processTaskRelations.isEmpty()) { |
||||||
|
Map<Long, ProcessTaskRelation> preTaskCodeMap = processTaskRelations.stream() |
||||||
|
.collect(Collectors.toMap(ProcessTaskRelation::getPreTaskCode, processTaskRelation -> processTaskRelation)); |
||||||
|
if (preTaskCodeMap.containsKey(preTaskCode) || (!preTaskCodeMap.containsKey(0L) && preTaskCode == 0L)) { |
||||||
|
putMsg(result, Status.PROCESS_TASK_RELATION_EXIST, processDefinitionCode); |
||||||
|
return result; |
||||||
|
} |
||||||
|
if (preTaskCodeMap.containsKey(0L) && preTaskCode != 0L) { |
||||||
|
ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(preTaskCodeMap.get(0L)); |
||||||
|
// delete no upstream
|
||||||
|
int delete = processTaskRelationMapper.deleteRelation(processTaskRelationLog); |
||||||
|
int deleteLog = processTaskRelationLogMapper.deleteRelation(processTaskRelationLog); |
||||||
|
if ((delete & deleteLog) == 0) { |
||||||
|
putMsg(result, Status.CREATE_PROCESS_TASK_RELATION_ERROR); |
||||||
|
throw new ServiceException(Status.CREATE_PROCESS_TASK_RELATION_ERROR); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
Date now = new Date(); |
||||||
|
List<ProcessTaskRelationLog> processTaskRelationLogs = new ArrayList<>(); |
||||||
|
if (preTaskCode != 0L) { |
||||||
|
// upstream is or not exist
|
||||||
|
List<ProcessTaskRelation> upstreamProcessTaskRelations = processTaskRelationMapper.queryByCode(projectCode, processDefinitionCode, 0L, preTaskCode); |
||||||
|
TaskDefinition preTaskDefinition = taskDefinitionMapper.queryByCode(preTaskCode); |
||||||
|
if (upstreamProcessTaskRelations.isEmpty()) { |
||||||
|
ProcessTaskRelationLog processTaskRelationLog = setRelationLog(processDefinition, now, loginUser.getId(), preTaskDefinition); |
||||||
|
processTaskRelationLog.setPreTaskCode(0L); |
||||||
|
processTaskRelationLog.setPreTaskVersion(0); |
||||||
|
processTaskRelationLogs.add(processTaskRelationLog); |
||||||
|
} |
||||||
|
TaskDefinition postTaskDefinition = taskDefinitionMapper.queryByCode(postTaskCode); |
||||||
|
ProcessTaskRelationLog processTaskRelationLog = setRelationLog(processDefinition, now, loginUser.getId(), postTaskDefinition); |
||||||
|
processTaskRelationLog.setPreTaskCode(preTaskDefinition.getCode()); |
||||||
|
processTaskRelationLog.setPreTaskVersion(preTaskDefinition.getVersion()); |
||||||
|
processTaskRelationLogs.add(processTaskRelationLog); |
||||||
|
} else { |
||||||
|
TaskDefinition postTaskDefinition = taskDefinitionMapper.queryByCode(postTaskCode); |
||||||
|
ProcessTaskRelationLog processTaskRelationLog = setRelationLog(processDefinition, now, loginUser.getId(), postTaskDefinition); |
||||||
|
processTaskRelationLog.setPreTaskCode(0L); |
||||||
|
processTaskRelationLog.setPreTaskVersion(0); |
||||||
|
processTaskRelationLogs.add(processTaskRelationLog); |
||||||
|
} |
||||||
|
int insert = processTaskRelationMapper.batchInsert(processTaskRelationLogs); |
||||||
|
int insertLog = processTaskRelationLogMapper.batchInsert(processTaskRelationLogs); |
||||||
|
if ((insert & insertLog) > 0) { |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
} else { |
||||||
|
putMsg(result, Status.CREATE_PROCESS_TASK_RELATION_ERROR); |
||||||
|
throw new ServiceException(Status.CREATE_PROCESS_TASK_RELATION_ERROR); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
private ProcessTaskRelationLog setRelationLog(ProcessDefinition processDefinition, Date now, int userId, TaskDefinition taskDefinition) { |
||||||
|
ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(); |
||||||
|
processTaskRelationLog.setProjectCode(processDefinition.getProjectCode()); |
||||||
|
processTaskRelationLog.setProcessDefinitionCode(processDefinition.getCode()); |
||||||
|
processTaskRelationLog.setProcessDefinitionVersion(processDefinition.getVersion()); |
||||||
|
processTaskRelationLog.setPostTaskCode(taskDefinition.getCode()); |
||||||
|
processTaskRelationLog.setPostTaskVersion(taskDefinition.getVersion()); |
||||||
|
processTaskRelationLog.setConditionType(ConditionType.NONE); |
||||||
|
processTaskRelationLog.setConditionParams("{}"); |
||||||
|
processTaskRelationLog.setCreateTime(now); |
||||||
|
processTaskRelationLog.setUpdateTime(now); |
||||||
|
processTaskRelationLog.setOperator(userId); |
||||||
|
processTaskRelationLog.setOperateTime(now); |
||||||
|
return processTaskRelationLog; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* move task to other processDefinition |
||||||
|
* |
||||||
|
* @param loginUser login user info |
||||||
|
* @param projectCode project code |
||||||
|
* @param processDefinitionCode process definition code |
||||||
|
* @param targetProcessDefinitionCode target process definition code |
||||||
|
* @param taskCode the current task code (the post task code) |
||||||
|
* @return move result code |
||||||
|
*/ |
||||||
|
@Transactional(rollbackFor = RuntimeException.class) |
||||||
|
@Override |
||||||
|
public Map<String, Object> moveTaskProcessRelation(User loginUser, long projectCode, long processDefinitionCode, long targetProcessDefinitionCode, long taskCode) { |
||||||
|
Project project = projectMapper.queryByCode(projectCode); |
||||||
|
//check user access for project
|
||||||
|
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, projectCode); |
||||||
|
if (result.get(Constants.STATUS) != Status.SUCCESS) { |
||||||
|
return result; |
||||||
|
} |
||||||
|
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(targetProcessDefinitionCode); |
||||||
|
if (processDefinition == null) { |
||||||
|
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, targetProcessDefinitionCode); |
||||||
|
return result; |
||||||
|
} |
||||||
|
if (processDefinition.getProjectCode() != projectCode) { |
||||||
|
putMsg(result, Status.PROJECT_PROCESS_NOT_MATCH); |
||||||
|
return result; |
||||||
|
} |
||||||
|
List<ProcessTaskRelation> downstreamList = processTaskRelationMapper.queryByCode(projectCode, processDefinitionCode, taskCode, 0L); |
||||||
|
if (CollectionUtils.isNotEmpty(downstreamList)) { |
||||||
|
Set<Long> postTaskCodes = downstreamList |
||||||
|
.stream() |
||||||
|
.map(ProcessTaskRelation::getPostTaskCode) |
||||||
|
.collect(Collectors.toSet()); |
||||||
|
putMsg(result, Status.TASK_HAS_DOWNSTREAM, org.apache.commons.lang.StringUtils.join(postTaskCodes, ",")); |
||||||
|
return result; |
||||||
|
} |
||||||
|
List<ProcessTaskRelation> upstreamList = processTaskRelationMapper.queryByCode(projectCode, processDefinitionCode, 0L, taskCode); |
||||||
|
if (upstreamList.isEmpty()) { |
||||||
|
putMsg(result, Status.PROCESS_TASK_RELATION_NOT_EXIST, "taskCode:" + taskCode); |
||||||
|
return result; |
||||||
|
} else { |
||||||
|
Set<Long> preTaskCodes = upstreamList |
||||||
|
.stream() |
||||||
|
.map(ProcessTaskRelation::getPreTaskCode) |
||||||
|
.collect(Collectors.toSet()); |
||||||
|
if (preTaskCodes.size() > 1 || !preTaskCodes.contains(0L)) { |
||||||
|
putMsg(result, Status.TASK_HAS_UPSTREAM, org.apache.commons.lang.StringUtils.join(preTaskCodes, ",")); |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
||||||
|
TaskDefinition taskDefinition = taskDefinitionMapper.queryByCode(taskCode); |
||||||
|
if (null == taskDefinition) { |
||||||
|
putMsg(result, Status.DATA_IS_NULL, "taskDefinition"); |
||||||
|
return result; |
||||||
|
} |
||||||
|
ObjectNode paramNode = JSONUtils.parseObject(taskDefinition.getTaskParams()); |
||||||
|
if (TaskType.DEPENDENT.getDesc().equals(taskDefinition.getTaskType())) { |
||||||
|
Set<Long> depProcessDefinitionCodes = new HashSet<>(); |
||||||
|
ObjectNode dependence = (ObjectNode) paramNode.get("dependence"); |
||||||
|
ArrayNode dependTaskList = JSONUtils.parseArray(JSONUtils.toJsonString(dependence.get("dependTaskList"))); |
||||||
|
for (int i = 0; i < dependTaskList.size(); i++) { |
||||||
|
ObjectNode dependTask = (ObjectNode) dependTaskList.path(i); |
||||||
|
ArrayNode dependItemList = JSONUtils.parseArray(JSONUtils.toJsonString(dependTask.get("dependItemList"))); |
||||||
|
for (int j = 0; j < dependItemList.size(); j++) { |
||||||
|
ObjectNode dependItem = (ObjectNode) dependItemList.path(j); |
||||||
|
long definitionCode = dependItem.get("definitionCode").asLong(); |
||||||
|
depProcessDefinitionCodes.add(definitionCode); |
||||||
|
} |
||||||
|
} |
||||||
|
if (depProcessDefinitionCodes.contains(targetProcessDefinitionCode)) { |
||||||
|
putMsg(result, DATA_IS_NOT_VALID, "targetProcessDefinitionCode"); |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
||||||
|
if (TaskType.SUB_PROCESS.getDesc().equals(taskDefinition.getTaskType())) { |
||||||
|
long subProcessDefinitionCode = paramNode.get("processDefinitionCode").asLong(); |
||||||
|
if (targetProcessDefinitionCode == subProcessDefinitionCode) { |
||||||
|
putMsg(result, DATA_IS_NOT_VALID, "targetProcessDefinitionCode"); |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
||||||
|
Date now = new Date(); |
||||||
|
ProcessTaskRelation processTaskRelation = upstreamList.get(0); |
||||||
|
ProcessTaskRelationLog processTaskRelationLog = processTaskRelationLogMapper.queryRelationLogByRelation(processTaskRelation); |
||||||
|
processTaskRelation.setProcessDefinitionCode(processDefinition.getCode()); |
||||||
|
processTaskRelation.setProcessDefinitionVersion(processDefinition.getVersion()); |
||||||
|
processTaskRelation.setUpdateTime(now); |
||||||
|
processTaskRelationLog.setProcessDefinitionCode(processDefinition.getCode()); |
||||||
|
processTaskRelationLog.setProcessDefinitionVersion(processDefinition.getVersion()); |
||||||
|
processTaskRelationLog.setUpdateTime(now); |
||||||
|
processTaskRelationLog.setOperator(loginUser.getId()); |
||||||
|
processTaskRelationLog.setOperateTime(now); |
||||||
|
int update = processTaskRelationMapper.updateById(processTaskRelation); |
||||||
|
int updateLog = processTaskRelationLogMapper.updateById(processTaskRelationLog); |
||||||
|
if (update == 0 || updateLog == 0) { |
||||||
|
putMsg(result, Status.MOVE_PROCESS_TASK_RELATION_ERROR); |
||||||
|
throw new ServiceException(Status.MOVE_PROCESS_TASK_RELATION_ERROR); |
||||||
|
} else { |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete process task relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param processDefinitionCode process definition code |
||||||
|
* @param taskCode the post task code |
||||||
|
* @return delete result code |
||||||
|
*/ |
||||||
|
@Transactional(rollbackFor = RuntimeException.class) |
||||||
|
@Override |
||||||
|
public Map<String, Object> deleteTaskProcessRelation(User loginUser, long projectCode, long processDefinitionCode, long taskCode) { |
||||||
|
Project project = projectMapper.queryByCode(projectCode); |
||||||
|
//check user access for project
|
||||||
|
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, projectCode); |
||||||
|
if (result.get(Constants.STATUS) != Status.SUCCESS) { |
||||||
|
return result; |
||||||
|
} |
||||||
|
if (taskCode == 0) { |
||||||
|
putMsg(result, Status.DELETE_TASK_PROCESS_RELATION_ERROR); |
||||||
|
return result; |
||||||
|
} |
||||||
|
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(processDefinitionCode); |
||||||
|
if (processDefinition == null) { |
||||||
|
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionCode); |
||||||
|
return result; |
||||||
|
} |
||||||
|
TaskDefinition taskDefinition = taskDefinitionMapper.queryByCode(taskCode); |
||||||
|
if (null == taskDefinition) { |
||||||
|
putMsg(result, Status.TASK_DEFINE_NOT_EXIST, taskCode); |
||||||
|
return result; |
||||||
|
} |
||||||
|
List<ProcessTaskRelation> downstreamList = processTaskRelationMapper.queryByCode(projectCode, processDefinitionCode, taskCode, 0L); |
||||||
|
if (CollectionUtils.isNotEmpty(downstreamList)) { |
||||||
|
Set<Long> postTaskCodes = downstreamList |
||||||
|
.stream() |
||||||
|
.map(ProcessTaskRelation::getPostTaskCode) |
||||||
|
.collect(Collectors.toSet()); |
||||||
|
putMsg(result, Status.TASK_HAS_DOWNSTREAM, org.apache.commons.lang.StringUtils.join(postTaskCodes, ",")); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(); |
||||||
|
processTaskRelationLog.setProjectCode(projectCode); |
||||||
|
processTaskRelationLog.setPostTaskCode(taskCode); |
||||||
|
processTaskRelationLog.setPostTaskVersion(taskDefinition.getVersion()); |
||||||
|
processTaskRelationLog.setProcessDefinitionCode(processDefinitionCode); |
||||||
|
processTaskRelationLog.setProcessDefinitionVersion(processDefinition.getVersion()); |
||||||
|
int deleteRelation = processTaskRelationMapper.deleteRelation(processTaskRelationLog); |
||||||
|
int deleteRelationLog = processTaskRelationLogMapper.deleteRelation(processTaskRelationLog); |
||||||
|
if (0 == deleteRelation || 0 == deleteRelationLog) { |
||||||
|
putMsg(result, Status.DELETE_TASK_PROCESS_RELATION_ERROR); |
||||||
|
throw new ServiceException(Status.DELETE_TASK_PROCESS_RELATION_ERROR); |
||||||
|
} |
||||||
|
if (TaskType.CONDITIONS.getDesc().equals(taskDefinition.getTaskType()) |
||||||
|
|| TaskType.DEPENDENT.getDesc().equals(taskDefinition.getTaskType()) |
||||||
|
|| TaskType.SUB_PROCESS.getDesc().equals(taskDefinition.getTaskType())) { |
||||||
|
int deleteTaskDefinition = taskDefinitionMapper.deleteByCode(taskCode); |
||||||
|
if (0 == deleteTaskDefinition) { |
||||||
|
putMsg(result, Status.DELETE_TASK_DEFINE_BY_CODE_ERROR); |
||||||
|
throw new ServiceException(Status.DELETE_TASK_DEFINE_BY_CODE_ERROR); |
||||||
|
} |
||||||
|
} |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete task upstream relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param preTaskCodes the pre task codes, sep ',' |
||||||
|
* @param taskCode the post task code |
||||||
|
* @return delete result code |
||||||
|
*/ |
||||||
|
@Transactional(rollbackFor = RuntimeException.class) |
||||||
|
@Override |
||||||
|
public Map<String, Object> deleteUpstreamRelation(User loginUser, long projectCode, String preTaskCodes, long taskCode) { |
||||||
|
Project project = projectMapper.queryByCode(projectCode); |
||||||
|
//check user access for project
|
||||||
|
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, projectCode); |
||||||
|
if (result.get(Constants.STATUS) != Status.SUCCESS) { |
||||||
|
return result; |
||||||
|
} |
||||||
|
if (StringUtils.isEmpty(preTaskCodes)) { |
||||||
|
putMsg(result, Status.DATA_IS_NULL, "preTaskCodes"); |
||||||
|
return result; |
||||||
|
} |
||||||
|
Status status = deleteUpstreamRelation(loginUser.getId(), projectCode, |
||||||
|
Lists.newArrayList(preTaskCodes.split(Constants.COMMA)).stream().map(Long::parseLong).distinct().toArray(Long[]::new), taskCode); |
||||||
|
if (status != Status.SUCCESS) { |
||||||
|
putMsg(result, status); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete task downstream relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param postTaskCodes the post task codes, sep ',' |
||||||
|
* @param taskCode the pre task code |
||||||
|
* @return delete result code |
||||||
|
*/ |
||||||
|
@Transactional(rollbackFor = RuntimeException.class) |
||||||
|
@Override |
||||||
|
public Map<String, Object> deleteDownstreamRelation(User loginUser, long projectCode, String postTaskCodes, long taskCode) { |
||||||
|
Project project = projectMapper.queryByCode(projectCode); |
||||||
|
//check user access for project
|
||||||
|
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, projectCode); |
||||||
|
if (result.get(Constants.STATUS) != Status.SUCCESS) { |
||||||
|
return result; |
||||||
|
} |
||||||
|
if (StringUtils.isEmpty(postTaskCodes)) { |
||||||
|
putMsg(result, Status.DATA_IS_NULL, "postTaskCodes"); |
||||||
|
return result; |
||||||
|
} |
||||||
|
List<ProcessTaskRelation> processTaskRelationList = processTaskRelationMapper.queryDownstreamByCode(projectCode, taskCode); |
||||||
|
Map<Long, ProcessTaskRelationLog> taskRelationLogMap = |
||||||
|
processTaskRelationList.stream() |
||||||
|
.map(ProcessTaskRelationLog::new) |
||||||
|
.collect(Collectors.toMap(ProcessTaskRelationLog::getPostTaskCode, processTaskRelationLog -> processTaskRelationLog)); |
||||||
|
Set<Long> postTaskCodesSet = Lists.newArrayList(postTaskCodes.split(Constants.COMMA)).stream().map(Long::parseLong).collect(Collectors.toSet()); |
||||||
|
int delete = 0; |
||||||
|
int deleteLog = 0; |
||||||
|
for (long postTaskCode : postTaskCodesSet) { |
||||||
|
ProcessTaskRelationLog processTaskRelationLog = taskRelationLogMap.get(postTaskCode); |
||||||
|
if (processTaskRelationLog != null) { |
||||||
|
delete += processTaskRelationMapper.deleteRelation(processTaskRelationLog); |
||||||
|
deleteLog += processTaskRelationLogMapper.deleteRelation(processTaskRelationLog); |
||||||
|
} |
||||||
|
} |
||||||
|
if ((delete & deleteLog) == 0) { |
||||||
|
throw new ServiceException(Status.DELETE_TASK_PROCESS_RELATION_ERROR); |
||||||
|
} else { |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query task upstream relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param taskCode current task code (post task code) |
||||||
|
* @return the upstream task definitions |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public Map<String, Object> queryUpstreamRelation(User loginUser, long projectCode, long taskCode) { |
||||||
|
Project project = projectMapper.queryByCode(projectCode); |
||||||
|
//check user access for project
|
||||||
|
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, projectCode); |
||||||
|
if (result.get(Constants.STATUS) != Status.SUCCESS) { |
||||||
|
return result; |
||||||
|
} |
||||||
|
List<ProcessTaskRelation> processTaskRelationList = processTaskRelationMapper.queryUpstreamByCode(projectCode, taskCode); |
||||||
|
List<TaskDefinitionLog> taskDefinitionLogList = new ArrayList<>(); |
||||||
|
if (CollectionUtils.isNotEmpty(processTaskRelationList)) { |
||||||
|
Set<TaskDefinition> taskDefinitions = processTaskRelationList |
||||||
|
.stream() |
||||||
|
.map(processTaskRelation -> { |
||||||
|
TaskDefinition taskDefinition = buildTaskDefinition(); |
||||||
|
taskDefinition.setProjectCode(processTaskRelation.getProjectCode()); |
||||||
|
taskDefinition.setCode(processTaskRelation.getPreTaskCode()); |
||||||
|
taskDefinition.setVersion(processTaskRelation.getPreTaskVersion()); |
||||||
|
return taskDefinition; |
||||||
|
}) |
||||||
|
.collect(Collectors.toSet()); |
||||||
|
taskDefinitionLogList = taskDefinitionLogMapper.queryByTaskDefinitions(taskDefinitions); |
||||||
|
} |
||||||
|
result.put(Constants.DATA_LIST, taskDefinitionLogList); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query task downstream relation |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param taskCode pre task code |
||||||
|
* @return the downstream task definitions |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public Map<String, Object> queryDownstreamRelation(User loginUser, long projectCode, long taskCode) { |
||||||
|
Project project = projectMapper.queryByCode(projectCode); |
||||||
|
//check user access for project
|
||||||
|
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, projectCode); |
||||||
|
if (result.get(Constants.STATUS) != Status.SUCCESS) { |
||||||
|
return result; |
||||||
|
} |
||||||
|
List<ProcessTaskRelation> processTaskRelationList = processTaskRelationMapper.queryDownstreamByCode(projectCode, taskCode); |
||||||
|
List<TaskDefinitionLog> taskDefinitionLogList = new ArrayList<>(); |
||||||
|
if (CollectionUtils.isNotEmpty(processTaskRelationList)) { |
||||||
|
Set<TaskDefinition> taskDefinitions = processTaskRelationList |
||||||
|
.stream() |
||||||
|
.map(processTaskRelation -> { |
||||||
|
TaskDefinition taskDefinition = buildTaskDefinition(); |
||||||
|
taskDefinition.setProjectCode(processTaskRelation.getProjectCode()); |
||||||
|
taskDefinition.setCode(processTaskRelation.getPostTaskCode()); |
||||||
|
taskDefinition.setVersion(processTaskRelation.getPostTaskVersion()); |
||||||
|
return taskDefinition; |
||||||
|
}) |
||||||
|
.collect(Collectors.toSet()); |
||||||
|
taskDefinitionLogList = taskDefinitionLogMapper.queryByTaskDefinitions(taskDefinitions); |
||||||
|
} |
||||||
|
result.put(Constants.DATA_LIST, taskDefinitionLogList); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete edge |
||||||
|
* |
||||||
|
* @param loginUser login user |
||||||
|
* @param projectCode project code |
||||||
|
* @param processDefinitionCode process definition code |
||||||
|
* @param preTaskCode pre task code |
||||||
|
* @param postTaskCode post task code |
||||||
|
* @return delete result code |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public Map<String, Object> deleteEdge(User loginUser, long projectCode, long processDefinitionCode, long preTaskCode, long postTaskCode) { |
||||||
|
Project project = projectMapper.queryByCode(projectCode); |
||||||
|
//check user access for project
|
||||||
|
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, projectCode); |
||||||
|
if (result.get(Constants.STATUS) != Status.SUCCESS) { |
||||||
|
return result; |
||||||
|
} |
||||||
|
List<ProcessTaskRelation> processTaskRelationList = processTaskRelationMapper.queryByCode(projectCode, processDefinitionCode, preTaskCode, postTaskCode); |
||||||
|
if (CollectionUtils.isEmpty(processTaskRelationList)) { |
||||||
|
putMsg(result, Status.DATA_IS_NULL, "processTaskRelationList"); |
||||||
|
return result; |
||||||
|
} |
||||||
|
if (processTaskRelationList.size() > 1) { |
||||||
|
putMsg(result, Status.DATA_IS_NOT_VALID, "processTaskRelationList"); |
||||||
|
return result; |
||||||
|
} |
||||||
|
ProcessTaskRelation processTaskRelation = processTaskRelationList.get(0); |
||||||
|
int upstreamCount = processTaskRelationMapper.countByCode(projectCode, processTaskRelation.getProcessDefinitionCode(), |
||||||
|
0L, processTaskRelation.getPostTaskCode()); |
||||||
|
|
||||||
|
if (upstreamCount == 0) { |
||||||
|
putMsg(result, Status.DATA_IS_NULL, "upstreamCount"); |
||||||
|
return result; |
||||||
|
} |
||||||
|
if (upstreamCount > 1) { |
||||||
|
int delete = processTaskRelationMapper.deleteById(processTaskRelation.getId()); |
||||||
|
if (delete == 0) { |
||||||
|
putMsg(result, Status.DELETE_EDGE_ERROR); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
processTaskRelation.setPreTaskVersion(0); |
||||||
|
processTaskRelation.setPreTaskCode(0L); |
||||||
|
int update = processTaskRelationMapper.updateById(processTaskRelation); |
||||||
|
if (update == 0) { |
||||||
|
putMsg(result, Status.DELETE_EDGE_ERROR); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* build task definition |
||||||
|
* |
||||||
|
* @return task definition |
||||||
|
*/ |
||||||
|
private TaskDefinition buildTaskDefinition() { |
||||||
|
|
||||||
|
return new TaskDefinition() { |
||||||
|
@Override |
||||||
|
public boolean equals(Object o) { |
||||||
|
if (this == o) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
if (!(o instanceof TaskDefinition)) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
TaskDefinition that = (TaskDefinition) o; |
||||||
|
return getCode() == that.getCode() |
||||||
|
&& getVersion() == that.getVersion() |
||||||
|
&& getProjectCode() == that.getProjectCode(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int hashCode() { |
||||||
|
return Objects.hash(getCode(), getVersion(), getProjectCode()); |
||||||
|
} |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete upstream relation |
||||||
|
* |
||||||
|
* @param projectCode project code |
||||||
|
* @param preTaskCodes pre task codes |
||||||
|
* @param taskCode pre task code |
||||||
|
* @return status |
||||||
|
*/ |
||||||
|
private Status deleteUpstreamRelation(int userId, long projectCode, Long[] preTaskCodes, long taskCode) { |
||||||
|
List<ProcessTaskRelation> upstreamList = processTaskRelationMapper.queryUpstreamByCodes(projectCode, taskCode, preTaskCodes); |
||||||
|
if (CollectionUtils.isEmpty(upstreamList)) { |
||||||
|
return Status.SUCCESS; |
||||||
|
} |
||||||
|
List<ProcessTaskRelationLog> upstreamLogList = new ArrayList<>(); |
||||||
|
Date now = new Date(); |
||||||
|
for (ProcessTaskRelation processTaskRelation : upstreamList) { |
||||||
|
ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(processTaskRelation); |
||||||
|
processTaskRelationLog.setOperator(userId); |
||||||
|
processTaskRelationLog.setOperateTime(now); |
||||||
|
processTaskRelationLog.setUpdateTime(now); |
||||||
|
upstreamLogList.add(processTaskRelationLog); |
||||||
|
} |
||||||
|
Map<Long, List<ProcessTaskRelationLog>> processTaskRelationListGroupByProcessDefinitionCode = upstreamLogList.stream() |
||||||
|
.collect(Collectors.groupingBy(ProcessTaskRelationLog::getProcessDefinitionCode)); |
||||||
|
// count upstream relation group by process definition code
|
||||||
|
List<Map<String, Long>> countListGroupByProcessDefinitionCode = processTaskRelationMapper |
||||||
|
.countUpstreamByCodeGroupByProcessDefinitionCode(projectCode, processTaskRelationListGroupByProcessDefinitionCode.keySet().toArray(new Long[0]), taskCode); |
||||||
|
|
||||||
|
List<ProcessTaskRelationLog> deletes = new ArrayList<>(); |
||||||
|
List<ProcessTaskRelationLog> updates = new ArrayList<>(); |
||||||
|
for (Map<String, Long> codeCountMap : countListGroupByProcessDefinitionCode) { |
||||||
|
long processDefinitionCode = codeCountMap.get("processDefinitionCode"); |
||||||
|
long countValue = codeCountMap.get("countValue"); |
||||||
|
List<ProcessTaskRelationLog> processTaskRelationLogList = processTaskRelationListGroupByProcessDefinitionCode.get(processDefinitionCode); |
||||||
|
if (countValue <= processTaskRelationLogList.size()) { |
||||||
|
ProcessTaskRelationLog processTaskRelationLog = processTaskRelationLogList.remove(0); |
||||||
|
if (processTaskRelationLog.getPreTaskCode() != 0) { |
||||||
|
processTaskRelationLog.setPreTaskCode(0); |
||||||
|
processTaskRelationLog.setPreTaskVersion(0); |
||||||
|
updates.add(processTaskRelationLog); |
||||||
|
} |
||||||
|
} |
||||||
|
if (!processTaskRelationLogList.isEmpty()) { |
||||||
|
deletes.addAll(processTaskRelationLogList); |
||||||
|
} |
||||||
|
} |
||||||
|
deletes.addAll(updates); |
||||||
|
int delete = 0; |
||||||
|
int deleteLog = 0; |
||||||
|
for (ProcessTaskRelationLog processTaskRelationLog : deletes) { |
||||||
|
delete += processTaskRelationMapper.deleteRelation(processTaskRelationLog); |
||||||
|
deleteLog += processTaskRelationLogMapper.deleteRelation(processTaskRelationLog); |
||||||
|
} |
||||||
|
if ((delete & deleteLog) == 0) { |
||||||
|
throw new ServiceException(Status.DELETE_TASK_PROCESS_RELATION_ERROR); |
||||||
|
} else { |
||||||
|
if (!updates.isEmpty()) { |
||||||
|
int insert = processTaskRelationMapper.batchInsert(updates); |
||||||
|
int insertLog = processTaskRelationLogMapper.batchInsert(updates); |
||||||
|
if ((insert & insertLog) == 0) { |
||||||
|
throw new ServiceException(Status.CREATE_PROCESS_TASK_RELATION_ERROR); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return Status.SUCCESS; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,84 @@ |
|||||||
|
/* |
||||||
|
* 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.controller; |
||||||
|
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; |
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.api.enums.Status; |
||||||
|
import org.apache.dolphinscheduler.api.service.ProcessTaskRelationService; |
||||||
|
import org.apache.dolphinscheduler.api.utils.Result; |
||||||
|
import org.apache.dolphinscheduler.common.Constants; |
||||||
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Test; |
||||||
|
import org.mockito.Mockito; |
||||||
|
import org.powermock.api.mockito.PowerMockito; |
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean; |
||||||
|
import org.springframework.http.MediaType; |
||||||
|
import org.springframework.test.web.servlet.MvcResult; |
||||||
|
|
||||||
|
/** |
||||||
|
* process task relation controller test |
||||||
|
*/ |
||||||
|
public class ProcessTaskRelationControllerTest extends AbstractControllerTest { |
||||||
|
|
||||||
|
@MockBean |
||||||
|
private ProcessTaskRelationService processTaskRelationService; |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryDownstreamRelation() throws Exception { |
||||||
|
Map<String, Object> mockResult = new HashMap<>(); |
||||||
|
mockResult.put(Constants.STATUS, Status.SUCCESS); |
||||||
|
PowerMockito.when(processTaskRelationService.queryDownstreamRelation(Mockito.any(), Mockito.anyLong(), Mockito.anyLong())) |
||||||
|
.thenReturn(mockResult); |
||||||
|
|
||||||
|
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/process-task-relation/{taskCode}/downstream", "1113", "123") |
||||||
|
.header(SESSION_ID, sessionId)) |
||||||
|
.andExpect(status().isOk()) |
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
||||||
|
.andReturn(); |
||||||
|
|
||||||
|
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); |
||||||
|
Assert.assertNotNull(result); |
||||||
|
Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryUpstreamRelation() throws Exception { |
||||||
|
Map<String, Object> mockResult = new HashMap<>(); |
||||||
|
mockResult.put(Constants.STATUS, Status.SUCCESS); |
||||||
|
PowerMockito.when(processTaskRelationService.queryUpstreamRelation(Mockito.any(), Mockito.anyLong(), Mockito.anyLong())) |
||||||
|
.thenReturn(mockResult); |
||||||
|
|
||||||
|
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/process-task-relation/{taskCode}/upstream", "1113", "123") |
||||||
|
.header(SESSION_ID, sessionId)) |
||||||
|
.andExpect(status().isOk()) |
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
||||||
|
.andReturn(); |
||||||
|
|
||||||
|
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); |
||||||
|
Assert.assertNotNull(result); |
||||||
|
Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,577 @@ |
|||||||
|
/* |
||||||
|
* 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.TaskType; |
||||||
|
import org.apache.dolphinscheduler.common.enums.UserType; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.Project; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.TaskDefinition; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; |
||||||
|
import org.apache.dolphinscheduler.dao.entity.User; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationLogMapper; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; |
||||||
|
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; |
||||||
|
|
||||||
|
import org.apache.commons.collections.CollectionUtils; |
||||||
|
|
||||||
|
import java.text.MessageFormat; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Objects; |
||||||
|
import java.util.Set; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
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; |
||||||
|
|
||||||
|
import com.google.common.collect.Lists; |
||||||
|
|
||||||
|
/** |
||||||
|
* process task instance relation service test |
||||||
|
*/ |
||||||
|
@RunWith(MockitoJUnitRunner.Silent.class) |
||||||
|
public class ProcessTaskRelationServiceTest { |
||||||
|
|
||||||
|
@InjectMocks |
||||||
|
ProcessTaskRelationServiceImpl processTaskRelationService; |
||||||
|
|
||||||
|
@Mock |
||||||
|
private ProjectMapper projectMapper; |
||||||
|
|
||||||
|
@Mock |
||||||
|
private ProjectServiceImpl projectService; |
||||||
|
|
||||||
|
@Mock |
||||||
|
private ProcessTaskRelationMapper processTaskRelationMapper; |
||||||
|
|
||||||
|
@Mock |
||||||
|
private TaskDefinitionLogMapper taskDefinitionLogMapper; |
||||||
|
|
||||||
|
@Mock |
||||||
|
private ProcessDefinitionMapper processDefinitionMapper; |
||||||
|
|
||||||
|
@Mock |
||||||
|
private TaskDefinitionMapper taskDefinitionMapper; |
||||||
|
|
||||||
|
@Mock |
||||||
|
private ProcessTaskRelationLogMapper processTaskRelationLogMapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* get Mock Admin User |
||||||
|
* |
||||||
|
* @return admin user |
||||||
|
*/ |
||||||
|
private User getAdminUser() { |
||||||
|
User loginUser = new User(); |
||||||
|
loginUser.setId(-1); |
||||||
|
loginUser.setUserName("admin"); |
||||||
|
loginUser.setUserType(UserType.GENERAL_USER); |
||||||
|
return loginUser; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* get mock Project |
||||||
|
* |
||||||
|
* @param projectCode projectCode |
||||||
|
* @return Project |
||||||
|
*/ |
||||||
|
private Project getProject(long projectCode) { |
||||||
|
Project project = new Project(); |
||||||
|
project.setCode(projectCode); |
||||||
|
project.setId(1); |
||||||
|
project.setName("project_test1"); |
||||||
|
project.setUserId(1); |
||||||
|
return project; |
||||||
|
} |
||||||
|
|
||||||
|
private void putMsg(Map<String, Object> result, Status status, Object... statusParams) { |
||||||
|
result.put(Constants.STATUS, status); |
||||||
|
if (statusParams != null && statusParams.length > 0) { |
||||||
|
result.put(Constants.MSG, MessageFormat.format(status.getMsg(), statusParams)); |
||||||
|
} else { |
||||||
|
result.put(Constants.MSG, status.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private TaskDefinitionLog buildTaskDefinitionLog(long projectCode, long code, int version) { |
||||||
|
|
||||||
|
TaskDefinitionLog taskDefinitionLog = new TaskDefinitionLog() { |
||||||
|
@Override |
||||||
|
public boolean equals(Object o) { |
||||||
|
if (this == o) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
if (!(o instanceof TaskDefinitionLog)) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
TaskDefinitionLog that = (TaskDefinitionLog) o; |
||||||
|
return getCode() == that.getCode() |
||||||
|
&& getVersion() == that.getVersion() |
||||||
|
&& getProjectCode() == that.getProjectCode(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int hashCode() { |
||||||
|
return Objects.hash(getCode(), getVersion(), getProjectCode()); |
||||||
|
} |
||||||
|
}; |
||||||
|
taskDefinitionLog.setProjectCode(projectCode); |
||||||
|
taskDefinitionLog.setCode(code); |
||||||
|
taskDefinitionLog.setVersion(version); |
||||||
|
return taskDefinitionLog; |
||||||
|
} |
||||||
|
|
||||||
|
private TaskDefinition buildTaskDefinition(long projectCode, long code, int version) { |
||||||
|
|
||||||
|
TaskDefinition taskDefinition = new TaskDefinition() { |
||||||
|
@Override |
||||||
|
public boolean equals(Object o) { |
||||||
|
if (this == o) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
if (!(o instanceof TaskDefinition)) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
TaskDefinition that = (TaskDefinition) o; |
||||||
|
return getCode() == that.getCode() |
||||||
|
&& getVersion() == that.getVersion() |
||||||
|
&& getProjectCode() == that.getProjectCode(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int hashCode() { |
||||||
|
return Objects.hash(getCode(), getVersion(), getProjectCode()); |
||||||
|
} |
||||||
|
}; |
||||||
|
taskDefinition.setProjectCode(projectCode); |
||||||
|
taskDefinition.setCode(code); |
||||||
|
taskDefinition.setVersion(version); |
||||||
|
return taskDefinition; |
||||||
|
} |
||||||
|
|
||||||
|
private List<ProcessTaskRelation> getProcessTaskUpstreamRelationList(long projectCode, long taskCode) { |
||||||
|
ProcessTaskRelation processTaskRelationUpstream0 = new ProcessTaskRelation(); |
||||||
|
processTaskRelationUpstream0.setPostTaskCode(taskCode); |
||||||
|
processTaskRelationUpstream0.setPreTaskVersion(1); |
||||||
|
processTaskRelationUpstream0.setProjectCode(projectCode); |
||||||
|
processTaskRelationUpstream0.setPreTaskCode(123); |
||||||
|
processTaskRelationUpstream0.setProcessDefinitionCode(123); |
||||||
|
ProcessTaskRelation processTaskRelationUpstream1 = new ProcessTaskRelation(); |
||||||
|
processTaskRelationUpstream1.setPostTaskCode(taskCode); |
||||||
|
processTaskRelationUpstream1.setPreTaskVersion(1); |
||||||
|
processTaskRelationUpstream1.setPreTaskCode(123); |
||||||
|
processTaskRelationUpstream1.setProcessDefinitionCode(124); |
||||||
|
processTaskRelationUpstream1.setProjectCode(projectCode); |
||||||
|
ProcessTaskRelation processTaskRelationUpstream2 = new ProcessTaskRelation(); |
||||||
|
processTaskRelationUpstream2.setPostTaskCode(taskCode); |
||||||
|
processTaskRelationUpstream2.setPreTaskVersion(2); |
||||||
|
processTaskRelationUpstream2.setPreTaskCode(123); |
||||||
|
processTaskRelationUpstream2.setProcessDefinitionCode(125); |
||||||
|
processTaskRelationUpstream2.setProjectCode(projectCode); |
||||||
|
List<ProcessTaskRelation> processTaskRelationList = new ArrayList<>(); |
||||||
|
processTaskRelationList.add(processTaskRelationUpstream0); |
||||||
|
processTaskRelationList.add(processTaskRelationUpstream1); |
||||||
|
processTaskRelationList.add(processTaskRelationUpstream2); |
||||||
|
return processTaskRelationList; |
||||||
|
} |
||||||
|
|
||||||
|
private List<ProcessTaskRelation> getProcessTaskDownstreamRelationList(long projectCode,long taskCode) { |
||||||
|
ProcessTaskRelation processTaskRelationDownstream0 = new ProcessTaskRelation(); |
||||||
|
processTaskRelationDownstream0.setPreTaskCode(taskCode); |
||||||
|
processTaskRelationDownstream0.setPostTaskCode(456); |
||||||
|
processTaskRelationDownstream0.setPostTaskVersion(1); |
||||||
|
processTaskRelationDownstream0.setProjectCode(projectCode); |
||||||
|
ProcessTaskRelation processTaskRelationDownstream1 = new ProcessTaskRelation(); |
||||||
|
processTaskRelationDownstream1.setPreTaskCode(taskCode); |
||||||
|
processTaskRelationDownstream1.setPostTaskCode(456); |
||||||
|
processTaskRelationDownstream1.setPostTaskVersion(1); |
||||||
|
processTaskRelationDownstream1.setProjectCode(projectCode); |
||||||
|
ProcessTaskRelation processTaskRelationDownstream2 = new ProcessTaskRelation(); |
||||||
|
processTaskRelationDownstream2.setPreTaskCode(taskCode); |
||||||
|
processTaskRelationDownstream2.setPostTaskCode(4567); |
||||||
|
processTaskRelationDownstream2.setPostTaskVersion(1); |
||||||
|
processTaskRelationDownstream2.setProjectCode(projectCode); |
||||||
|
List<ProcessTaskRelation> processTaskRelationList = new ArrayList<>(); |
||||||
|
processTaskRelationList.add(processTaskRelationDownstream0); |
||||||
|
processTaskRelationList.add(processTaskRelationDownstream1); |
||||||
|
processTaskRelationList.add(processTaskRelationDownstream2); |
||||||
|
return processTaskRelationList; |
||||||
|
} |
||||||
|
|
||||||
|
private ProcessDefinition getProcessDefinition() { |
||||||
|
ProcessDefinition processDefinition = new ProcessDefinition(); |
||||||
|
processDefinition.setId(1); |
||||||
|
processDefinition.setProjectCode(1L); |
||||||
|
processDefinition.setName("test_pdf"); |
||||||
|
processDefinition.setTenantId(1); |
||||||
|
processDefinition.setDescription(""); |
||||||
|
processDefinition.setCode(1L); |
||||||
|
processDefinition.setVersion(1); |
||||||
|
return processDefinition; |
||||||
|
} |
||||||
|
|
||||||
|
private TaskDefinition getTaskDefinition() { |
||||||
|
TaskDefinition taskDefinition = new TaskDefinition(); |
||||||
|
taskDefinition.setProjectCode(1L); |
||||||
|
taskDefinition.setCode(1L); |
||||||
|
taskDefinition.setVersion(1); |
||||||
|
taskDefinition.setTaskType(TaskType.SHELL.getDesc()); |
||||||
|
return taskDefinition; |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testCreateProcessTaskRelation() { |
||||||
|
long projectCode = 1L; |
||||||
|
long processDefinitionCode = 1L; |
||||||
|
long preTaskCode = 0L; |
||||||
|
long postTaskCode = 1L; |
||||||
|
|
||||||
|
Project project = getProject(projectCode); |
||||||
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
||||||
|
|
||||||
|
User loginUser = new User(); |
||||||
|
loginUser.setId(-1); |
||||||
|
loginUser.setUserType(UserType.GENERAL_USER); |
||||||
|
|
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
putMsg(result, Status.SUCCESS, projectCode); |
||||||
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
||||||
|
Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(getProcessDefinition()); |
||||||
|
Mockito.when(processTaskRelationMapper.queryByCode(projectCode, processDefinitionCode, preTaskCode, postTaskCode)).thenReturn(Lists.newArrayList()); |
||||||
|
Mockito.when(taskDefinitionMapper.queryByCode(postTaskCode)).thenReturn(getTaskDefinition()); |
||||||
|
List<ProcessTaskRelationLog> processTaskRelationList = Lists.newArrayList(); |
||||||
|
ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(); |
||||||
|
processTaskRelationLog.setProjectCode(projectCode); |
||||||
|
processTaskRelationLog.setProcessDefinitionCode(processDefinitionCode); |
||||||
|
processTaskRelationLog.setPreTaskCode(0L); |
||||||
|
processTaskRelationLog.setPreTaskVersion(0); |
||||||
|
processTaskRelationLog.setPostTaskCode(postTaskCode); |
||||||
|
processTaskRelationLog.setPostTaskVersion(1); |
||||||
|
processTaskRelationList.add(processTaskRelationLog); |
||||||
|
Mockito.when(processTaskRelationMapper.batchInsert(processTaskRelationList)).thenReturn(1); |
||||||
|
Mockito.when(processTaskRelationLogMapper.batchInsert(processTaskRelationList)).thenReturn(1); |
||||||
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testMoveTaskProcessRelation() { |
||||||
|
long projectCode = 1L; |
||||||
|
long processDefinitionCode = 1L; |
||||||
|
long taskCode = 1L; |
||||||
|
|
||||||
|
Project project = getProject(projectCode); |
||||||
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
||||||
|
|
||||||
|
User loginUser = new User(); |
||||||
|
loginUser.setId(-1); |
||||||
|
loginUser.setUserType(UserType.GENERAL_USER); |
||||||
|
|
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
putMsg(result, Status.SUCCESS, projectCode); |
||||||
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
||||||
|
Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(getProcessDefinition()); |
||||||
|
Mockito.when(processTaskRelationMapper.queryByCode(projectCode, processDefinitionCode, taskCode, 0L)).thenReturn(Lists.newArrayList()); |
||||||
|
Mockito.when(taskDefinitionMapper.queryByCode(taskCode)).thenReturn(getTaskDefinition()); |
||||||
|
List<ProcessTaskRelation> processTaskRelationList = Lists.newArrayList(); |
||||||
|
ProcessTaskRelation processTaskRelation = new ProcessTaskRelation(); |
||||||
|
processTaskRelation.setProjectCode(projectCode); |
||||||
|
processTaskRelation.setProcessDefinitionCode(processDefinitionCode); |
||||||
|
processTaskRelation.setPreTaskCode(0L); |
||||||
|
processTaskRelation.setPreTaskVersion(0); |
||||||
|
processTaskRelation.setPostTaskCode(taskCode); |
||||||
|
processTaskRelation.setPostTaskVersion(1); |
||||||
|
processTaskRelationList.add(processTaskRelation); |
||||||
|
ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(); |
||||||
|
processTaskRelationLog.setProjectCode(projectCode); |
||||||
|
processTaskRelationLog.setProcessDefinitionCode(processDefinitionCode); |
||||||
|
processTaskRelationLog.setPreTaskCode(0L); |
||||||
|
processTaskRelationLog.setPreTaskVersion(0); |
||||||
|
processTaskRelationLog.setPostTaskCode(taskCode); |
||||||
|
processTaskRelationLog.setPostTaskVersion(1); |
||||||
|
Mockito.when(processTaskRelationMapper.queryByCode(projectCode, processDefinitionCode, 0L, taskCode)).thenReturn(processTaskRelationList); |
||||||
|
Mockito.when(processTaskRelationLogMapper.queryRelationLogByRelation(processTaskRelation)).thenReturn(processTaskRelationLog); |
||||||
|
Mockito.when(processTaskRelationMapper.updateById(processTaskRelation)).thenReturn(1); |
||||||
|
Mockito.when(processTaskRelationLogMapper.updateById(processTaskRelationLog)).thenReturn(1); |
||||||
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryDownstreamRelation() { |
||||||
|
long projectCode = 1L; |
||||||
|
long taskCode = 2L; |
||||||
|
|
||||||
|
Project project = getProject(projectCode); |
||||||
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
||||||
|
|
||||||
|
User loginUser = new User(); |
||||||
|
loginUser.setId(-1); |
||||||
|
loginUser.setUserType(UserType.GENERAL_USER); |
||||||
|
|
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
putMsg(result, Status.SUCCESS, projectCode); |
||||||
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
||||||
|
|
||||||
|
List<ProcessTaskRelation> processTaskRelationList = getProcessTaskDownstreamRelationList(projectCode,taskCode); |
||||||
|
|
||||||
|
Mockito.when(processTaskRelationMapper.queryDownstreamByCode(projectCode,taskCode)) |
||||||
|
.thenReturn(processTaskRelationList); |
||||||
|
|
||||||
|
if (CollectionUtils.isNotEmpty(processTaskRelationList)) { |
||||||
|
Set<TaskDefinition> taskDefinitions = processTaskRelationList |
||||||
|
.stream() |
||||||
|
.map(processTaskRelation -> { |
||||||
|
TaskDefinition taskDefinition = buildTaskDefinition( |
||||||
|
processTaskRelation.getProjectCode(), |
||||||
|
processTaskRelation.getPostTaskCode(), |
||||||
|
processTaskRelation.getPostTaskVersion()); |
||||||
|
return taskDefinition; |
||||||
|
}) |
||||||
|
.collect(Collectors.toSet()); |
||||||
|
|
||||||
|
Set<TaskDefinitionLog> taskDefinitionLogSet = processTaskRelationList |
||||||
|
.stream() |
||||||
|
.map(processTaskRelation -> { |
||||||
|
TaskDefinitionLog taskDefinitionLog = buildTaskDefinitionLog( |
||||||
|
processTaskRelation.getProjectCode(), |
||||||
|
processTaskRelation.getPostTaskCode(), |
||||||
|
processTaskRelation.getPostTaskVersion() |
||||||
|
); |
||||||
|
return taskDefinitionLog; |
||||||
|
}) |
||||||
|
.collect(Collectors.toSet()); |
||||||
|
List<TaskDefinitionLog> taskDefinitionLogList = taskDefinitionLogSet.stream().collect(Collectors.toList()); |
||||||
|
Mockito.when(taskDefinitionLogMapper.queryByTaskDefinitions(taskDefinitions)) |
||||||
|
.thenReturn(taskDefinitionLogList); |
||||||
|
} |
||||||
|
Map<String, Object> relation = processTaskRelationService |
||||||
|
.queryDownstreamRelation(loginUser, projectCode, taskCode); |
||||||
|
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); |
||||||
|
Assert.assertEquals(2, ((List) relation.get("data")).size()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testQueryUpstreamRelation() { |
||||||
|
long projectCode = 1L; |
||||||
|
long taskCode = 2L; |
||||||
|
|
||||||
|
Project project = getProject(projectCode); |
||||||
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
||||||
|
|
||||||
|
User loginUser = new User(); |
||||||
|
loginUser.setId(-1); |
||||||
|
loginUser.setUserType(UserType.GENERAL_USER); |
||||||
|
|
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
putMsg(result, Status.SUCCESS, projectCode); |
||||||
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
||||||
|
List<ProcessTaskRelation> processTaskRelationList = getProcessTaskUpstreamRelationList(projectCode,taskCode); |
||||||
|
|
||||||
|
Mockito.when(processTaskRelationMapper.queryUpstreamByCode(projectCode, taskCode)).thenReturn(processTaskRelationList); |
||||||
|
|
||||||
|
if (CollectionUtils.isNotEmpty(processTaskRelationList)) { |
||||||
|
Set<TaskDefinition> taskDefinitions = processTaskRelationList |
||||||
|
.stream() |
||||||
|
.map(processTaskRelation -> { |
||||||
|
TaskDefinition taskDefinition = buildTaskDefinition( |
||||||
|
processTaskRelation.getProjectCode(), |
||||||
|
processTaskRelation.getPreTaskCode(), |
||||||
|
processTaskRelation.getPreTaskVersion()); |
||||||
|
return taskDefinition; |
||||||
|
}) |
||||||
|
.collect(Collectors.toSet()); |
||||||
|
|
||||||
|
Set<TaskDefinitionLog> taskDefinitionLogSet = processTaskRelationList |
||||||
|
.stream() |
||||||
|
.map(processTaskRelation -> { |
||||||
|
TaskDefinitionLog taskDefinitionLog = buildTaskDefinitionLog( |
||||||
|
processTaskRelation.getProjectCode(), |
||||||
|
processTaskRelation.getPreTaskCode(), |
||||||
|
processTaskRelation.getPreTaskVersion()); |
||||||
|
return taskDefinitionLog; |
||||||
|
}) |
||||||
|
.collect(Collectors.toSet()); |
||||||
|
List<TaskDefinitionLog> taskDefinitionLogList = taskDefinitionLogSet.stream().collect(Collectors.toList()); |
||||||
|
Mockito.when(taskDefinitionLogMapper.queryByTaskDefinitions(taskDefinitions)) |
||||||
|
.thenReturn(taskDefinitionLogList); |
||||||
|
} |
||||||
|
Map<String, Object> relation = processTaskRelationService |
||||||
|
.queryUpstreamRelation(loginUser, projectCode, taskCode); |
||||||
|
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); |
||||||
|
Assert.assertEquals(2, ((List) relation.get("data")).size()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testDeleteDownstreamRelation() { |
||||||
|
long projectCode = 1L; |
||||||
|
long taskCode = 2L; |
||||||
|
Project project = getProject(projectCode); |
||||||
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
||||||
|
|
||||||
|
User loginUser = new User(); |
||||||
|
loginUser.setId(-1); |
||||||
|
loginUser.setUserType(UserType.GENERAL_USER); |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
putMsg(result, Status.SUCCESS, projectCode); |
||||||
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
||||||
|
List<ProcessTaskRelation> processTaskRelationList = new ArrayList<>(); |
||||||
|
ProcessTaskRelation processTaskRelation = new ProcessTaskRelation(); |
||||||
|
processTaskRelation.setProjectCode(projectCode); |
||||||
|
processTaskRelation.setProcessDefinitionCode(1L); |
||||||
|
processTaskRelation.setPreTaskCode(taskCode); |
||||||
|
processTaskRelation.setPostTaskCode(123L); |
||||||
|
processTaskRelationList.add(processTaskRelation); |
||||||
|
Mockito.when(processTaskRelationMapper.queryDownstreamByCode(projectCode, taskCode)).thenReturn(processTaskRelationList); |
||||||
|
ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(processTaskRelation); |
||||||
|
Mockito.when(processTaskRelationMapper.deleteRelation(processTaskRelationLog)).thenReturn(1); |
||||||
|
Mockito.when(processTaskRelationLogMapper.deleteRelation(processTaskRelationLog)).thenReturn(1); |
||||||
|
Map<String, Object> result1 = processTaskRelationService.deleteDownstreamRelation(loginUser, projectCode, "123", taskCode); |
||||||
|
Assert.assertEquals(Status.SUCCESS, result1.get(Constants.STATUS)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testDeleteUpstreamRelation() { |
||||||
|
long projectCode = 1L; |
||||||
|
long taskCode = 2L; |
||||||
|
Project project = getProject(projectCode); |
||||||
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
||||||
|
|
||||||
|
User loginUser = new User(); |
||||||
|
loginUser.setId(-1); |
||||||
|
loginUser.setUserType(UserType.GENERAL_USER); |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
putMsg(result, Status.SUCCESS, projectCode); |
||||||
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
||||||
|
Mockito.when(processTaskRelationMapper.queryUpstreamByCodes(projectCode, taskCode, new Long[]{123L})).thenReturn(Lists.newArrayList()); |
||||||
|
List<Map<String, Long>> countListGroupByProcessDefinitionCode = new ArrayList<>(); |
||||||
|
countListGroupByProcessDefinitionCode.add(new HashMap<String, Long>() { |
||||||
|
{ |
||||||
|
put("processDefinitionCode", 123L); |
||||||
|
put("countValue", 2L); |
||||||
|
} |
||||||
|
}); |
||||||
|
countListGroupByProcessDefinitionCode.add(new HashMap<String, Long>() { |
||||||
|
{ |
||||||
|
put("processDefinitionCode", 124L); |
||||||
|
put("countValue", 1L); |
||||||
|
} |
||||||
|
}); |
||||||
|
countListGroupByProcessDefinitionCode.add(new HashMap<String, Long>() { |
||||||
|
{ |
||||||
|
put("processDefinitionCode", 125L); |
||||||
|
put("countValue", 3L); |
||||||
|
} |
||||||
|
}); |
||||||
|
ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(); |
||||||
|
processTaskRelationLog.setProjectCode(projectCode); |
||||||
|
processTaskRelationLog.setPreTaskCode(0L); |
||||||
|
processTaskRelationLog.setPreTaskVersion(0); |
||||||
|
processTaskRelationLog.setPostTaskCode(taskCode); |
||||||
|
processTaskRelationLog.setPostTaskVersion(2); |
||||||
|
Mockito.when(processTaskRelationMapper.countUpstreamByCodeGroupByProcessDefinitionCode(projectCode, new Long[]{123L, 124L, 125L}, 2)).thenReturn(countListGroupByProcessDefinitionCode); |
||||||
|
Mockito.when(processTaskRelationMapper.deleteRelation(processTaskRelationLog)).thenReturn(1); |
||||||
|
Mockito.when(processTaskRelationLogMapper.deleteRelation(processTaskRelationLog)).thenReturn(1); |
||||||
|
Map<String, Object> result1 = processTaskRelationService.deleteUpstreamRelation(loginUser, projectCode, "123", taskCode); |
||||||
|
Assert.assertEquals(Status.SUCCESS, result1.get(Constants.STATUS)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testDeleteTaskProcessRelation() { |
||||||
|
long projectCode = 1L; |
||||||
|
long taskCode = 1L; |
||||||
|
long processDefinitionCode = 1L; |
||||||
|
long preTaskCode = 4L; |
||||||
|
long postTaskCode = 5L; |
||||||
|
Project project = getProject(projectCode); |
||||||
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
||||||
|
|
||||||
|
User loginUser = new User(); |
||||||
|
loginUser.setId(-1); |
||||||
|
loginUser.setUserType(UserType.GENERAL_USER); |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
putMsg(result, Status.SUCCESS, projectCode); |
||||||
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
||||||
|
Mockito.when(processTaskRelationMapper.queryByCode(projectCode, processDefinitionCode, preTaskCode, postTaskCode)).thenReturn(Lists.newArrayList()); |
||||||
|
ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(); |
||||||
|
processTaskRelationLog.setProjectCode(projectCode); |
||||||
|
processTaskRelationLog.setPreTaskCode(taskCode); |
||||||
|
processTaskRelationLog.setProcessDefinitionCode(processDefinitionCode); |
||||||
|
Mockito.when(processTaskRelationMapper.deleteRelation(processTaskRelationLog)).thenReturn(1); |
||||||
|
Mockito.when(processDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(getProcessDefinition()); |
||||||
|
Mockito.when(taskDefinitionMapper.queryByCode(taskCode)).thenReturn(getTaskDefinition()); |
||||||
|
TaskDefinition taskDefinition = new TaskDefinition(); |
||||||
|
taskDefinition.setTaskType(TaskType.CONDITIONS.getDesc()); |
||||||
|
Mockito.when(taskDefinitionMapper.queryByCode(taskCode)).thenReturn(taskDefinition); |
||||||
|
Mockito.when(taskDefinitionMapper.deleteByCode(taskCode)).thenReturn(1); |
||||||
|
processTaskRelationLog = new ProcessTaskRelationLog(); |
||||||
|
processTaskRelationLog.setProjectCode(projectCode); |
||||||
|
processTaskRelationLog.setPostTaskCode(taskCode); |
||||||
|
processTaskRelationLog.setProcessDefinitionCode(processDefinitionCode); |
||||||
|
processTaskRelationLog.setProcessDefinitionVersion(1); |
||||||
|
Mockito.when(processTaskRelationMapper.deleteRelation(processTaskRelationLog)).thenReturn(1); |
||||||
|
Mockito.when(processTaskRelationLogMapper.deleteRelation(processTaskRelationLog)).thenReturn(1); |
||||||
|
result = processTaskRelationService.deleteTaskProcessRelation(loginUser, projectCode, processDefinitionCode, taskCode); |
||||||
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testDeleteEdge() { |
||||||
|
long projectCode = 1L; |
||||||
|
long processDefinitionCode = 3L; |
||||||
|
long preTaskCode = 4L; |
||||||
|
long postTaskCode = 5L; |
||||||
|
Project project = getProject(projectCode); |
||||||
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
||||||
|
|
||||||
|
User loginUser = new User(); |
||||||
|
loginUser.setId(-1); |
||||||
|
loginUser.setUserType(UserType.GENERAL_USER); |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
putMsg(result, Status.SUCCESS, projectCode); |
||||||
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
||||||
|
ProcessTaskRelation processTaskRelation = new ProcessTaskRelation(); |
||||||
|
processTaskRelation.setProjectCode(projectCode); |
||||||
|
processTaskRelation.setProcessDefinitionCode(processDefinitionCode); |
||||||
|
processTaskRelation.setPreTaskCode(preTaskCode); |
||||||
|
processTaskRelation.setPostTaskCode(postTaskCode); |
||||||
|
List<ProcessTaskRelation> processTaskRelationList = new ArrayList<>(); |
||||||
|
processTaskRelationList.add(processTaskRelation); |
||||||
|
Mockito.when(processTaskRelationMapper.queryByCode(projectCode, processDefinitionCode, preTaskCode, postTaskCode)).thenReturn(processTaskRelationList); |
||||||
|
Mockito.when(processTaskRelationMapper.countByCode(projectCode, processDefinitionCode, 0L, postTaskCode)).thenReturn(1); |
||||||
|
Mockito.when(processTaskRelationMapper.deleteById(processTaskRelation.getId())).thenReturn(1); |
||||||
|
Mockito.when(processTaskRelationMapper.updateById(processTaskRelation)).thenReturn(1); |
||||||
|
result = processTaskRelationService.deleteEdge(loginUser, projectCode, processDefinitionCode, preTaskCode, postTaskCode); |
||||||
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
||||||
|
} |
||||||
|
} |
@ -1,69 +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. |
|
||||||
# |
|
||||||
|
|
||||||
# datasource configuration |
|
||||||
spring.datasource.driver-class-name=org.postgresql.Driver |
|
||||||
spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/dolphinscheduler |
|
||||||
spring.datasource.username=root |
|
||||||
spring.datasource.password=root |
|
||||||
|
|
||||||
# mysql example |
|
||||||
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver |
|
||||||
#spring.datasource.url=jdbc:mysql://127.0.0.1:3306/dolphinscheduler?useUnicode=true&characterEncoding=UTF-8 |
|
||||||
#spring.datasource.username=ds_user |
|
||||||
#spring.datasource.password=dolphinscheduler |
|
||||||
|
|
||||||
# connection configuration |
|
||||||
#spring.datasource.initialSize=5 |
|
||||||
# min connection number |
|
||||||
#spring.datasource.minIdle=5 |
|
||||||
# max connection number |
|
||||||
#spring.datasource.maxActive=50 |
|
||||||
|
|
||||||
# max wait time for get a connection in milliseconds. if configuring maxWait, fair locks are enabled by default and concurrency efficiency decreases. |
|
||||||
# If necessary, unfair locks can be used by configuring the useUnfairLock attribute to true. |
|
||||||
#spring.datasource.maxWait=60000 |
|
||||||
|
|
||||||
# milliseconds for check to close free connections |
|
||||||
#spring.datasource.timeBetweenEvictionRunsMillis=60000 |
|
||||||
|
|
||||||
# the Destroy thread detects the connection interval and closes the physical connection in milliseconds if the connection idle time is greater than or equal to minEvictableIdleTimeMillis. |
|
||||||
#spring.datasource.timeBetweenConnectErrorMillis=60000 |
|
||||||
|
|
||||||
# the longest time a connection remains idle without being evicted, in milliseconds |
|
||||||
#spring.datasource.minEvictableIdleTimeMillis=300000 |
|
||||||
|
|
||||||
#the SQL used to check whether the connection is valid requires a query statement. If validation Query is null, testOnBorrow, testOnReturn, and testWhileIdle will not work. |
|
||||||
#spring.datasource.validationQuery=SELECT 1 |
|
||||||
|
|
||||||
#check whether the connection is valid for timeout, in seconds |
|
||||||
#spring.datasource.validationQueryTimeout=3 |
|
||||||
|
|
||||||
# when applying for a connection, if it is detected that the connection is idle longer than time Between Eviction Runs Millis, |
|
||||||
# validation Query is performed to check whether the connection is valid |
|
||||||
#spring.datasource.testWhileIdle=true |
|
||||||
|
|
||||||
#execute validation to check if the connection is valid when applying for a connection |
|
||||||
#spring.datasource.testOnBorrow=true |
|
||||||
#execute validation to check if the connection is valid when the connection is returned |
|
||||||
#spring.datasource.testOnReturn=false |
|
||||||
#spring.datasource.defaultAutoCommit=true |
|
||||||
#spring.datasource.keepAlive=true |
|
||||||
|
|
||||||
# open PSCache, specify count PSCache for every connection |
|
||||||
#spring.datasource.poolPreparedStatements=true |
|
||||||
#spring.datasource.maxPoolPreparedStatementPerConnectionSize=20 |
|
@ -0,0 +1,115 @@ |
|||||||
|
/* |
||||||
|
* 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. |
||||||
|
*/ |
||||||
|
<template> |
||||||
|
<el-dialog |
||||||
|
:title="$t('Format DAG')" |
||||||
|
:visible.sync="visible" |
||||||
|
width="500px" |
||||||
|
class="dag-layout-modal" |
||||||
|
:append-to-body="true" |
||||||
|
> |
||||||
|
<el-form |
||||||
|
ref="form" |
||||||
|
:model="form" |
||||||
|
label-width="100px" |
||||||
|
class="dag-layout-form" |
||||||
|
> |
||||||
|
<el-form-item :label="$t('layoutType')"> |
||||||
|
<el-radio-group v-model="form.type"> |
||||||
|
<el-radio label="grid">{{ $t("gridLayout") }}</el-radio> |
||||||
|
<el-radio label="dagre">{{ $t("dagreLayout") }}</el-radio> |
||||||
|
</el-radio-group> |
||||||
|
</el-form-item> |
||||||
|
<el-form-item :label="$t('rows')" v-if="form.type === LAYOUT_TYPE.GRID"> |
||||||
|
<el-input-number |
||||||
|
v-model="form.rows" |
||||||
|
:min="0" |
||||||
|
size="small" |
||||||
|
></el-input-number> |
||||||
|
</el-form-item> |
||||||
|
<el-form-item :label="$t('cols')" v-if="form.type === LAYOUT_TYPE.GRID"> |
||||||
|
<el-input-number |
||||||
|
v-model="form.cols" |
||||||
|
:min="0" |
||||||
|
size="small" |
||||||
|
></el-input-number> |
||||||
|
</el-form-item> |
||||||
|
</el-form> |
||||||
|
<span slot="footer" class="dialog-footer"> |
||||||
|
<el-button size="small" @click="close">{{ $t("Cancel") }}</el-button> |
||||||
|
<el-button size="small" type="primary" @click="submit">{{ |
||||||
|
$t("Confirm") |
||||||
|
}}</el-button> |
||||||
|
</span> |
||||||
|
</el-dialog> |
||||||
|
</template> |
||||||
|
<script> |
||||||
|
export const LAYOUT_TYPE = { |
||||||
|
GRID: 'grid', |
||||||
|
DAGRE: 'dagre' |
||||||
|
} |
||||||
|
|
||||||
|
export const DEFAULT_LAYOUT_CONFIG = { |
||||||
|
cols: 0, |
||||||
|
nodesep: 50, |
||||||
|
padding: 50, |
||||||
|
ranksep: 50, |
||||||
|
rows: 0, |
||||||
|
type: LAYOUT_TYPE.DAGRE |
||||||
|
} |
||||||
|
|
||||||
|
export default { |
||||||
|
data () { |
||||||
|
return { |
||||||
|
visible: false, |
||||||
|
form: { ...DEFAULT_LAYOUT_CONFIG }, |
||||||
|
LAYOUT_TYPE |
||||||
|
} |
||||||
|
}, |
||||||
|
methods: { |
||||||
|
show () { |
||||||
|
this.visible = true |
||||||
|
}, |
||||||
|
close () { |
||||||
|
this.visible = false |
||||||
|
}, |
||||||
|
submit () { |
||||||
|
this.$emit('submit', this.form) |
||||||
|
this.close() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
</script> |
||||||
|
<style lang="scss" scoped> |
||||||
|
.dag-layout-modal { |
||||||
|
::v-deep .el-dialog__header { |
||||||
|
border-bottom: solid 1px #d4d4d4; |
||||||
|
} |
||||||
|
|
||||||
|
::v-deep .dag-layout-form { |
||||||
|
margin-top: 20px; |
||||||
|
} |
||||||
|
|
||||||
|
::v-deep .el-radio { |
||||||
|
margin-bottom: 0; |
||||||
|
} |
||||||
|
|
||||||
|
.el-form-item { |
||||||
|
margin-bottom: 10px; |
||||||
|
} |
||||||
|
} |
||||||
|
</style> |
@ -0,0 +1,145 @@ |
|||||||
|
/* |
||||||
|
* 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
import { |
||||||
|
NODE, |
||||||
|
EDGE, |
||||||
|
PORT, |
||||||
|
NODE_HOVER, |
||||||
|
PORT_HOVER, |
||||||
|
EDGE_HOVER, |
||||||
|
PORT_SELECTED, |
||||||
|
NODE_SELECTED, |
||||||
|
EDGE_SELECTED, |
||||||
|
X6_PORT_OUT_NAME |
||||||
|
} from './x6-helper' |
||||||
|
import _ from 'lodash' |
||||||
|
|
||||||
|
export default { |
||||||
|
data () { |
||||||
|
return { |
||||||
|
hoverCell: null |
||||||
|
} |
||||||
|
}, |
||||||
|
methods: { |
||||||
|
bindStyleEvent (graph) { |
||||||
|
// nodes and edges hover
|
||||||
|
graph.on('cell:mouseenter', (data) => { |
||||||
|
const { cell, e } = data |
||||||
|
const isStatusIcon = (tagName) => |
||||||
|
tagName && |
||||||
|
(tagName.toLocaleLowerCase() === 'em' || |
||||||
|
tagName.toLocaleLowerCase() === 'body') |
||||||
|
if (!isStatusIcon(e.target.tagName)) { |
||||||
|
this.hoverCell = cell |
||||||
|
this.updateCellStyle(cell, graph) |
||||||
|
} |
||||||
|
}) |
||||||
|
graph.on('cell:mouseleave', ({ cell }) => { |
||||||
|
this.hoverCell = null |
||||||
|
this.updateCellStyle(cell, graph) |
||||||
|
}) |
||||||
|
// select
|
||||||
|
graph.on('cell:selected', ({ cell }) => { |
||||||
|
this.updateCellStyle(cell, graph) |
||||||
|
}) |
||||||
|
graph.on('cell:unselected', ({ cell }) => { |
||||||
|
this.updateCellStyle(cell, graph) |
||||||
|
}) |
||||||
|
}, |
||||||
|
updateCellStyle (cell, graph) { |
||||||
|
if (cell.isEdge()) { |
||||||
|
this.setEdgeStyle(cell, graph) |
||||||
|
} else if (cell.isNode()) { |
||||||
|
this.setNodeStyle(cell, graph) |
||||||
|
} |
||||||
|
}, |
||||||
|
/** |
||||||
|
* Set node style |
||||||
|
* @param {Node} node |
||||||
|
* @param {Graph} graph |
||||||
|
*/ |
||||||
|
setNodeStyle (node, graph) { |
||||||
|
const isHover = node === this.hoverCell |
||||||
|
const isSelected = graph.isSelected(node) |
||||||
|
const portHover = _.cloneDeep(PORT_HOVER.groups[X6_PORT_OUT_NAME].attrs) |
||||||
|
const portSelected = _.cloneDeep(PORT_SELECTED.groups[X6_PORT_OUT_NAME].attrs) |
||||||
|
const portDefault = _.cloneDeep(PORT.groups[X6_PORT_OUT_NAME].attrs) |
||||||
|
const nodeHover = _.merge(_.cloneDeep(NODE.attrs), NODE_HOVER.attrs) |
||||||
|
const nodeSelected = _.merge(_.cloneDeep(NODE.attrs), NODE_SELECTED.attrs) |
||||||
|
|
||||||
|
let img = null |
||||||
|
let nodeAttrs = null |
||||||
|
let portAttrs = null |
||||||
|
|
||||||
|
if (isHover || isSelected) { |
||||||
|
img = require(`../images/task-icos/${node.data.taskType.toLocaleLowerCase()}_hover.png`) |
||||||
|
if (isHover) { |
||||||
|
nodeAttrs = nodeHover |
||||||
|
portAttrs = _.merge(portDefault, portHover) |
||||||
|
} else { |
||||||
|
nodeAttrs = nodeSelected |
||||||
|
portAttrs = _.merge(portDefault, portSelected) |
||||||
|
} |
||||||
|
} else { |
||||||
|
img = require(`../images/task-icos/${node.data.taskType.toLocaleLowerCase()}.png`) |
||||||
|
nodeAttrs = NODE.attrs |
||||||
|
portAttrs = portDefault |
||||||
|
} |
||||||
|
node.setAttrByPath('image/xlink:href', img) |
||||||
|
node.setAttrs(nodeAttrs) |
||||||
|
node.setPortProp( |
||||||
|
X6_PORT_OUT_NAME, |
||||||
|
'attrs', |
||||||
|
portAttrs |
||||||
|
) |
||||||
|
}, |
||||||
|
/** |
||||||
|
* Set edge style |
||||||
|
* @param {Edge} edge |
||||||
|
* @param {Graph} graph |
||||||
|
*/ |
||||||
|
setEdgeStyle (edge, graph) { |
||||||
|
const isHover = edge === this.hoverCell |
||||||
|
const isSelected = graph.isSelected(edge) |
||||||
|
const labelName = this.getEdgeLabelName ? this.getEdgeLabelName(edge) : '' |
||||||
|
let edgeProps = null |
||||||
|
|
||||||
|
if (isHover) { |
||||||
|
edgeProps = _.merge(_.cloneDeep(EDGE), EDGE_HOVER) |
||||||
|
} else if (isSelected) { |
||||||
|
edgeProps = _.merge(_.cloneDeep(EDGE), EDGE_SELECTED) |
||||||
|
} else { |
||||||
|
edgeProps = _.cloneDeep(EDGE) |
||||||
|
} |
||||||
|
|
||||||
|
edge.setAttrs(edgeProps.attrs) |
||||||
|
edge.setLabels([ |
||||||
|
{ |
||||||
|
..._.merge( |
||||||
|
{ |
||||||
|
attrs: _.cloneDeep(edgeProps.defaultLabel.attrs) |
||||||
|
}, |
||||||
|
{ |
||||||
|
attrs: { label: { text: labelName } } |
||||||
|
} |
||||||
|
) |
||||||
|
} |
||||||
|
]) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue