This is an automated email from the ASF dual-hosted git repository.

aiceflower pushed a commit to branch release-0.9.4
in repository https://gitbox.apache.org/repos/asf/linkis.git

commit 23bfead9448282c9939afb97030dbf9873801048
Author: jftang <[email protected]>
AuthorDate: Wed Jun 3 17:50:06 2020 +0800

    1.add replication creator configuration from 'IDE' interface
    2.add 'unit' field for table 'linkis_config_key'
---
 db/linkis_ddl.sql                                  |  1 +
 db/linkis_dml.sql                                  |  4 +-
 db/module/linkis_configuration.sql                 |  1 +
 db/module/linkis_configuration_dml.sql             |  4 +-
 .../linkis/configuration/dao/ConfigMapper.java     | 18 +++++--
 .../linkis/configuration/dao/impl/ConfigMapper.xml | 45 +++++++++++++++++
 .../linkis/configuration/entity/ConfigKey.java     |  8 +++
 .../configuration/entity/ConfigKeyValue.java       |  9 ++++
 .../configuration/entity/ConfigKeyValueVO.java     | 27 ++++++++++
 .../restful/api/ConfigurationRestfulApi.java       | 58 ++++++++++++++++++++++
 .../util/ConfigurationConfiguration.java           | 27 ++++++++++
 .../service/ConfigurationService.scala             | 43 ++++++++++++++--
 12 files changed, 235 insertions(+), 10 deletions(-)

