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

qicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 0106b0b  refactor admin : transfer  to copy properties, and optimize 
message.(#2706) (#2750)
0106b0b is described below

commit 0106b0bf2e9288d12e36c625b92953b921e5a391
Author: Yadong <[email protected]>
AuthorDate: Tue Jan 11 20:31:50 2022 +0800

    refactor admin : transfer  to copy properties, and optimize message.(#2706) 
(#2750)
---
 .../shenyu/admin/model/vo/DashboardUserEditVO.java |  5 +-
 .../admin/model/vo/LoginDashboardUserVO.java       | 11 +--
 .../service/impl/DashboardUserServiceImpl.java     |  5 +-
 .../admin/transfer/DashboardUserTransfer.java      | 94 ++++++++++++++++++++++
 .../shenyu/admin/utils/ShenyuResultMessage.java    |  8 +-
 .../grpc/resolver/ShenyuServiceInstanceLists.java  |  5 +-
 .../grpc/transfer/ShenyuServiceTransfer.java       | 42 ++++++++++
 7 files changed, 148 insertions(+), 22 deletions(-)

diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/DashboardUserEditVO.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/DashboardUserEditVO.java
index 14c860a..5a3834c 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/DashboardUserEditVO.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/DashboardUserEditVO.java
@@ -17,7 +17,7 @@
 
 package org.apache.shenyu.admin.model.vo;
 
-import org.springframework.beans.BeanUtils;
+import org.apache.shenyu.admin.transfer.DashboardUserTransfer;
 
 import java.util.List;
 import java.util.Objects;
@@ -89,8 +89,7 @@ public class DashboardUserEditVO extends DashboardUserVO {
      */
     public static DashboardUserEditVO buildDashboardUserEditVO(final 
DashboardUserVO dashboardUserVO, final List<RoleVO> roles, final List<RoleVO> 
allRoles) {
         return Optional.ofNullable(dashboardUserVO).map(item -> {
-            DashboardUserEditVO vo = new DashboardUserEditVO();
-            BeanUtils.copyProperties(item, vo);
+            DashboardUserEditVO vo = 
DashboardUserTransfer.INSTANCE.transfer2EditVO(dashboardUserVO);
             vo.setRoles(roles);
             vo.setAllRoles(allRoles);
             return vo;
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/LoginDashboardUserVO.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/LoginDashboardUserVO.java
index 14d9d1e..a589f0e 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/LoginDashboardUserVO.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/LoginDashboardUserVO.java
@@ -17,9 +17,7 @@
 
 package org.apache.shenyu.admin.model.vo;
 
-import org.springframework.beans.BeanUtils;
-
-import java.util.Optional;
+import org.apache.shenyu.admin.transfer.DashboardUserTransfer;
 
 /**
  * login dashboard return user info's vo.
@@ -63,11 +61,6 @@ public class LoginDashboardUserVO extends DashboardUserVO {
      * @return {@linkplain LoginDashboardUserVO}
      */
     public static LoginDashboardUserVO buildLoginDashboardUserVO(final 
DashboardUserVO dashboardUserVO) {
-        return Optional.ofNullable(dashboardUserVO)
-                .map(item -> {
-                    LoginDashboardUserVO vo = new LoginDashboardUserVO();
-                    BeanUtils.copyProperties(item, vo);
-                    return vo;
-                }).orElse(null);
+        return 
DashboardUserTransfer.INSTANCE.transferVO2LoginVO(dashboardUserVO);
     }
 }
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DashboardUserServiceImpl.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DashboardUserServiceImpl.java
index 3763431..285eb51 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DashboardUserServiceImpl.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DashboardUserServiceImpl.java
@@ -40,12 +40,12 @@ import org.apache.shenyu.admin.model.vo.DashboardUserVO;
 import org.apache.shenyu.admin.model.vo.LoginDashboardUserVO;
 import org.apache.shenyu.admin.model.vo.RoleVO;
 import org.apache.shenyu.admin.service.DashboardUserService;
+import org.apache.shenyu.admin.transfer.DashboardUserTransfer;
 import org.apache.shenyu.admin.utils.AesUtils;
 import org.apache.shenyu.admin.utils.JwtUtils;
 import org.apache.shenyu.common.constant.AdminConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeanUtils;
 import org.springframework.ldap.NameNotFoundException;
 import org.springframework.ldap.core.LdapTemplate;
 import org.springframework.ldap.support.LdapEncoder;
@@ -269,8 +269,7 @@ public class DashboardUserServiceImpl implements 
DashboardUserService {
                             .enabled(true)
                             .build();
                     createOrUpdate(dashboardUserDTO);
-                    dashboardUserVO = new DashboardUserVO();
-                    BeanUtils.copyProperties(dashboardUserDTO, 
dashboardUserVO);
+                    dashboardUserVO = 
DashboardUserTransfer.INSTANCE.transferDTO2VO(dashboardUserDTO);
                 }
             }
             return dashboardUserVO;
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/transfer/DashboardUserTransfer.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/transfer/DashboardUserTransfer.java
new file mode 100644
index 0000000..5a1f93e
--- /dev/null
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/transfer/DashboardUserTransfer.java
@@ -0,0 +1,94 @@
+/*
+ * 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.shenyu.admin.transfer;
+
+import org.apache.shenyu.admin.model.dto.DashboardUserDTO;
+import org.apache.shenyu.admin.model.vo.DashboardUserEditVO;
+import org.apache.shenyu.admin.model.vo.DashboardUserVO;
+import org.apache.shenyu.admin.model.vo.LoginDashboardUserVO;
+
+import java.util.Optional;
+
+/**
+ * The interface dashboard user transfer.
+ */
+public enum DashboardUserTransfer {
+
+    /**
+     * The constant INSTANCE.
+     */
+    INSTANCE;
+
+    /**
+     * conversion data to VO
+     * @param dashboardUserDTO original data
+     * @return {@linkplain DashboardUserVO}
+     */
+    public DashboardUserVO transferDTO2VO(final DashboardUserDTO 
dashboardUserDTO) {
+        return Optional.ofNullable(dashboardUserDTO).map(data -> {
+                    DashboardUserVO dashboardVO = new DashboardUserVO();
+                    dashboardVO.setId(data.getId());
+                    dashboardVO.setUserName(data.getUserName());
+                    dashboardVO.setPassword(data.getPassword());
+                    dashboardVO.setRole(data.getRole());
+                    dashboardVO.setEnabled(data.getEnabled());
+                    return dashboardVO;
+                })
+                .orElseGet(null);
+    }
+
+    /**
+     * conversion dashboardUserVO to loginDashboardUserVO
+     * @param dashboardUserVO original data
+     * @return {@linkplain LoginDashboardUserVO}
+     */
+    public LoginDashboardUserVO transferVO2LoginVO(final DashboardUserVO 
dashboardUserVO) {
+        return Optional.ofNullable(dashboardUserVO).map(data -> {
+                    LoginDashboardUserVO dashboardVO = new 
LoginDashboardUserVO();
+                    dashboardVO.setId(data.getId());
+                    dashboardVO.setUserName(data.getUserName());
+                    dashboardVO.setPassword(data.getPassword());
+                    dashboardVO.setRole(data.getRole());
+                    dashboardVO.setEnabled(data.getEnabled());
+                    dashboardVO.setDateCreated(data.getDateCreated());
+                    dashboardVO.setDateUpdated(data.getDateUpdated());
+                    return dashboardVO;
+                })
+                .orElseGet(null);
+    }
+
+    /**
+     * conversion dashboardUserVO to dashboardUserEditVO
+     * @param dashboardUserVO
+     * @return {@linkplain DashboardUserEditVO}
+     */
+    public DashboardUserEditVO transfer2EditVO(final DashboardUserVO 
dashboardUserVO) {
+        return Optional.ofNullable(dashboardUserVO).map(data -> {
+                    DashboardUserEditVO vo = new DashboardUserEditVO();
+                    vo.setId(data.getId());
+                    vo.setPassword(data.getPassword());
+                    vo.setUserName(data.getUserName());
+                    vo.setRole(data.getRole());
+                    vo.setEnabled(data.getEnabled());
+                    vo.setDateCreated(data.getDateCreated());
+                    vo.setDateUpdated(data.getDateUpdated());
+                    return vo;
+                }).orElseGet(null);
+    }
+
+}
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/ShenyuResultMessage.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/ShenyuResultMessage.java
index 49ffe0a..5bb407e 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/ShenyuResultMessage.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/ShenyuResultMessage.java
@@ -46,15 +46,15 @@ public final class ShenyuResultMessage {
 
     public static final String ROLE_CREATE_ERROR = "can not create super role";
 
-    public static final String DASHBOARD_QUERY_ERROR = "users info is empty";
+    public static final String DASHBOARD_QUERY_ERROR = "user info is empty";
 
-    public static final String DASHBOARD_CREATE_USER_ERROR = "user info not 
empty";
+    public static final String DASHBOARD_CREATE_USER_ERROR = "empty user info, 
please confirm";
 
     public static final String PLATFORM_LOGIN_SUCCESS = "login dashboard user 
success";
 
-    public static final String PLATFORM_LOGIN_ERROR = " username or password 
error";
+    public static final String PLATFORM_LOGIN_ERROR = "username or password 
error";
 
-    public static final String LOGIN_USER_DISABLE_ERROR = " the user has 
already disabled.";
+    public static final String LOGIN_USER_DISABLE_ERROR = "the user is 
disabled";
 
     public static final String PARAMETER_ERROR = "parameter error";
 
diff --git 
a/shenyu-plugin/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/resolver/ShenyuServiceInstanceLists.java
 
b/shenyu-plugin/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/resolver/ShenyuServiceInstanceLists.java
index 0f3f1a7..ec4e251 100644
--- 
a/shenyu-plugin/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/resolver/ShenyuServiceInstanceLists.java
+++ 
b/shenyu-plugin/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/resolver/ShenyuServiceInstanceLists.java
@@ -17,7 +17,7 @@
 
 package org.apache.shenyu.plugin.grpc.resolver;
 
-import org.springframework.beans.BeanUtils;
+import org.apache.shenyu.plugin.grpc.transfer.ShenyuServiceTransfer;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -103,8 +103,7 @@ public class ShenyuServiceInstanceLists {
     public List<ShenyuServiceInstance> getCopyInstances() {
         List<ShenyuServiceInstance> copy = new 
ArrayList<>(shenyuServiceInstances.size());
         shenyuServiceInstances.forEach(instance -> {
-            ShenyuServiceInstance cp = new ShenyuServiceInstance();
-            BeanUtils.copyProperties(instance, cp);
+            ShenyuServiceInstance cp = 
ShenyuServiceTransfer.INSTANCE.deepCopy(instance);
             copy.add(cp);
         });
         return copy;
diff --git 
a/shenyu-plugin/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/transfer/ShenyuServiceTransfer.java
 
b/shenyu-plugin/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/transfer/ShenyuServiceTransfer.java
new file mode 100644
index 0000000..c83cd28
--- /dev/null
+++ 
b/shenyu-plugin/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/transfer/ShenyuServiceTransfer.java
@@ -0,0 +1,42 @@
+/*
+ * 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.shenyu.plugin.grpc.transfer;
+
+import org.apache.shenyu.plugin.grpc.resolver.ShenyuServiceInstance;
+
+import java.util.Optional;
+
+/**
+ * The shenyu service instance info transfer.
+ */
+public enum ShenyuServiceTransfer {
+
+    /**
+     * The constant INSTANCE.
+     */
+    INSTANCE;
+
+    /**
+     * deep copy instance
+     * @param instance source data
+     * @return The new instance
+     */
+    public ShenyuServiceInstance deepCopy(final ShenyuServiceInstance 
instance) {
+        return Optional.ofNullable(instance).map(data -> new 
ShenyuServiceInstance(data.getHost(), data.getPort(), 
data.getMetadata())).orElseGet(null);
+    }
+}

Reply via email to