Browse Source

[Fix-5483] [Bug][API] Can't view variables in the page of Process Instance (#5631)

2.0.7-release
kyoty 4 years ago committed by CalvinKirs
parent
commit
71a44f8a57
  1. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java
  2. 16
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java
  3. 8
      dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/JSONUtilsTest.java

8
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) { for (TaskInstance taskInstance : taskInstanceList) {
TaskDefinitionLog taskDefinitionLog = taskDefinitionLogMapper.queryByDefinitionCodeAndVersion( TaskDefinitionLog taskDefinitionLog = taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(
taskInstance.getTaskCode(), taskInstance.getTaskDefinitionVersion()); taskInstance.getTaskCode(), taskInstance.getTaskDefinitionVersion());
String parameter = taskDefinitionLog.getTaskParams();
Map<String, String> map = JSONUtils.toMap(parameter); String localParams = JSONUtils.getNodeString(taskDefinitionLog.getTaskParams(), LOCAL_PARAMS);
String localParams = map.get(LOCAL_PARAMS); if (StringUtils.isNotEmpty(localParams)) {
if (localParams != null && !localParams.isEmpty()) {
localParams = ParameterUtils.convertParameterPlaceholders(localParams, timeParams); localParams = ParameterUtils.convertParameterPlaceholders(localParams, timeParams);
List<Property> localParamsList = JSONUtils.toList(localParams, Property.class); List<Property> localParamsList = JSONUtils.toList(localParams, Property.class);
@ -674,7 +673,6 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
localUserDefParams.put(taskDefinitionLog.getName(), localParamsMap); localUserDefParams.put(taskDefinitionLog.getName(), localParamsMap);
} }
} }
} }
return localUserDefParams; return localUserDefParams;
} }

16
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.Map;
import java.util.TimeZone; import java.util.TimeZone;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -220,6 +221,21 @@ public class JSONUtils {
return parseObject(json, new TypeReference<Map<String, String>>() {}); return parseObject(json, new TypeReference<Map<String, String>>() {});
} }
/**
* 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 * json to map
* *

8
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/JSONUtilsTest.java

@ -146,6 +146,14 @@ public class JSONUtilsTest {
Assert.assertNull(JSONUtils.parseObject("foo", String.class)); Assert.assertNull(JSONUtils.parseObject("foo", String.class));
} }
@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 @Test
public void testJsonByteArray() { public void testJsonByteArray() {
String str = "foo"; String str = "foo";

Loading…
Cancel
Save