diff --git a/db/linkis_ddl.sql b/db/linkis_ddl.sql
index 206e5293df..b8462fb409 100644
--- a/db/linkis_ddl.sql
+++ b/db/linkis_ddl.sql
@@ -146,6 +146,7 @@ CREATE TABLE `linkis_config_key` (
   `is_hidden` tinyint(1) DEFAULT NULL COMMENT 'Whether it is hidden from user. 
If set to 1(true), then user cannot modify, however, it could still be used in 
back-end',
   `is_advanced` tinyint(1) DEFAULT NULL COMMENT 'Whether it is an advanced 
parameter. If set to 1(true), parameters would be displayed only when user 
choose to do so',
   `level` tinyint(1) DEFAULT NULL COMMENT 'Basis for displaying sorting in the 
front-end. Higher the level is, higher the rank the parameter gets',
+  `unit` varchar(64) DEFAULT NULL,
   PRIMARY KEY (`id`),
   KEY `application_id` (`application_id`)
 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4;
diff --git a/db/linkis_dml.sql b/db/linkis_dml.sql
index fb000d023c..b3edd58949 100644
--- a/db/linkis_dml.sql
+++ b/db/linkis_dml.sql
@@ -38,8 +38,8 @@ INSERT INTO `linkis_config_key` (`id`, `key`, `description`, 
`name`, `applicatio
 INSERT INTO `linkis_config_key` (`id`, `key`, `description`, `name`, 
`application_id`, `default_value`, `validate_type`, `validate_range`, 
`is_hidden`, `is_advanced`, `level`) VALUES (0, 
'wds.linkis.tmpfile.clean.time', 'tmp文件清理时间', 'tmp文件清理时间', @application_id, 
'10:00', 'None', NULL, '0', '0', '1');
 
 INSERT INTO `linkis_config_key` (`id`, `key`, `description`, `name`, 
`application_id`, `default_value`, `validate_type`, `validate_range`, 
`is_hidden`, `is_advanced`, `level`) VALUES (0, 
'wds.linkis.yarnqueue.cores.max', '取值范围:1-500,单位:个', '队列CPU使用上限', 
@application_id, '150', 'Regex', '^(?:[1-9]\\d?|[1234]\\d{2}|500)$', '0', '0', 
'1');
-INSERT INTO `linkis_config_key` (`id`, `key`, `description`, `name`, 
`application_id`, `default_value`, `validate_type`, `validate_range`, 
`is_hidden`, `is_advanced`, `level`) VALUES (0, 
'wds.linkis.yarnqueue.memory.max', '取值范围:1-1000,单位:G', '队列内存使用上限', 
@application_id, '300G', 'Regex', '^([1-9]\\d{0,2}|1000)(G|g)$', '0', '0', '1');
-INSERT INTO `linkis_config_key` (`id`, `key`, `description`, `name`, 
`application_id`, `default_value`, `validate_type`, `validate_range`, 
`is_hidden`, `is_advanced`, `level`) VALUES (0, 'wds.linkis.client.memory.max', 
'取值范围:1-1000,单位:G', '驱动器内存使用上限', @application_id, '20G', 'Regex', 
'^([1-9]\\d{0,1}|100)(G|g)$', '0', '0', '1');
+INSERT INTO `linkis_config_key` (`id`, `key`, `description`, `name`, 
`application_id`, `default_value`, `validate_type`, `validate_range`, 
`is_hidden`, `is_advanced`, `level`, `unit`) VALUES (0, 
'wds.linkis.yarnqueue.memory.max', '取值范围:1-1000,单位:G', '队列内存使用上限', 
@application_id, '300G', 'Regex', '^([1-9]\\d{0,2}|1000)(G|g)$', '0', '0', '1', 
'G');
+INSERT INTO `linkis_config_key` (`id`, `key`, `description`, `name`, 
`application_id`, `default_value`, `validate_type`, `validate_range`, 
`is_hidden`, `is_advanced`, `level`, `unit`) VALUES (0, 
'wds.linkis.client.memory.max', '取值范围:1-1000,单位:G', '驱动器内存使用上限', 
@application_id, '20G', 'Regex', '^([1-9]\\d{0,1}|100)(G|g)$', '0', '0', '1', 
'G');
 INSERT INTO `linkis_config_key` (`id`, `key`, `description`, `name`, 
`application_id`, `default_value`, `validate_type`, `validate_range`, 
`is_hidden`, `is_advanced`, `level`) VALUES (0, 'wds.linkis.instance', 
'范围:1-20,单位:个', '引擎最大并发数', @application_id, '10', 'NumInterval', '[1,20]', '0', 
'0', '1');
 
 
diff --git a/db/module/linkis_configuration.sql 
b/db/module/linkis_configuration.sql
index acc92cd81b..1f433220fc 100644
--- a/db/module/linkis_configuration.sql
+++ b/db/module/linkis_configuration.sql
@@ -61,6 +61,7 @@ CREATE TABLE `linkis_config_key` (
   `is_hidden` tinyint(1) DEFAULT NULL COMMENT 'Whether it is hidden from user. 
If set to 1(true), then user cannot modify, however, it could still be used in 
back-end',
   `is_advanced` tinyint(1) DEFAULT NULL COMMENT 'Whether it is an advanced 
parameter. If set to 1(true), parameters would be displayed only when user 
choose to do so',
   `level` tinyint(1) DEFAULT NULL COMMENT 'Basis for displaying sorting in the 
front-end. Higher the level is, higher the rank the parameter gets',
+  `unit` varchar(64) DEFAULT NULL,
   PRIMARY KEY (`id`),
   KEY `application_id` (`application_id`)
 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4;
diff --git a/db/module/linkis_configuration_dml.sql 
b/db/module/linkis_configuration_dml.sql
index 7b3b8e7d96..4e845aca3d 100644
--- a/db/module/linkis_configuration_dml.sql
+++ b/db/module/linkis_configuration_dml.sql
@@ -43,8 +43,8 @@ INSERT INTO `linkis_config_key` (`id`, `key`, `description`, 
`name`, `applicatio
 #INSERT INTO `linkis_config_key` (`id`, `key`, `description`, `name`, 
`application_id`, `default_value`, `validate_type`, `validate_range`, 
`is_hidden`, `is_advanced`, `level`) VALUES (0, 
'wds.linkis.tmpfile.clean.time', 'tmp文件清理时间', 'tmp文件清理时间', @application_id, 
'10:00', 'None', NULL, '0', '0', '1');
 
 #INSERT INTO `linkis_config_key` (`id`, `key`, `description`, `name`, 
`application_id`, `default_value`, `validate_type`, `validate_range`, 
`is_hidden`, `is_advanced`, `level`) VALUES (0, 
'wds.linkis.yarnqueue.cores.max', '取值范围:1-500,单位:个', '队列CPU使用上限', 
@application_id, '150', 'Regex', '^(?:[1-9]\\d?|[1234]\\d{2}|500)$', '0', '0', 
'1');
-#INSERT INTO `linkis_config_key` (`id`, `key`, `description`, `name`, 
`application_id`, `default_value`, `validate_type`, `validate_range`, 
`is_hidden`, `is_advanced`, `level`) VALUES (0, 
'wds.linkis.yarnqueue.memory.max', '取值范围:1-1000,单位:G', '队列内存使用上限', 
@application_id, '300G', 'Regex', '^([1-9]\\d{0,2}|1000)(G|g)$', '0', '0', '1');
-INSERT INTO `linkis_config_key` (`id`, `key`, `description`, `name`, 
`application_id`, `default_value`, `validate_type`, `validate_range`, 
`is_hidden`, `is_advanced`, `level`) VALUES (0, 'wds.linkis.client.memory.max', 
'取值范围:1-1000,单位:G', '驱动器内存使用上限', @application_id, '20G', 'Regex', 
'^([1-9]\\d{0,1}|100)(G|g)$', '0', '0', '1');
+#INSERT INTO `linkis_config_key` (`id`, `key`, `description`, `name`, 
`application_id`, `default_value`, `validate_type`, `validate_range`, 
`is_hidden`, `is_advanced`, `level`, `unit`) VALUES (0, 
'wds.linkis.yarnqueue.memory.max', '取值范围:1-1000,单位:G', '队列内存使用上限', 
@application_id, '300G', 'Regex', '^([1-9]\\d{0,2}|1000)(G|g)$', '0', '0', 
'1','G');
+INSERT INTO `linkis_config_key` (`id`, `key`, `description`, `name`, 
`application_id`, `default_value`, `validate_type`, `validate_range`, 
`is_hidden`, `is_advanced`, `level`, `unit`) VALUES (0, 
'wds.linkis.client.memory.max', '取值范围:1-100,单位:G', '驱动器内存使用上限', 
@application_id, '20G', 'Regex', '^([1-9]\\d{0,1}|100)(G|g)$', '0', '0', '1', 
'G');
 #INSERT INTO `linkis_config_key` (`id`, `key`, `description`, `name`, 
