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/incubator-dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 68de43a  [Fix-4776][Alert] Alert instance edit page partial parameter 
values are not displayed (#4782)
68de43a is described below

commit 68de43ad2754a3b4d753c6e7ffa7b045b132d307
Author: zhuangchong <[email protected]>
AuthorDate: Fri Feb 19 09:50:47 2021 +0800

    [Fix-4776][Alert] Alert instance edit page partial parameter values are not 
displayed (#4782)
    
    * generate warning instance plugin params.
    
    * update PluginParamsTransfer.generatePluginParams method.
    
    * update code style in the AlertPluginInstanceServiceImpl class.
    
    * JSONUtils rollback.
    
    * rerun e2e test.
    
    * update alert channel generate params.
    
    * update email alert channel test class.
    
    * update json utils parse object method.
    
    * update the data structure of the alarm script plug-in script type 
parameter to String.
---
 .../dingtalk/DingTalkAlertChannelFactory.java      | 11 +++--
 .../alert/email/EmailAlertChannelFactory.java      | 23 +++++----
 .../alert/feishu/FeiShuAlertChannelFactory.java    | 11 +++--
 .../alert/script/ScriptAlertChannelFactory.java    |  4 +-
 .../plugin/alert/script/ScriptSender.java          |  6 +--
 .../plugin/alert/script/ScriptType.java            | 14 ------
 .../plugin/alert/script/ScriptSenderTest.java      |  2 +-
 .../impl/AlertPluginInstanceServiceImpl.java       | 20 ++------
 .../dolphinscheduler/spi/alert/AlertInfo.java      |  2 +-
 .../spi/params/PluginParamsTransfer.java           | 35 +++++++++++++-
 .../dolphinscheduler/spi/params/RadioParam.java    |  4 +-
 .../spi/params/base/PluginParams.java              | 22 ++++++---
 .../dolphinscheduler/spi/utils/Constants.java      | 55 ++++++++++++++++++++++
 .../dolphinscheduler/spi/utils/JSONUtils.java      | 34 +++++++++++++
 14 files changed, 181 insertions(+), 62 deletions(-)

diff --git 
a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java
 
b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java
index 0a6851a..b0f07b6 100644
--- 
a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java
+++ 
b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java
@@ -17,6 +17,11 @@
 
 package org.apache.dolphinscheduler.plugin.alert.dingtalk;
 
+import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_FALSE;
+import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_NO;
+import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_TRUE;
+import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_YES;
+
 import org.apache.dolphinscheduler.spi.alert.AlertChannel;
 import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory;
 import org.apache.dolphinscheduler.spi.params.InputParam;
@@ -52,9 +57,9 @@ public class DingTalkAlertChannelFactory implements 
AlertChannelFactory {
             .build();
         RadioParam isEnableProxy =
             
RadioParam.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_PROXY_ENABLE, 
DingTalkParamsConstants.NAME_DING_TALK_PROXY_ENABLE)
-                    .addParamsOptions(new ParamsOptions("YES", true, false))
-                    .addParamsOptions(new ParamsOptions("NO", false, false))
-                .setValue(true)
+                    .addParamsOptions(new ParamsOptions(STRING_YES, 
STRING_TRUE, false))
+                    .addParamsOptions(new ParamsOptions(STRING_NO, 
STRING_FALSE, false))
+                .setValue(STRING_TRUE)
                 .addValidate(Validate.newBuilder()
                     .setRequired(false)
                     .build())
diff --git 
a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactory.java
 
b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactory.java
index f8aa17f..ba71d79 100644
--- 
a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactory.java
+++ 
b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactory.java
@@ -17,6 +17,11 @@
 
 package org.apache.dolphinscheduler.plugin.alert.email;
 
+import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_FALSE;
+import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_NO;
+import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_TRUE;
+import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_YES;
+
 import org.apache.dolphinscheduler.spi.alert.AlertChannel;
 import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory;
 import org.apache.dolphinscheduler.spi.alert.AlertConstants;
@@ -72,9 +77,9 @@ public class EmailAlertChannelFactory implements 
AlertChannelFactory {
                 .build();
 
         RadioParam enableSmtpAuth = 
RadioParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_AUTH, 
MailParamsConstants.MAIL_SMTP_AUTH)
-                .addParamsOptions(new ParamsOptions("YES", true, false))
-                .addParamsOptions(new ParamsOptions("NO", false, false))
-                .setValue(true)
+                .addParamsOptions(new ParamsOptions(STRING_YES, STRING_TRUE, 
false))
+                .addParamsOptions(new ParamsOptions(STRING_NO, STRING_FALSE, 
false))
+                .setValue(STRING_TRUE)
                 .addValidate(Validate.newBuilder().setRequired(true).build())
                 .build();
 
@@ -87,16 +92,16 @@ public class EmailAlertChannelFactory implements 
AlertChannelFactory {
                 .build();
 
         RadioParam enableTls = 
RadioParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_STARTTLS_ENABLE, 
MailParamsConstants.MAIL_SMTP_STARTTLS_ENABLE)
-                .addParamsOptions(new ParamsOptions("YES", true, false))
-                .addParamsOptions(new ParamsOptions("NO", false, false))
-                .setValue(false)
+                .addParamsOptions(new ParamsOptions(STRING_YES, STRING_TRUE, 
false))
+                .addParamsOptions(new ParamsOptions(STRING_NO, STRING_FALSE, 
false))
+                .setValue(STRING_FALSE)
                 .addValidate(Validate.newBuilder().setRequired(true).build())
                 .build();
 
         RadioParam enableSsl = 
RadioParam.newBuilder(MailParamsConstants.NAME_MAIL_SMTP_SSL_ENABLE, 
MailParamsConstants.MAIL_SMTP_SSL_ENABLE)
-                .addParamsOptions(new ParamsOptions("YES", true, false))
-                .addParamsOptions(new ParamsOptions("NO", false, false))
-                .setValue(false)
+                .addParamsOptions(new ParamsOptions(STRING_YES, STRING_TRUE, 
false))
+                .addParamsOptions(new ParamsOptions(STRING_NO, STRING_FALSE, 
false))
+                .setValue(STRING_FALSE)
                 .addValidate(Validate.newBuilder().setRequired(true).build())
                 .build();
 
diff --git 
a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactory.java
 
b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactory.java
index 0e863f9..d85b423 100644
--- 
a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactory.java
+++ 
b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactory.java
@@ -17,6 +17,11 @@
 
 package org.apache.dolphinscheduler.plugin.alert.feishu;
 
+import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_FALSE;
+import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_NO;
+import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_TRUE;
+import static org.apache.dolphinscheduler.spi.utils.Constants.STRING_YES;
+
 import org.apache.dolphinscheduler.spi.alert.AlertChannel;
 import org.apache.dolphinscheduler.spi.alert.AlertChannelFactory;
 import org.apache.dolphinscheduler.spi.params.InputParam;
@@ -44,9 +49,9 @@ public class FeiShuAlertChannelFactory implements 
AlertChannelFactory {
                 .build();
         RadioParam isEnableProxy =
                 
RadioParam.newBuilder(FeiShuParamsConstants.NAME_FEI_SHU_PROXY_ENABLE, 
FeiShuParamsConstants.NAME_FEI_SHU_PROXY_ENABLE)
-                        .addParamsOptions(new ParamsOptions("YES", true, 
false))
-                        .addParamsOptions(new ParamsOptions("NO", false, 
false))
-                        .setValue(true)
+                        .addParamsOptions(new ParamsOptions(STRING_YES, 
STRING_TRUE, false))
+                        .addParamsOptions(new ParamsOptions(STRING_NO, 
STRING_FALSE, false))
+                        .setValue(STRING_TRUE)
                         .addValidate(Validate.newBuilder()
                                 .setRequired(false)
                                 .build())
diff --git 
a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java
 
b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java
index 70ab763..a81cb4f 100644
--- 
a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java
+++ 
b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java
@@ -56,8 +56,8 @@ public class ScriptAlertChannelFactory implements 
AlertChannelFactory {
                 .build();
 
         RadioParam scriptTypeParams = 
RadioParam.newBuilder(ScriptParamsConstants.NAME_SCRIPT_TYPE, 
ScriptParamsConstants.SCRIPT_TYPE)
-                .addParamsOptions(new 
ParamsOptions(ScriptType.SHELL.getDescp(), ScriptType.SHELL.getCode(), false))
-                .setValue(ScriptType.SHELL.getCode())
+                .addParamsOptions(new 
ParamsOptions(ScriptType.SHELL.getDescp(), ScriptType.SHELL.getDescp(), false))
+                .setValue(ScriptType.SHELL.getDescp())
                 .addValidate(Validate.newBuilder().setRequired(true).build())
                 .build();
 
diff --git 
a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
 
b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
index 377c318..638a500 100644
--- 
a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
+++ 
b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
@@ -33,19 +33,19 @@ public class ScriptSender {
 
     private String scriptPath;
 
-    private Integer scriptType;
+    private String scriptType;
 
     private String userParams;
 
     ScriptSender(Map<String, String> config) {
         scriptPath = config.get(ScriptParamsConstants.NAME_SCRIPT_PATH);
-        scriptType = 
Integer.parseInt(config.get(ScriptParamsConstants.NAME_SCRIPT_TYPE));
+        scriptType = config.get(ScriptParamsConstants.NAME_SCRIPT_TYPE);
         userParams = config.get(ScriptParamsConstants.NAME_SCRIPT_USER_PARAMS);
     }
 
     AlertResult sendScriptAlert(String msg) {
         AlertResult alertResult = new AlertResult();
-        if (ScriptType.of(scriptType).equals(ScriptType.SHELL)) {
+        if (ScriptType.SHELL.getDescp().equals(scriptType)) {
             return executeShellScript(msg);
         }
         return alertResult;
diff --git 
a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java
 
b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java
index 59b17d0..ff3b809 100644
--- 
a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java
+++ 
b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java
@@ -45,18 +45,4 @@ public enum ScriptType {
         return descp;
     }
 
-    private static final Map<Integer, ScriptType> SCRIPT_TYPE_MAP = new 
HashMap<>();
-
-    static {
-        for (ScriptType scriptType : ScriptType.values()) {
-            SCRIPT_TYPE_MAP.put(scriptType.code, scriptType);
-        }
-    }
-
-    public static ScriptType of(Integer code) {
-        if (SCRIPT_TYPE_MAP.containsKey(code)) {
-            return SCRIPT_TYPE_MAP.get(code);
-        }
-        throw new IllegalArgumentException("invalid code : " + code);
-    }
 }
diff --git 
a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java
 
b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java
index 1cd74cf..7f15ed8 100644
--- 
a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java
+++ 
b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java
@@ -40,7 +40,7 @@ public class ScriptSenderTest {
     @Before
     public void initScriptConfig() {
 
-        scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_TYPE, 
String.valueOf(ScriptType.SHELL.getCode()));
+        scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_TYPE, 
String.valueOf(ScriptType.SHELL.getDescp()));
         scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_USER_PARAMS, 
"userParams");
         scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_PATH, shellFilPath);
     }
diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertPluginInstanceServiceImpl.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertPluginInstanceServiceImpl.java
index 4d3d35a..c8ff99c 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertPluginInstanceServiceImpl.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertPluginInstanceServiceImpl.java
@@ -32,9 +32,6 @@ import 
org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper;
 import org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper;
 import org.apache.dolphinscheduler.dao.mapper.PluginDefineMapper;
 import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer;
-import org.apache.dolphinscheduler.spi.params.base.PluginParams;
-
-import org.apache.commons.collections4.MapUtils;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -250,26 +247,15 @@ public class AlertPluginInstanceServiceImpl extends 
BaseService implements Alert
     }
 
     /**
-     * parseToPluginUiParams
+     * parse To Plugin Ui Params
      *
      * @param pluginParamsMapString k-v data
      * @param pluginUiParams Complete parameters(include ui)
      * @return Complete parameters list(include ui)
      */
     private String parseToPluginUiParams(String pluginParamsMapString, String 
pluginUiParams) {
-        Map<String, String> paramsMap = JSONUtils.toMap(pluginParamsMapString);
-        if (MapUtils.isEmpty(paramsMap)) {
-            return null;
-        }
-        List<PluginParams> pluginParamsList = JSONUtils.toList(pluginUiParams, 
PluginParams.class);
-        List<PluginParams> newPluginParamsList = new 
ArrayList<>(pluginParamsList.size());
-        pluginParamsList.forEach(pluginParams -> {
-            pluginParams.setValue(paramsMap.get(pluginParams.getName()));
-            newPluginParamsList.add(pluginParams);
-
-        });
-
-        return JSONUtils.toJsonString(newPluginParamsList);
+        List<Map<String, Object>> pluginParamsList = 
PluginParamsTransfer.generatePluginParams(pluginParamsMapString, 
pluginUiParams);
+        return JSONUtils.toJsonString(pluginParamsList);
     }
 
     private boolean checkHasAssociatedAlertGroup(String id) {
diff --git 
a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertInfo.java
 
b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertInfo.java
index d6e5456..8f61fe2 100644
--- 
a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertInfo.java
+++ 
b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/alert/AlertInfo.java
@@ -27,7 +27,7 @@ public class AlertInfo {
     /**
      * all params this plugin need is in alertProps
      */
-    private Map<String,String> alertParams;
+    private Map<String, String> alertParams;
 
     /**
      * the alert content
diff --git 
a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/PluginParamsTransfer.java
 
b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/PluginParamsTransfer.java
index c9b14b9..3e709ad 100644
--- 
a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/PluginParamsTransfer.java
+++ 
b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/PluginParamsTransfer.java
@@ -17,6 +17,9 @@
 
 package org.apache.dolphinscheduler.spi.params;
 
+import static 
org.apache.dolphinscheduler.spi.utils.Constants.STRING_PLUGIN_PARAM_FIELD;
+import static 
org.apache.dolphinscheduler.spi.utils.Constants.STRING_PLUGIN_PARAM_VALUE;
+
 import org.apache.dolphinscheduler.spi.params.base.PluginParams;
 import org.apache.dolphinscheduler.spi.utils.JSONUtils;
 
@@ -24,6 +27,8 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import com.fasterxml.jackson.core.type.TypeReference;
+
 /**
  * plugin params pojo and json transfer tool
  */
@@ -44,8 +49,36 @@ public class PluginParamsTransfer {
         List<PluginParams> pluginParams = 
transferJsonToParamsList(paramsJsonStr);
         Map<String, String> paramsMap = new HashMap<>();
         for (PluginParams param : pluginParams) {
-            paramsMap.put(param.getName(), null != param.getValue() ? 
param.getValue().toString() : null);
+            paramsMap.put(param.getName(), param.getValue() == null ? null : 
param.getValue().toString());
         }
         return paramsMap;
     }
+
+    /**
+     * generate Plugin Params
+     *
+     * @param paramsJsonStr paramsJsonStr value
+     * @param pluginParamsTemplate pluginParamsTemplate
+     * @return return plugin params value
+     */
+    public static List<Map<String, Object>> generatePluginParams(String 
paramsJsonStr, String pluginParamsTemplate) {
+        Map<String, Object> paramsMap = JSONUtils.toMap(paramsJsonStr);
+        return generatePluginParams(paramsMap, pluginParamsTemplate);
+    }
+
+    /**
+     * generate Plugin Params
+     *
+     * @param paramsMap paramsMap
+     * @param pluginParamsTemplate pluginParamsTemplate
+     * @return return plugin params value
+     */
+    public static List<Map<String, Object>> generatePluginParams(Map<String, 
Object> paramsMap, String pluginParamsTemplate) {
+        if (paramsMap == null || paramsMap.isEmpty()) {
+            return null;
+        }
+        List<Map<String, Object>> pluginParamsList = 
JSONUtils.parseObject(pluginParamsTemplate, new TypeReference<List<Map<String, 
Object>>>() {});
+        pluginParamsList.forEach(pluginParams -> 
pluginParams.put(STRING_PLUGIN_PARAM_VALUE, 
paramsMap.get(pluginParams.get(STRING_PLUGIN_PARAM_FIELD))));
+        return pluginParamsList;
+    }
 }
diff --git 
a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/RadioParam.java
 
b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/RadioParam.java
index 824c7fe..2822dfd 100644
--- 
a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/RadioParam.java
+++ 
b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/RadioParam.java
@@ -17,6 +17,8 @@
 
 package org.apache.dolphinscheduler.spi.params;
 
+import static 
org.apache.dolphinscheduler.spi.utils.Constants.STRING_PLUGIN_PARAM_OPTIONS;
+
 import org.apache.dolphinscheduler.spi.params.base.FormType;
 import org.apache.dolphinscheduler.spi.params.base.ParamsOptions;
 import org.apache.dolphinscheduler.spi.params.base.PluginParams;
@@ -32,7 +34,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
  */
 public class RadioParam extends PluginParams {
 
-    @JsonProperty("options")
+    @JsonProperty(STRING_PLUGIN_PARAM_OPTIONS)
     private List<ParamsOptions> paramsOptionsList;
 
     private RadioParam(Builder builder) {
diff --git 
a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/base/PluginParams.java
 
b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/base/PluginParams.java
index 34d60a2..3815528 100644
--- 
a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/base/PluginParams.java
+++ 
b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/base/PluginParams.java
@@ -17,6 +17,14 @@
 
 package org.apache.dolphinscheduler.spi.params.base;
 
+import static 
org.apache.dolphinscheduler.spi.utils.Constants.STRING_PLUGIN_PARAM_FIELD;
+import static 
org.apache.dolphinscheduler.spi.utils.Constants.STRING_PLUGIN_PARAM_NAME;
+import static 
org.apache.dolphinscheduler.spi.utils.Constants.STRING_PLUGIN_PARAM_PROPS;
+import static 
org.apache.dolphinscheduler.spi.utils.Constants.STRING_PLUGIN_PARAM_TITLE;
+import static 
org.apache.dolphinscheduler.spi.utils.Constants.STRING_PLUGIN_PARAM_TYPE;
+import static 
org.apache.dolphinscheduler.spi.utils.Constants.STRING_PLUGIN_PARAM_VALIDATE;
+import static 
org.apache.dolphinscheduler.spi.utils.Constants.STRING_PLUGIN_PARAM_VALUE;
+
 import static java.util.Objects.requireNonNull;
 
 import java.util.List;
@@ -35,34 +43,34 @@ public class PluginParams {
     /**
      * param name
      */
-    @JsonProperty("field")
+    @JsonProperty(STRING_PLUGIN_PARAM_FIELD)
     protected String name;
 
     /**
      * param name
      */
-    @JsonProperty("name")
+    @JsonProperty(STRING_PLUGIN_PARAM_NAME)
     protected String fieldName;
 
-    @JsonProperty("props")
+    @JsonProperty(STRING_PLUGIN_PARAM_PROPS)
     protected ParamsProps props;
 
-    @JsonProperty("type")
+    @JsonProperty(STRING_PLUGIN_PARAM_TYPE)
     protected String formType;
 
     /**
      * Name displayed on the page
      */
-    @JsonProperty("title")
+    @JsonProperty(STRING_PLUGIN_PARAM_TITLE)
     protected String title;
 
     /**
      * default value or value input by user in the page
      */
-    @JsonProperty("value")
+    @JsonProperty(STRING_PLUGIN_PARAM_VALUE)
     protected Object value;
 
-    @JsonProperty("validate")
+    @JsonProperty(STRING_PLUGIN_PARAM_VALIDATE)
     protected List<Validate> validateList;
 
     protected PluginParams(Builder builder) {
diff --git 
a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/utils/Constants.java
 
b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/utils/Constants.java
new file mode 100644
index 0000000..d653d4e
--- /dev/null
+++ 
b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/utils/Constants.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.spi.utils;
+
+/**
+ * constants
+ */
+public class Constants {
+    private Constants() {
+        throw new IllegalStateException("Constants class");
+    }
+
+    /** alert plugin param field string **/
+    public static final String STRING_PLUGIN_PARAM_FIELD = "field";
+    /** alert plugin param name string **/
+    public static final String STRING_PLUGIN_PARAM_NAME = "name";
+    /** alert plugin param props string **/
+    public static final String STRING_PLUGIN_PARAM_PROPS = "props";
+    /** alert plugin param type string **/
+    public static final String STRING_PLUGIN_PARAM_TYPE = "type";
+    /** alert plugin param title string **/
+    public static final String STRING_PLUGIN_PARAM_TITLE = "title";
+    /** alert plugin param value string **/
+    public static final String STRING_PLUGIN_PARAM_VALUE = "value";
+    /** alert plugin param validate string **/
+    public static final String STRING_PLUGIN_PARAM_VALIDATE = "validate";
+    /** alert plugin param options string **/
+    public static final String STRING_PLUGIN_PARAM_OPTIONS = "options";
+
+
+    /** string true */
+    public static final String STRING_TRUE = "true";
+    /** string false */
+    public static final String STRING_FALSE = "false";
+    /** string yes */
+    public static final String STRING_YES = "YES";
+    /** string no */
+    public static final String STRING_NO = "NO";
+
+}
diff --git 
a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/utils/JSONUtils.java
 
b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/utils/JSONUtils.java
index 89d6e50..e87e210 100644
--- 
a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/utils/JSONUtils.java
+++ 
b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/utils/JSONUtils.java
@@ -24,11 +24,13 @@ import static 
com.fasterxml.jackson.databind.DeserializationFeature.READ_UNKNOWN
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.TimeZone;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.ObjectWriter;
 import com.fasterxml.jackson.databind.SerializationFeature;
@@ -125,6 +127,38 @@ public class JSONUtils {
     }
 
     /**
+     * json to map
+     *
+     * @param json json
+     * @return json to map
+     */
+    public static <K, V> Map<K, V> toMap(String json) {
+        return parseObject(json, new TypeReference<Map<K, V>>() {});
+    }
+
+    /**
+     * json to object
+     *
+     * @param json json string
+     * @param type type reference
+     * @param <T>
+     * @return return parse object
+     */
+    public static <T> T parseObject(String json, TypeReference<T> type) {
+        if (StringUtils.isEmpty(json)) {
+            return null;
+        }
+
+        try {
+            return objectMapper.readValue(json, type);
+        } catch (Exception e) {
+            logger.error("json to map exception!", e);
+        }
+
+        return null;
+    }
+
+    /**
      * object to json string
      *
      * @param object object

Reply via email to