samz406 commented on a change in pull request #2884:
URL:
https://github.com/apache/incubator-dolphinscheduler/pull/2884#discussion_r444686335
##########
File path:
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java
##########
@@ -295,38 +294,209 @@ private String getResourceIds(ProcessData processData) {
/**
* copy process definition
*
- * @param loginUser login user
- * @param projectName project name
- * @param processId process definition id
- * @return copy result code
+ * @param loginUser loginUser
+ * @param processId processId
+ * @param targetProject targetProject
+ * @return
+ * @throws JsonProcessingException
*/
- public Map<String, Object> copyProcessDefinition(User loginUser, String
projectName, Integer processId) throws JsonProcessingException {
+ private Map<String, Object> copyProcessDefinition(User loginUser,
+ Integer processId,
+ Project targetProject)
throws JsonProcessingException {
Map<String, Object> result = new HashMap<>(5);
- Project project = projectMapper.queryByName(projectName);
-
- Map<String, Object> checkResult =
projectService.checkProjectAndAuth(loginUser, project, projectName);
- Status resultStatus = (Status) checkResult.get(Constants.STATUS);
- if (resultStatus != Status.SUCCESS) {
- return checkResult;
- }
ProcessDefinition processDefinition =
processDefineMapper.selectById(processId);
if (processDefinition == null) {
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processId);
return result;
} else {
+
return createProcessDefinition(
loginUser,
- projectName,
+ targetProject.getName(),
processDefinition.getName() + "_copy_" +
System.currentTimeMillis(),
processDefinition.getProcessDefinitionJson(),
processDefinition.getDescription(),
processDefinition.getLocations(),
processDefinition.getConnects());
+
+ }
+ }
+
+ /**
+ * batch copy or move process definition
+ * @param loginUser loginUser
+ * @param projectName projectName
+ * @param processDefinitionIds processDefinitionIds
+ * @param targetProjectId targetProjectId
+ * @param isCopy isCopy
+ * @return
+ */
+ public Map<String, Object> batchCopyOrMoveProcessDefinition(User loginUser,
+ String projectName,
+ String
processDefinitionIds,
+ int targetProjectId,
boolean isCopy){
+ Map<String, Object> result = new HashMap<>(5);
+ List<String> failedIdList = new ArrayList<>();
+
+ if (StringUtils.isEmpty(processDefinitionIds)) {
+ putMsg(result, Status.PROCESS_DEFINITION_IDS_IS_EMPTY,
processDefinitionIds);
+ return result;
+ }
+
+ //check src project auth
+ Map<String, Object> checkResult = checkProjectAndAuth(loginUser,
projectName);
+ if (checkResult != null) {
+ return checkResult;
+ }
+
+ Project targetProject = projectMapper.queryDetailById(targetProjectId);
+ if(targetProject == null){
+ putMsg(result, Status.PROJECT_NOT_FOUNT, targetProjectId);
+ return result;
+ }
+
+ if(!(targetProject.getName()).equals(projectName)){
+ Map<String, Object> checkTargetProjectResult =
checkProjectAndAuth(loginUser, targetProject.getName());
+ if (checkTargetProjectResult != null) {
+ return checkTargetProjectResult;
+ }
+ }
+
+ String[] processDefinitionIdList =
processDefinitionIds.split(Constants.COMMA);
+ if(isCopy){
+ doBatchCopyProcessDefinition(loginUser, targetProject,
failedIdList, processDefinitionIdList);
+ }else{
+ doBatchMoveProcessDefinition(targetProject, failedIdList,
processDefinitionIdList);
+ }
+
+ checkBatchOperateResult(projectName,targetProject.getName(),result,
failedIdList,isCopy);
+
+ return result;
+ }
+
+ /**
+ * batch move process definition
+ * @param targetProject targetProject
+ * @param failedIdList failedIdList
+ * @param processDefinitionIdList processDefinitionIdList
+ */
+ private void doBatchMoveProcessDefinition(Project targetProject,
List<String> failedIdList, String[] processDefinitionIdList) {
+ for(String processDefinitionId:processDefinitionIdList){
+ try {
+ Map<String, Object> moveProcessDefinitionResult =
+
moveProcessDefinition(Integer.valueOf(processDefinitionId),targetProject);
+ if
(!Status.SUCCESS.equals(moveProcessDefinitionResult.get(Constants.STATUS))) {
+ failedIdList.add((String)
moveProcessDefinitionResult.get(Constants.MSG));
+ logger.error((String)
moveProcessDefinitionResult.get(Constants.MSG));
+ }
+ } catch (Exception e) {
+ failedIdList.add(processDefinitionId);
+ }
+ }
+ }
+
+ /**
+ * batch copy process definition
+ * @param loginUser loginUser
+ * @param targetProject targetProject
+ * @param failedIdList failedIdList
+ * @param processDefinitionIdList processDefinitionIdList
+ */
+ private void doBatchCopyProcessDefinition(User loginUser, Project
targetProject, List<String> failedIdList, String[] processDefinitionIdList) {
+ for(String processDefinitionId:processDefinitionIdList){
+ try {
+ Map<String, Object> copyProcessDefinitionResult =
+
copyProcessDefinition(loginUser,Integer.valueOf(processDefinitionId),targetProject);
+ if
(!Status.SUCCESS.equals(copyProcessDefinitionResult.get(Constants.STATUS))) {
+ failedIdList.add((String)
copyProcessDefinitionResult.get(Constants.MSG));
Review comment:
I have two questions:
1 Follow your current design. There may be a splicing return. Part of the
error description and part of the id situation are not clear.
2 I think that the id should not be returned here, the process name should
be returned, and the front end should be prompted, which of the several process
errors is ok. If the id is returned, the front-end operator does not understand
which process problem these id refers to
我有两点疑问,
1 按照你现在设计。有可能会出现拼接返回 一部分是错误描述,一部分是id情况 ,这样描述不清晰了。
2
我觉得这里不应该返回id,应该返回流程名称。给前端提示,哪个几个流程错误就ok了,如果返回id,前端操作人员也不理解这些id指的是哪个流程问题。你觉得了
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]