`application_id`, `default_value`, `validate_type`, `validate_range`, 
`is_hidden`, `is_advanced`, `level`) VALUES (0, 'wds.linkis.instance', 
'范围:1-20,单位:个', '引擎最大并发数', @application_id, '10', 'NumInterval', '[1,20]', '0', 
'0', '1');
 
 
diff --git 
a/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/dao/ConfigMapper.java
 
b/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/dao/ConfigMapper.java
index ba59a45b65..0e51693145 100644
--- 
a/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/dao/ConfigMapper.java
+++ 
b/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/dao/ConfigMapper.java
@@ -35,16 +35,28 @@ public interface ConfigMapper {
 
     ConfigTree selectTreeByTreeID(@Param("id") Long id);
 
-    List<ConfigKey> selectKeysByTreeID(@Param("treeID") Long 
treeID,@Param("creatorID") Long creatorID);
+    List<ConfigKey> selectKeysByTreeID(@Param("treeID") Long treeID, 
@Param("creatorID") Long creatorID);
 
     void insertValue(ConfigKeyUser configKeyUser);
 
     ConfigKeyUser selectValueByKeyId(@Param("keyID") Long keyID, 
@Param("userName") String userName, @Param("appID") Long appID);
 
-    List<ConfigKeyValue> selectAllAppKVs( @Param("creatorID")Long 
creatorID,@Param("appID") Long appID);
+    List<ConfigKeyValue> selectAllAppKVs(@Param("creatorID") Long creatorID, 
@Param("appID") Long appID);
 
-    void updateUserValue(@Param("value") String value,@Param("id") Long id);
+    void updateUserValue(@Param("value") String value, @Param("id") Long id);
 
     ConfigKey selectKeyByKeyID(Long keyID);
 
+    List<ConfigKey> listKeyByCreatorAndAppName(@Param("creatorID") Long 
creatorID, @Param("appID") Long appID);
+
+    void insertCreator(String creator);
+
+    Long selectTreeIDByKeyID(Long keyID);
+
+    void insertKey(ConfigKey key);
+
+    void insertKeyTree(@Param("keyID") Long keyID, @Param("treeID") Long 
treeID);
+
+    ConfigTree selectTreeByAppIDAndName(@Param("appID") Long appID, 
@Param("treeName") String treeName);
+
 }
