You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ki...@apache.org on 2021/06/13 03:44:04 UTC
[dolphinscheduler] branch dev updated: [Fix-5483] [Bug][API] Can't
view variables in the page of Process Instance (#5631)
This is an automated email from the ASF dual-hosted git repository.
kirs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 0d5037e [Fix-5483] [Bug][API] Can't view variables in the page of Process Instance (#5631)
0d5037e is described below
commit 0d5037e7c37d7903d9172f165b348058f1ddbf88
Author: kyoty <ec...@gmail.com>
AuthorDate: Sun Jun 13 11:43:53 2021 +0800
[Fix-5483] [Bug][API] Can't view variables in the page of Process Instance (#5631)
---
.../api/service/impl/ProcessInstanceServiceImpl.java | 8 +++-----
.../apache/dolphinscheduler/common/utils/JSONUtils.java | 16 ++++++++++++++++
.../dolphinscheduler/common/utils/JSONUtilsTest.java | 8 ++++++++
3 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java
index 1a28411..a86a00b 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java
@@ -660,10 +660,9 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
for (TaskInstance taskInstance : taskInstanceList) {
TaskDefinitionLog taskDefinitionLog = taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(
taskInstance.getTaskCode(), taskInstance.getTaskDefinitionVersion());
- String parameter = taskDefinitionLog.getTaskParams();
- Map<String, String> map = JSONUtils.toMap(parameter);
- String localParams = map.get(LOCAL_PARAMS);
- if (localParams != null && !localParams.isEmpty()) {
+
+ String localParams = JSONUtils.getNodeString(taskDefinitionLog.getTaskParams(), LOCAL_PARAMS);
+ if (StringUtils.isNotEmpty(localParams)) {
localParams = ParameterUtils.convertParameterPlaceholders(localParams, timeParams);
List<Property> localParamsList = JSONUtils.toList(localParams, Property.class);
@@ -674,7 +673,6 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
localUserDefParams.put(taskDefinitionLog.getName(), localParamsMap);
}
}
-
}
return localUserDefParams;
}
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java
index b8c949b..9e929e3 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java
@@ -31,6 +31,7 @@ import java.util.List;
import java.util.Map;
import java.util.TimeZone;
+import com.fasterxml.jackson.core.JsonProcessingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -221,6 +222,21 @@ public class JSONUtils {
}
/**
+ * from the key-value generated json to get the str value no matter the real type of value
+ * @param json the json str
+ * @param nodeName key
+ * @return the str value of key
+ */
+ public static String getNodeString(String json, String nodeName) {
+ try {
+ JsonNode rootNode = objectMapper.readTree(json);
+ return rootNode.has(nodeName) ? rootNode.get(nodeName).toString() : "";
+ } catch (JsonProcessingException e) {
+ return "";
+ }
+ }
+
+ /**
* json to map
*
* @param json json
diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/JSONUtilsTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/JSONUtilsTest.java
index af12d5a..d9398f8 100644
--- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/JSONUtilsTest.java
+++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/JSONUtilsTest.java
@@ -147,6 +147,14 @@ public class JSONUtilsTest {
}
@Test
+ public void testNodeString() {
+ Assert.assertEquals("", JSONUtils.getNodeString("", "key"));
+ Assert.assertEquals("", JSONUtils.getNodeString("abc", "key"));
+ Assert.assertEquals("", JSONUtils.getNodeString("{\"bar\":\"foo\"}", "key"));
+ Assert.assertEquals("\"foo\"", JSONUtils.getNodeString("{\"bar\":\"foo\"}", "bar"));
+ }
+
+ @Test
public void testJsonByteArray() {
String str = "foo";
byte[] serializeByte = JSONUtils.toJsonByteArray(str);