Browse Source

[Feature][JsonSplit-api]move of processDefinition, the projectCode instead of projectName (#5744)

* select-by-code of processDefinition

* fix ut

* prcessDefinition copy

* move of processDefinition api and the projectCode instead of projectName

* fix ut

* fix ut

* fix review

Co-authored-by: JinyLeeChina <297062848@qq.com>
2.0.7-release
JinyLeeChina 4 years ago committed by GitHub
parent
commit
14035c03e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 214
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java
  2. 29
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java
  3. 97
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java
  4. 466
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
  5. 1
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java
  6. 139
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java
  7. 4
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandlerTest.java
  8. 351
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
  9. 4
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java

214
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java

@ -25,6 +25,7 @@ import static org.apache.dolphinscheduler.api.enums.Status.DELETE_PROCESS_DEFINE
import static org.apache.dolphinscheduler.api.enums.Status.DELETE_PROCESS_DEFINITION_VERSION_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.DELETE_PROCESS_DEFINITION_VERSION_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.ENCAPSULATION_TREEVIEW_STRUCTURE_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.ENCAPSULATION_TREEVIEW_STRUCTURE_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.IMPORT_PROCESS_DEFINE_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROCESS_DEFINITION_LIST; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROCESS_DEFINITION_LIST;
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROCESS_DEFINITION_LIST_PAGING_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROCESS_DEFINITION_LIST_PAGING_ERROR;
@ -66,6 +67,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
@ -73,7 +75,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
/** /**
@ -81,7 +82,7 @@ import springfox.documentation.annotations.ApiIgnore;
*/ */
@Api(tags = "PROCESS_DEFINITION_TAG") @Api(tags = "PROCESS_DEFINITION_TAG")
@RestController @RestController
@RequestMapping("projects/{projectName}/process") @RequestMapping("projects/{projectCode}/process")
public class ProcessDefinitionController extends BaseController { public class ProcessDefinitionController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(ProcessDefinitionController.class); private static final Logger logger = LoggerFactory.getLogger(ProcessDefinitionController.class);
@ -93,7 +94,7 @@ public class ProcessDefinitionController extends BaseController {
* create process definition * create process definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param name process definition name * @param name process definition name
* @param description description * @param description description
* @param globalParams globalParams * @param globalParams globalParams
@ -116,7 +117,7 @@ public class ProcessDefinitionController extends BaseController {
@ApiException(CREATE_PROCESS_DEFINITION) @ApiException(CREATE_PROCESS_DEFINITION)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result createProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result createProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "name", required = true) String name, @RequestParam(value = "name", required = true) String name,
@RequestParam(value = "description", required = false) String description, @RequestParam(value = "description", required = false) String description,
@RequestParam(value = "globalParams", required = false, defaultValue = "[]") String globalParams, @RequestParam(value = "globalParams", required = false, defaultValue = "[]") String globalParams,
@ -126,7 +127,7 @@ public class ProcessDefinitionController extends BaseController {
@RequestParam(value = "tenantCode", required = true) String tenantCode, @RequestParam(value = "tenantCode", required = true) String tenantCode,
@RequestParam(value = "taskRelationJson", required = true) String taskRelationJson) throws JsonProcessingException { @RequestParam(value = "taskRelationJson", required = true) String taskRelationJson) throws JsonProcessingException {
Map<String, Object> result = processDefinitionService.createProcessDefinition(loginUser, projectName, name, description, globalParams, Map<String, Object> result = processDefinitionService.createProcessDefinition(loginUser, projectCode, name, description, globalParams,
connects, locations, timeout, tenantCode, taskRelationJson); connects, locations, timeout, tenantCode, taskRelationJson);
return returnDataList(result); return returnDataList(result);
} }
@ -135,59 +136,57 @@ public class ProcessDefinitionController extends BaseController {
* copy process definition * copy process definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processDefinitionCodes process definition codes * @param processDefinitionCodes process definition codes
* @param targetProjectName target project name * @param targetProjectCode target project code
* @return copy result code * @return copy result code
*/ */
@ApiOperation(value = "copy", notes = "COPY_PROCESS_DEFINITION_NOTES") @ApiOperation(value = "copy", notes = "COPY_PROCESS_DEFINITION_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionCodes", value = "PROCESS_DEFINITION_CODES", required = true, dataType = "String", example = "3,4"), @ApiImplicitParam(name = "processDefinitionCodes", value = "PROCESS_DEFINITION_CODES", required = true, dataType = "String", example = "3,4"),
@ApiImplicitParam(name = "targetProjectName", value = "TARGET_PROJECT_NAME", required = true, dataType = "String", example = "ddd") @ApiImplicitParam(name = "targetProjectCode", value = "TARGET_PROJECT_CODE", required = true, dataType = "Long", example = "123")
}) })
@PostMapping(value = "/copy") @PostMapping(value = "/copy")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(BATCH_COPY_PROCESS_DEFINITION_ERROR) @ApiException(BATCH_COPY_PROCESS_DEFINITION_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result copyProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result copyProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "processDefinitionCodes", required = true) String processDefinitionCodes, @RequestParam(value = "processDefinitionCodes", required = true) String processDefinitionCodes,
@RequestParam(value = "targetProjectName", required = true) String targetProjectName) { @RequestParam(value = "targetProjectCode", required = true) long targetProjectCode) {
return returnDataList( return returnDataList(processDefinitionService.batchCopyProcessDefinition(loginUser, projectCode, processDefinitionCodes, targetProjectCode));
processDefinitionService.batchCopyProcessDefinition(loginUser, projectName, processDefinitionCodes, targetProjectName));
} }
/** /**
* move process definition * move process definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processDefinitionIds process definition ids * @param processDefinitionCodes process definition codes
* @param targetProjectId target project id * @param targetProjectCode target project code
* @return move result code * @return move result code
*/ */
@ApiOperation(value = "moveProcessDefinition", notes = "MOVE_PROCESS_DEFINITION_NOTES") @ApiOperation(value = "moveProcessDefinition", notes = "MOVE_PROCESS_DEFINITION_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionIds", value = "PROCESS_DEFINITION_IDS", required = true, dataType = "String", example = "3,4"), @ApiImplicitParam(name = "processDefinitionCodes", value = "PROCESS_DEFINITION_CODES", required = true, dataType = "String", example = "3,4"),
@ApiImplicitParam(name = "targetProjectId", value = "TARGET_PROJECT_ID", required = true, dataType = "Int", example = "10") @ApiImplicitParam(name = "targetProjectCode", value = "TARGET_PROJECT_CODE", required = true, dataType = "Long", example = "123")
}) })
@PostMapping(value = "/move") @PostMapping(value = "/move")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(BATCH_MOVE_PROCESS_DEFINITION_ERROR) @ApiException(BATCH_MOVE_PROCESS_DEFINITION_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result moveProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result moveProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "processDefinitionIds", required = true) String processDefinitionIds, @RequestParam(value = "processDefinitionCodes", required = true) String processDefinitionCodes,
@RequestParam(value = "targetProjectId", required = true) int targetProjectId) { @RequestParam(value = "targetProjectCode", required = true) long targetProjectCode) {
return returnDataList( return returnDataList(processDefinitionService.batchMoveProcessDefinition(loginUser, projectCode, processDefinitionCodes, targetProjectCode));
processDefinitionService.batchMoveProcessDefinition(loginUser, projectName, processDefinitionIds, targetProjectId));
} }
/** /**
* verify process definition name unique * verify process definition name unique
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param name name * @param name name
* @return true if process definition name not exists, otherwise false * @return true if process definition name not exists, otherwise false
*/ */
@ -200,9 +199,9 @@ public class ProcessDefinitionController extends BaseController {
@ApiException(VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR) @ApiException(VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result verifyProcessDefinitionName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result verifyProcessDefinitionName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "name", required = true) String name) { @RequestParam(value = "name", required = true) String name) {
Map<String, Object> result = processDefinitionService.verifyProcessDefinitionName(loginUser, projectName, name); Map<String, Object> result = processDefinitionService.verifyProcessDefinitionName(loginUser, projectCode, name);
return returnDataList(result); return returnDataList(result);
} }
@ -210,7 +209,7 @@ public class ProcessDefinitionController extends BaseController {
* update process definition * update process definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param name process definition name * @param name process definition name
* @param code process definition code * @param code process definition code
* @param description description * @param description description
@ -237,7 +236,7 @@ public class ProcessDefinitionController extends BaseController {
@ApiException(UPDATE_PROCESS_DEFINITION_ERROR) @ApiException(UPDATE_PROCESS_DEFINITION_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result updateProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result updateProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "name", required = true) String name, @RequestParam(value = "name", required = true) String name,
@RequestParam(value = "code", required = true) long code, @RequestParam(value = "code", required = true) long code,
@RequestParam(value = "description", required = false) String description, @RequestParam(value = "description", required = false) String description,
@ -249,7 +248,7 @@ public class ProcessDefinitionController extends BaseController {
@RequestParam(value = "taskRelationJson", required = true) String taskRelationJson, @RequestParam(value = "taskRelationJson", required = true) String taskRelationJson,
@RequestParam(value = "releaseState", required = false, defaultValue = "OFFLINE") ReleaseState releaseState) { @RequestParam(value = "releaseState", required = false, defaultValue = "OFFLINE") ReleaseState releaseState) {
Map<String, Object> result = processDefinitionService.updateProcessDefinition(loginUser, projectName, name, code, description, globalParams, Map<String, Object> result = processDefinitionService.updateProcessDefinition(loginUser, projectCode, name, code, description, globalParams,
connects, locations, timeout, tenantCode, taskRelationJson); connects, locations, timeout, tenantCode, taskRelationJson);
// If the update fails, the result will be returned directly // If the update fails, the result will be returned directly
if (result.get(Constants.STATUS) != Status.SUCCESS) { if (result.get(Constants.STATUS) != Status.SUCCESS) {
@ -258,7 +257,7 @@ public class ProcessDefinitionController extends BaseController {
// Judge whether to go online after editing,0 means offline, 1 means online // Judge whether to go online after editing,0 means offline, 1 means online
if (releaseState == ReleaseState.ONLINE) { if (releaseState == ReleaseState.ONLINE) {
result = processDefinitionService.releaseProcessDefinition(loginUser, projectName, code, releaseState); result = processDefinitionService.releaseProcessDefinition(loginUser, projectCode, code, releaseState);
} }
return returnDataList(result); return returnDataList(result);
} }
@ -267,13 +266,13 @@ public class ProcessDefinitionController extends BaseController {
* query process definition version paging list info * query process definition version paging list info
* *
* @param loginUser login user info * @param loginUser login user info
* @param projectName the process definition project name * @param projectCode project code
* @param pageNo the process definition version list current page number * @param pageNo the process definition version list current page number
* @param pageSize the process definition version list page size * @param pageSize the process definition version list page size
* @param processDefinitionCode the process definition code * @param processDefinitionCode the process definition code
* @return the process definition version list * @return the process definition version list
*/ */
@ApiOperation(value = "queryProcessDefinitionVersions", notes = "QUERY_PROCESS_DEFINITION_VERSIONS_NOTES") @ApiOperation(value = "queryVersions", notes = "QUERY_PROCESS_DEFINITION_VERSIONS_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "100"),
@ -284,13 +283,11 @@ public class ProcessDefinitionController extends BaseController {
@ApiException(QUERY_PROCESS_DEFINITION_VERSIONS_ERROR) @ApiException(QUERY_PROCESS_DEFINITION_VERSIONS_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryProcessDefinitionVersions(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryProcessDefinitionVersions(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "pageNo") int pageNo, @RequestParam(value = "pageNo") int pageNo,
@RequestParam(value = "pageSize") int pageSize, @RequestParam(value = "pageSize") int pageSize,
@RequestParam(value = "processDefinitionCode") long processDefinitionCode) { @RequestParam(value = "processDefinitionCode") long processDefinitionCode) {
Map<String, Object> result = processDefinitionService.queryProcessDefinitionVersions(loginUser Map<String, Object> result = processDefinitionService.queryProcessDefinitionVersions(loginUser, projectCode, pageNo, pageSize, processDefinitionCode);
, projectName, pageNo, pageSize, processDefinitionCode);
return returnDataList(result); return returnDataList(result);
} }
@ -298,12 +295,12 @@ public class ProcessDefinitionController extends BaseController {
* switch certain process definition version * switch certain process definition version
* *
* @param loginUser login user info * @param loginUser login user info
* @param projectName the process definition project name * @param projectCode project code
* @param processDefinitionId the process definition id * @param processDefinitionId the process definition id
* @param version the version user want to switch * @param version the version user want to switch
* @return switch version result code * @return switch version result code
*/ */
@ApiOperation(value = "switchProcessDefinitionVersion", notes = "SWITCH_PROCESS_DEFINITION_VERSION_NOTES") @ApiOperation(value = "switchVersion", notes = "SWITCH_PROCESS_DEFINITION_VERSION_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "version", value = "VERSION", required = true, dataType = "Long", example = "100") @ApiImplicitParam(name = "version", value = "VERSION", required = true, dataType = "Long", example = "100")
@ -313,11 +310,10 @@ public class ProcessDefinitionController extends BaseController {
@ApiException(SWITCH_PROCESS_DEFINITION_VERSION_ERROR) @ApiException(SWITCH_PROCESS_DEFINITION_VERSION_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result switchProcessDefinitionVersion(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result switchProcessDefinitionVersion(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "processDefinitionId") int processDefinitionId, @RequestParam(value = "processDefinitionId") int processDefinitionId,
@RequestParam(value = "version") long version) { @RequestParam(value = "version") long version) {
Map<String, Object> result = processDefinitionService.switchProcessDefinitionVersion(loginUser, projectName Map<String, Object> result = processDefinitionService.switchProcessDefinitionVersion(loginUser, projectCode, processDefinitionId, version);
, processDefinitionId, version);
return returnDataList(result); return returnDataList(result);
} }
@ -325,12 +321,12 @@ public class ProcessDefinitionController extends BaseController {
* delete the certain process definition version by version and process definition id * delete the certain process definition version by version and process definition id
* *
* @param loginUser login user info * @param loginUser login user info
* @param projectName the process definition project name * @param projectCode project code
* @param processDefinitionId process definition id * @param processDefinitionId process definition id
* @param version the process definition version user want to delete * @param version the process definition version user want to delete
* @return delete version result code * @return delete version result code
*/ */
@ApiOperation(value = "deleteProcessDefinitionVersion", notes = "DELETE_PROCESS_DEFINITION_VERSION_NOTES") @ApiOperation(value = "deleteVersion", notes = "DELETE_PROCESS_DEFINITION_VERSION_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "version", value = "VERSION", required = true, dataType = "Long", example = "100") @ApiImplicitParam(name = "version", value = "VERSION", required = true, dataType = "Long", example = "100")
@ -340,10 +336,10 @@ public class ProcessDefinitionController extends BaseController {
@ApiException(DELETE_PROCESS_DEFINITION_VERSION_ERROR) @ApiException(DELETE_PROCESS_DEFINITION_VERSION_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result deleteProcessDefinitionVersion(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result deleteProcessDefinitionVersion(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "processDefinitionId") int processDefinitionId, @RequestParam(value = "processDefinitionId") int processDefinitionId,
@RequestParam(value = "version") long version) { @RequestParam(value = "version") long version) {
Map<String, Object> result = processDefinitionService.deleteByProcessDefinitionIdAndVersion(loginUser, projectName, processDefinitionId, version); Map<String, Object> result = processDefinitionService.deleteByProcessDefinitionIdAndVersion(loginUser, projectCode, processDefinitionId, version);
return returnDataList(result); return returnDataList(result);
} }
@ -351,12 +347,12 @@ public class ProcessDefinitionController extends BaseController {
* release process definition * release process definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param code process definition code * @param code process definition code
* @param releaseState release state * @param releaseState release state
* @return release result code * @return release result code
*/ */
@ApiOperation(value = "releaseProcessDefinition", notes = "RELEASE_PROCESS_DEFINITION_NOTES") @ApiOperation(value = "release", notes = "RELEASE_PROCESS_DEFINITION_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, type = "String"), @ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, type = "String"),
@ApiImplicitParam(name = "code", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "Long", example = "123456789"), @ApiImplicitParam(name = "code", value = "PROCESS_DEFINITION_CODE", required = true, dataType = "Long", example = "123456789"),
@ -367,11 +363,10 @@ public class ProcessDefinitionController extends BaseController {
@ApiException(RELEASE_PROCESS_DEFINITION_ERROR) @ApiException(RELEASE_PROCESS_DEFINITION_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result releaseProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result releaseProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "code", required = true) long code, @RequestParam(value = "code", required = true) long code,
@RequestParam(value = "releaseState", required = true) ReleaseState releaseState) { @RequestParam(value = "releaseState", required = true) ReleaseState releaseState) {
Map<String, Object> result = processDefinitionService.releaseProcessDefinition(loginUser, projectCode, code, releaseState);
Map<String, Object> result = processDefinitionService.releaseProcessDefinition(loginUser, projectName, code, releaseState);
return returnDataList(result); return returnDataList(result);
} }
@ -379,7 +374,7 @@ public class ProcessDefinitionController extends BaseController {
* query detail of process definition by code * query detail of process definition by code
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param code process definition id * @param code process definition id
* @return process definition detail * @return process definition detail
*/ */
@ -392,9 +387,9 @@ public class ProcessDefinitionController extends BaseController {
@ApiException(QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR) @ApiException(QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryProcessDefinitionByCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryProcessDefinitionByCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "code", required = true) long code) { @RequestParam(value = "code", required = true) long code) {
Map<String, Object> result = processDefinitionService.queryProcessDefinitionByCode(loginUser, projectName, code); Map<String, Object> result = processDefinitionService.queryProcessDefinitionByCode(loginUser, projectCode, code);
return returnDataList(result); return returnDataList(result);
} }
@ -402,23 +397,22 @@ public class ProcessDefinitionController extends BaseController {
* query detail of process definition by name * query detail of process definition by name
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processDefinitionName process definition name * @param processDefinitionName process definition name
* @return process definition detail * @return process definition detail
*/ */
@ApiOperation(value = "queryProcessDefinitionByName", notes = "QUERY_PROCESS_DEFINITION_BY_NAME_NOTES") @ApiOperation(value = "queryProcessDefinitionByName", notes = "QUERY_PROCESS_DEFINITION_BY_NAME_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionName", value = "PROCESS_DEFINITION_ID", required = true, dataType = "String") @ApiImplicitParam(name = "processDefinitionName", value = "PROCESS_DEFINITION_NAME", required = true, dataType = "String")
}) })
@GetMapping(value = "/select-by-name") @GetMapping(value = "/select-by-name")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR) @ApiException(QUERY_DATAIL_OF_PROCESS_DEFINITION_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result<ProcessDefinition> queryProcessDefinitionByName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result<ProcessDefinition> queryProcessDefinitionByName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("processDefinitionName") String processDefinitionName @RequestParam("processDefinitionName") String processDefinitionName) {
) { Map<String, Object> result = processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, processDefinitionName);
Map<String, Object> result = processDefinitionService.queryProcessDefinitionByName(loginUser, projectName, processDefinitionName);
return returnDataList(result); return returnDataList(result);
} }
@ -426,18 +420,17 @@ public class ProcessDefinitionController extends BaseController {
* query Process definition list * query Process definition list
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @return process definition list * @return process definition list
*/ */
@ApiOperation(value = "queryProcessDefinitionList", notes = "QUERY_PROCESS_DEFINITION_LIST_NOTES") @ApiOperation(value = "queryList", notes = "QUERY_PROCESS_DEFINITION_LIST_NOTES")
@GetMapping(value = "/list") @GetMapping(value = "/list")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_PROCESS_DEFINITION_LIST) @ApiException(QUERY_PROCESS_DEFINITION_LIST)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryProcessDefinitionList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryProcessDefinitionList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode) {
) { Map<String, Object> result = processDefinitionService.queryProcessDefinitionList(loginUser, projectCode);
Map<String, Object> result = processDefinitionService.queryProcessDefinitionList(loginUser, projectName);
return returnDataList(result); return returnDataList(result);
} }
@ -445,14 +438,14 @@ public class ProcessDefinitionController extends BaseController {
* query process definition list paging * query process definition list paging
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param searchVal search value * @param searchVal search value
* @param pageNo page number * @param pageNo page number
* @param pageSize page size * @param pageSize page size
* @param userId user id * @param userId user id
* @return process definition page * @return process definition page
*/ */
@ApiOperation(value = "queryProcessDefinitionListPaging", notes = "QUERY_PROCESS_DEFINITION_LIST_PAGING_NOTES") @ApiOperation(value = "queryListPaging", notes = "QUERY_PROCESS_DEFINITION_LIST_PAGING_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "100"), @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", required = false, type = "String"), @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", required = false, type = "String"),
@ -464,7 +457,7 @@ public class ProcessDefinitionController extends BaseController {
@ApiException(QUERY_PROCESS_DEFINITION_LIST_PAGING_ERROR) @ApiException(QUERY_PROCESS_DEFINITION_LIST_PAGING_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryProcessDefinitionListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryProcessDefinitionListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam(value = "searchVal", required = false) String searchVal, @RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam(value = "userId", required = false, defaultValue = "0") Integer userId, @RequestParam(value = "userId", required = false, defaultValue = "0") Integer userId,
@ -474,7 +467,7 @@ public class ProcessDefinitionController extends BaseController {
return returnDataListPaging(result); return returnDataListPaging(result);
} }
searchVal = ParameterUtils.handleEscapes(searchVal); searchVal = ParameterUtils.handleEscapes(searchVal);
result = processDefinitionService.queryProcessDefinitionListPaging(loginUser, projectName, searchVal, pageNo, pageSize, userId); result = processDefinitionService.queryProcessDefinitionListPaging(loginUser, projectCode, searchVal, pageNo, pageSize, userId);
return returnDataListPaging(result); return returnDataListPaging(result);
} }
@ -482,7 +475,7 @@ public class ProcessDefinitionController extends BaseController {
* encapsulation treeview structure * encapsulation treeview structure
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param id process definition id * @param id process definition id
* @param limit limit * @param limit limit
* @return tree view json data * @return tree view json data
@ -497,7 +490,7 @@ public class ProcessDefinitionController extends BaseController {
@ApiException(ENCAPSULATION_TREEVIEW_STRUCTURE_ERROR) @ApiException(ENCAPSULATION_TREEVIEW_STRUCTURE_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result viewTree(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result viewTree(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("processId") Integer id, @RequestParam("processId") Integer id,
@RequestParam("limit") Integer limit) throws Exception { @RequestParam("limit") Integer limit) throws Exception {
Map<String, Object> result = processDefinitionService.viewTree(id, limit); Map<String, Object> result = processDefinitionService.viewTree(id, limit);
@ -508,7 +501,7 @@ public class ProcessDefinitionController extends BaseController {
* get tasks list by process definition code * get tasks list by process definition code
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processDefinitionCode process definition code * @param processDefinitionCode process definition code
* @return task list * @return task list
*/ */
@ -521,10 +514,10 @@ public class ProcessDefinitionController extends BaseController {
@ApiException(GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR) @ApiException(GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR)
public Result getNodeListByDefinitionCode( public Result getNodeListByDefinitionCode(
@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("processDefinitionCode") Long processDefinitionCode) throws Exception { @RequestParam("processDefinitionCode") Long processDefinitionCode) {
logger.info("query task node name list by definitionCode, login user:{}, project name:{}, code : {}", logger.info("query task node name list by definitionCode, login user:{}, project name:{}, code : {}",
loginUser.getUserName(), projectName, processDefinitionCode); loginUser.getUserName(), projectCode, processDefinitionCode);
Map<String, Object> result = processDefinitionService.getTaskNodeListByDefinitionCode(processDefinitionCode); Map<String, Object> result = processDefinitionService.getTaskNodeListByDefinitionCode(processDefinitionCode);
return returnDataList(result); return returnDataList(result);
} }
@ -533,7 +526,7 @@ public class ProcessDefinitionController extends BaseController {
* get tasks list by process definition code list * get tasks list by process definition code list
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processDefinitionCodeList process definition code list * @param processDefinitionCodeList process definition code list
* @return node list data * @return node list data
*/ */
@ -544,9 +537,8 @@ public class ProcessDefinitionController extends BaseController {
@GetMapping(value = "get-task-list") @GetMapping(value = "get-task-list")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR) @ApiException(GET_TASKS_LIST_BY_PROCESS_DEFINITION_ID_ERROR)
public Result getNodeListByDefinitionCodeList( public Result getNodeListByDefinitionCodeList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
@RequestParam("processDefinitionCodeList") String processDefinitionCodeList) { @RequestParam("processDefinitionCodeList") String processDefinitionCodeList) {
Map<String, Object> result = processDefinitionService.getTaskNodeListByDefinitionCodeList(processDefinitionCodeList); Map<String, Object> result = processDefinitionService.getTaskNodeListByDefinitionCodeList(processDefinitionCodeList);
return returnDataList(result); return returnDataList(result);
@ -556,11 +548,11 @@ public class ProcessDefinitionController extends BaseController {
* delete process definition by id * delete process definition by id
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processDefinitionId process definition id * @param processDefinitionId process definition id
* @return delete result code * @return delete result code
*/ */
@ApiOperation(value = "deleteProcessDefinitionById", notes = "DELETE_PROCESS_DEFINITION_BY_ID_NOTES") @ApiOperation(value = "deleteByCode", notes = "DELETE_PROCESS_DEFINITION_BY_ID_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", dataType = "Int", example = "100") @ApiImplicitParam(name = "processDefinitionId", value = "PROCESS_DEFINITION_ID", dataType = "Int", example = "100")
}) })
@ -569,22 +561,21 @@ public class ProcessDefinitionController extends BaseController {
@ApiException(DELETE_PROCESS_DEFINE_BY_ID_ERROR) @ApiException(DELETE_PROCESS_DEFINE_BY_ID_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result deleteProcessDefinitionById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result deleteProcessDefinitionById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("processDefinitionId") Integer processDefinitionId @RequestParam("processDefinitionId") Integer processDefinitionId) {
) { Map<String, Object> result = processDefinitionService.deleteProcessDefinitionById(loginUser, projectCode, processDefinitionId);
Map<String, Object> result = processDefinitionService.deleteProcessDefinitionById(loginUser, projectName, processDefinitionId);
return returnDataList(result); return returnDataList(result);
} }
/** /**
* batch delete process definition by ids * batch delete process definition by codes
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processDefinitionIds process definition id list * @param processDefinitionIds process definition id list
* @return delete result code * @return delete result code
*/ */
@ApiOperation(value = "batchDeleteProcessDefinitionByIds", notes = "BATCH_DELETE_PROCESS_DEFINITION_BY_IDS_NOTES") @ApiOperation(value = "batchDeleteByCodes", notes = "BATCH_DELETE_PROCESS_DEFINITION_BY_IDS_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionIds", value = "PROCESS_DEFINITION_IDS", type = "String") @ApiImplicitParam(name = "processDefinitionIds", value = "PROCESS_DEFINITION_IDS", type = "String")
}) })
@ -593,7 +584,7 @@ public class ProcessDefinitionController extends BaseController {
@ApiException(BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR) @ApiException(BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result batchDeleteProcessDefinitionByIds(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result batchDeleteProcessDefinitionByIds(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("processDefinitionIds") String processDefinitionIds @RequestParam("processDefinitionIds") String processDefinitionIds
) { ) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
@ -603,7 +594,7 @@ public class ProcessDefinitionController extends BaseController {
for (String strProcessDefinitionId : processDefinitionIdArray) { for (String strProcessDefinitionId : processDefinitionIdArray) {
int processDefinitionId = Integer.parseInt(strProcessDefinitionId); int processDefinitionId = Integer.parseInt(strProcessDefinitionId);
try { try {
Map<String, Object> deleteResult = processDefinitionService.deleteProcessDefinitionById(loginUser, projectName, processDefinitionId); Map<String, Object> deleteResult = processDefinitionService.deleteProcessDefinitionById(loginUser, projectCode, processDefinitionId);
if (!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))) { if (!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))) {
deleteFailedIdList.add(strProcessDefinitionId); deleteFailedIdList.add(strProcessDefinitionId);
logger.error((String) deleteResult.get(Constants.MSG)); logger.error((String) deleteResult.get(Constants.MSG));
@ -624,15 +615,15 @@ public class ProcessDefinitionController extends BaseController {
} }
/** /**
* batch export process definition by ids * batch export process definition by codes
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processDefinitionIds process definition ids * @param processDefinitionIds process definition ids
* @param response response * @param response response
*/ */
@ApiOperation(value = "batchExportProcessDefinitionByIds", notes = "BATCH_EXPORT_PROCESS_DEFINITION_BY_IDS_NOTES") @ApiOperation(value = "batchExportByCodes", notes = "BATCH_EXPORT_PROCESS_DEFINITION_BY_IDS_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "processDefinitionIds", value = "PROCESS_DEFINITION_ID", required = true, dataType = "String") @ApiImplicitParam(name = "processDefinitionIds", value = "PROCESS_DEFINITION_ID", required = true, dataType = "String")
}) })
@ -640,31 +631,54 @@ public class ProcessDefinitionController extends BaseController {
@ResponseBody @ResponseBody
@AccessLogAnnotation(ignoreRequestArgs = {"loginUser", "response"}) @AccessLogAnnotation(ignoreRequestArgs = {"loginUser", "response"})
public void batchExportProcessDefinitionByIds(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public void batchExportProcessDefinitionByIds(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("processDefinitionIds") String processDefinitionIds, @RequestParam("processDefinitionIds") String processDefinitionIds,
HttpServletResponse response) { HttpServletResponse response) {
try { try {
processDefinitionService.batchExportProcessDefinitionByIds(loginUser, projectName, processDefinitionIds, response); processDefinitionService.batchExportProcessDefinitionByIds(loginUser, projectCode, processDefinitionIds, response);
} catch (Exception e) { } catch (Exception e) {
logger.error(Status.BATCH_EXPORT_PROCESS_DEFINE_BY_IDS_ERROR.getMsg(), e); logger.error(Status.BATCH_EXPORT_PROCESS_DEFINE_BY_IDS_ERROR.getMsg(), e);
} }
} }
/** /**
* query process definition all by project id * query all process definition by project code
* *
* @param loginUser login user * @param loginUser login user
* @param projectId project id * @param projectCode project code
* @return process definition list * @return process definition list
*/ */
@ApiOperation(value = "queryProcessDefinitionAllByProjectId", notes = "QUERY_PROCESS_DEFINITION_All_BY_PROJECT_ID_NOTES") @ApiOperation(value = "queryAllByProjectCode", notes = "QUERY_PROCESS_DEFINITION_All_BY_PROJECT_ID_NOTES")
@GetMapping(value = "/queryProcessDefinitionAllByProjectId") @GetMapping(value = "/queryAllByProjectCode")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_PROCESS_DEFINITION_LIST) @ApiException(QUERY_PROCESS_DEFINITION_LIST)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryProcessDefinitionAllByProjectId(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryAllProcessDefinitionByProjectCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("projectId") Integer projectId) { @RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode) {
Map<String, Object> result = processDefinitionService.queryProcessDefinitionAllByProjectId(projectId); Map<String, Object> result = processDefinitionService.queryAllProcessDefinitionByProjectCode(loginUser, projectCode);
return returnDataList(result);
}
/**
* import process definition
*
* @param loginUser login user
* @param projectCode project code
* @param file resource file
* @return import result code
*/
@ApiOperation(value = "importProcessDefinition", notes = "IMPORT_PROCESS_DEFINITION_NOTES")
@ApiImplicitParams({
@ApiImplicitParam(name = "file", value = "RESOURCE_FILE", required = true, dataType = "MultipartFile")
})
@PostMapping(value = "/import")
@ApiException(IMPORT_PROCESS_DEFINE_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = {"loginUser", "file"})
public Result importProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("file") MultipartFile file) {
Map<String, Object> result = processDefinitionService.importProcessDefinition(loginUser, projectCode, file);
return returnDataList(result); return returnDataList(result);
} }

29
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java

@ -19,7 +19,6 @@ package org.apache.dolphinscheduler.api.controller;
import static org.apache.dolphinscheduler.api.enums.Status.CREATE_PROJECT_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.CREATE_PROJECT_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.DELETE_PROJECT_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.DELETE_PROJECT_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.IMPORT_PROCESS_DEFINE_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_AUTHORIZED_AND_USER_CREATED_PROJECT_ERROR; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_AUTHORIZED_AND_USER_CREATED_PROJECT_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_AUTHORIZED_PROJECT; import static org.apache.dolphinscheduler.api.enums.Status.QUERY_AUTHORIZED_PROJECT;
@ -30,7 +29,6 @@ import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_PROJECT_ERROR;
import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException; import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.ProcessDefinitionService;
import org.apache.dolphinscheduler.api.service.ProjectService; import org.apache.dolphinscheduler.api.service.ProjectService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
@ -48,7 +46,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
@ -67,9 +64,6 @@ public class ProjectController extends BaseController {
@Autowired @Autowired
private ProjectService projectService; private ProjectService projectService;
@Autowired
private ProcessDefinitionService processDefinitionService;
/** /**
* create project * create project
* *
@ -256,29 +250,6 @@ public class ProjectController extends BaseController {
return returnDataList(result); return returnDataList(result);
} }
/**
* import process definition
*
* @param loginUser login user
* @param file resource file
* @param projectName project name
* @return import result code
*/
@ApiOperation(value = "importProcessDefinition", notes = "EXPORT_PROCESS_DEFINITION_NOTES")
@ApiImplicitParams({
@ApiImplicitParam(name = "file", value = "RESOURCE_FILE", required = true, dataType = "MultipartFile")
})
@PostMapping(value = "/import-definition")
@ApiException(IMPORT_PROCESS_DEFINE_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = {"loginUser", "file"})
public Result importProcessDefinition(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("file") MultipartFile file,
@RequestParam("projectName") String projectName) {
Map<String, Object> result = processDefinitionService.importProcessDefinition(loginUser, file, projectName);
return returnDataList(result);
}
/** /**
* query all project list * query all project list
* *

97
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java

@ -38,7 +38,7 @@ public interface ProcessDefinitionService {
* create process definition * create process definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param name process definition name * @param name process definition name
* @param description description * @param description description
* @param globalParams global params * @param globalParams global params
@ -51,7 +51,7 @@ public interface ProcessDefinitionService {
* @throws JsonProcessingException JsonProcessingException * @throws JsonProcessingException JsonProcessingException
*/ */
Map<String, Object> createProcessDefinition(User loginUser, Map<String, Object> createProcessDefinition(User loginUser,
String projectName, long projectCode,
String name, String name,
String description, String description,
String globalParams, String globalParams,
@ -65,17 +65,17 @@ public interface ProcessDefinitionService {
* query process definition list * query process definition list
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @return definition list * @return definition list
*/ */
Map<String, Object> queryProcessDefinitionList(User loginUser, Map<String, Object> queryProcessDefinitionList(User loginUser,
String projectName); long projectCode);
/** /**
* query process definition list paging * query process definition list paging
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param searchVal search value * @param searchVal search value
* @param pageNo page number * @param pageNo page number
* @param pageSize page size * @param pageSize page size
@ -83,7 +83,7 @@ public interface ProcessDefinitionService {
* @return process definition page * @return process definition page
*/ */
Map<String, Object> queryProcessDefinitionListPaging(User loginUser, Map<String, Object> queryProcessDefinitionListPaging(User loginUser,
String projectName, long projectCode,
String searchVal, String searchVal,
Integer pageNo, Integer pageNo,
Integer pageSize, Integer pageSize,
@ -93,59 +93,59 @@ public interface ProcessDefinitionService {
* query detail of process definition * query detail of process definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param code process definition code * @param code process definition code
* @return process definition detail * @return process definition detail
*/ */
Map<String, Object> queryProcessDefinitionByCode(User loginUser, Map<String, Object> queryProcessDefinitionByCode(User loginUser,
String projectName, long projectCode,
long code); long code);
/** /**
* query datail of process definition * query datail of process definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processDefinitionName process definition name * @param processDefinitionName process definition name
* @return process definition detail * @return process definition detail
*/ */
Map<String, Object> queryProcessDefinitionByName(User loginUser, Map<String, Object> queryProcessDefinitionByName(User loginUser,
String projectName, long projectCode,
String processDefinitionName); String processDefinitionName);
/** /**
* batch copy process definition * batch copy process definition
* *
* @param loginUser loginUser * @param loginUser loginUser
* @param projectName projectName * @param projectCode projectCode
* @param processDefinitionCodes processDefinitionCodes * @param processDefinitionCodes processDefinitionCodes
* @param targetProjectName targetProjectName * @param targetProjectCode targetProjectCode
*/ */
Map<String, Object> batchCopyProcessDefinition(User loginUser, Map<String, Object> batchCopyProcessDefinition(User loginUser,
String projectName, long projectCode,
String processDefinitionCodes, String processDefinitionCodes,
String targetProjectName); long targetProjectCode);
/** /**
* batch move process definition * batch move process definition
* *
* @param loginUser loginUser * @param loginUser loginUser
* @param projectName projectName * @param projectCode projectCode
* @param processDefinitionIds processDefinitionIds * @param processDefinitionCodes processDefinitionCodes
* @param targetProjectId targetProjectId * @param targetProjectCode targetProjectCode
*/ */
Map<String, Object> batchMoveProcessDefinition(User loginUser, Map<String, Object> batchMoveProcessDefinition(User loginUser,
String projectName, long projectCode,
String processDefinitionIds, String processDefinitionCodes,
int targetProjectId); long targetProjectCode);
/** /**
* update process definition * update process definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param name process definition name * @param name process definition name
* @param code process definition code * @param code process definition code
* @param description description * @param description description
@ -158,7 +158,7 @@ public interface ProcessDefinitionService {
* @return update result code * @return update result code
*/ */
Map<String, Object> updateProcessDefinition(User loginUser, Map<String, Object> updateProcessDefinition(User loginUser,
String projectName, long projectCode,
String name, String name,
long code, long code,
String description, String description,
@ -173,37 +173,37 @@ public interface ProcessDefinitionService {
* verify process definition name unique * verify process definition name unique
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param name name * @param name name
* @return true if process definition name not exists, otherwise false * @return true if process definition name not exists, otherwise false
*/ */
Map<String, Object> verifyProcessDefinitionName(User loginUser, Map<String, Object> verifyProcessDefinitionName(User loginUser,
String projectName, long projectCode,
String name); String name);
/** /**
* delete process definition by id * delete process definition by id
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processDefinitionId process definition id * @param processDefinitionId process definition id
* @return delete result code * @return delete result code
*/ */
Map<String, Object> deleteProcessDefinitionById(User loginUser, Map<String, Object> deleteProcessDefinitionById(User loginUser,
String projectName, long projectCode,
Integer processDefinitionId); Integer processDefinitionId);
/** /**
* release process definition: online / offline * release process definition: online / offline
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param code process definition code * @param code process definition code
* @param releaseState release state * @param releaseState release state
* @return release result code * @return release result code
*/ */
Map<String, Object> releaseProcessDefinition(User loginUser, Map<String, Object> releaseProcessDefinition(User loginUser,
String projectName, long projectCode,
long code, long code,
ReleaseState releaseState); ReleaseState releaseState);
@ -211,12 +211,12 @@ public interface ProcessDefinitionService {
* batch export process definition by ids * batch export process definition by ids
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processDefinitionIds process definition ids * @param processDefinitionIds process definition ids
* @param response http servlet response * @param response http servlet response
*/ */
void batchExportProcessDefinitionByIds(User loginUser, void batchExportProcessDefinitionByIds(User loginUser,
String projectName, long projectCode,
String processDefinitionIds, String processDefinitionIds,
HttpServletResponse response); HttpServletResponse response);
@ -224,13 +224,13 @@ public interface ProcessDefinitionService {
* import process definition * import process definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectCode project code
* @param file process metadata json file * @param file process metadata json file
* @param currentProjectName current project name
* @return import process * @return import process
*/ */
Map<String, Object> importProcessDefinition(User loginUser, Map<String, Object> importProcessDefinition(User loginUser,
MultipartFile file, long projectCode,
String currentProjectName); MultipartFile file);
/** /**
* check the process definition node meets the specifications * check the process definition node meets the specifications
@ -259,12 +259,12 @@ public interface ProcessDefinitionService {
Map<String, Object> getTaskNodeListByDefinitionCodeList(String defineCodeList); Map<String, Object> getTaskNodeListByDefinitionCodeList(String defineCodeList);
/** /**
* query process definition all by project id * query process definition all by project code
* *
* @param projectId project id * @param projectCode project code
* @return process definitions in the project * @return process definitions in the project
*/ */
Map<String, Object> queryProcessDefinitionAllByProjectId(Integer projectId); Map<String, Object> queryAllProcessDefinitionByProjectCode(User loginUser, long projectCode);
/** /**
* Encapsulates the TreeView structure * Encapsulates the TreeView structure
@ -281,38 +281,45 @@ public interface ProcessDefinitionService {
* switch the defined process definition verison * switch the defined process definition verison
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processDefinitionId process definition id * @param processDefinitionId process definition id
* @param version the version user want to switch * @param version the version user want to switch
* @return switch process definition version result code * @return switch process definition version result code
*/ */
Map<String, Object> switchProcessDefinitionVersion(User loginUser, String projectName Map<String, Object> switchProcessDefinitionVersion(User loginUser,
, int processDefinitionId, long version); long projectCode,
int processDefinitionId,
long version);
/** /**
* query the pagination versions info by one certain process definition code * query the pagination versions info by one certain process definition code
* *
* @param loginUser login user info to check auth * @param loginUser login user info to check auth
* @param projectName process definition project name * @param projectCode project code
* @param pageNo page number * @param pageNo page number
* @param pageSize page size * @param pageSize page size
* @param processDefinitionCode process definition code * @param processDefinitionCode process definition code
* @return the pagination process definition versions info of the certain process definition * @return the pagination process definition versions info of the certain process definition
*/ */
Map<String, Object> queryProcessDefinitionVersions(User loginUser, String projectName, Map<String, Object> queryProcessDefinitionVersions(User loginUser,
int pageNo, int pageSize, long processDefinitionCode); long projectCode,
int pageNo,
int pageSize,
long processDefinitionCode);
/** /**
* delete one certain process definition by version number and process definition id * delete one certain process definition by version number and process definition id
* *
* @param loginUser login user info to check auth * @param loginUser login user info to check auth
* @param projectName process definition project name * @param projectCode project code
* @param processDefinitionId process definition id * @param processDefinitionId process definition id
* @param version version number * @param version version number
* @return delele result code * @return delele result code
*/ */
Map<String, Object> deleteByProcessDefinitionIdAndVersion(User loginUser, String projectName, Map<String, Object> deleteByProcessDefinitionIdAndVersion(User loginUser,
int processDefinitionId, long version); long projectCode,
int processDefinitionId,
long version);
/** /**
* check has associated process definition * check has associated process definition

466
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java

@ -173,7 +173,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* create process definition * create process definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param name process definition name * @param name process definition name
* @param description description * @param description description
* @param globalParams global params * @param globalParams global params
@ -187,7 +187,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map<String, Object> createProcessDefinition(User loginUser, public Map<String, Object> createProcessDefinition(User loginUser,
String projectName, long projectCode,
String name, String name,
String description, String description,
String globalParams, String globalParams,
@ -196,12 +196,12 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
int timeout, int timeout,
String tenantCode, String tenantCode,
String taskRelationJson) { String taskRelationJson) {
Project project = projectMapper.queryByCode(projectCode);
Map<String, Object> result = checkProjectAndAuth(loginUser, projectName); //check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
if (result.get(Constants.STATUS) != Status.SUCCESS) { if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result; return result;
} }
long projectCode = (long) result.get(Constants.PROJECT_CODE);
List<ProcessTaskRelationLog> taskRelationList = JSONUtils.toList(taskRelationJson, ProcessTaskRelationLog.class); List<ProcessTaskRelationLog> taskRelationList = JSONUtils.toList(taskRelationJson, ProcessTaskRelationLog.class);
Map<String, Object> checkRelationJson = checkTaskRelationList(taskRelationList, taskRelationJson); Map<String, Object> checkRelationJson = checkTaskRelationList(taskRelationList, taskRelationJson);
@ -284,16 +284,18 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* query process definition list * query process definition list
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @return definition list * @return definition list
*/ */
@Override @Override
public Map<String, Object> queryProcessDefinitionList(User loginUser, String projectName) { public Map<String, Object> queryProcessDefinitionList(User loginUser, long projectCode) {
Map<String, Object> result = checkProjectAndAuth(loginUser, projectName); Project project = projectMapper.queryByCode(projectCode);
//check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
if (result.get(Constants.STATUS) != Status.SUCCESS) { if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result; return result;
} }
List<ProcessDefinition> resourceList = processDefinitionMapper.queryAllDefinitionList((long) result.get(Constants.PROJECT_CODE)); List<ProcessDefinition> resourceList = processDefinitionMapper.queryAllDefinitionList(projectCode);
resourceList.forEach(processDefinition -> { resourceList.forEach(processDefinition -> {
ProcessData processData = processService.genProcessData(processDefinition); ProcessData processData = processService.genProcessData(processDefinition);
@ -302,7 +304,6 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
result.put(Constants.DATA_LIST, resourceList); result.put(Constants.DATA_LIST, resourceList);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
return result; return result;
} }
@ -310,7 +311,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* query process definition list paging * query process definition list paging
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param searchVal search value * @param searchVal search value
* @param pageNo page number * @param pageNo page number
* @param pageSize page size * @param pageSize page size
@ -318,15 +319,12 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* @return process definition page * @return process definition page
*/ */
@Override @Override
public Map<String, Object> queryProcessDefinitionListPaging(User loginUser, String projectName, String searchVal, Integer pageNo, Integer pageSize, Integer userId) { public Map<String, Object> queryProcessDefinitionListPaging(User loginUser, long projectCode, String searchVal, Integer pageNo, Integer pageSize, Integer userId) {
Project project = projectMapper.queryByCode(projectCode);
Map<String, Object> result = new HashMap<>(); //check user access for project
Project project = projectMapper.queryByName(projectName); Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
if (result.get(Constants.STATUS) != Status.SUCCESS) {
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); return result;
Status resultStatus = (Status) checkResult.get(Constants.STATUS);
if (resultStatus != Status.SUCCESS) {
return checkResult;
} }
Page<ProcessDefinition> page = new Page<>(pageNo, pageSize); Page<ProcessDefinition> page = new Page<>(pageNo, pageSize);
@ -358,24 +356,20 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* query detail of process definition * query detail of process definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param code process definition code * @param code process definition code
* @return process definition detail * @return process definition detail
*/ */
@Override @Override
public Map<String, Object> queryProcessDefinitionByCode(User loginUser, String projectName, long code) { public Map<String, Object> queryProcessDefinitionByCode(User loginUser, long projectCode, long code) {
Project project = projectMapper.queryByCode(projectCode);
Map<String, Object> result = new HashMap<>(); //check user access for project
Project project = projectMapper.queryByName(projectName); Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
if (result.get(Constants.STATUS) != Status.SUCCESS) {
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); return result;
Status resultStatus = (Status) checkResult.get(Constants.STATUS);
if (resultStatus != Status.SUCCESS) {
return checkResult;
} }
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(code); ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(code);
if (processDefinition == null) { if (processDefinition == null) {
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, code); putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, code);
} else { } else {
@ -387,12 +381,13 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
} }
@Override @Override
public Map<String, Object> queryProcessDefinitionByName(User loginUser, String projectName, String processDefinitionName) { public Map<String, Object> queryProcessDefinitionByName(User loginUser, long projectCode, String processDefinitionName) {
Map<String, Object> result = checkProjectAndAuth(loginUser, projectName); Project project = projectMapper.queryByCode(projectCode);
//check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
if (result.get(Constants.STATUS) != Status.SUCCESS) { if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result; return result;
} }
long projectCode = (long) result.get(Constants.PROJECT_CODE);
ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineName(projectCode, processDefinitionName); ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineName(projectCode, processDefinitionName);
if (processDefinition == null) { if (processDefinition == null) {
@ -410,7 +405,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* update process definition * update process definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param name process definition name * @param name process definition name
* @param code process definition code * @param code process definition code
* @param description description * @param description description
@ -424,7 +419,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
*/ */
@Override @Override
public Map<String, Object> updateProcessDefinition(User loginUser, public Map<String, Object> updateProcessDefinition(User loginUser,
String projectName, long projectCode,
String name, String name,
long code, long code,
String description, String description,
@ -434,11 +429,12 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
int timeout, int timeout,
String tenantCode, String tenantCode,
String taskRelationJson) { String taskRelationJson) {
Map<String, Object> result = checkProjectAndAuth(loginUser, projectName); Project project = projectMapper.queryByCode(projectCode);
//check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
if (result.get(Constants.STATUS) != Status.SUCCESS) { if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result; return result;
} }
long projectCode = (long) result.get(Constants.PROJECT_CODE);
List<ProcessTaskRelationLog> taskRelationList = JSONUtils.toList(taskRelationJson, ProcessTaskRelationLog.class); List<ProcessTaskRelationLog> taskRelationList = JSONUtils.toList(taskRelationJson, ProcessTaskRelationLog.class);
Map<String, Object> checkRelationJson = checkTaskRelationList(taskRelationList, taskRelationJson); Map<String, Object> checkRelationJson = checkTaskRelationList(taskRelationList, taskRelationJson);
@ -465,10 +461,18 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
} }
processDefinition.set(projectCode, name, description, globalParams, locations, connects, timeout, tenant.getId()); processDefinition.set(projectCode, name, description, globalParams, locations, connects, timeout, tenant.getId());
return updateProcessDefine(loginUser, result, taskRelationList, processDefinition);
}
private Map<String, Object> updateProcessDefine(User loginUser,
Map<String, Object> result,
List<ProcessTaskRelationLog> taskRelationList,
ProcessDefinition processDefinition) {
processDefinition.setUpdateTime(new Date()); processDefinition.setUpdateTime(new Date());
int insertVersion = processService.saveProcessDefine(loginUser, processDefinition, true); int insertVersion = processService.saveProcessDefine(loginUser, processDefinition, true);
if (insertVersion > 0) { if (insertVersion > 0) {
int insertResult = processService.saveTaskRelation(loginUser, projectCode, code, insertVersion, taskRelationList); int insertResult = processService.saveTaskRelation(loginUser, processDefinition.getProjectCode(),
processDefinition.getCode(), insertVersion, taskRelationList);
if (insertResult > 0) { if (insertResult > 0) {
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
result.put(Constants.DATA_LIST, processDefinition); result.put(Constants.DATA_LIST, processDefinition);
@ -481,25 +485,21 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
return result; return result;
} }
/** /**
* verify process definition name unique * verify process definition name unique
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param name name * @param name name
* @return true if process definition name not exists, otherwise false * @return true if process definition name not exists, otherwise false
*/ */
@Override @Override
public Map<String, Object> verifyProcessDefinitionName(User loginUser, String projectName, String name) { public Map<String, Object> verifyProcessDefinitionName(User loginUser, long projectCode, String name) {
Project project = projectMapper.queryByCode(projectCode);
Map<String, Object> result = new HashMap<>(); //check user access for project
Project project = projectMapper.queryByName(projectName); Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
if (result.get(Constants.STATUS) != Status.SUCCESS) {
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); return result;
Status resultEnum = (Status) checkResult.get(Constants.STATUS);
if (resultEnum != Status.SUCCESS) {
return checkResult;
} }
ProcessDefinition processDefinition = processDefinitionMapper.verifyByDefineName(project.getCode(), name.trim()); ProcessDefinition processDefinition = processDefinitionMapper.verifyByDefineName(project.getCode(), name.trim());
if (processDefinition == null) { if (processDefinition == null) {
@ -514,21 +514,18 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* delete process definition by id * delete process definition by id
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processDefinitionId process definition id * @param processDefinitionId process definition id
* @return delete result code * @return delete result code
*/ */
@Override @Override
@Transactional(rollbackFor = RuntimeException.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> deleteProcessDefinitionById(User loginUser, String projectName, Integer processDefinitionId) { public Map<String, Object> deleteProcessDefinitionById(User loginUser, long projectCode, Integer processDefinitionId) {
Project project = projectMapper.queryByCode(projectCode);
Map<String, Object> result = new HashMap<>(); //check user access for project
Project project = projectMapper.queryByName(projectName); Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
if (result.get(Constants.STATUS) != Status.SUCCESS) {
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); return result;
Status resultEnum = (Status) checkResult.get(Constants.STATUS);
if (resultEnum != Status.SUCCESS) {
return checkResult;
} }
ProcessDefinition processDefinition = processDefinitionMapper.selectById(processDefinitionId); ProcessDefinition processDefinition = processDefinitionMapper.selectById(processDefinitionId);
@ -589,21 +586,19 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* release process definition: online / offline * release process definition: online / offline
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param code process definition code * @param code process definition code
* @param releaseState release state * @param releaseState release state
* @return release result code * @return release result code
*/ */
@Override @Override
@Transactional(rollbackFor = RuntimeException.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> releaseProcessDefinition(User loginUser, String projectName, long code, ReleaseState releaseState) { public Map<String, Object> releaseProcessDefinition(User loginUser, long projectCode, long code, ReleaseState releaseState) {
HashMap<String, Object> result = new HashMap<>(); Project project = projectMapper.queryByCode(projectCode);
Project project = projectMapper.queryByName(projectName); //check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); if (result.get(Constants.STATUS) != Status.SUCCESS) {
Status resultEnum = (Status) checkResult.get(Constants.STATUS); return result;
if (resultEnum != Status.SUCCESS) {
return checkResult;
} }
// check state // check state
@ -661,20 +656,15 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* batch export process definition by ids * batch export process definition by ids
*/ */
@Override @Override
public void batchExportProcessDefinitionByIds(User loginUser, String projectName, String processDefinitionIds, HttpServletResponse response) { public void batchExportProcessDefinitionByIds(User loginUser, long projectCode, String processDefinitionIds, HttpServletResponse response) {
if (StringUtils.isEmpty(processDefinitionIds)) { if (StringUtils.isEmpty(processDefinitionIds)) {
return; return;
} }
Project project = projectMapper.queryByCode(projectCode);
//export project info
Project project = projectMapper.queryByName(projectName);
//check user access for project //check user access for project
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
Status resultStatus = (Status) checkResult.get(Constants.STATUS); if (result.get(Constants.STATUS) != Status.SUCCESS) {
if (resultStatus != Status.SUCCESS) {
return; return;
} }
@ -807,13 +797,13 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* import process definition * import process definition
* *
* @param loginUser login user * @param loginUser login user
* @param projectCode project code
* @param file process metadata json file * @param file process metadata json file
* @param currentProjectName current project name
* @return import process * @return import process
*/ */
@Override @Override
@Transactional(rollbackFor = RuntimeException.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> importProcessDefinition(User loginUser, MultipartFile file, String currentProjectName) { public Map<String, Object> importProcessDefinition(User loginUser, long projectCode, MultipartFile file) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
String processMetaJson = FileUtils.file2String(file); String processMetaJson = FileUtils.file2String(file);
List<ProcessMeta> processMetaList = JSONUtils.toList(processMetaJson, ProcessMeta.class); List<ProcessMeta> processMetaList = JSONUtils.toList(processMetaJson, ProcessMeta.class);
@ -826,7 +816,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
for (ProcessMeta processMeta : processMetaList) { for (ProcessMeta processMeta : processMetaList) {
if (!checkAndImportProcessDefinition(loginUser, currentProjectName, result, processMeta)) { if (!checkAndImportProcessDefinition(loginUser, projectCode, result, processMeta)) {
return result; return result;
} }
} }
@ -837,7 +827,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
/** /**
* check and import process definition * check and import process definition
*/ */
private boolean checkAndImportProcessDefinition(User loginUser, String currentProjectName, Map<String, Object> result, ProcessMeta processMeta) { private boolean checkAndImportProcessDefinition(User loginUser, long projectCode, Map<String, Object> result, ProcessMeta processMeta) {
if (!checkImportanceParams(processMeta, result)) { if (!checkImportanceParams(processMeta, result)) {
return false; return false;
@ -846,14 +836,14 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
//deal with process name //deal with process name
String processDefinitionName = processMeta.getProcessDefinitionName(); String processDefinitionName = processMeta.getProcessDefinitionName();
//use currentProjectName to query //use currentProjectName to query
Project targetProject = projectMapper.queryByName(currentProjectName); Project targetProject = projectMapper.queryByCode(projectCode);
if (null != targetProject) { if (null != targetProject) {
processDefinitionName = recursionProcessDefinitionName(targetProject.getCode(), processDefinitionName = recursionProcessDefinitionName(targetProject.getCode(),
processDefinitionName, 1); processDefinitionName, 1);
} }
//unique check //unique check
Map<String, Object> checkResult = verifyProcessDefinitionName(loginUser, currentProjectName, processDefinitionName); Map<String, Object> checkResult = verifyProcessDefinitionName(loginUser, projectCode, processDefinitionName);
Status status = (Status) checkResult.get(Constants.STATUS); Status status = (Status) checkResult.get(Constants.STATUS);
if (Status.SUCCESS.equals(status)) { if (Status.SUCCESS.equals(status)) {
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
@ -865,7 +855,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
// get create process result // get create process result
Map<String, Object> createProcessResult = Map<String, Object> createProcessResult =
getCreateProcessResult(loginUser, getCreateProcessResult(loginUser,
currentProjectName, targetProject.getName(),
result, result,
processMeta, processMeta,
processDefinitionName, processDefinitionName,
@ -882,7 +872,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
//scheduler param //scheduler param
return getImportProcessScheduleResult(loginUser, return getImportProcessScheduleResult(loginUser,
currentProjectName, targetProject.getName(),
result, result,
processMeta, processMeta,
processDefinitionName, processDefinitionName,
@ -1252,25 +1242,27 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
} }
/** /**
* query process definition all by project id * query process definition all by project code
* *
* @param projectId project id * @param loginUser loginUser
* @param projectCode project code
* @return process definitions in the project * @return process definitions in the project
*/ */
@Override @Override
public Map<String, Object> queryProcessDefinitionAllByProjectId(Integer projectId) { public Map<String, Object> queryAllProcessDefinitionByProjectCode(User loginUser, long projectCode) {
Project project = projectMapper.queryByCode(projectCode);
HashMap<String, Object> result = new HashMap<>(); //check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
Project project = projectMapper.selectById(projectId); if (result.get(Constants.STATUS) != Status.SUCCESS) {
List<ProcessDefinition> resourceList = processDefinitionMapper.queryAllDefinitionList(project.getCode()); return result;
}
List<ProcessDefinition> resourceList = processDefinitionMapper.queryAllDefinitionList(projectCode);
resourceList.forEach(processDefinition -> { resourceList.forEach(processDefinition -> {
ProcessData processData = processService.genProcessData(processDefinition); ProcessData processData = processService.genProcessData(processDefinition);
processDefinition.setProcessDefinitionJson(JSONUtils.toJsonString(processData)); processDefinition.setProcessDefinitionJson(JSONUtils.toJsonString(processData));
}); });
result.put(Constants.DATA_LIST, resourceList); result.put(Constants.DATA_LIST, resourceList);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
return result; return result;
} }
@ -1280,10 +1272,9 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* @param processId process definition id * @param processId process definition id
* @param limit limit * @param limit limit
* @return tree view json data * @return tree view json data
* @throws Exception exception
*/ */
@Override @Override
public Map<String, Object> viewTree(Integer processId, Integer limit) throws Exception { public Map<String, Object> viewTree(Integer processId, Integer limit) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
ProcessDefinition processDefinition = processDefinitionMapper.selectById(processId); ProcessDefinition processDefinition = processDefinitionMapper.selectById(processId);
@ -1446,64 +1437,26 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
return recursionProcessDefinitionName(projectCode, processDefinitionName, num + 1); return recursionProcessDefinitionName(projectCode, processDefinitionName, num + 1);
} }
private Map<String, Object> copyProcessDefinition(User loginUser,
Long processCode,
long targetProjectCode) {
Map<String, Object> result = new HashMap<>();
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(processCode);
if (processDefinition == null) {
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processCode);
return result;
}
List<ProcessTaskRelationLog> taskRelationList =
processTaskRelationLogMapper.queryByProcessCodeAndVersion(processDefinition.getCode(), processDefinition.getVersion());
if (taskRelationList.isEmpty()) {
putMsg(result, Status.PROCESS_TASK_RELATION_NOT_EXIST, processCode);
return result;
}
processDefinition.setName(processDefinition.getName() + "_copy_" + DateUtils.getCurrentTimeStamp());
processDefinition.setProjectCode(targetProjectCode);
return createProcessDefine(loginUser, result, taskRelationList, processDefinition);
}
/** /**
* batch copy process definition * batch copy process definition
* *
* @param loginUser loginUser * @param loginUser loginUser
* @param projectName projectName * @param projectCode projectCode
* @param processDefinitionCodes processDefinitionCodes * @param processDefinitionCodes processDefinitionCodes
* @param targetProjectName targetProjectName * @param targetProjectCode targetProjectCode
*/ */
@Override @Override
public Map<String, Object> batchCopyProcessDefinition(User loginUser, public Map<String, Object> batchCopyProcessDefinition(User loginUser,
String projectName, long projectCode,
String processDefinitionCodes, String processDefinitionCodes,
String targetProjectName) { long targetProjectCode) {
List<String> failedProcessList = new ArrayList<>(); Map<String, Object> result = checkParams(loginUser, projectCode, processDefinitionCodes, targetProjectCode);
//check src project auth
Map<String, Object> result = checkProjectAndAuth(loginUser, projectName);
if (result.get(Constants.STATUS) != Status.SUCCESS) { if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result; return result;
} }
if (StringUtils.isEmpty(processDefinitionCodes)) { List<String> failedProcessList = new ArrayList<>();
putMsg(result, Status.PROCESS_DEFINITION_CODES_IS_EMPTY, processDefinitionCodes); doBatchOperateProcessDefinition(loginUser, targetProjectCode, failedProcessList, processDefinitionCodes, result, true);
return result; checkBatchOperateResult(projectCode, targetProjectCode, result, failedProcessList, true);
}
long targetProjectCode = 0L;
if (!(targetProjectName).equals(projectName)) {
Map<String, Object> checkTargetProjectResult = checkProjectAndAuth(loginUser, targetProjectName);
if (checkTargetProjectResult.get(Constants.STATUS) != Status.SUCCESS) {
return checkTargetProjectResult;
} else {
targetProjectCode = (long) checkTargetProjectResult.get(Constants.PROJECT_CODE);
}
}
String[] processDefinitionCodeList = processDefinitionCodes.split(Constants.COMMA);
doBatchCopyProcessDefinition(loginUser, targetProjectCode, failedProcessList, processDefinitionCodeList);
checkBatchOperateResult(projectName, targetProjectName, result, failedProcessList, true);
return result; return result;
} }
@ -1511,117 +1464,100 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* batch move process definition * batch move process definition
* *
* @param loginUser loginUser * @param loginUser loginUser
* @param projectName projectName * @param projectCode projectCode
* @param processDefinitionIds processDefinitionIds * @param processDefinitionCodes processDefinitionCodes
* @param targetProjectId targetProjectId * @param targetProjectCode targetProjectCode
*/ */
@Override @Override
public Map<String, Object> batchMoveProcessDefinition(User loginUser, public Map<String, Object> batchMoveProcessDefinition(User loginUser,
String projectName, long projectCode,
String processDefinitionIds, String processDefinitionCodes,
int targetProjectId) { long targetProjectCode) {
List<String> failedProcessList = new ArrayList<>(); Map<String, Object> result = checkParams(loginUser, projectCode, processDefinitionCodes, targetProjectCode);
//check src project auth
Map<String, Object> result = checkProjectAndAuth(loginUser, projectName);
if (result.get(Constants.STATUS) != Status.SUCCESS) { if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result; return result;
} }
if (projectCode == targetProjectCode) {
if (StringUtils.isEmpty(processDefinitionIds)) {
putMsg(result, Status.PROCESS_DEFINITION_CODES_IS_EMPTY, processDefinitionIds);
return result; return result;
} }
List<String> failedProcessList = new ArrayList<>();
Project targetProject = projectMapper.queryDetailById(targetProjectId); doBatchOperateProcessDefinition(loginUser, targetProjectCode, failedProcessList, processDefinitionCodes, result, false);
if (targetProject == null) { checkBatchOperateResult(projectCode, targetProjectCode, result, failedProcessList, false);
putMsg(result, Status.PROJECT_NOT_FOUNT, targetProjectId);
return result; return result;
} }
if (!(targetProject.getName()).equals(projectName)) { private Map<String, Object> checkParams(User loginUser,
Map<String, Object> checkTargetProjectResult = checkProjectAndAuth(loginUser, targetProject.getName()); long projectCode,
if (checkTargetProjectResult != null) { String processDefinitionCodes,
return checkTargetProjectResult; long targetProjectCode) {
Project project = projectMapper.queryByCode(projectCode);
//check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result;
} }
if (StringUtils.isEmpty(processDefinitionCodes)) {
putMsg(result, Status.PROCESS_DEFINITION_CODES_IS_EMPTY, processDefinitionCodes);
return result;
} }
Integer[] definitionIds = Arrays.stream(processDefinitionIds.split(Constants.COMMA)).map(Integer::parseInt).toArray(Integer[]::new); if (projectCode != targetProjectCode) {
List<ProcessDefinition> processDefinitionList = processDefinitionMapper.queryDefinitionListByIdList(definitionIds); Project targetProject = projectMapper.queryByCode(targetProjectCode);
for (ProcessDefinition processDefinition : processDefinitionList) { //check user access for project
ProcessDefinitionLog processDefinitionLog = moveProcessDefinition(loginUser, targetProject.getCode(), processDefinition, result, failedProcessList); Map<String, Object> targetResult = projectService.checkProjectAndAuth(loginUser, targetProject, targetProject.getName());
if (processDefinitionLog != null) { if (targetResult.get(Constants.STATUS) != Status.SUCCESS) {
moveTaskRelation(loginUser, processDefinition.getProjectCode(), processDefinitionLog); return targetResult;
} }
} }
checkBatchOperateResult(projectName, targetProject.getName(), result, failedProcessList, false);
return result; return result;
} }
private ProcessDefinitionLog moveProcessDefinition(User loginUser, Long targetProjectCode, ProcessDefinition processDefinition, private void doBatchOperateProcessDefinition(User loginUser,
Map<String, Object> result, List<String> failedProcessList) { long targetProjectCode,
try { List<String> failedProcessList,
Integer version = processDefinitionLogMapper.queryMaxVersionForDefinition(processDefinition.getCode()); String processDefinitionCodes,
ProcessDefinitionLog processDefinitionLog = new ProcessDefinitionLog(processDefinition); Map<String, Object> result,
processDefinitionLog.setVersion(version == null || version == 0 ? 1 : version + 1); boolean isCopy) {
processDefinitionLog.setProjectCode(targetProjectCode); Set<Long> definitionCodes = Arrays.stream(processDefinitionCodes.split(Constants.COMMA)).map(Long::parseLong).collect(Collectors.toSet());
processDefinitionLog.setOperator(loginUser.getId()); List<ProcessDefinition> processDefinitionList = processDefinitionMapper.queryByCodes(definitionCodes);
Date now = new Date(); Set<Long> queryCodes = processDefinitionList.stream().map(ProcessDefinition::getCode).collect(Collectors.toSet());
processDefinitionLog.setOperateTime(now); // definitionCodes - queryCodes
processDefinitionLog.setUpdateTime(now); Set<Long> diffCode = definitionCodes.stream().filter(code -> !queryCodes.contains(code)).collect(Collectors.toSet());
processDefinitionLog.setCreateTime(now); diffCode.forEach(code -> failedProcessList.add(code + "[null]"));
int update = processDefinitionMapper.updateById(processDefinitionLog); for (ProcessDefinition processDefinition : processDefinitionList) {
int insertLog = processDefinitionLogMapper.insert(processDefinitionLog); List<ProcessTaskRelation> processTaskRelations =
if ((insertLog & update) > 0) { processTaskRelationMapper.queryByProcessCode(processDefinition.getProjectCode(), processDefinition.getCode());
putMsg(result, Status.SUCCESS); List<ProcessTaskRelationLog> taskRelationList = processTaskRelations.stream().map(ProcessTaskRelationLog::new).collect(Collectors.toList());
processDefinition.setProjectCode(targetProjectCode);
if (isCopy) {
processDefinition.setName(processDefinition.getName() + "_copy_" + DateUtils.getCurrentTimeStamp());
createProcessDefine(loginUser, result, taskRelationList, processDefinition);
} else { } else {
failedProcessList.add(processDefinition.getId() + "[" + processDefinition.getName() + "]"); updateProcessDefine(loginUser, result, taskRelationList, processDefinition);
putMsg(result, Status.UPDATE_PROCESS_DEFINITION_ERROR);
} }
return processDefinitionLog; if (result.get(Constants.STATUS) != Status.SUCCESS) {
} catch (Exception e) { failedProcessList.add(processDefinition.getCode() + "[" + processDefinition.getName() + "]");
putMsg(result, Status.UPDATE_PROCESS_DEFINITION_ERROR);
failedProcessList.add(processDefinition.getId() + "[" + processDefinition.getName() + "]");
logger.error("move processDefinition error: {}", e.getMessage(), e);
}
return null;
}
private void moveTaskRelation(User loginUser, Long projectCode, ProcessDefinitionLog processDefinition) {
List<ProcessTaskRelation> processTaskRelationList = processTaskRelationMapper.queryByProcessCode(projectCode, processDefinition.getCode());
if (!processTaskRelationList.isEmpty()) {
processTaskRelationMapper.deleteByCode(projectCode, processDefinition.getCode());
} }
Date now = new Date();
for (ProcessTaskRelation processTaskRelation : processTaskRelationList) {
processTaskRelation.setProjectCode(processDefinition.getProjectCode());
processTaskRelation.setProcessDefinitionVersion(processDefinition.getVersion());
processTaskRelation.setCreateTime(now);
processTaskRelation.setUpdateTime(now);
processService.saveTaskRelation(loginUser, processTaskRelation);
} }
} }
/** /**
* switch the defined process definition verison * switch the defined process definition version
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param processDefinitionId process definition id * @param processDefinitionId process definition id
* @param version the version user want to switch * @param version the version user want to switch
* @return switch process definition version result code * @return switch process definition version result code
*/ */
@Override @Override
public Map<String, Object> switchProcessDefinitionVersion(User loginUser, String projectName public Map<String, Object> switchProcessDefinitionVersion(User loginUser, long projectCode, int processDefinitionId, long version) {
, int processDefinitionId, long version) { Project project = projectMapper.queryByCode(projectCode);
//check user access for project
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
Project project = projectMapper.queryByName(projectName); if (result.get(Constants.STATUS) != Status.SUCCESS) {
// check project auth return result;
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName);
Status resultStatus = (Status) checkResult.get(Constants.STATUS);
if (resultStatus != Status.SUCCESS) {
return checkResult;
} }
ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineId(processDefinitionId); ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineId(processDefinitionId);
@ -1651,76 +1587,22 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
return result; return result;
} }
/**
* batch copy process definition
*
* @param loginUser loginUser
* @param targetProjectCode targetProjectCode
* @param failedProcessList failedProcessList
* @param processDefinitionCodeList processDefinitionCodeList
*/
private void doBatchCopyProcessDefinition(User loginUser, long targetProjectCode, List<String> failedProcessList, String[] processDefinitionCodeList) {
for (String processDefinitionCode : processDefinitionCodeList) {
try {
Map<String, Object> copyProcessDefinitionResult = copyProcessDefinition(loginUser, Long.valueOf(processDefinitionCode), targetProjectCode);
if (!Status.SUCCESS.equals(copyProcessDefinitionResult.get(Constants.STATUS))) {
setFailedProcessList(failedProcessList, processDefinitionCode);
logger.error((String) copyProcessDefinitionResult.get(Constants.MSG));
}
} catch (Exception e) {
setFailedProcessList(failedProcessList, processDefinitionCode);
logger.error("copy processDefinition error: {}", e.getMessage(), e);
}
}
}
/**
* set failed processList
*
* @param failedProcessList failedProcessList
* @param processDefinitionId processDefinitionId
*/
private void setFailedProcessList(List<String> failedProcessList, String processDefinitionId) {
ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineId(Integer.parseInt(processDefinitionId));
if (processDefinition != null) {
failedProcessList.add(processDefinitionId + "[" + processDefinition.getName() + "]");
} else {
failedProcessList.add(processDefinitionId + "[null]");
}
}
/**
* check project and auth
*
* @param loginUser loginUser
* @param projectName projectName
*/
private Map<String, Object> checkProjectAndAuth(User loginUser, String projectName) {
Project project = projectMapper.queryByName(projectName);
//check user access for project
Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, projectName);
if (result.get(Constants.STATUS) == Status.SUCCESS) {
result.put(Constants.PROJECT_CODE, project.getCode());
}
return result;
}
/** /**
* check batch operate result * check batch operate result
* *
* @param srcProjectName srcProjectName * @param srcProjectCode srcProjectCode
* @param targetProjectName targetProjectName * @param targetProjectCode targetProjectCode
* @param result result * @param result result
* @param failedProcessList failedProcessList * @param failedProcessList failedProcessList
* @param isCopy isCopy * @param isCopy isCopy
*/ */
private void checkBatchOperateResult(String srcProjectName, String targetProjectName, private void checkBatchOperateResult(long srcProjectCode, long targetProjectCode,
Map<String, Object> result, List<String> failedProcessList, boolean isCopy) { Map<String, Object> result, List<String> failedProcessList, boolean isCopy) {
if (!failedProcessList.isEmpty()) { if (!failedProcessList.isEmpty()) {
if (isCopy) { if (isCopy) {
putMsg(result, Status.COPY_PROCESS_DEFINITION_ERROR, srcProjectName, targetProjectName, String.join(",", failedProcessList)); putMsg(result, Status.COPY_PROCESS_DEFINITION_ERROR, srcProjectCode, targetProjectCode, String.join(",", failedProcessList));
} else { } else {
putMsg(result, Status.MOVE_PROCESS_DEFINITION_ERROR, srcProjectName, targetProjectName, String.join(",", failedProcessList)); putMsg(result, Status.MOVE_PROCESS_DEFINITION_ERROR, srcProjectCode, targetProjectCode, String.join(",", failedProcessList));
} }
} else { } else {
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
@ -1744,14 +1626,14 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* query the pagination versions info by one certain process definition code * query the pagination versions info by one certain process definition code
* *
* @param loginUser login user info to check auth * @param loginUser login user info to check auth
* @param projectName process definition project name * @param projectCode project code
* @param pageNo page number * @param pageNo page number
* @param pageSize page size * @param pageSize page size
* @param processDefinitionCode process definition code * @param processDefinitionCode process definition code
* @return the pagination process definition versions info of the certain process definition * @return the pagination process definition versions info of the certain process definition
*/ */
@Override @Override
public Map<String, Object> queryProcessDefinitionVersions(User loginUser, String projectName, int pageNo, int pageSize, long processDefinitionCode) { public Map<String, Object> queryProcessDefinitionVersions(User loginUser, long projectCode, int pageNo, int pageSize, long processDefinitionCode) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
@ -1764,7 +1646,9 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
return result; return result;
} }
result = checkProjectAndAuth(loginUser, projectName); Project project = projectMapper.queryByCode(projectCode);
//check user access for project
result.putAll(projectService.checkProjectAndAuth(loginUser, project, project.getName()));
if (result.get(Constants.STATUS) != Status.SUCCESS) { if (result.get(Constants.STATUS) != Status.SUCCESS) {
return result; return result;
} }
@ -1791,20 +1675,18 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* delete one certain process definition by version number and process definition id * delete one certain process definition by version number and process definition id
* *
* @param loginUser login user info to check auth * @param loginUser login user info to check auth
* @param projectName process definition project name * @param projectCode project code
* @param processDefinitionId process definition id * @param processDefinitionId process definition id
* @param version version number * @param version version number
* @return delele result code * @return delele result code
*/ */
@Override @Override
public Map<String, Object> deleteByProcessDefinitionIdAndVersion(User loginUser, String projectName, int processDefinitionId, long version) { public Map<String, Object> deleteByProcessDefinitionIdAndVersion(User loginUser, long projectCode, int processDefinitionId, long version) {
Map<String, Object> result = new HashMap<>(); Project project = projectMapper.queryByCode(projectCode);
Project project = projectMapper.queryByName(projectName); //check user access for project
// check project auth Map<String, Object> result = projectService.checkProjectAndAuth(loginUser, project, project.getName());
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); if (result.get(Constants.STATUS) != Status.SUCCESS) {
Status resultStatus = (Status) checkResult.get(Constants.STATUS); return result;
if (resultStatus != Status.SUCCESS) {
return checkResult;
} }
ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineId(processDefinitionId); ProcessDefinition processDefinition = processDefinitionMapper.queryByDefineId(processDefinitionId);

1
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java

@ -140,6 +140,7 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
/** /**
* check project and authorization * check project and authorization
* // TODO projectCode will be instead of projectName
* *
* @param loginUser login user * @param loginUser login user
* @param project project * @param project project

139
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java

@ -76,7 +76,7 @@ public class ProcessDefinitionControllerTest {
+ "\"condition_type\":0,\"condition_params\":{}},{\"name\":\"\",\"pre_task_code\":123456789,\"pre_task_version\":1," + "\"condition_type\":0,\"condition_params\":{}},{\"name\":\"\",\"pre_task_code\":123456789,\"pre_task_version\":1,"
+ "\"post_task_code\":123451234,\"post_task_version\":1,\"condition_type\":0,\"condition_params\":{}}]"; + "\"post_task_code\":123451234,\"post_task_version\":1,\"condition_type\":0,\"condition_params\":{}}]";
String projectName = "test"; long projectCode = 1L;
String name = "dag_test"; String name = "dag_test";
String description = "desc test"; String description = "desc test";
String globalParams = "[]"; String globalParams = "[]";
@ -88,10 +88,10 @@ public class ProcessDefinitionControllerTest {
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
result.put(Constants.DATA_LIST, 1); result.put(Constants.DATA_LIST, 1);
Mockito.when(processDefinitionService.createProcessDefinition(user, projectName, name, description, globalParams, Mockito.when(processDefinitionService.createProcessDefinition(user, projectCode, name, description, globalParams,
connects, locations, timeout, tenantCode, json)).thenReturn(result); connects, locations, timeout, tenantCode, json)).thenReturn(result);
Result response = processDefinitionController.createProcessDefinition(user, projectName, name, description, globalParams, Result response = processDefinitionController.createProcessDefinition(user, projectCode, name, description, globalParams,
connects, locations, timeout, tenantCode, json); connects, locations, timeout, tenantCode, json);
Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
} }
@ -106,27 +106,25 @@ public class ProcessDefinitionControllerTest {
} }
@Test @Test
public void testVerifyProcessDefinitionName() throws Exception { public void testVerifyProcessDefinitionName() {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROCESS_DEFINITION_NAME_EXIST); putMsg(result, Status.PROCESS_DEFINITION_NAME_EXIST);
String projectName = "test"; long projectCode = 1L;
String name = "dag_test"; String name = "dag_test";
Mockito.when(processDefinitionService.verifyProcessDefinitionName(user, projectName, name)).thenReturn(result); Mockito.when(processDefinitionService.verifyProcessDefinitionName(user, projectCode, name)).thenReturn(result);
Result response = processDefinitionController.verifyProcessDefinitionName(user, projectName, name); Result response = processDefinitionController.verifyProcessDefinitionName(user, projectCode, name);
Assert.assertTrue(response.isStatus(Status.PROCESS_DEFINITION_NAME_EXIST)); Assert.assertTrue(response.isStatus(Status.PROCESS_DEFINITION_NAME_EXIST));
} }
@Test @Test
public void updateProcessDefinition() throws Exception { public void updateProcessDefinition() {
String json = "[{\"name\":\"\",\"pre_task_code\":0,\"pre_task_version\":0,\"post_task_code\":123456789,\"post_task_version\":1," String json = "[{\"name\":\"\",\"pre_task_code\":0,\"pre_task_version\":0,\"post_task_code\":123456789,\"post_task_version\":1,"
+ "\"condition_type\":0,\"condition_params\":{}},{\"name\":\"\",\"pre_task_code\":123456789,\"pre_task_version\":1," + "\"condition_type\":0,\"condition_params\":{}},{\"name\":\"\",\"pre_task_code\":123456789,\"pre_task_version\":1,"
+ "\"post_task_code\":123451234,\"post_task_version\":1,\"condition_type\":0,\"condition_params\":{}}]"; + "\"post_task_code\":123451234,\"post_task_version\":1,\"condition_type\":0,\"condition_params\":{}}]";
String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"; String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}";
String projectName = "test"; long projectCode = 1L;
String name = "dag_test"; String name = "dag_test";
String description = "desc test"; String description = "desc test";
String connects = "[]"; String connects = "[]";
@ -138,37 +136,37 @@ public class ProcessDefinitionControllerTest {
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
result.put("processDefinitionId", 1); result.put("processDefinitionId", 1);
Mockito.when(processDefinitionService.updateProcessDefinition(user, projectName, name, code, description, globalParams, Mockito.when(processDefinitionService.updateProcessDefinition(user, projectCode, name, code, description, globalParams,
connects, locations, timeout, tenantCode, json)).thenReturn(result); connects, locations, timeout, tenantCode, json)).thenReturn(result);
Result response = processDefinitionController.updateProcessDefinition(user, projectName, name, code, description, globalParams, Result response = processDefinitionController.updateProcessDefinition(user, projectCode, name, code, description, globalParams,
connects, locations, timeout, tenantCode, json, ReleaseState.OFFLINE); connects, locations, timeout, tenantCode, json, ReleaseState.OFFLINE);
Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
} }
@Test @Test
public void testReleaseProcessDefinition() throws Exception { public void testReleaseProcessDefinition() {
String projectName = "test"; long projectCode = 1L;
int id = 1; int id = 1;
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
Mockito.when(processDefinitionService.releaseProcessDefinition(user, projectName, id, ReleaseState.OFFLINE)).thenReturn(result); Mockito.when(processDefinitionService.releaseProcessDefinition(user, projectCode, id, ReleaseState.OFFLINE)).thenReturn(result);
Result response = processDefinitionController.releaseProcessDefinition(user, projectName, id, ReleaseState.OFFLINE); Result response = processDefinitionController.releaseProcessDefinition(user, projectCode, id, ReleaseState.OFFLINE);
Assert.assertTrue(response != null && response.isSuccess()); Assert.assertTrue(response != null && response.isSuccess());
} }
@Test @Test
public void testQueryProcessDefinitionByCode() { public void testQueryProcessDefinitionByCode() {
String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"; String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}";
String projectName = "test"; long projectCode = 1L;
String name = "dag_test"; String name = "dag_test";
String description = "desc test"; String description = "desc test";
String connects = "[]"; String connects = "[]";
long code = 1L; long code = 1L;
ProcessDefinition processDefinition = new ProcessDefinition(); ProcessDefinition processDefinition = new ProcessDefinition();
processDefinition.setProjectName(projectName); processDefinition.setProjectCode(projectCode);
processDefinition.setConnects(connects); processDefinition.setConnects(connects);
processDefinition.setDescription(description); processDefinition.setDescription(description);
processDefinition.setCode(code); processDefinition.setCode(code);
@ -179,69 +177,59 @@ public class ProcessDefinitionControllerTest {
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
result.put(Constants.DATA_LIST, processDefinition); result.put(Constants.DATA_LIST, processDefinition);
Mockito.when(processDefinitionService.queryProcessDefinitionByCode(user, projectName, code)).thenReturn(result); Mockito.when(processDefinitionService.queryProcessDefinitionByCode(user, projectCode, code)).thenReturn(result);
Result response = processDefinitionController.queryProcessDefinitionByCode(user, projectName, code); Result response = processDefinitionController.queryProcessDefinitionByCode(user, projectCode, code);
Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
} }
@Test @Test
public void testBatchCopyProcessDefinition() throws Exception { public void testBatchCopyProcessDefinition() {
long projectCode = 1L;
String projectName = "test"; long targetProjectCode = 2L;
String targetProjectName = "test1";
String code = "1"; String code = "1";
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
Mockito.when(processDefinitionService.batchCopyProcessDefinition(user, projectName, code, targetProjectName)).thenReturn(result); Mockito.when(processDefinitionService.batchCopyProcessDefinition(user, projectCode, code, targetProjectCode)).thenReturn(result);
Result response = processDefinitionController.copyProcessDefinition(user, projectName, code, targetProjectName); Result response = processDefinitionController.copyProcessDefinition(user, projectCode, code, targetProjectCode);
Assert.assertTrue(response != null && response.isSuccess()); Assert.assertTrue(response != null && response.isSuccess());
} }
@Test @Test
public void testBatchMoveProcessDefinition() throws Exception { public void testBatchMoveProcessDefinition() {
long projectCode = 1L;
String projectName = "test"; long targetProjectCode = 2L;
int targetProjectId = 2;
String id = "1"; String id = "1";
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
Mockito.when(processDefinitionService.batchMoveProcessDefinition(user, projectName, id, targetProjectId)).thenReturn(result); Mockito.when(processDefinitionService.batchMoveProcessDefinition(user, projectCode, id, targetProjectCode)).thenReturn(result);
Result response = processDefinitionController.moveProcessDefinition(user, projectName, id, targetProjectId); Result response = processDefinitionController.moveProcessDefinition(user, projectCode, id, targetProjectCode);
Assert.assertTrue(response != null && response.isSuccess()); Assert.assertTrue(response != null && response.isSuccess());
} }
@Test @Test
public void testQueryProcessDefinitionList() throws Exception { public void testQueryProcessDefinitionList() {
long projectCode = 1L;
String projectName = "test";
List<ProcessDefinition> resourceList = getDefinitionList(); List<ProcessDefinition> resourceList = getDefinitionList();
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
result.put(Constants.DATA_LIST, resourceList); result.put(Constants.DATA_LIST, resourceList);
Mockito.when(processDefinitionService.queryProcessDefinitionList(user, projectName)).thenReturn(result); Mockito.when(processDefinitionService.queryProcessDefinitionList(user, projectCode)).thenReturn(result);
Result response = processDefinitionController.queryProcessDefinitionList(user, projectName); Result response = processDefinitionController.queryProcessDefinitionList(user, projectCode);
Assert.assertTrue(response != null && response.isSuccess()); Assert.assertTrue(response != null && response.isSuccess());
} }
public List<ProcessDefinition> getDefinitionList() { public List<ProcessDefinition> getDefinitionList() {
List<ProcessDefinition> resourceList = new ArrayList<>(); List<ProcessDefinition> resourceList = new ArrayList<>();
String json = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1"
+ "\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}"
+ "\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval"
+ "\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\""
+ ":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}";
String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"; String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}";
String projectName = "test"; String projectName = "test";
String name = "dag_test"; String name = "dag_test";
@ -275,76 +263,76 @@ public class ProcessDefinitionControllerTest {
} }
@Test @Test
public void testDeleteProcessDefinitionById() throws Exception { public void testDeleteProcessDefinitionById() {
String projectName = "test"; long projectCode = 1L;
int id = 1; int id = 1;
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
Mockito.when(processDefinitionService.deleteProcessDefinitionById(user, projectName, id)).thenReturn(result); Mockito.when(processDefinitionService.deleteProcessDefinitionById(user, projectCode, id)).thenReturn(result);
Result response = processDefinitionController.deleteProcessDefinitionById(user, projectName, id); Result response = processDefinitionController.deleteProcessDefinitionById(user, projectCode, id);
Assert.assertTrue(response != null && response.isSuccess()); Assert.assertTrue(response != null && response.isSuccess());
} }
@Test @Test
public void testGetNodeListByDefinitionId() throws Exception { public void testGetNodeListByDefinitionId() {
String projectName = "test"; long projectCode = 1L;
Long code = 1L; Long code = 1L;
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
Mockito.when(processDefinitionService.getTaskNodeListByDefinitionCode(code)).thenReturn(result); Mockito.when(processDefinitionService.getTaskNodeListByDefinitionCode(code)).thenReturn(result);
Result response = processDefinitionController.getNodeListByDefinitionCode(user, projectName, code); Result response = processDefinitionController.getNodeListByDefinitionCode(user, projectCode, code);
Assert.assertTrue(response != null && response.isSuccess()); Assert.assertTrue(response != null && response.isSuccess());
} }
@Test @Test
public void testGetNodeListByDefinitionIdList() throws Exception { public void testGetNodeListByDefinitionIdList() throws Exception {
String projectName = "test"; long projectCode = 1L;
String codeList = "1,2,3"; String codeList = "1,2,3";
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
Mockito.when(processDefinitionService.getTaskNodeListByDefinitionCodeList(codeList)).thenReturn(result); Mockito.when(processDefinitionService.getTaskNodeListByDefinitionCodeList(codeList)).thenReturn(result);
Result response = processDefinitionController.getNodeListByDefinitionCodeList(user, projectName, codeList); Result response = processDefinitionController.getNodeListByDefinitionCodeList(user, projectCode, codeList);
Assert.assertTrue(response != null && response.isSuccess()); Assert.assertTrue(response != null && response.isSuccess());
} }
@Test @Test
public void testQueryProcessDefinitionAllByProjectId() throws Exception { public void testQueryProcessDefinitionAllByProjectId() {
int projectId = 1; long projectCode = 1L;
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
Mockito.when(processDefinitionService.queryProcessDefinitionAllByProjectId(projectId)).thenReturn(result); Mockito.when(processDefinitionService.queryAllProcessDefinitionByProjectCode(user, projectCode)).thenReturn(result);
Result response = processDefinitionController.queryProcessDefinitionAllByProjectId(user, projectId); Result response = processDefinitionController.queryAllProcessDefinitionByProjectCode(user, projectCode);
Assert.assertTrue(response != null && response.isSuccess()); Assert.assertTrue(response != null && response.isSuccess());
} }
@Test @Test
public void testViewTree() throws Exception { public void testViewTree() throws Exception {
String projectName = "test"; long projectCode = 1L;
int processId = 1; int processId = 1;
int limit = 2; int limit = 2;
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
Mockito.when(processDefinitionService.viewTree(processId, limit)).thenReturn(result); Mockito.when(processDefinitionService.viewTree(processId, limit)).thenReturn(result);
Result response = processDefinitionController.viewTree(user, projectName, processId, limit); Result response = processDefinitionController.viewTree(user, projectCode, processId, limit);
Assert.assertTrue(response != null && response.isSuccess()); Assert.assertTrue(response != null && response.isSuccess());
} }
@Test @Test
public void testQueryProcessDefinitionListPaging() throws Exception { public void testQueryProcessDefinitionListPaging() throws Exception {
String projectName = "test"; long projectCode = 1L;
int pageNo = 1; int pageNo = 1;
int pageSize = 10; int pageSize = 10;
String searchVal = ""; String searchVal = "";
@ -354,38 +342,37 @@ public class ProcessDefinitionControllerTest {
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
result.put(Constants.DATA_LIST, new PageInfo<Resource>(1, 10)); result.put(Constants.DATA_LIST, new PageInfo<Resource>(1, 10));
Mockito.when(processDefinitionService.queryProcessDefinitionListPaging(user, projectName, searchVal, pageNo, pageSize, userId)).thenReturn(result); Mockito.when(processDefinitionService.queryProcessDefinitionListPaging(user, projectCode, searchVal, pageNo, pageSize, userId)).thenReturn(result);
Result response = processDefinitionController.queryProcessDefinitionListPaging(user, projectName, pageNo, searchVal, userId, pageSize); Result response = processDefinitionController.queryProcessDefinitionListPaging(user, projectCode, pageNo, searchVal, userId, pageSize);
Assert.assertTrue(response != null && response.isSuccess()); Assert.assertTrue(response != null && response.isSuccess());
} }
@Test @Test
public void testBatchExportProcessDefinitionByIds() throws Exception { public void testBatchExportProcessDefinitionByIds() throws Exception {
String processDefinitionIds = "1,2"; String processDefinitionIds = "1,2";
String projectName = "test"; long projectCode = 1L;
HttpServletResponse response = new MockHttpServletResponse(); HttpServletResponse response = new MockHttpServletResponse();
Mockito.doNothing().when(this.processDefinitionService).batchExportProcessDefinitionByIds(user, projectName, processDefinitionIds, response); Mockito.doNothing().when(this.processDefinitionService).batchExportProcessDefinitionByIds(user, projectCode, processDefinitionIds, response);
processDefinitionController.batchExportProcessDefinitionByIds(user, projectName, processDefinitionIds, response); processDefinitionController.batchExportProcessDefinitionByIds(user, projectCode, processDefinitionIds, response);
} }
@Test @Test
public void testQueryProcessDefinitionVersions() { public void testQueryProcessDefinitionVersions() {
String projectName = "test"; long projectCode = 1L;
Map<String, Object> resultMap = new HashMap<>(); Map<String, Object> resultMap = new HashMap<>();
putMsg(resultMap, Status.SUCCESS); putMsg(resultMap, Status.SUCCESS);
resultMap.put(Constants.DATA_LIST, new PageInfo<ProcessDefinitionLog>(1, 10)); resultMap.put(Constants.DATA_LIST, new PageInfo<ProcessDefinitionLog>(1, 10));
Mockito.when(processDefinitionService.queryProcessDefinitionVersions( Mockito.when(processDefinitionService.queryProcessDefinitionVersions(
user user
, projectName , projectCode
, 1 , 1
, 10 , 10
, 1)) , 1))
.thenReturn(resultMap); .thenReturn(resultMap);
Result result = processDefinitionController.queryProcessDefinitionVersions( Result result = processDefinitionController.queryProcessDefinitionVersions(
user user
, projectName , projectCode
, 1 , 1
, 10 , 10
, 1); , 1);
@ -395,29 +382,29 @@ public class ProcessDefinitionControllerTest {
@Test @Test
public void testSwitchProcessDefinitionVersion() { public void testSwitchProcessDefinitionVersion() {
String projectName = "test"; long projectCode = 1L;
Map<String, Object> resultMap = new HashMap<>(); Map<String, Object> resultMap = new HashMap<>();
putMsg(resultMap, Status.SUCCESS); putMsg(resultMap, Status.SUCCESS);
Mockito.when(processDefinitionService.switchProcessDefinitionVersion(user, projectName, 1, 10)).thenReturn(resultMap); Mockito.when(processDefinitionService.switchProcessDefinitionVersion(user, projectCode, 1, 10)).thenReturn(resultMap);
Result result = processDefinitionController.switchProcessDefinitionVersion(user, projectName, 1, 10); Result result = processDefinitionController.switchProcessDefinitionVersion(user, projectCode, 1, 10);
Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode()); Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode());
} }
@Test @Test
public void testDeleteProcessDefinitionVersion() { public void testDeleteProcessDefinitionVersion() {
String projectName = "test"; long projectCode = 1L;
Map<String, Object> resultMap = new HashMap<>(); Map<String, Object> resultMap = new HashMap<>();
putMsg(resultMap, Status.SUCCESS); putMsg(resultMap, Status.SUCCESS);
Mockito.when(processDefinitionService.deleteByProcessDefinitionIdAndVersion( Mockito.when(processDefinitionService.deleteByProcessDefinitionIdAndVersion(
user user
, projectName , projectCode
, 1 , 1
, 10)) , 10))
.thenReturn(resultMap); .thenReturn(resultMap);
Result result = processDefinitionController.deleteProcessDefinitionVersion( Result result = processDefinitionController.deleteProcessDefinitionVersion(
user user
, projectName , projectCode
, 1 , 1
, 10); , 10);
Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode()); Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode());

4
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/exceptions/ApiExceptionHandlerTest.java

@ -46,9 +46,9 @@ public class ApiExceptionHandlerTest {
public void exceptionHandlerRuntime() throws NoSuchMethodException { public void exceptionHandlerRuntime() throws NoSuchMethodException {
ApiExceptionHandler handler = new ApiExceptionHandler(); ApiExceptionHandler handler = new ApiExceptionHandler();
ProcessDefinitionController controller = new ProcessDefinitionController(); ProcessDefinitionController controller = new ProcessDefinitionController();
Method method = controller.getClass().getMethod("batchExportProcessDefinitionByIds", User.class, String.class, String.class, HttpServletResponse.class); Method method = controller.getClass().getMethod("queryAllProcessDefinitionByProjectCode", User.class, long.class);
HandlerMethod hm = new HandlerMethod(controller, method); HandlerMethod hm = new HandlerMethod(controller, method);
Result result = handler.exceptionHandler(new RuntimeException("test exception"), hm); Result result = handler.exceptionHandler(new RuntimeException("test exception"), hm);
Assert.assertEquals(Status.INTERNAL_SERVER_ERROR_ARGS.getCode(),result.getCode().intValue()); Assert.assertEquals(Status.QUERY_PROCESS_DEFINITION_LIST.getCode(),result.getCode().intValue());
} }
} }

351
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java

@ -44,6 +44,7 @@ import org.apache.dolphinscheduler.dao.entity.DataSource;
import org.apache.dolphinscheduler.dao.entity.ProcessData; import org.apache.dolphinscheduler.dao.entity.ProcessData;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation;
import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.entity.Schedule; import org.apache.dolphinscheduler.dao.entity.Schedule;
import org.apache.dolphinscheduler.dao.entity.TaskInstance; import org.apache.dolphinscheduler.dao.entity.TaskInstance;
@ -67,6 +68,8 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -253,55 +256,55 @@ public class ProcessDefinitionServiceTest {
@Test @Test
public void testQueryProcessDefinitionList() { public void testQueryProcessDefinitionList() {
String projectName = "project_test1"; long projectCode = 1L;
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Project project = getProject(projectName); Project project = getProject(projectCode);
User loginUser = new User(); User loginUser = new User();
loginUser.setId(-1); loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
//project not found //project not found
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> map = processDefinitionService.queryProcessDefinitionList(loginUser, "project_test1"); Map<String, Object> map = processDefinitionService.queryProcessDefinitionList(loginUser, projectCode);
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
//project check auth success //project check auth success
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
List<ProcessDefinition> resourceList = new ArrayList<>(); List<ProcessDefinition> resourceList = new ArrayList<>();
resourceList.add(getProcessDefinition()); resourceList.add(getProcessDefinition());
Mockito.when(processDefineMapper.queryAllDefinitionList(project.getCode())).thenReturn(resourceList); Mockito.when(processDefineMapper.queryAllDefinitionList(project.getCode())).thenReturn(resourceList);
Map<String, Object> checkSuccessRes = processDefinitionService.queryProcessDefinitionList(loginUser, "project_test1"); Map<String, Object> checkSuccessRes = processDefinitionService.queryProcessDefinitionList(loginUser, projectCode);
Assert.assertEquals(Status.SUCCESS, checkSuccessRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, checkSuccessRes.get(Constants.STATUS));
} }
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testQueryProcessDefinitionListPaging() { public void testQueryProcessDefinitionListPaging() {
String projectName = "project_test1"; long projectCode = 1L;
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Project project = getProject(projectName); Project project = getProject(projectCode);
User loginUser = new User(); User loginUser = new User();
loginUser.setId(-1); loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
//project not found //project not found
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> map = processDefinitionService.queryProcessDefinitionListPaging(loginUser, "project_test1", "", 1, 5, 0); Map<String, Object> map = processDefinitionService.queryProcessDefinitionListPaging(loginUser, projectCode, "", 1, 5, 0);
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
loginUser.setId(1); loginUser.setId(1);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Page<ProcessDefinition> page = new Page<>(1, 10); Page<ProcessDefinition> page = new Page<>(1, 10);
page.setTotal(30); page.setTotal(30);
Mockito.when(processDefineMapper.queryDefineListPaging( Mockito.when(processDefineMapper.queryDefineListPaging(
@ -312,229 +315,211 @@ public class ProcessDefinitionServiceTest {
, Mockito.anyBoolean())).thenReturn(page); , Mockito.anyBoolean())).thenReturn(page);
Map<String, Object> map1 = processDefinitionService.queryProcessDefinitionListPaging( Map<String, Object> map1 = processDefinitionService.queryProcessDefinitionListPaging(
loginUser, projectName, "", 1, 10, loginUser.getId()); loginUser, 1L, "", 1, 10, loginUser.getId());
Assert.assertEquals(Status.SUCCESS, map1.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, map1.get(Constants.STATUS));
} }
@Test @Test
public void testQueryProcessDefinitionByCode() { public void testQueryProcessDefinitionByCode() {
String projectName = "project_test1"; long projectCode = 1L;
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Project project = getProject(projectName); Project project = getProject(projectCode);
User loginUser = new User(); User loginUser = new User();
loginUser.setId(-1); loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
//project check auth fail //project check auth fail
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> map = processDefinitionService.queryProcessDefinitionByCode(loginUser, Map<String, Object> map = processDefinitionService.queryProcessDefinitionByCode(loginUser, 1L, 1L);
"project_test1", 1L);
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
//project check auth success, instance not exist //project check auth success, instance not exist
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
DagData dagData = new DagData(getProcessDefinition(), null, null); DagData dagData = new DagData(getProcessDefinition(), null, null);
Mockito.when(processService.genDagData(Mockito.any())).thenReturn(dagData); Mockito.when(processService.genDagData(Mockito.any())).thenReturn(dagData);
Map<String, Object> instanceNotexitRes = processDefinitionService.queryProcessDefinitionByCode(loginUser, Map<String, Object> instanceNotexitRes = processDefinitionService.queryProcessDefinitionByCode(loginUser, projectCode, 1L);
"project_test1", 1L);
Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotexitRes.get(Constants.STATUS)); Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotexitRes.get(Constants.STATUS));
//instance exit //instance exit
Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(getProcessDefinition()); Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(getProcessDefinition());
Map<String, Object> successRes = processDefinitionService.queryProcessDefinitionByCode(loginUser, putMsg(result, Status.SUCCESS, projectCode);
"project_test1", 46L); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> successRes = processDefinitionService.queryProcessDefinitionByCode(loginUser, projectCode, 46L);
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
} }
@Test @Test
public void testQueryProcessDefinitionByName() { public void testQueryProcessDefinitionByName() {
String projectName = "project_test1"; long projectCode = 1L;
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Project project = getProject(projectName); Project project = getProject(projectCode);
User loginUser = new User(); User loginUser = new User();
loginUser.setId(-1); loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
//project check auth fail //project check auth fail
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> map = processDefinitionService.queryProcessDefinitionByName(loginUser, Map<String, Object> map = processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, "test_def");
"project_test1", "test_def");
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
//project check auth success, instance not exist //project check auth success, instance not exist
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Mockito.when(processDefineMapper.queryByDefineName(project.getCode(), "test_def")).thenReturn(null); Mockito.when(processDefineMapper.queryByDefineName(project.getCode(), "test_def")).thenReturn(null);
ProcessData processData = getProcessData(); ProcessData processData = getProcessData();
Mockito.when(processService.genProcessData(Mockito.any())).thenReturn(processData); Mockito.when(processService.genProcessData(Mockito.any())).thenReturn(processData);
Map<String, Object> instanceNotexitRes = processDefinitionService.queryProcessDefinitionByName(loginUser, Map<String, Object> instanceNotexitRes = processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, "test_def");
"project_test1", "test_def");
Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotexitRes.get(Constants.STATUS)); Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotexitRes.get(Constants.STATUS));
//instance exit //instance exit
Mockito.when(processDefineMapper.queryByDefineName(project.getCode(), "test")).thenReturn(getProcessDefinition()); Mockito.when(processDefineMapper.queryByDefineName(project.getCode(), "test")).thenReturn(getProcessDefinition());
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> successRes = processDefinitionService.queryProcessDefinitionByName(loginUser, Map<String, Object> successRes = processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, "test");
"project_test1", "test");
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
} }
@Test @Test
public void testBatchCopyProcessDefinition() { public void testBatchCopyProcessDefinition() {
long projectCode = 1L;
String projectName = "project_test1"; Project project = getProject(projectCode);
Project project = getProject(projectName);
User loginUser = new User(); User loginUser = new User();
loginUser.setId(1); loginUser.setId(1);
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
// copy project definition ids empty test // copy project definition ids empty test
Map<String, Object> map = processDefinitionService.batchCopyProcessDefinition(loginUser, projectName, StringUtils.EMPTY, "project_test2"); Map<String, Object> map = processDefinitionService.batchCopyProcessDefinition(loginUser, projectCode, StringUtils.EMPTY, 2L);
Assert.assertEquals(Status.PROCESS_DEFINITION_CODES_IS_EMPTY, map.get(Constants.STATUS)); Assert.assertEquals(Status.PROCESS_DEFINITION_CODES_IS_EMPTY, map.get(Constants.STATUS));
// project check auth fail // project check auth fail
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> map1 = processDefinitionService.batchCopyProcessDefinition( Map<String, Object> map1 = processDefinitionService.batchCopyProcessDefinition(
loginUser, projectName, String.valueOf(project.getId()), "project_test2"); loginUser, projectCode, String.valueOf(project.getId()), 2L);
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map1.get(Constants.STATUS)); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map1.get(Constants.STATUS));
// project check auth success, target project is null
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName));
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
putMsg(result, Status.PROJECT_NOT_FOUNT, "project_test2");
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
Map<String, Object> map2 = processDefinitionService.batchCopyProcessDefinition(
loginUser, projectName, String.valueOf(project.getId()), "project_test2");
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map2.get(Constants.STATUS));
// project check auth success, target project name not equal project name, check auth target project fail // project check auth success, target project name not equal project name, check auth target project fail
Project project1 = getProject(projectName); projectCode = 2L;
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project1); Project project1 = getProject(projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project1);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
// instance exit
ProcessDefinition definition = getProcessDefinition(); ProcessDefinition definition = getProcessDefinition();
definition.setLocations("{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"); List<ProcessDefinition> processDefinitionList = new ArrayList<>();
definition.setConnects("[]"); processDefinitionList.add(definition);
Set<Long> definitionCodes = Arrays.stream("46".split(Constants.COMMA)).map(Long::parseLong).collect(Collectors.toSet());
Mockito.when(processDefineMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList);
Map<String, Object> map3 = processDefinitionService.batchCopyProcessDefinition( Map<String, Object> map3 = processDefinitionService.batchCopyProcessDefinition(
loginUser, projectName, "46", projectName); loginUser, projectCode, "46", 1L);
Assert.assertEquals(Status.COPY_PROCESS_DEFINITION_ERROR, map3.get(Constants.STATUS)); Assert.assertEquals(Status.COPY_PROCESS_DEFINITION_ERROR, map3.get(Constants.STATUS));
} }
@Test @Test
public void testBatchMoveProcessDefinition() { public void testBatchMoveProcessDefinition() {
String projectName = "project_test1"; long projectCode = 1L;
Project project1 = getProject(projectName); Project project1 = getProject(projectCode);
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project1); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project1);
String projectName2 = "project_test2";
Project project2 = getProject(projectName2);
Mockito.when(projectMapper.queryByName(projectName2)).thenReturn(project2);
int targetProjectId = 2;
Mockito.when(projectMapper.queryDetailById(targetProjectId)).thenReturn(getProjectById(targetProjectId));
Project project = getProject(projectName); long projectCode2 = 2L;
Project targetProject = getProjectById(targetProjectId); Project project2 = getProject(projectCode2);
Mockito.when(projectMapper.queryByCode(projectCode2)).thenReturn(project2);
User loginUser = new User(); User loginUser = new User();
loginUser.setId(-1); loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Map<String, Object> result2 = new HashMap<>(); Mockito.when(projectService.checkProjectAndAuth(loginUser, project1, project1.getName())).thenReturn(result);
putMsg(result2, Status.SUCCESS, targetProject.getName()); Mockito.when(projectService.checkProjectAndAuth(loginUser, project2, project2.getName())).thenReturn(result);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project2, projectName2)).thenReturn(result);
ProcessDefinition definition = getProcessDefinition(); ProcessDefinition definition = getProcessDefinition();
definition.setLocations("{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"); List<ProcessDefinition> processDefinitionList = new ArrayList<>();
definition.setConnects("[]"); processDefinitionList.add(definition);
Set<Long> definitionCodes = Arrays.stream("46".split(Constants.COMMA)).map(Long::parseLong).collect(Collectors.toSet());
Mockito.when(processDefineMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList);
Mockito.when(processTaskRelationMapper.queryByProcessCode(projectCode, 46L)).thenReturn(getProcessTaskRelation(projectCode, 46L));
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
Map<String, Object> successRes = processDefinitionService.batchMoveProcessDefinition( Map<String, Object> successRes = processDefinitionService.batchMoveProcessDefinition(
loginUser, "project_test1", "46", 2); loginUser, projectCode, "46", projectCode2);
Assert.assertEquals(Status.MOVE_PROCESS_DEFINITION_ERROR, successRes.get(Constants.STATUS));
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
} }
@Test @Test
public void deleteProcessDefinitionByIdTest() { public void deleteProcessDefinitionByIdTest() {
String projectName = "project_test1"; long projectCode = 1L;
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Project project = getProject(projectName); Project project = getProject(projectCode);
User loginUser = new User(); User loginUser = new User();
loginUser.setId(-1); loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
//project check auth fail //project check auth fail
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> map = processDefinitionService.deleteProcessDefinitionById(loginUser, "project_test1", 6); Map<String, Object> map = processDefinitionService.deleteProcessDefinitionById(loginUser, projectCode, 6);
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
//project check auth success, instance not exist //project check auth success, instance not exist
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Mockito.when(processDefineMapper.selectById(1)).thenReturn(null); Mockito.when(processDefineMapper.selectById(1)).thenReturn(null);
Map<String, Object> instanceNotexitRes = processDefinitionService.deleteProcessDefinitionById(loginUser, Map<String, Object> instanceNotExitRes = processDefinitionService.deleteProcessDefinitionById(loginUser, projectCode, 1);
"project_test1", 1); Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotExitRes.get(Constants.STATUS));
Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotexitRes.get(Constants.STATUS));
ProcessDefinition processDefinition = getProcessDefinition(); ProcessDefinition processDefinition = getProcessDefinition();
putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
//user no auth //user no auth
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
Mockito.when(processDefineMapper.selectById(46)).thenReturn(processDefinition); Mockito.when(processDefineMapper.selectById(46)).thenReturn(processDefinition);
Map<String, Object> userNoAuthRes = processDefinitionService.deleteProcessDefinitionById(loginUser, Map<String, Object> userNoAuthRes = processDefinitionService.deleteProcessDefinitionById(loginUser, projectCode, 46);
"project_test1", 46);
Assert.assertEquals(Status.USER_NO_OPERATION_PERM, userNoAuthRes.get(Constants.STATUS)); Assert.assertEquals(Status.USER_NO_OPERATION_PERM, userNoAuthRes.get(Constants.STATUS));
//process definition online //process definition online
loginUser.setUserType(UserType.ADMIN_USER); loginUser.setUserType(UserType.ADMIN_USER);
putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
processDefinition.setReleaseState(ReleaseState.ONLINE); processDefinition.setReleaseState(ReleaseState.ONLINE);
Mockito.when(processDefineMapper.selectById(46)).thenReturn(processDefinition); Mockito.when(processDefineMapper.selectById(46)).thenReturn(processDefinition);
Map<String, Object> dfOnlineRes = processDefinitionService.deleteProcessDefinitionById(loginUser, Map<String, Object> dfOnlineRes = processDefinitionService.deleteProcessDefinitionById(loginUser,projectCode, 46);
"project_test1", 46);
Assert.assertEquals(Status.PROCESS_DEFINE_STATE_ONLINE, dfOnlineRes.get(Constants.STATUS)); Assert.assertEquals(Status.PROCESS_DEFINE_STATE_ONLINE, dfOnlineRes.get(Constants.STATUS));
//scheduler list elements > 1 //scheduler list elements > 1
processDefinition.setReleaseState(ReleaseState.OFFLINE); processDefinition.setReleaseState(ReleaseState.OFFLINE);
Mockito.when(processDefineMapper.selectById(46)).thenReturn(processDefinition); Mockito.when(processDefineMapper.selectById(46)).thenReturn(processDefinition);
putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
List<Schedule> schedules = new ArrayList<>(); List<Schedule> schedules = new ArrayList<>();
schedules.add(getSchedule()); schedules.add(getSchedule());
schedules.add(getSchedule()); schedules.add(getSchedule());
Mockito.when(scheduleMapper.queryByProcessDefinitionId(46)).thenReturn(schedules); Mockito.when(scheduleMapper.queryByProcessDefinitionId(46)).thenReturn(schedules);
Map<String, Object> schedulerGreaterThanOneRes = processDefinitionService.deleteProcessDefinitionById(loginUser, Map<String, Object> schedulerGreaterThanOneRes = processDefinitionService.deleteProcessDefinitionById(loginUser, projectCode, 46);
"project_test1", 46);
Assert.assertEquals(Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR, schedulerGreaterThanOneRes.get(Constants.STATUS)); Assert.assertEquals(Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR, schedulerGreaterThanOneRes.get(Constants.STATUS));
//scheduler online //scheduler online
@ -542,103 +527,104 @@ public class ProcessDefinitionServiceTest {
Schedule schedule = getSchedule(); Schedule schedule = getSchedule();
schedule.setReleaseState(ReleaseState.ONLINE); schedule.setReleaseState(ReleaseState.ONLINE);
schedules.add(schedule); schedules.add(schedule);
putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Mockito.when(scheduleMapper.queryByProcessDefinitionId(46)).thenReturn(schedules); Mockito.when(scheduleMapper.queryByProcessDefinitionId(46)).thenReturn(schedules);
Map<String, Object> schedulerOnlineRes = processDefinitionService.deleteProcessDefinitionById(loginUser, Map<String, Object> schedulerOnlineRes = processDefinitionService.deleteProcessDefinitionById(loginUser, projectCode, 46);
"project_test1", 46);
Assert.assertEquals(Status.SCHEDULE_CRON_STATE_ONLINE, schedulerOnlineRes.get(Constants.STATUS)); Assert.assertEquals(Status.SCHEDULE_CRON_STATE_ONLINE, schedulerOnlineRes.get(Constants.STATUS));
//delete fail //delete fail
schedules.clear(); schedules.clear();
schedule.setReleaseState(ReleaseState.OFFLINE); schedule.setReleaseState(ReleaseState.OFFLINE);
schedules.add(schedule); schedules.add(schedule);
putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Mockito.when(scheduleMapper.queryByProcessDefinitionId(46)).thenReturn(schedules); Mockito.when(scheduleMapper.queryByProcessDefinitionId(46)).thenReturn(schedules);
Mockito.when(processDefineMapper.deleteById(46)).thenReturn(0); Mockito.when(processDefineMapper.deleteById(46)).thenReturn(0);
Map<String, Object> deleteFail = processDefinitionService.deleteProcessDefinitionById(loginUser, Map<String, Object> deleteFail = processDefinitionService.deleteProcessDefinitionById(loginUser, projectCode, 46);
"project_test1", 46);
Assert.assertEquals(Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR, deleteFail.get(Constants.STATUS)); Assert.assertEquals(Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR, deleteFail.get(Constants.STATUS));
//delete success //delete success
Mockito.when(processDefineMapper.deleteById(46)).thenReturn(1); Mockito.when(processDefineMapper.deleteById(46)).thenReturn(1);
Map<String, Object> deleteSuccess = processDefinitionService.deleteProcessDefinitionById(loginUser, putMsg(result, Status.SUCCESS, projectCode);
"project_test1", 46); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> deleteSuccess = processDefinitionService.deleteProcessDefinitionById(loginUser, projectCode, 46);
Assert.assertEquals(Status.SUCCESS, deleteSuccess.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, deleteSuccess.get(Constants.STATUS));
} }
@Test @Test
public void testReleaseProcessDefinition() { public void testReleaseProcessDefinition() {
long projectCode = 1L;
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
String projectName = "project_test1"; Project project = getProject(projectCode);
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName));
Project project = getProject(projectName);
User loginUser = new User(); User loginUser = new User();
loginUser.setId(1); loginUser.setId(1);
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
//project check auth fail //project check auth fail
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> map = processDefinitionService.releaseProcessDefinition(loginUser, "project_test1", Map<String, Object> map = processDefinitionService.releaseProcessDefinition(loginUser, projectCode,
6, ReleaseState.OFFLINE); 6, ReleaseState.OFFLINE);
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
// project check auth success, processs definition online // project check auth success, processs definition online
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(getProcessDefinition()); Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(getProcessDefinition());
Map<String, Object> onlineRes = processDefinitionService.releaseProcessDefinition( Map<String, Object> onlineRes = processDefinitionService.releaseProcessDefinition(
loginUser, "project_test1", 46, ReleaseState.ONLINE); loginUser, projectCode, 46, ReleaseState.ONLINE);
Assert.assertEquals(Status.SUCCESS, onlineRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, onlineRes.get(Constants.STATUS));
// project check auth success, processs definition online // project check auth success, processs definition online
ProcessDefinition processDefinition1 = getProcessDefinition(); ProcessDefinition processDefinition1 = getProcessDefinition();
processDefinition1.setResourceIds("1,2"); processDefinition1.setResourceIds("1,2");
Map<String, Object> onlineWithResourceRes = processDefinitionService.releaseProcessDefinition( Map<String, Object> onlineWithResourceRes = processDefinitionService.releaseProcessDefinition(
loginUser, "project_test1", 46, ReleaseState.ONLINE); loginUser, projectCode, 46, ReleaseState.ONLINE);
Assert.assertEquals(Status.SUCCESS, onlineWithResourceRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, onlineWithResourceRes.get(Constants.STATUS));
// release error code // release error code
Map<String, Object> failRes = processDefinitionService.releaseProcessDefinition( Map<String, Object> failRes = processDefinitionService.releaseProcessDefinition(
loginUser, "project_test1", 46, ReleaseState.getEnum(2)); loginUser, projectCode, 46, ReleaseState.getEnum(2));
Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, failRes.get(Constants.STATUS)); Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, failRes.get(Constants.STATUS));
} }
@Test @Test
public void testVerifyProcessDefinitionName() { public void testVerifyProcessDefinitionName() {
String projectName = "project_test1"; long projectCode = 1L;
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Project project = getProject(projectName); Project project = getProject(projectCode);
User loginUser = new User(); User loginUser = new User();
loginUser.setId(-1); loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER); loginUser.setUserType(UserType.GENERAL_USER);
//project check auth fail //project check auth fail
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
Map<String, Object> map = processDefinitionService.verifyProcessDefinitionName(loginUser, Map<String, Object> map = processDefinitionService.verifyProcessDefinitionName(loginUser,
"project_test1", "test_pdf"); projectCode, "test_pdf");
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
//project check auth success, process not exist //project check auth success, process not exist
putMsg(result, Status.SUCCESS, projectName); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(processDefineMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(null); Mockito.when(processDefineMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(null);
Map<String, Object> processNotExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser, Map<String, Object> processNotExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser,
"project_test1", "test_pdf"); projectCode, "test_pdf");
Assert.assertEquals(Status.SUCCESS, processNotExistRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, processNotExistRes.get(Constants.STATUS));
//process exist //process exist
Mockito.when(processDefineMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(getProcessDefinition()); Mockito.when(processDefineMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(getProcessDefinition());
Map<String, Object> processExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser, Map<String, Object> processExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser,
"project_test1", "test_pdf"); projectCode, "test_pdf");
Assert.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST, processExistRes.get(Constants.STATUS)); Assert.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST, processExistRes.get(Constants.STATUS));
} }
@Test @Test
public void testCheckProcessNodeList() { public void testCheckProcessNodeList() {
Map<String, Object> dataNotValidRes = processDefinitionService.checkProcessNodeList(null, ""); Map<String, Object> dataNotValidRes = processDefinitionService.checkProcessNodeList(null, "");
Assert.assertEquals(Status.DATA_IS_NOT_VALID, dataNotValidRes.get(Constants.STATUS)); Assert.assertEquals(Status.DATA_IS_NOT_VALID, dataNotValidRes.get(Constants.STATUS));
@ -721,26 +707,26 @@ public class ProcessDefinitionServiceTest {
} }
@Test @Test
public void testQueryProcessDefinitionAllByProjectId() { public void testQueryAllProcessDefinitionByProjectCode() {
int projectId = 1; User loginUser = new User();
Long projectCode = 2L; loginUser.setId(1);
Project project = new Project(); loginUser.setUserType(UserType.GENERAL_USER);
project.setId(projectId); Map<String, Object> result = new HashMap<>();
project.setCode(projectCode); long projectCode = 2L;
Mockito.when(projectMapper.selectById(projectId)).thenReturn(project); Project project = getProject(projectCode);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
ProcessDefinition processDefinition = getProcessDefinition(); ProcessDefinition processDefinition = getProcessDefinition();
List<ProcessDefinition> processDefinitionList = new ArrayList<>(); List<ProcessDefinition> processDefinitionList = new ArrayList<>();
processDefinitionList.add(processDefinition); processDefinitionList.add(processDefinition);
Project test = getProject("test"); Mockito.when(processDefineMapper.queryAllDefinitionList(projectCode)).thenReturn(processDefinitionList);
Mockito.when(projectMapper.selectById(projectId)).thenReturn(test); Map<String, Object> successRes = processDefinitionService.queryAllProcessDefinitionByProjectCode(loginUser, projectCode);
Mockito.when(processDefineMapper.queryAllDefinitionList(test.getCode())).thenReturn(processDefinitionList);
Map<String, Object> successRes = processDefinitionService.queryProcessDefinitionAllByProjectId(projectId);
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
} }
@Test @Test
public void testViewTree() throws Exception { public void testViewTree() {
//process definition not exist //process definition not exist
ProcessDefinition processDefinition = getProcessDefinition(); ProcessDefinition processDefinition = getProcessDefinition();
processDefinition.setProcessDefinitionJson(SHELL_JSON); processDefinition.setProcessDefinitionJson(SHELL_JSON);
@ -892,9 +878,9 @@ public class ProcessDefinitionServiceTest {
loginUser.setId(1); loginUser.setId(1);
loginUser.setUserType(UserType.ADMIN_USER); loginUser.setUserType(UserType.ADMIN_USER);
String currentProjectName = "testProject"; long currentProjectCode = 1L;
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, currentProjectName); putMsg(result, Status.SUCCESS, currentProjectCode);
ProcessDefinition shellDefinition2 = new ProcessDefinition(); ProcessDefinition shellDefinition2 = new ProcessDefinition();
shellDefinition2.setId(46); shellDefinition2.setId(46);
@ -902,10 +888,10 @@ public class ProcessDefinitionServiceTest {
shellDefinition2.setProjectId(2); shellDefinition2.setProjectId(2);
shellDefinition2.setProcessDefinitionJson(subProcessJson); shellDefinition2.setProcessDefinitionJson(subProcessJson);
Mockito.when(projectMapper.queryByName(currentProjectName)).thenReturn(getProject(currentProjectName)); Mockito.when(projectMapper.queryByCode(currentProjectCode)).thenReturn(getProject(currentProjectCode));
Mockito.when(projectService.checkProjectAndAuth(loginUser, getProject(currentProjectName), currentProjectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, getProject(currentProjectCode), "test")).thenReturn(result);
Map<String, Object> importProcessResult = processDefinitionService.importProcessDefinition(loginUser, multipartFile, currentProjectName); Map<String, Object> importProcessResult = processDefinitionService.importProcessDefinition(loginUser, currentProjectCode, multipartFile);
Assert.assertEquals(Status.SUCCESS, importProcessResult.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, importProcessResult.get(Constants.STATUS));
@ -923,13 +909,13 @@ public class ProcessDefinitionServiceTest {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
String projectName = "project_test1"; long projectCode = 1L;
Project project = getProject(projectName); Project project = getProject(projectCode);
ProcessDefinition processDefinition = getProcessDefinition(); ProcessDefinition processDefinition = getProcessDefinition();
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
String sqlDependentJson = "{\n" String sqlDependentJson = "{\n"
+ " \"globalParams\": [\n" + " \"globalParams\": [\n"
@ -1020,7 +1006,7 @@ public class ProcessDefinitionServiceTest {
+ " \"tenantId\": 1,\n" + " \"tenantId\": 1,\n"
+ " \"timeout\": 0\n" + " \"timeout\": 0\n"
+ "}"; + "}";
Map<String, Object> updateResult = processDefinitionService.updateProcessDefinition(loginUser, projectName, "test", 1, Map<String, Object> updateResult = processDefinitionService.updateProcessDefinition(loginUser, projectCode, "test", 1,
"", "", "", "", 0, "root", sqlDependentJson); "", "", "", "", 0, "root", sqlDependentJson);
Assert.assertEquals(Status.DATA_IS_NOT_VALID, updateResult.get(Constants.STATUS)); Assert.assertEquals(Status.DATA_IS_NOT_VALID, updateResult.get(Constants.STATUS));
@ -1029,7 +1015,7 @@ public class ProcessDefinitionServiceTest {
@Test @Test
public void testBatchExportProcessDefinitionByIds() throws IOException { public void testBatchExportProcessDefinitionByIds() throws IOException {
processDefinitionService.batchExportProcessDefinitionByIds( processDefinitionService.batchExportProcessDefinitionByIds(
null, null, null, null); null, 1L, null, null);
String processDefinitionJson = "{\"globalParams\":[],\"tasks\":[{\"conditionResult\":" String processDefinitionJson = "{\"globalParams\":[],\"tasks\":[{\"conditionResult\":"
+ "{\"failedNode\":[\"\"],\"successNode\":[\"\"]},\"delayTime\":\"0\",\"dependence\":{}" + "{\"failedNode\":[\"\"],\"successNode\":[\"\"]},\"delayTime\":\"0\",\"dependence\":{}"
@ -1042,24 +1028,24 @@ public class ProcessDefinitionServiceTest {
loginUser.setId(1); loginUser.setId(1);
loginUser.setUserType(UserType.ADMIN_USER); loginUser.setUserType(UserType.ADMIN_USER);
String projectName = "project_test1"; long projectCode = 1L;
Project project = getProject(projectName); Project project = getProject(projectCode);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.PROJECT_NOT_FOUNT); putMsg(result, Status.PROJECT_NOT_FOUNT);
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result);
processDefinitionService.batchExportProcessDefinitionByIds( processDefinitionService.batchExportProcessDefinitionByIds(
loginUser, projectName, "1", null); loginUser, projectCode, "1", null);
ProcessDefinition processDefinition = new ProcessDefinition(); ProcessDefinition processDefinition = new ProcessDefinition();
processDefinition.setId(1); processDefinition.setId(1);
processDefinition.setProcessDefinitionJson(processDefinitionJson); processDefinition.setProcessDefinitionJson(processDefinitionJson);
Map<String, Object> checkResult = new HashMap<>(); Map<String, Object> checkResult = new HashMap<>();
checkResult.put(Constants.STATUS, Status.SUCCESS); checkResult.put(Constants.STATUS, Status.SUCCESS);
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(checkResult); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(checkResult);
Mockito.when(processDefineMapper.queryByDefineId(1)).thenReturn(processDefinition); Mockito.when(processDefineMapper.queryByDefineId(1)).thenReturn(processDefinition);
HttpServletResponse response = mock(HttpServletResponse.class); HttpServletResponse response = mock(HttpServletResponse.class);
@ -1069,7 +1055,7 @@ public class ProcessDefinitionServiceTest {
ServletOutputStream outputStream = mock(ServletOutputStream.class); ServletOutputStream outputStream = mock(ServletOutputStream.class);
when(response.getOutputStream()).thenReturn(outputStream); when(response.getOutputStream()).thenReturn(outputStream);
processDefinitionService.batchExportProcessDefinitionByIds( processDefinitionService.batchExportProcessDefinitionByIds(
loginUser, projectName, "1", response); loginUser, projectCode, "1", response);
Assert.assertNotNull(processDefinitionService.exportProcessMetaData(processDefinition)); Assert.assertNotNull(processDefinitionService.exportProcessMetaData(processDefinition));
} }
@ -1093,6 +1079,7 @@ public class ProcessDefinitionServiceTest {
private ProcessDefinition getProcessDefinition() { private ProcessDefinition getProcessDefinition() {
ProcessDefinition processDefinition = new ProcessDefinition(); ProcessDefinition processDefinition = new ProcessDefinition();
processDefinition.setId(46); processDefinition.setId(46);
processDefinition.setProjectCode(1L);
processDefinition.setName("test_pdf"); processDefinition.setName("test_pdf");
processDefinition.setProjectId(2); processDefinition.setProjectId(2);
processDefinition.setTenantId(1); processDefinition.setTenantId(1);
@ -1105,18 +1092,28 @@ public class ProcessDefinitionServiceTest {
/** /**
* get mock Project * get mock Project
* *
* @param projectName projectName * @param projectCode projectCode
* @return Project * @return Project
*/ */
private Project getProject(String projectName) { private Project getProject(long projectCode) {
Project project = new Project(); Project project = new Project();
project.setCode(1L); project.setCode(projectCode);
project.setId(1); project.setId(1);
project.setName(projectName); project.setName("test");
project.setUserId(1); project.setUserId(1);
return project; return project;
} }
private List<ProcessTaskRelation> getProcessTaskRelation(long projectCode, long processCode) {
List<ProcessTaskRelation> processTaskRelations = new ArrayList<>();
ProcessTaskRelation processTaskRelation = new ProcessTaskRelation();
processTaskRelation.setProjectCode(projectCode);
processTaskRelation.setProcessDefinitionCode(processCode);
processTaskRelation.setProcessDefinitionVersion(1);
processTaskRelations.add(processTaskRelation);
return processTaskRelations;
}
/** /**
* get mock Project * get mock Project
* *

4
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java

@ -709,10 +709,6 @@ public final class Constants {
* projectId * projectId
*/ */
public static final String PROJECT_ID = "projectId"; public static final String PROJECT_ID = "projectId";
/**
* projectCode
*/
public static final String PROJECT_CODE = "projectCode";
/** /**
* processId * processId
*/ */

Loading…
Cancel
Save