diff --git 
a/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/dao/impl/ConfigMapper.xml
 
b/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/dao/impl/ConfigMapper.xml
index 0737ae28ad..610f935675 100644
--- 
a/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/dao/impl/ConfigMapper.xml
+++ 
b/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/dao/impl/ConfigMapper.xml
@@ -24,6 +24,10 @@
         id, `application_id`,`key_id`,`user_name`,`value`
     </sql>
 
+    <sql id="key_List">
+        id, 
`key`,`description`,`name`,`application_id`,`default_value`,`validate_type`,`validate_range`,`is_hidden`,`is_advanced`,`level`,`unit`
+    </sql>
+
     <select id="selectAppIDByAppName" resultType="Long">
         SELECT bda.id from linkis_application bda WHERE bda.name=#{name}
     </select>
@@ -113,4 +117,45 @@
         SELECT * from linkis_config_key where id = #{keyID}
     </select>
 
+    <select id="listKeyByCreatorAndAppName" 
resultType="com.webank.wedatasphere.linkis.configuration.entity.ConfigKey">
+        SELECT
+            `key`.*
+        FROM
+            linkis_config_tree tree,
+            linkis_config_key_tree kt,
+            linkis_config_key `key`
+        WHERE
+            tree.id = kt.tree_id
+        AND kt.key_id = `key`.id
+        AND `key`.application_id = #{creatorID}
+        AND tree.application_id = #{appID}
+    </select>
+
+    <insert id="insertCreator">
+        INSERT INTO linkis_application values(NULL,#{creator},NULL,NULL)
+    </insert>
+
+    <select id="selectTreeIDByKeyID" resultType="Long">
+        SELECT
+            kt.tree_id
+        FROM
+            linkis_config_key_tree kt
+        WHERE
+            kt.key_id = #{keyID}
+    </select>
+
+    <insert id="insertKey" useGeneratedKeys="true" keyProperty="id" 
parameterType ="com.webank.wedatasphere.linkis.configuration.entity.ConfigKey">
+        INSERT INTO linkis_config_key(<include refid="key_List"/>)
+        VALUES (#{id},#{key},#{description},
+        
#{name},#{applicationID},#{defaultValue},#{validateType},#{validateRange},#{isAdvanced},#{isHidden},#{level},#{unit})
+    </insert>
+
+    <insert id="insertKeyTree">
+        INSERT INTO linkis_config_key_tree values(NULL,#{keyID},#{treeID})
+    </insert>
+
+    <select id="selectTreeByAppIDAndName" 
resultType="com.webank.wedatasphere.linkis.configuration.entity.ConfigTree">
+        SELECT * FROM  linkis_config_tree WHERE `name` = #{treeName} AND 
`application_id` = #{appID}
+    </select>
+
 </mapper>
\ No newline at end of file
diff --git 
a/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/entity/ConfigKey.java
 
b/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/entity/ConfigKey.java
index e4af929c2b..ca5dc197f9 100644
--- 
a/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/entity/ConfigKey.java
+++ 
b/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/entity/ConfigKey.java
@@ -32,7 +32,15 @@ public class ConfigKey {
     private Boolean isAdvanced;
     private Boolean isHidden;
     private Integer level;
+    private String unit;
 
+    public String getUnit() {
+        return unit;
+    }
+
+    public void setUnit(String unit) {
+        this.unit = unit;
+    }
 
     public Long getId() {
         return id;
diff --git 
a/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/entity/ConfigKeyValue.java
 
b/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/entity/ConfigKeyValue.java
index 580930699c..387d0bcffd 100644
--- 
a/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/entity/ConfigKeyValue.java
+++ 
b/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/entity/ConfigKeyValue.java
@@ -36,6 +36,15 @@ public class ConfigKeyValue {
     private Long applicationID;
     private String userName;
     private String value;
+    private String unit;
+
+    public String getUnit() {
+        return unit;
+    }
+
+    public void setUnit(String unit) {
+        this.unit = unit;
+    }
 
     public Long getKeyID() {
         return keyID;
diff --git 
a/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/entity/ConfigKeyValueVO.java
 
b/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/entity/ConfigKeyValueVO.java
index a3f0ab68c7..74cd232aa8 100644
--- 
a/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/entity/ConfigKeyValueVO.java
+++ 
b/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/entity/ConfigKeyValueVO.java
@@ -31,6 +31,33 @@ public class ConfigKeyValueVO {
     private String value;
     private Integer level;
     private String defaultValue;
+    private String validateType;
+    private String validateRange;
+    private String unit;
+
+    public String getUnit() {
+        return unit;
+    }
+
+    public void setUnit(String unit) {
+        this.unit = unit;
+    }
+
+    public String getValidateRange() {
+        return validateRange;
+    }
+
+    public void setValidateRange(String validateRange) {
+        this.validateRange = validateRange;
+    }
+
+    public String getValidateType() {
+        return validateType;
+    }
+
+    public void setValidateType(String validateType) {
+        this.validateType = validateType;
+    }
 
     public Long getKeyID() {
         return keyID;
diff --git 
a/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/restful/api/ConfigurationRestfulApi.java
 
b/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/restful/api/ConfigurationRestfulApi.java
index 24bc0385da..ecb571c5db 100644
--- 
a/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/restful/api/ConfigurationRestfulApi.java
+++ 
b/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/restful/api/ConfigurationRestfulApi.java
@@ -20,7 +20,9 @@ import 
com.webank.wedatasphere.linkis.configuration.entity.ConfigKey;
 import com.webank.wedatasphere.linkis.configuration.entity.ConfigKeyUser;
 import com.webank.wedatasphere.linkis.configuration.entity.ConfigKeyValueVO;
 import com.webank.wedatasphere.linkis.configuration.entity.ConfigTree;
+import 
com.webank.wedatasphere.linkis.configuration.exception.ConfigurationException;
 import 
com.webank.wedatasphere.linkis.configuration.service.ConfigurationService;
+import 
com.webank.wedatasphere.linkis.configuration.util.ConfigurationConfiguration;
 import com.webank.wedatasphere.linkis.server.BDPJettyServerHelper;
 import com.webank.wedatasphere.linkis.server.Message;
 import com.webank.wedatasphere.linkis.server.security.SecurityFilter;
@@ -28,6 +30,7 @@ import org.codehaus.jackson.JsonNode;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.*;
@@ -52,6 +55,61 @@ public class ConfigurationRestfulApi {
 
     ObjectMapper mapper = new ObjectMapper();
 
+    @GET
+    @Path("/addKey")
+    public Response addKey(@Context HttpServletRequest req,
+                                   @QueryParam("appName") String appName,
+                                   @QueryParam("creator") String creator,
+                                   @QueryParam("token") String token,
+                                   @QueryParam("treeName") String treeName,
+                                   @QueryParam("keyJson") String keyJson) 
throws ConfigurationException {
+        String username = SecurityFilter.getLoginUsername(req);
+        if(StringUtils.isEmpty(appName) || StringUtils.isEmpty(creator) || 
StringUtils.isEmpty(token)){
+            throw new ConfigurationException("params cannot be empty!");
+        }
+        //todo检验token
+        if(!token.equals(ConfigurationConfiguration.COPYKEYTOKEN)){
+            throw new ConfigurationException("token is error");
+        }
+        List<ConfigKey> keys = 
configurationService.listKeyByCreatorAndAppName(creator,appName);
+        if(keys.isEmpty()){
+            //判断和copyKeyFromIDE相反,只允许在有key的情况下添加
+            throw new ConfigurationException(creator + ":" + appName +  ",keys 
is empty ,cannot add key");
+        }
+        ConfigKey configKey = BDPJettyServerHelper.gson().fromJson(keyJson, 
ConfigKey.class);
+        // TODO: 2019/12/30  configKey参数校验
+        configurationService.addKey(creator,appName,treeName,configKey);
+        return Message.messageToResponse(Message.ok());
+    }
+
+
+    @GET
+    @Path("/copyKeyFromIDE")
+    public Response copyKeyFromIDE(@Context HttpServletRequest req,
+                                  @QueryParam("appName") String appName,
+                                  @QueryParam("creator") String creator,
+                                  @QueryParam("token") String token) throws 
ConfigurationException {
+        String username = SecurityFilter.getLoginUsername(req);
+        if(StringUtils.isEmpty(appName) || StringUtils.isEmpty(creator) || 
StringUtils.isEmpty(token)){
+            throw new ConfigurationException("params cannot be empty!");
+        }
+        //todo检验token
+        if(!token.equals(ConfigurationConfiguration.COPYKEYTOKEN)){
+            throw new ConfigurationException("token is error");
+        }
+        List<ConfigKey> keys = 
configurationService.listKeyByCreatorAndAppName(creator,appName);
+        if(!keys.isEmpty()){
+            throw new ConfigurationException(creator + ":" + appName +  ",keys 
is no empty cannot copy key");
+        }
+        configurationService.insertCreator(creator);
+        List<ConfigKey> IDEkeys = 
configurationService.listKeyByCreatorAndAppName("IDE",appName);
+        if (IDEkeys.isEmpty()) {
+            throw new ConfigurationException("IDE:"+ appName + ",cannot find 
any key to copy");
+        }
+        IDEkeys.forEach(k 
->configurationService.copyKeyFromIDE(k,creator,appName));
+        return Message.messageToResponse(Message.ok());
+    }
+
     @GET
     @Path("/getFullTreesByAppName")
     public Response getFullTreesByAppName(@Context HttpServletRequest req, 
@QueryParam("appName") String appName, @QueryParam("creator") String creator) {
diff --git 
a/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/util/ConfigurationConfiguration.java
 
b/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/util/ConfigurationConfiguration.java
new file mode 100644
index 0000000000..8ce5b0c706
--- /dev/null
+++ 
b/publicService/configuration/src/main/java/com/webank/wedatasphere/linkis/configuration/util/ConfigurationConfiguration.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2019 WeBank
+ *
+ * Licensed 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 com.webank.wedatasphere.linkis.configuration.util;
+
+import com.webank.wedatasphere.linkis.common.conf.CommonVars$;
+
+/**
+ * Created by patinousward on 2019/12/30.
+ */
+public class ConfigurationConfiguration {
+
+    public static final String COPYKEYTOKEN = 
CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token","e1051-s").getValue();
+}
diff --git 
a/publicService/configuration/src/main/scala/com/webank/wedatasphere/linkis/configuration/service/ConfigurationService.scala
 
b/publicService/configuration/src/main/scala/com/webank/wedatasphere/linkis/configuration/service/ConfigurationService.scala
index 5628c368b9..b692243e46 100644
--- 
a/publicService/configuration/src/main/scala/com/webank/wedatasphere/linkis/configuration/service/ConfigurationService.scala
+++ 
b/publicService/configuration/src/main/scala/com/webank/wedatasphere/linkis/configuration/service/ConfigurationService.scala
@@ -21,7 +21,7 @@ import java.util
 
 import com.webank.wedatasphere.linkis.common.utils.{Logging, Utils}
 import com.webank.wedatasphere.linkis.configuration.dao.ConfigMapper
-import com.webank.wedatasphere.linkis.configuration.entity._
+import com.webank.wedatasphere.linkis.configuration.entity.{ConfigKey, _}
 import 
com.webank.wedatasphere.linkis.configuration.exception.ConfigurationException
 import com.webank.wedatasphere.linkis.configuration.util.Constants
 import com.webank.wedatasphere.linkis.configuration.validate.ValidatorManager
@@ -31,6 +31,7 @@ import org.apache.commons.lang.StringUtils
 import org.springframework.beans.BeanUtils
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.stereotype.Service
+import org.springframework.transaction.annotation.Transactional
 
 /**
   * Created by allenlliu on 2019/4/8.
@@ -42,9 +43,44 @@ class ConfigurationService extends Logging {
 
   @Autowired private var validatorManager: ValidatorManager = _
 
+  @Transactional
+  def addKey(creator:String,appName:String,treeName:String,key: ConfigKey): 
Unit ={
+    val appID:Long = configMapper.selectAppIDByAppName(appName)
+    val creatorID: Long = configMapper.selectAppIDByAppName(creator)
+    val tree:ConfigTree = configMapper.selectTreeByAppIDAndName(appID,treeName)
+    key.setId(null)
+    key.setApplicationID(creatorID)
+    configMapper.insertKey(key)
+    configMapper.insertKeyTree(key.getId,tree.getId)
+  }
+
+  def insertCreator(creator:String): Unit ={
+    val creatorID: Long = configMapper.selectAppIDByAppName(creator)
+    if(creatorID == null) configMapper.insertCreator(creator) else 
warn(s"creator${creator} exists")
+  }
+
+  def listKeyByCreatorAndAppName(creator:String, 
appName:String):java.util.List[ConfigKey] ={
+    val creatorID: Long = configMapper.selectAppIDByAppName(creator)
+    val appID:Long = configMapper.selectAppIDByAppName(appName)
+    configMapper.listKeyByCreatorAndAppName(creatorID,appID)
+  }
+
+  @Transactional
+  def copyKeyFromIDE(key:ConfigKey,creator:String, appName:String) ={
+    val creatorID: Long = configMapper.selectAppIDByAppName(creator)
+    key.setApplicationID(creatorID)
+    val treeID = configMapper.selectTreeIDByKeyID(key.getId)
+    key.setId(null)
+    configMapper.insertKey(key)
+    configMapper.insertKeyTree(key.getId,treeID)
+  }
+
 
   def updateUserValue(setting: ConfigKeyValueVO) = {
     if (!StringUtils.isEmpty(setting.getValue)) {
+      if(!StringUtils.isEmpty(setting.getUnit) && 
!setting.getValue.contains(setting.getUnit) && 
!setting.getValue.contains(setting.getUnit.toLowerCase)){
+        setting.setValue(setting.getValue + setting.getUnit)
+      }
       val key = configMapper.selectKeyByKeyID(setting.getKeyID)
       info(s"Save parameter ${key.getKey} value ${setting.getValue} is not 
empty, enter checksum...(保存参数${key.getKey}值${setting.getValue}不为空,进入校验...)")
       if 
(!validatorManager.getOrCreateValidator(key.getValidateType).validate(setting.getValue,
 key.getValidateRange)) {
@@ -83,6 +119,7 @@ class ConfigurationService extends Logging {
     vo.setValidateType(key.getValidateType)
     vo.setValue(value.getValue)
     vo.setValueID(value.getId)
+    vo.setUnit(key.getUnit)
     vo
   }
 
@@ -138,8 +175,8 @@ class ConfigurationService extends Logging {
   }
 
   private def getValueByKeyId(keyID: Long, userName: String, appName: String): 
ConfigKeyUser = {
-    val appID = configMapper.selectAppIDByAppName(appName);
-    configMapper.selectValueByKeyId(keyID, userName, appID);
+    val appID = configMapper.selectAppIDByAppName(appName)
+    configMapper.selectValueByKeyId(keyID, userName, appID)
   }
 
   def queryAppConfigWithGlobal(userName: String, creator: String, appName: 
String, isMerge: Boolean): ResponseQueryConfig = {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to