From 1eaf1f62349cdd469bce092297bacfc7893d1d0d Mon Sep 17 00:00:00 2001 From: JinyLeeChina <42576980+JinyLeeChina@users.noreply.github.com> Date: Wed, 24 Mar 2021 11:44:14 +0800 Subject: [PATCH] [Feature][JsonSplit] fix taskId in processDefinitionJson (#5136) * modify checkDAGRing and ProcessService method * merge * modify dagRing * modify process instance for project home page * fix save process bug * codeStyle * Fix logical bug in saving process definition * codeSytle * Fix bug in interface of queryProcessDefinitionList * codeSytle * Fix api bug" * fix taskId in processDefinitionJson Co-authored-by: JinyLeeChina <297062848@qq.com> --- .../common/utils/StringUtils.java | 30 +++++++++++++++++++ .../service/process/ProcessService.java | 8 +++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/StringUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/StringUtils.java index e6cd041c57..3ec1a2e39b 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/StringUtils.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/StringUtils.java @@ -23,6 +23,8 @@ public class StringUtils { public static final String EMPTY = ""; + public static final int INDEX_NOT_FOUND = -1; + private StringUtils() { throw new UnsupportedOperationException("Construct StringUtils"); } @@ -89,4 +91,32 @@ public class StringUtils { public static boolean equalsIgnoreCase(String str1, String str2) { return str1 == null ? str2 == null : str1.equalsIgnoreCase(str2); } + + public static String substringBefore(final String str, final String separator) { + if (isEmpty(str) || separator == null) { + return str; + } + if (separator.isEmpty()) { + return EMPTY; + } + final int pos = str.indexOf(separator); + if (pos == INDEX_NOT_FOUND) { + return str; + } + return str.substring(0, pos); + } + + public static String substringAfter(final String str, final String separator) { + if (isEmpty(str)) { + return str; + } + if (separator == null) { + return EMPTY; + } + final int pos = str.indexOf(separator); + if (pos == INDEX_NOT_FOUND) { + return EMPTY; + } + return str.substring(pos + separator.length()); + } } diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java index a1f5eca8b8..2c826dc592 100644 --- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java +++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java @@ -2239,7 +2239,8 @@ public class ProcessService { } private void setTaskFromTaskNode(TaskNode taskNode, TaskDefinition taskDefinition) { - taskDefinition.setName(taskNode.getName()); + // TODO for the front-end UI, name with id + taskDefinition.setName(taskNode.getId() + "|" + taskNode.getName()); taskDefinition.setDescription(taskNode.getDesc()); taskDefinition.setTaskType(TaskType.of(taskNode.getType())); taskDefinition.setTaskParams(TaskType.of(taskNode.getType()) == TaskType.DEPENDENT ? taskNode.getDependence() : taskNode.getParams()); @@ -2499,9 +2500,10 @@ public class ProcessService { Map taskDefinitionLogMap = taskDefinitionLogs.stream().collect(Collectors.toMap(TaskDefinitionLog::getCode, log -> log)); taskNodeMap.forEach((k, v) -> { TaskDefinitionLog taskDefinitionLog = taskDefinitionLogMap.get(k); - v.setId("task-" + taskDefinitionLog.getId()); + // TODO split from name + v.setId(StringUtils.substringBefore(taskDefinitionLog.getName(), "|")); v.setCode(taskDefinitionLog.getCode()); - v.setName(taskDefinitionLog.getName()); + v.setName(StringUtils.substringAfter(taskDefinitionLog.getName(), "|")); v.setDesc(taskDefinitionLog.getDescription()); v.setType(taskDefinitionLog.getTaskType().getDescp().toUpperCase()); v.setRunFlag(taskDefinitionLog.getFlag() == Flag.YES ? Constants.FLOWNODE_RUN_FLAG_NORMAL : Constants.FLOWNODE_RUN_FLAG_FORBIDDEN);