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 a53195f  [Improvement-3369][api] Introduce alert group and users 
service interface for clear code (#4758)
a53195f is described below

commit a53195fa15f2a8e66db60bb1f2143ddab36adb4e
Author: Shiwen Cheng <[email protected]>
AuthorDate: Thu Feb 18 15:05:49 2021 +0800

    [Improvement-3369][api] Introduce alert group and users service interface 
for clear code (#4758)
---
 .../api/controller/AlertGroupController.java       |   3 +-
 .../api/service/AlertGroupService.java             | 140 +---
 .../dolphinscheduler/api/service/BaseService.java  |  15 +-
 .../dolphinscheduler/api/service/UsersService.java | 875 +--------------------
 .../AlertGroupServiceImpl.java}                    |  20 +-
 .../UsersServiceImpl.java}                         |  45 +-
 .../api/service/AlertGroupServiceTest.java         |   7 +-
 .../api/service/UsersServiceTest.java              |   3 +-
 .../common/utils/PropertyUtils.java                |   2 +-
 9 files changed, 76 insertions(+), 1034 deletions(-)

diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java
index 1059052..464c921 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java
@@ -32,7 +32,6 @@ import 
org.apache.dolphinscheduler.common.utils.ParameterUtils;
 import org.apache.dolphinscheduler.common.utils.StringUtils;
 import org.apache.dolphinscheduler.dao.entity.User;
 
-import java.util.HashMap;
 import java.util.Map;
 
 import org.slf4j.Logger;
@@ -111,7 +110,7 @@ public class AlertGroupController extends BaseController {
     public Result list(@ApiIgnore @RequestAttribute(value = 
Constants.SESSION_USER) User loginUser) {
         logger.info("login  user {}, query all alertGroup",
                 loginUser.getUserName());
-        HashMap<String, Object> result = alertGroupService.queryAlertgroup();
+        Map<String, Object> result = alertGroupService.queryAlertgroup();
         return returnDataList(result);
     }
 
diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java
index e1e63a6..71e09ca 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java
@@ -17,55 +17,21 @@
 
 package org.apache.dolphinscheduler.api.service;
 
-import org.apache.dolphinscheduler.api.enums.Status;
-import org.apache.dolphinscheduler.api.utils.PageInfo;
-import org.apache.dolphinscheduler.common.Constants;
-import org.apache.dolphinscheduler.common.enums.AlertType;
-import org.apache.dolphinscheduler.common.utils.CollectionUtils;
-import org.apache.dolphinscheduler.common.utils.StringUtils;
-import org.apache.dolphinscheduler.dao.entity.AlertGroup;
 import org.apache.dolphinscheduler.dao.entity.User;
-import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper;
 
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-
 /**
  * alert group service
  */
-@Service
-public class AlertGroupService extends BaseService {
-
-    private static final Logger logger = 
LoggerFactory.getLogger(AlertGroupService.class);
-
-    @Autowired
-    private AlertGroupMapper alertGroupMapper;
+public interface AlertGroupService {
 
     /**
      * query alert group list
      *
      * @return alert group list
      */
-    public HashMap<String, Object> queryAlertgroup() {
-
-        HashMap<String, Object> result = new HashMap<>();
-        List<AlertGroup> alertGroups = alertGroupMapper.queryAllGroupList();
-        result.put(Constants.DATA_LIST, alertGroups);
-        putMsg(result, Status.SUCCESS);
-
-        return result;
-    }
+    Map<String, Object> queryAlertgroup();
 
     /**
      * paging query alarm group list
@@ -76,24 +42,7 @@ public class AlertGroupService extends BaseService {
      * @param pageSize page size
      * @return alert group list page
      */
-    public Map<String, Object> listPaging(User loginUser, String searchVal, 
Integer pageNo, Integer pageSize) {
-
-        Map<String, Object> result = new HashMap<>();
-        if (isNotAdmin(loginUser, result)) {
-            return result;
-        }
-
-        Page<AlertGroup> page = new Page(pageNo, pageSize);
-        IPage<AlertGroup> alertGroupIPage = 
alertGroupMapper.queryAlertGroupPage(
-            page, searchVal);
-        PageInfo<AlertGroup> pageInfo = new PageInfo<>(pageNo, pageSize);
-        pageInfo.setTotalCount((int) alertGroupIPage.getTotal());
-        pageInfo.setLists(alertGroupIPage.getRecords());
-        result.put(Constants.DATA_LIST, pageInfo);
-        putMsg(result, Status.SUCCESS);
-
-        return result;
-    }
+    Map<String, Object> listPaging(User loginUser, String searchVal, Integer 
pageNo, Integer pageSize);
 
     /**
      * create alert group
@@ -104,33 +53,7 @@ public class AlertGroupService extends BaseService {
      * @param alertInstanceIds alertInstanceIds
      * @return create result code
      */
-    public Map<String, Object> createAlertgroup(User loginUser, String 
groupName, String desc, String alertInstanceIds) {
-        Map<String, Object> result = new HashMap<>();
-        //only admin can operate
-        if (isNotAdmin(loginUser, result)) {
-            return result;
-        }
-
-        AlertGroup alertGroup = new AlertGroup();
-        Date now = new Date();
-
-        alertGroup.setGroupName(groupName);
-        alertGroup.setAlertInstanceIds(alertInstanceIds);
-        alertGroup.setDescription(desc);
-        alertGroup.setCreateTime(now);
-        alertGroup.setUpdateTime(now);
-        alertGroup.setCreateUserId(loginUser.getId());
-
-        // insert
-        int insert = alertGroupMapper.insert(alertGroup);
-
-        if (insert > 0) {
-            putMsg(result, Status.SUCCESS);
-        } else {
-            putMsg(result, Status.CREATE_ALERT_GROUP_ERROR);
-        }
-        return result;
-    }
+    Map<String, Object> createAlertgroup(User loginUser, String groupName, 
String desc, String alertInstanceIds);
 
     /**
      * updateProcessInstance alert group
@@ -142,35 +65,7 @@ public class AlertGroupService extends BaseService {
      * @param alertInstanceIds alertInstanceIds
      * @return update result code
      */
-    public Map<String, Object> updateAlertgroup(User loginUser, int id, String 
groupName, String desc, String alertInstanceIds) {
-        Map<String, Object> result = new HashMap<>();
-
-        if (isNotAdmin(loginUser, result)) {
-            return result;
-        }
-
-        AlertGroup alertGroup = alertGroupMapper.selectById(id);
-
-        if (alertGroup == null) {
-            putMsg(result, Status.ALERT_GROUP_NOT_EXIST);
-            return result;
-
-        }
-
-        Date now = new Date();
-
-        if (StringUtils.isNotEmpty(groupName)) {
-            alertGroup.setGroupName(groupName);
-        }
-        alertGroup.setDescription(desc);
-        alertGroup.setUpdateTime(now);
-        alertGroup.setCreateUserId(loginUser.getId());
-        alertGroup.setAlertInstanceIds(alertInstanceIds);
-        // updateProcessInstance
-        alertGroupMapper.updateById(alertGroup);
-        putMsg(result, Status.SUCCESS);
-        return result;
-    }
+    Map<String, Object> updateAlertgroup(User loginUser, int id, String 
groupName, String desc, String alertInstanceIds);
 
     /**
      * delete alert group by id
@@ -179,25 +74,7 @@ public class AlertGroupService extends BaseService {
      * @param id alert group id
      * @return delete result code
      */
-    @Transactional(rollbackFor = RuntimeException.class)
-    public Map<String, Object> delAlertgroupById(User loginUser, int id) {
-        Map<String, Object> result = new HashMap<>();
-        result.put(Constants.STATUS, false);
-
-        //only admin can operate
-        if (isNotAdmin(loginUser, result)) {
-            return result;
-        }
-        //check exist
-        AlertGroup alertGroup = alertGroupMapper.selectById(id);
-        if (alertGroup == null) {
-            putMsg(result, Status.ALERT_GROUP_NOT_EXIST);
-            return result;
-        }
-        alertGroupMapper.deleteById(id);
-        putMsg(result, Status.SUCCESS);
-        return result;
-    }
+    Map<String, Object> delAlertgroupById(User loginUser, int id);
 
     /**
      * verify group name exists
@@ -205,8 +82,5 @@ public class AlertGroupService extends BaseService {
      * @param groupName group name
      * @return check result code
      */
-    public boolean existGroupName(String groupName) {
-        List<AlertGroup> alertGroup = 
alertGroupMapper.queryByGroupName(groupName);
-        return CollectionUtils.isNotEmpty(alertGroup);
-    }
+    boolean existGroupName(String groupName);
 }
diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/BaseService.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/BaseService.java
index 55826bf..e9a40db 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/BaseService.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/BaseService.java
@@ -16,20 +16,17 @@
  */
 package org.apache.dolphinscheduler.api.service;
 
-import java.text.MessageFormat;
-import java.util.Map;
-
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-
 import org.apache.dolphinscheduler.api.enums.Status;
 import org.apache.dolphinscheduler.api.utils.Result;
 import org.apache.dolphinscheduler.common.Constants;
 import org.apache.dolphinscheduler.common.enums.UserType;
 import org.apache.dolphinscheduler.common.utils.HadoopUtils;
-import org.apache.dolphinscheduler.common.utils.StringUtils;
 import org.apache.dolphinscheduler.dao.entity.User;
 
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.Map;
+
 /**
  * base service
  */
@@ -117,9 +114,9 @@ public class BaseService {
      * create tenant dir if not exists
      *
      * @param tenantCode tenant code
-     * @throws Exception if hdfs operation exception
+     * @throws IOException if hdfs operation exception
      */
-    protected void createTenantDirIfNotExists(String tenantCode) throws 
Exception {
+    protected void createTenantDirIfNotExists(String tenantCode) throws 
IOException {
 
         String resourcePath = HadoopUtils.getHdfsResDir(tenantCode);
         String udfsPath = HadoopUtils.getHdfsUdfDir(tenantCode);
diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
index 3fb5f64..ff73e52 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
@@ -17,96 +17,18 @@
 
 package org.apache.dolphinscheduler.api.service;
 
-import org.apache.dolphinscheduler.api.dto.resources.ResourceComponent;
-import 
org.apache.dolphinscheduler.api.dto.resources.visitor.ResourceTreeVisitor;
-import org.apache.dolphinscheduler.api.enums.Status;
-import org.apache.dolphinscheduler.api.exceptions.ServiceException;
-import org.apache.dolphinscheduler.api.utils.CheckUtils;
-import org.apache.dolphinscheduler.api.utils.PageInfo;
 import org.apache.dolphinscheduler.api.utils.Result;
-import org.apache.dolphinscheduler.common.Constants;
-import org.apache.dolphinscheduler.common.enums.Flag;
-import org.apache.dolphinscheduler.common.enums.ResourceType;
 import org.apache.dolphinscheduler.common.enums.UserType;
-import org.apache.dolphinscheduler.common.utils.CollectionUtils;
-import org.apache.dolphinscheduler.common.utils.EncryptionUtils;
-import org.apache.dolphinscheduler.common.utils.HadoopUtils;
-import org.apache.dolphinscheduler.common.utils.PropertyUtils;
-import org.apache.dolphinscheduler.common.utils.StringUtils;
-import org.apache.dolphinscheduler.dao.entity.AlertGroup;
-import org.apache.dolphinscheduler.dao.entity.DatasourceUser;
-import org.apache.dolphinscheduler.dao.entity.ProjectUser;
-import org.apache.dolphinscheduler.dao.entity.Resource;
-import org.apache.dolphinscheduler.dao.entity.ResourcesUser;
-import org.apache.dolphinscheduler.dao.entity.Tenant;
-import org.apache.dolphinscheduler.dao.entity.UDFUser;
 import org.apache.dolphinscheduler.dao.entity.User;
-import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper;
-import org.apache.dolphinscheduler.dao.mapper.DataSourceUserMapper;
-import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper;
-import org.apache.dolphinscheduler.dao.mapper.ProjectUserMapper;
-import org.apache.dolphinscheduler.dao.mapper.ResourceMapper;
-import org.apache.dolphinscheduler.dao.mapper.ResourceUserMapper;
-import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
-import org.apache.dolphinscheduler.dao.mapper.UDFUserMapper;
-import org.apache.dolphinscheduler.dao.mapper.UserMapper;
-import org.apache.dolphinscheduler.dao.utils.ResourceProcessDefinitionUtils;
 
 import java.io.IOException;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 
 /**
- * user service
+ * users service
  */
-@Service
-public class UsersService extends BaseService {
-
-    private static final Logger logger = 
LoggerFactory.getLogger(UsersService.class);
-
-    @Autowired
-    private UserMapper userMapper;
-
-    @Autowired
-    private TenantMapper tenantMapper;
-
-    @Autowired
-    private ProjectUserMapper projectUserMapper;
-
-    @Autowired
-    private ResourceUserMapper resourcesUserMapper;
-
-    @Autowired
-    private ResourceMapper resourceMapper;
-
-    @Autowired
-    private DataSourceUserMapper datasourceUserMapper;
-
-    @Autowired
-    private UDFUserMapper udfUserMapper;
-
-    @Autowired
-    private AlertGroupMapper alertGroupMapper;
-
-    @Autowired
-    private ProcessDefinitionMapper processDefinitionMapper;
-
+public interface UsersService {
 
     /**
      * create user, only system admin have permission
@@ -121,104 +43,16 @@ public class UsersService extends BaseService {
      * @return create result code
      * @throws Exception exception
      */
-    @Transactional(rollbackFor = Exception.class)
-    public Map<String, Object> createUser(User loginUser,
-                                          String userName,
-                                          String userPassword,
-                                          String email,
-                                          int tenantId,
-                                          String phone,
-                                          String queue,
-                                          int state) throws Exception {
-
-        Map<String, Object> result = new HashMap<>(5);
-
-        //check all user params
-        String msg = this.checkUserParams(userName, userPassword, email, 
phone);
-
-        if (!StringUtils.isEmpty(msg)) {
-            putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, msg);
-            return result;
-        }
-        if (!isAdmin(loginUser)) {
-            putMsg(result, Status.USER_NO_OPERATION_PERM);
-            return result;
-        }
-
-        if (!checkTenantExists(tenantId)) {
-            putMsg(result, Status.TENANT_NOT_EXIST);
-            return result;
-        }
-
-        User user = createUser(userName, userPassword, email, tenantId, phone, 
queue, state);
+    Map<String, Object> createUser(User loginUser, String userName, String 
userPassword, String email,
+                                   int tenantId, String phone, String queue, 
int state) throws IOException;
 
-        Tenant tenant = tenantMapper.queryById(tenantId);
-        // resource upload startup
-        if (PropertyUtils.getResUploadStartupState()) {
-            // if tenant not exists
-            if 
(!HadoopUtils.getInstance().exists(HadoopUtils.getHdfsTenantDir(tenant.getTenantCode())))
 {
-                createTenantDirIfNotExists(tenant.getTenantCode());
-            }
-            String userPath = 
HadoopUtils.getHdfsUserDir(tenant.getTenantCode(), user.getId());
-            HadoopUtils.getInstance().mkdir(userPath);
-        }
-
-        putMsg(result, Status.SUCCESS);
-        return result;
-
-    }
-
-    @Transactional(rollbackFor = RuntimeException.class)
-    public User createUser(String userName,
-                           String userPassword,
-                           String email,
-                           int tenantId,
-                           String phone,
-                           String queue,
-                           int state) {
-        User user = new User();
-        Date now = new Date();
-
-        user.setUserName(userName);
-        user.setUserPassword(EncryptionUtils.getMd5(userPassword));
-        user.setEmail(email);
-        user.setTenantId(tenantId);
-        user.setPhone(phone);
-        user.setState(state);
-        // create general users, administrator users are currently built-in
-        user.setUserType(UserType.GENERAL_USER);
-        user.setCreateTime(now);
-        user.setUpdateTime(now);
-        if (StringUtils.isEmpty(queue)) {
-            queue = "";
-        }
-        user.setQueue(queue);
-
-        // save user
-        userMapper.insert(user);
-        return user;
-    }
+    User createUser(String userName, String userPassword, String email,
+                    int tenantId, String phone, String queue, int state);
 
     /***
      * create User for ldap login
      */
-    @Transactional(rollbackFor = Exception.class)
-    public User createUser(UserType userType, String userId, String email) {
-        User user = new User();
-        Date now = new Date();
-
-        user.setUserName(userId);
-        user.setEmail(email);
-        // create general users, administrator users are currently built-in
-        user.setUserType(userType);
-        user.setCreateTime(now);
-        user.setUpdateTime(now);
-        user.setQueue("");
-
-        // save user
-        userMapper.insert(user);
-        return user;
-    }
+    User createUser(UserType userType, String userId, String email);
 
     /**
      * get user by user name
@@ -226,9 +60,7 @@ public class UsersService extends BaseService {
      * @param userName user name
      * @return exist user or null
      */
-    public User getUserByUserName(String userName) {
-        return userMapper.queryByUserNameAccurately(userName);
-    }
+    User getUserByUserName(String userName);
 
     /**
      * query user by id
@@ -236,9 +68,7 @@ public class UsersService extends BaseService {
      * @param id id
      * @return user info
      */
-    public User queryUser(int id) {
-        return userMapper.selectById(id);
-    }
+    User queryUser(int id);
 
     /**
      * query user
@@ -246,9 +76,7 @@ public class UsersService extends BaseService {
      * @param name name
      * @return user info
      */
-    public User queryUser(String name) {
-        return userMapper.queryByUserNameAccurately(name);
-    }
+    User queryUser(String name);
 
     /**
      * query user
@@ -257,10 +85,7 @@ public class UsersService extends BaseService {
      * @param password password
      * @return user info
      */
-    public User queryUser(String name, String password) {
-        String md5 = EncryptionUtils.getMd5(password);
-        return userMapper.queryUserByNamePassword(name, md5);
-    }
+    User queryUser(String name, String password);
 
     /**
      * get user id by user name
@@ -268,20 +93,7 @@ public class UsersService extends BaseService {
      * @param name user name
      * @return if name empty 0, user not exists -1, user exist user id
      */
-    public int getUserIdByName(String name) {
-        //executor name query
-        int executorId = 0;
-        if (StringUtils.isNotEmpty(name)) {
-            User executor = queryUser(name);
-            if (null != executor) {
-                executorId = executor.getId();
-            } else {
-                executorId = -1;
-            }
-        }
-
-        return executorId;
-    }
+    int getUserIdByName(String name);
 
     /**
      * query user list
@@ -292,25 +104,7 @@ public class UsersService extends BaseService {
      * @param pageSize page size
      * @return user list page
      */
-    public Map<String, Object> queryUserList(User loginUser, String searchVal, 
Integer pageNo, Integer pageSize) {
-        Map<String, Object> result = new HashMap<>(5);
-
-        if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) 
{
-            return result;
-        }
-
-        Page<User> page = new Page(pageNo, pageSize);
-
-        IPage<User> scheduleList = userMapper.queryUserPaging(page, searchVal);
-
-        PageInfo<User> pageInfo = new PageInfo<>(pageNo, pageSize);
-        pageInfo.setTotalCount((int) scheduleList.getTotal());
-        pageInfo.setLists(scheduleList.getRecords());
-        result.put(Constants.DATA_LIST, pageInfo);
-        putMsg(result, Status.SUCCESS);
-
-        return result;
-    }
+    Map<String, Object> queryUserList(User loginUser, String searchVal, 
Integer pageNo, Integer pageSize);
 
     /**
      * updateProcessInstance user
@@ -327,128 +121,8 @@ public class UsersService extends BaseService {
      * @return update result code
      * @throws Exception exception
      */
-    public Map<String, Object> updateUser(User loginUser, int userId,
-                                          String userName,
-                                          String userPassword,
-                                          String email,
-                                          int tenantId,
-                                          String phone,
-                                          String queue,
-                                          int state) throws Exception {
-        Map<String, Object> result = new HashMap<>(5);
-        result.put(Constants.STATUS, false);
-
-        if (check(result, !hasPerm(loginUser, userId), 
Status.USER_NO_OPERATION_PERM)) {
-            return result;
-        }
-        User user = userMapper.selectById(userId);
-        if (user == null) {
-            putMsg(result, Status.USER_NOT_EXIST, userId);
-            return result;
-        }
-        if (StringUtils.isNotEmpty(userName)) {
-
-            if (!CheckUtils.checkUserName(userName)) {
-                putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, 
userName);
-                return result;
-            }
-
-            User tempUser = userMapper.queryByUserNameAccurately(userName);
-            if (tempUser != null && tempUser.getId() != userId) {
-                putMsg(result, Status.USER_NAME_EXIST);
-                return result;
-            }
-            user.setUserName(userName);
-        }
-
-        if (StringUtils.isNotEmpty(userPassword)) {
-            if (!CheckUtils.checkPassword(userPassword)) {
-                putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, 
userPassword);
-                return result;
-            }
-            user.setUserPassword(EncryptionUtils.getMd5(userPassword));
-        }
-
-        if (StringUtils.isNotEmpty(email)) {
-            if (!CheckUtils.checkEmail(email)) {
-                putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, email);
-                return result;
-            }
-            user.setEmail(email);
-        }
-
-        if (StringUtils.isNotEmpty(phone) && !CheckUtils.checkPhone(phone)) {
-            putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, phone);
-            return result;
-        }
-        user.setPhone(phone);
-        user.setQueue(queue);
-        user.setState(state);
-        Date now = new Date();
-        user.setUpdateTime(now);
-
-        //if user switches the tenant, the user's resources need to be copied 
to the new tenant
-        if (user.getTenantId() != tenantId) {
-            Tenant oldTenant = tenantMapper.queryById(user.getTenantId());
-            //query tenant
-            Tenant newTenant = tenantMapper.queryById(tenantId);
-            if (newTenant != null) {
-                // if hdfs startup
-                if (PropertyUtils.getResUploadStartupState() && oldTenant != 
null) {
-                    String newTenantCode = newTenant.getTenantCode();
-                    String oldResourcePath = 
HadoopUtils.getHdfsResDir(oldTenant.getTenantCode());
-                    String oldUdfsPath = 
HadoopUtils.getHdfsUdfDir(oldTenant.getTenantCode());
-
-                    // if old tenant dir exists
-                    if (HadoopUtils.getInstance().exists(oldResourcePath)) {
-                        String newResourcePath = 
HadoopUtils.getHdfsResDir(newTenantCode);
-                        String newUdfsPath = 
HadoopUtils.getHdfsUdfDir(newTenantCode);
-
-                        //file resources list
-                        List<Resource> fileResourcesList = 
resourceMapper.queryResourceList(
-                                null, userId, ResourceType.FILE.ordinal());
-                        if (CollectionUtils.isNotEmpty(fileResourcesList)) {
-                            ResourceTreeVisitor resourceTreeVisitor = new 
ResourceTreeVisitor(fileResourcesList);
-                            ResourceComponent resourceComponent = 
resourceTreeVisitor.visit();
-                            copyResourceFiles(resourceComponent, 
oldResourcePath, newResourcePath);
-                        }
-
-                        //udf resources
-                        List<Resource> udfResourceList = 
resourceMapper.queryResourceList(
-                                null, userId, ResourceType.UDF.ordinal());
-                        if (CollectionUtils.isNotEmpty(udfResourceList)) {
-                            ResourceTreeVisitor resourceTreeVisitor = new 
ResourceTreeVisitor(udfResourceList);
-                            ResourceComponent resourceComponent = 
resourceTreeVisitor.visit();
-                            copyResourceFiles(resourceComponent, oldUdfsPath, 
newUdfsPath);
-                        }
-
-                        //Delete the user from the old tenant directory
-                        String oldUserPath = 
HadoopUtils.getHdfsUserDir(oldTenant.getTenantCode(), userId);
-                        HadoopUtils.getInstance().delete(oldUserPath, true);
-                    } else {
-                        // if old tenant dir not exists , create
-                        createTenantDirIfNotExists(oldTenant.getTenantCode());
-                    }
-
-                    if 
(HadoopUtils.getInstance().exists(HadoopUtils.getHdfsTenantDir(newTenant.getTenantCode())))
 {
-                        //create user in the new tenant directory
-                        String newUserPath = 
HadoopUtils.getHdfsUserDir(newTenant.getTenantCode(), user.getId());
-                        HadoopUtils.getInstance().mkdir(newUserPath);
-                    } else {
-                        // if new tenant dir not exists , create
-                        createTenantDirIfNotExists(newTenant.getTenantCode());
-                    }
-
-                }
-            }
-            user.setTenantId(tenantId);
-        }
-
-        // updateProcessInstance user
-        userMapper.updateById(user);
-        putMsg(result, Status.SUCCESS);
-        return result;
-    }
+    Map<String, Object> updateUser(User loginUser, int userId, String 
userName, String userPassword, String email,
+                                   int tenantId, String phone, String queue, 
int state) throws IOException;
 
     /**
      * delete user
@@ -458,36 +132,7 @@ public class UsersService extends BaseService {
      * @return delete result code
      * @throws Exception exception when operate hdfs
      */
-    public Map<String, Object> deleteUserById(User loginUser, int id) throws 
Exception {
-        Map<String, Object> result = new HashMap<>(5);
-        //only admin can operate
-        if (!isAdmin(loginUser)) {
-            putMsg(result, Status.USER_NO_OPERATION_PERM, id);
-            return result;
-        }
-        //check exist
-        User tempUser = userMapper.selectById(id);
-        if (tempUser == null) {
-            putMsg(result, Status.USER_NOT_EXIST, id);
-            return result;
-        }
-        // delete user
-        User user = userMapper.queryTenantCodeByUserId(id);
-
-        if (user != null) {
-            if (PropertyUtils.getResUploadStartupState()) {
-                String userPath = 
HadoopUtils.getHdfsUserDir(user.getTenantCode(), id);
-                if (HadoopUtils.getInstance().exists(userPath)) {
-                    HadoopUtils.getInstance().delete(userPath, true);
-                }
-            }
-        }
-
-        userMapper.deleteById(id);
-        putMsg(result, Status.SUCCESS);
-
-        return result;
-    }
+    Map<String, Object> deleteUserById(User loginUser, int id) throws 
IOException;
 
     /**
      * grant project
@@ -497,46 +142,7 @@ public class UsersService extends BaseService {
      * @param projectIds project id array
      * @return grant result code
      */
-    @Transactional(rollbackFor = RuntimeException.class)
-    public Map<String, Object> grantProject(User loginUser, int userId, String 
projectIds) {
-        Map<String, Object> result = new HashMap<>(5);
-        result.put(Constants.STATUS, false);
-
-        //only admin can operate
-        if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) 
{
-            return result;
-        }
-
-        //check exist
-        User tempUser = userMapper.selectById(userId);
-        if (tempUser == null) {
-            putMsg(result, Status.USER_NOT_EXIST, userId);
-            return result;
-        }
-        //if the selected projectIds are empty, delete all items associated 
with the user
-        projectUserMapper.deleteProjectRelation(0, userId);
-
-        if (check(result, StringUtils.isEmpty(projectIds), Status.SUCCESS)) {
-            return result;
-        }
-
-        String[] projectIdArr = projectIds.split(",");
-
-        for (String projectId : projectIdArr) {
-            Date now = new Date();
-            ProjectUser projectUser = new ProjectUser();
-            projectUser.setUserId(userId);
-            projectUser.setProjectId(Integer.parseInt(projectId));
-            projectUser.setPerm(7);
-            projectUser.setCreateTime(now);
-            projectUser.setUpdateTime(now);
-            projectUserMapper.insert(projectUser);
-        }
-
-        putMsg(result, Status.SUCCESS);
-
-        return result;
-    }
+    Map<String, Object> grantProject(User loginUser, int userId, String 
projectIds);
 
 
     /**
@@ -547,93 +153,7 @@ public class UsersService extends BaseService {
      * @param resourceIds resource id array
      * @return grant result code
      */
-    @Transactional(rollbackFor = RuntimeException.class)
-    public Map<String, Object> grantResources(User loginUser, int userId, 
String resourceIds) {
-        Map<String, Object> result = new HashMap<>(5);
-        //only admin can operate
-        if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) 
{
-            return result;
-        }
-        User user = userMapper.selectById(userId);
-        if (user == null) {
-            putMsg(result, Status.USER_NOT_EXIST, userId);
-            return result;
-        }
-
-        Set<Integer> needAuthorizeResIds = new HashSet();
-        if (StringUtils.isNotBlank(resourceIds)) {
-            String[] resourceFullIdArr = resourceIds.split(",");
-            // need authorize resource id set
-            for (String resourceFullId : resourceFullIdArr) {
-                String[] resourceIdArr = resourceFullId.split("-");
-                for (int i = 0; i <= resourceIdArr.length - 1; i++) {
-                    int resourceIdValue = Integer.parseInt(resourceIdArr[i]);
-                    needAuthorizeResIds.add(resourceIdValue);
-                }
-            }
-        }
-
-
-        //get the authorized resource id list by user id
-        List<Resource> oldAuthorizedRes = 
resourceMapper.queryAuthorizedResourceList(userId);
-        //if resource type is UDF,need check whether it is bound by UDF functon
-        Set<Integer> oldAuthorizedResIds = oldAuthorizedRes.stream().map(t -> 
t.getId()).collect(Collectors.toSet());
-
-        //get the unauthorized resource id list
-        oldAuthorizedResIds.removeAll(needAuthorizeResIds);
-
-        if (CollectionUtils.isNotEmpty(oldAuthorizedResIds)) {
-
-            // get all resource id of process definitions those is released
-            List<Map<String, Object>> list = 
processDefinitionMapper.listResourcesByUser(userId);
-            Map<Integer, Set<Integer>> resourceProcessMap = 
ResourceProcessDefinitionUtils.getResourceProcessDefinitionMap(list);
-            Set<Integer> resourceIdSet = resourceProcessMap.keySet();
-
-            resourceIdSet.retainAll(oldAuthorizedResIds);
-            if (CollectionUtils.isNotEmpty(resourceIdSet)) {
-                logger.error("can't be deleted,because it is used of process 
definition");
-                for (Integer resId : resourceIdSet) {
-                    logger.error("resource id:{} is used of process definition 
{}", resId, resourceProcessMap.get(resId));
-                }
-                putMsg(result, Status.RESOURCE_IS_USED);
-                return result;
-            }
-
-        }
-
-        resourcesUserMapper.deleteResourceUser(userId, 0);
-
-        if (check(result, StringUtils.isEmpty(resourceIds), Status.SUCCESS)) {
-            return result;
-        }
-
-        for (int resourceIdValue : needAuthorizeResIds) {
-            Resource resource = resourceMapper.selectById(resourceIdValue);
-            if (resource == null) {
-                putMsg(result, Status.RESOURCE_NOT_EXIST);
-                return result;
-            }
-
-            Date now = new Date();
-            ResourcesUser resourcesUser = new ResourcesUser();
-            resourcesUser.setUserId(userId);
-            resourcesUser.setResourcesId(resourceIdValue);
-            if (resource.isDirectory()) {
-                resourcesUser.setPerm(Constants.AUTHORIZE_READABLE_PERM);
-            } else {
-                resourcesUser.setPerm(Constants.AUTHORIZE_WRITABLE_PERM);
-            }
-
-            resourcesUser.setCreateTime(now);
-            resourcesUser.setUpdateTime(now);
-            resourcesUserMapper.insert(resourcesUser);
-
-        }
-
-        putMsg(result, Status.SUCCESS);
-
-        return result;
-    }
+    Map<String, Object> grantResources(User loginUser, int userId, String 
resourceIds);
 
 
     /**
@@ -644,43 +164,7 @@ public class UsersService extends BaseService {
      * @param udfIds udf id array
      * @return grant result code
      */
-    @Transactional(rollbackFor = RuntimeException.class)
-    public Map<String, Object> grantUDFFunction(User loginUser, int userId, 
String udfIds) {
-        Map<String, Object> result = new HashMap<>(5);
-
-        //only admin can operate
-        if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) 
{
-            return result;
-        }
-        User user = userMapper.selectById(userId);
-        if (user == null) {
-            putMsg(result, Status.USER_NOT_EXIST, userId);
-            return result;
-        }
-
-        udfUserMapper.deleteByUserId(userId);
-
-        if (check(result, StringUtils.isEmpty(udfIds), Status.SUCCESS)) {
-            return result;
-        }
-
-        String[] resourcesIdArr = udfIds.split(",");
-
-        for (String udfId : resourcesIdArr) {
-            Date now = new Date();
-            UDFUser udfUser = new UDFUser();
-            udfUser.setUserId(userId);
-            udfUser.setUdfId(Integer.parseInt(udfId));
-            udfUser.setPerm(7);
-            udfUser.setCreateTime(now);
-            udfUser.setUpdateTime(now);
-            udfUserMapper.insert(udfUser);
-        }
-
-        putMsg(result, Status.SUCCESS);
-
-        return result;
-    }
+    Map<String, Object> grantUDFFunction(User loginUser, int userId, String 
udfIds);
 
 
     /**
@@ -691,45 +175,7 @@ public class UsersService extends BaseService {
      * @param datasourceIds data source id array
      * @return grant result code
      */
-    @Transactional(rollbackFor = RuntimeException.class)
-    public Map<String, Object> grantDataSource(User loginUser, int userId, 
String datasourceIds) {
-        Map<String, Object> result = new HashMap<>(5);
-        result.put(Constants.STATUS, false);
-
-        //only admin can operate
-        if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) 
{
-            return result;
-        }
-        User user = userMapper.selectById(userId);
-        if (user == null) {
-            putMsg(result, Status.USER_NOT_EXIST, userId);
-            return result;
-        }
-
-        datasourceUserMapper.deleteByUserId(userId);
-
-        if (check(result, StringUtils.isEmpty(datasourceIds), Status.SUCCESS)) 
{
-            return result;
-        }
-
-        String[] datasourceIdArr = datasourceIds.split(",");
-
-        for (String datasourceId : datasourceIdArr) {
-            Date now = new Date();
-
-            DatasourceUser datasourceUser = new DatasourceUser();
-            datasourceUser.setUserId(userId);
-            datasourceUser.setDatasourceId(Integer.parseInt(datasourceId));
-            datasourceUser.setPerm(7);
-            datasourceUser.setCreateTime(now);
-            datasourceUser.setUpdateTime(now);
-            datasourceUserMapper.insert(datasourceUser);
-        }
-
-        putMsg(result, Status.SUCCESS);
-
-        return result;
-    }
+    Map<String, Object> grantDataSource(User loginUser, int userId, String 
datasourceIds);
 
     /**
      * query user info
@@ -737,34 +183,7 @@ public class UsersService extends BaseService {
      * @param loginUser login user
      * @return user info
      */
-    public Map<String, Object> getUserInfo(User loginUser) {
-
-        Map<String, Object> result = new HashMap<>();
-
-        User user = null;
-        if (loginUser.getUserType() == UserType.ADMIN_USER) {
-            user = loginUser;
-        } else {
-            user = userMapper.queryDetailsById(loginUser.getId());
-
-            List<AlertGroup> alertGroups = 
alertGroupMapper.queryByUserId(loginUser.getId());
-
-            StringBuilder sb = new StringBuilder();
-
-            if (alertGroups != null && alertGroups.size() > 0) {
-                for (int i = 0; i < alertGroups.size() - 1; i++) {
-                    sb.append(alertGroups.get(i).getGroupName() + ",");
-                }
-                sb.append(alertGroups.get(alertGroups.size() - 1));
-                user.setAlertGroup(sb.toString());
-            }
-        }
-
-        result.put(Constants.DATA_LIST, user);
-
-        putMsg(result, Status.SUCCESS);
-        return result;
-    }
+    Map<String, Object> getUserInfo(User loginUser);
 
     /**
      * query user list
@@ -772,19 +191,7 @@ public class UsersService extends BaseService {
      * @param loginUser login user
      * @return user list
      */
-    public Map<String, Object> queryAllGeneralUsers(User loginUser) {
-        Map<String, Object> result = new HashMap<>(5);
-        //only admin can operate
-        if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) 
{
-            return result;
-        }
-
-        List<User> userList = userMapper.queryAllGeneralUser();
-        result.put(Constants.DATA_LIST, userList);
-        putMsg(result, Status.SUCCESS);
-
-        return result;
-    }
+    Map<String, Object> queryAllGeneralUsers(User loginUser);
 
 
     /**
@@ -793,19 +200,7 @@ public class UsersService extends BaseService {
      * @param loginUser login user
      * @return user list
      */
-    public Map<String, Object> queryUserList(User loginUser) {
-        Map<String, Object> result = new HashMap<>(5);
-        //only admin can operate
-        if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) 
{
-            return result;
-        }
-
-        List<User> userList = userMapper.selectList(null);
-        result.put(Constants.DATA_LIST, userList);
-        putMsg(result, Status.SUCCESS);
-
-        return result;
-    }
+    Map<String, Object> queryUserList(User loginUser);
 
     /**
      * verify user name exists
@@ -813,20 +208,7 @@ public class UsersService extends BaseService {
      * @param userName user name
      * @return true if user name not exists, otherwise return false
      */
-    public Result verifyUserName(String userName) {
-
-        Result result = new Result();
-        User user = userMapper.queryByUserNameAccurately(userName);
-        if (user != null) {
-            logger.error("user {} has exist, can't create again.", userName);
-
-            putMsg(result, Status.USER_NAME_EXIST);
-        } else {
-            putMsg(result, Status.SUCCESS);
-        }
-
-        return result;
-    }
+    Result<Object> verifyUserName(String userName);
 
 
     /**
@@ -836,34 +218,7 @@ public class UsersService extends BaseService {
      * @param alertgroupId alert group id
      * @return unauthorize result code
      */
-    public Map<String, Object> unauthorizedUser(User loginUser, Integer 
alertgroupId) {
-
-        Map<String, Object> result = new HashMap<>(5);
-        //only admin can operate
-        if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) 
{
-            return result;
-        }
-
-        List<User> userList = userMapper.selectList(null);
-        List<User> resultUsers = new ArrayList<>();
-        Set<User> userSet = null;
-        if (userList != null && userList.size() > 0) {
-            userSet = new HashSet<>(userList);
-
-            List<User> authedUserList = 
userMapper.queryUserListByAlertGroupId(alertgroupId);
-
-            Set<User> authedUserSet = null;
-            if (authedUserList != null && authedUserList.size() > 0) {
-                authedUserSet = new HashSet<>(authedUserList);
-                userSet.removeAll(authedUserSet);
-            }
-            resultUsers = new ArrayList<>(userSet);
-        }
-        result.put(Constants.DATA_LIST, resultUsers);
-        putMsg(result, Status.SUCCESS);
-
-        return result;
-    }
+    Map<String, Object> unauthorizedUser(User loginUser, Integer alertgroupId);
 
 
     /**
@@ -873,86 +228,7 @@ public class UsersService extends BaseService {
      * @param alertgroupId alert group id
      * @return authorized result code
      */
-    public Map<String, Object> authorizedUser(User loginUser, Integer 
alertgroupId) {
-        Map<String, Object> result = new HashMap<>(5);
-        //only admin can operate
-        if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) 
{
-            return result;
-        }
-        List<User> userList = 
userMapper.queryUserListByAlertGroupId(alertgroupId);
-        result.put(Constants.DATA_LIST, userList);
-        putMsg(result, Status.SUCCESS);
-
-        return result;
-    }
-
-    /**
-     * @param tenantId tenant id
-     * @return true if tenant exists, otherwise return false
-     */
-    private boolean checkTenantExists(int tenantId) {
-        return tenantMapper.queryById(tenantId) != null ? true : false;
-    }
-
-    /**
-     * @return if check failed return the field, otherwise return null
-     */
-    private String checkUserParams(String userName, String password, String 
email, String phone) {
-
-        String msg = null;
-        if (!CheckUtils.checkUserName(userName)) {
-
-            msg = userName;
-        } else if (!CheckUtils.checkPassword(password)) {
-
-            msg = password;
-        } else if (!CheckUtils.checkEmail(email)) {
-
-            msg = email;
-        } else if (!CheckUtils.checkPhone(phone)) {
-
-            msg = phone;
-        }
-
-        return msg;
-    }
-
-    /**
-     * copy resource files
-     *
-     * @param resourceComponent resource component
-     * @param srcBasePath src base path
-     * @param dstBasePath dst base path
-     * @throws IOException io exception
-     */
-    private void copyResourceFiles(ResourceComponent resourceComponent, String 
srcBasePath, String dstBasePath) throws IOException {
-        List<ResourceComponent> components = resourceComponent.getChildren();
-
-        if (CollectionUtils.isNotEmpty(components)) {
-            for (ResourceComponent component : components) {
-                // verify whether exist
-                if (!HadoopUtils.getInstance().exists(String.format("%s/%s", 
srcBasePath, component.getFullName()))) {
-                    logger.error("resource file: {} not exist,copy error", 
component.getFullName());
-                    throw new ServiceException(Status.RESOURCE_NOT_EXIST);
-                }
-
-                if (!component.isDirctory()) {
-                    // copy it to dst
-                    HadoopUtils.getInstance().copy(String.format("%s/%s", 
srcBasePath, component.getFullName()), String.format("%s/%s", dstBasePath, 
component.getFullName()), false, true);
-                    continue;
-                }
-
-                if (CollectionUtils.isEmpty(component.getChildren())) {
-                    // if not exist,need create it
-                    if 
(!HadoopUtils.getInstance().exists(String.format("%s/%s", dstBasePath, 
component.getFullName()))) {
-                        HadoopUtils.getInstance().mkdir(String.format("%s/%s", 
dstBasePath, component.getFullName()));
-                    }
-                } else {
-                    copyResourceFiles(component, srcBasePath, dstBasePath);
-                }
-            }
-        }
-    }
+    Map<String, Object> authorizedUser(User loginUser, Integer alertgroupId);
 
     /**
      * register user, default state is 0, default tenant_id is 1, no phone, no 
queue
@@ -964,27 +240,7 @@ public class UsersService extends BaseService {
      * @return register result code
      * @throws Exception exception
      */
-    @Transactional(rollbackFor = RuntimeException.class)
-    public Map<String, Object> registerUser(String userName, String 
userPassword, String repeatPassword, String email) {
-        Map<String, Object> result = new HashMap<>();
-
-        //check user params
-        String msg = this.checkUserParams(userName, userPassword, email, "");
-
-        if (!StringUtils.isEmpty(msg)) {
-            putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, msg);
-            return result;
-        }
-
-        if (!userPassword.equals(repeatPassword)) {
-            putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, "two 
passwords are not same");
-            return result;
-        }
-        User user = createUser(userName, userPassword, email, 1, "", "", 
Flag.NO.ordinal());
-        putMsg(result, Status.SUCCESS);
-        result.put(Constants.DATA_LIST, user);
-        return result;
-    }
+    Map<String, Object> registerUser(String userName, String userPassword, 
String repeatPassword, String email);
 
     /**
      * activate user, only system admin have permission, change user state 
code 0 to 1
@@ -993,41 +249,7 @@ public class UsersService extends BaseService {
      * @param userName user name
      * @return create result code
      */
-    public Map<String, Object> activateUser(User loginUser, String userName) {
-        Map<String, Object> result = new HashMap<>();
-        result.put(Constants.STATUS, false);
-
-        if (!isAdmin(loginUser)) {
-            putMsg(result, Status.USER_NO_OPERATION_PERM);
-            return result;
-        }
-
-        if (!CheckUtils.checkUserName(userName)) {
-            putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, userName);
-            return result;
-        }
-
-        User user = userMapper.queryByUserNameAccurately(userName);
-
-        if (user == null) {
-            putMsg(result, Status.USER_NOT_EXIST, userName);
-            return result;
-        }
-
-        if (user.getState() != Flag.NO.ordinal()) {
-            putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, userName);
-            return result;
-        }
-
-        user.setState(Flag.YES.ordinal());
-        Date now = new Date();
-        user.setUpdateTime(now);
-        userMapper.updateById(user);
-        User responseUser = userMapper.queryByUserNameAccurately(userName);
-        putMsg(result, Status.SUCCESS);
-        result.put(Constants.DATA_LIST, responseUser);
-        return result;
-    }
+    Map<String, Object> activateUser(User loginUser, String userName);
 
     /**
      * activate user, only system admin have permission, change users state 
code 0 to 1
@@ -1036,44 +258,5 @@ public class UsersService extends BaseService {
      * @param userNames user name
      * @return create result code
      */
-    public Map<String, Object> batchActivateUser(User loginUser, List<String> 
userNames) {
-        Map<String, Object> result = new HashMap<>();
-
-        if (!isAdmin(loginUser)) {
-            putMsg(result, Status.USER_NO_OPERATION_PERM);
-            return result;
-        }
-
-        int totalSuccess = 0;
-        List<String> successUserNames = new ArrayList<>();
-        Map<String, Object> successRes = new HashMap<>();
-        int totalFailed = 0;
-        List<Map<String, String>> failedInfo = new ArrayList<>();
-        Map<String, Object> failedRes = new HashMap<>();
-        for (String userName : userNames) {
-            Map<String, Object> tmpResult = activateUser(loginUser, userName);
-            if (tmpResult.get(Constants.STATUS) != Status.SUCCESS) {
-                totalFailed++;
-                Map<String, String> failedBody = new HashMap<>();
-                failedBody.put("userName", userName);
-                Status status = (Status) tmpResult.get(Constants.STATUS);
-                String errorMessage = MessageFormat.format(status.getMsg(), 
userName);
-                failedBody.put("msg", errorMessage);
-                failedInfo.add(failedBody);
-            } else {
-                totalSuccess++;
-                successUserNames.add(userName);
-            }
-        }
-        successRes.put("sum", totalSuccess);
-        successRes.put("userName", successUserNames);
-        failedRes.put("sum", totalFailed);
-        failedRes.put("info", failedInfo);
-        Map<String, Object> res = new HashMap<>();
-        res.put("success", successRes);
-        res.put("failed", failedRes);
-        putMsg(result, Status.SUCCESS);
-        result.put(Constants.DATA_LIST, res);
-        return result;
-    }
+    Map<String, Object> batchActivateUser(User loginUser, List<String> 
userNames);
 }
diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java
similarity index 92%
copy from 
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java
copy to 
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java
index e1e63a6..a038717 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java
@@ -15,12 +15,13 @@
  * limitations under the License.
  */
 
-package org.apache.dolphinscheduler.api.service;
+package org.apache.dolphinscheduler.api.service.impl;
 
 import org.apache.dolphinscheduler.api.enums.Status;
+import org.apache.dolphinscheduler.api.service.AlertGroupService;
+import org.apache.dolphinscheduler.api.service.BaseService;
 import org.apache.dolphinscheduler.api.utils.PageInfo;
 import org.apache.dolphinscheduler.common.Constants;
-import org.apache.dolphinscheduler.common.enums.AlertType;
 import org.apache.dolphinscheduler.common.utils.CollectionUtils;
 import org.apache.dolphinscheduler.common.utils.StringUtils;
 import org.apache.dolphinscheduler.dao.entity.AlertGroup;
@@ -32,8 +33,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -42,12 +41,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 
 /**
- * alert group service
+ * alert group service impl
  */
 @Service
-public class AlertGroupService extends BaseService {
-
-    private static final Logger logger = 
LoggerFactory.getLogger(AlertGroupService.class);
+public class AlertGroupServiceImpl extends BaseService implements 
AlertGroupService {
 
     @Autowired
     private AlertGroupMapper alertGroupMapper;
@@ -57,7 +54,7 @@ public class AlertGroupService extends BaseService {
      *
      * @return alert group list
      */
-    public HashMap<String, Object> queryAlertgroup() {
+    public Map<String, Object> queryAlertgroup() {
 
         HashMap<String, Object> result = new HashMap<>();
         List<AlertGroup> alertGroups = alertGroupMapper.queryAllGroupList();
@@ -83,9 +80,9 @@ public class AlertGroupService extends BaseService {
             return result;
         }
 
-        Page<AlertGroup> page = new Page(pageNo, pageSize);
+        Page<AlertGroup> page = new Page<>(pageNo, pageSize);
         IPage<AlertGroup> alertGroupIPage = 
alertGroupMapper.queryAlertGroupPage(
-            page, searchVal);
+                page, searchVal);
         PageInfo<AlertGroup> pageInfo = new PageInfo<>(pageNo, pageSize);
         pageInfo.setTotalCount((int) alertGroupIPage.getTotal());
         pageInfo.setLists(alertGroupIPage.getRecords());
@@ -166,7 +163,6 @@ public class AlertGroupService extends BaseService {
         alertGroup.setUpdateTime(now);
         alertGroup.setCreateUserId(loginUser.getId());
         alertGroup.setAlertInstanceIds(alertInstanceIds);
-        // updateProcessInstance
         alertGroupMapper.updateById(alertGroup);
         putMsg(result, Status.SUCCESS);
         return result;
diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java
similarity index 97%
copy from 
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
copy to 
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java
index 3fb5f64..d1416df 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java
@@ -15,12 +15,14 @@
  * limitations under the License.
  */
 
-package org.apache.dolphinscheduler.api.service;
+package org.apache.dolphinscheduler.api.service.impl;
 
 import org.apache.dolphinscheduler.api.dto.resources.ResourceComponent;
 import 
org.apache.dolphinscheduler.api.dto.resources.visitor.ResourceTreeVisitor;
 import org.apache.dolphinscheduler.api.enums.Status;
 import org.apache.dolphinscheduler.api.exceptions.ServiceException;
+import org.apache.dolphinscheduler.api.service.BaseService;
+import org.apache.dolphinscheduler.api.service.UsersService;
 import org.apache.dolphinscheduler.api.utils.CheckUtils;
 import org.apache.dolphinscheduler.api.utils.PageInfo;
 import org.apache.dolphinscheduler.api.utils.Result;
@@ -73,12 +75,12 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 
 /**
- * user service
+ * users service impl
  */
 @Service
-public class UsersService extends BaseService {
+public class UsersServiceImpl extends BaseService implements UsersService {
 
-    private static final Logger logger = 
LoggerFactory.getLogger(UsersService.class);
+    private static final Logger logger = 
LoggerFactory.getLogger(UsersServiceImpl.class);
 
     @Autowired
     private UserMapper userMapper;
@@ -129,7 +131,7 @@ public class UsersService extends BaseService {
                                           int tenantId,
                                           String phone,
                                           String queue,
-                                          int state) throws Exception {
+                                          int state) throws IOException {
 
         Map<String, Object> result = new HashMap<>(5);
 
@@ -299,7 +301,7 @@ public class UsersService extends BaseService {
             return result;
         }
 
-        Page<User> page = new Page(pageNo, pageSize);
+        Page<User> page = new Page<>(pageNo, pageSize);
 
         IPage<User> scheduleList = userMapper.queryUserPaging(page, searchVal);
 
@@ -334,7 +336,7 @@ public class UsersService extends BaseService {
                                           int tenantId,
                                           String phone,
                                           String queue,
-                                          int state) throws Exception {
+                                          int state) throws IOException {
         Map<String, Object> result = new HashMap<>(5);
         result.put(Constants.STATUS, false);
 
@@ -458,7 +460,7 @@ public class UsersService extends BaseService {
      * @return delete result code
      * @throws Exception exception when operate hdfs
      */
-    public Map<String, Object> deleteUserById(User loginUser, int id) throws 
Exception {
+    public Map<String, Object> deleteUserById(User loginUser, int id) throws 
IOException {
         Map<String, Object> result = new HashMap<>(5);
         //only admin can operate
         if (!isAdmin(loginUser)) {
@@ -538,7 +540,6 @@ public class UsersService extends BaseService {
         return result;
     }
 
-
     /**
      * grant resource
      *
@@ -560,7 +561,7 @@ public class UsersService extends BaseService {
             return result;
         }
 
-        Set<Integer> needAuthorizeResIds = new HashSet();
+        Set<Integer> needAuthorizeResIds = new HashSet<>();
         if (StringUtils.isNotBlank(resourceIds)) {
             String[] resourceFullIdArr = resourceIds.split(",");
             // need authorize resource id set
@@ -573,11 +574,10 @@ public class UsersService extends BaseService {
             }
         }
 
-
         //get the authorized resource id list by user id
         List<Resource> oldAuthorizedRes = 
resourceMapper.queryAuthorizedResourceList(userId);
-        //if resource type is UDF,need check whether it is bound by UDF functon
-        Set<Integer> oldAuthorizedResIds = oldAuthorizedRes.stream().map(t -> 
t.getId()).collect(Collectors.toSet());
+        //if resource type is UDF,need check whether it is bound by UDF 
function
+        Set<Integer> oldAuthorizedResIds = 
oldAuthorizedRes.stream().map(Resource::getId).collect(Collectors.toSet());
 
         //get the unauthorized resource id list
         oldAuthorizedResIds.removeAll(needAuthorizeResIds);
@@ -635,7 +635,6 @@ public class UsersService extends BaseService {
         return result;
     }
 
-
     /**
      * grant udf function
      *
@@ -682,7 +681,6 @@ public class UsersService extends BaseService {
         return result;
     }
 
-
     /**
      * grant datasource
      *
@@ -751,7 +749,7 @@ public class UsersService extends BaseService {
 
             StringBuilder sb = new StringBuilder();
 
-            if (alertGroups != null && alertGroups.size() > 0) {
+            if (alertGroups != null && !alertGroups.isEmpty()) {
                 for (int i = 0; i < alertGroups.size() - 1; i++) {
                     sb.append(alertGroups.get(i).getGroupName() + ",");
                 }
@@ -786,7 +784,6 @@ public class UsersService extends BaseService {
         return result;
     }
 
-
     /**
      * query user list
      *
@@ -813,13 +810,11 @@ public class UsersService extends BaseService {
      * @param userName user name
      * @return true if user name not exists, otherwise return false
      */
-    public Result verifyUserName(String userName) {
+    public Result<Object> verifyUserName(String userName) {
 
-        Result result = new Result();
+        Result<Object> result = new Result<>();
         User user = userMapper.queryByUserNameAccurately(userName);
         if (user != null) {
-            logger.error("user {} has exist, can't create again.", userName);
-
             putMsg(result, Status.USER_NAME_EXIST);
         } else {
             putMsg(result, Status.SUCCESS);
@@ -828,7 +823,6 @@ public class UsersService extends BaseService {
         return result;
     }
 
-
     /**
      * unauthorized user
      *
@@ -847,13 +841,13 @@ public class UsersService extends BaseService {
         List<User> userList = userMapper.selectList(null);
         List<User> resultUsers = new ArrayList<>();
         Set<User> userSet = null;
-        if (userList != null && userList.size() > 0) {
+        if (userList != null && !userList.isEmpty()) {
             userSet = new HashSet<>(userList);
 
             List<User> authedUserList = 
userMapper.queryUserListByAlertGroupId(alertgroupId);
 
             Set<User> authedUserSet = null;
-            if (authedUserList != null && authedUserList.size() > 0) {
+            if (authedUserList != null && !authedUserList.isEmpty()) {
                 authedUserSet = new HashSet<>(authedUserList);
                 userSet.removeAll(authedUserSet);
             }
@@ -865,7 +859,6 @@ public class UsersService extends BaseService {
         return result;
     }
 
-
     /**
      * authorized user
      *
@@ -891,7 +884,7 @@ public class UsersService extends BaseService {
      * @return true if tenant exists, otherwise return false
      */
     private boolean checkTenantExists(int tenantId) {
-        return tenantMapper.queryById(tenantId) != null ? true : false;
+        return tenantMapper.queryById(tenantId) != null;
     }
 
     /**
diff --git 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java
 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java
index b7b6575..e85dbde 100644
--- 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java
+++ 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AlertGroupServiceTest.java
@@ -21,9 +21,9 @@ import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 
 import org.apache.dolphinscheduler.api.enums.Status;
+import org.apache.dolphinscheduler.api.service.impl.AlertGroupServiceImpl;
 import org.apache.dolphinscheduler.api.utils.PageInfo;
 import org.apache.dolphinscheduler.common.Constants;
-import org.apache.dolphinscheduler.common.enums.AlertType;
 import org.apache.dolphinscheduler.common.enums.UserType;
 import org.apache.dolphinscheduler.common.utils.CollectionUtils;
 import org.apache.dolphinscheduler.dao.entity.AlertGroup;
@@ -31,7 +31,6 @@ import org.apache.dolphinscheduler.dao.entity.User;
 import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -54,7 +53,7 @@ public class AlertGroupServiceTest {
     private static final Logger logger = 
LoggerFactory.getLogger(AlertGroupServiceTest.class);
 
     @InjectMocks
-    private AlertGroupService alertGroupService;
+    private AlertGroupServiceImpl alertGroupService;
     @Mock
     private AlertGroupMapper alertGroupMapper;
 
@@ -64,7 +63,7 @@ public class AlertGroupServiceTest {
     public void testQueryAlertGroup() {
 
         
Mockito.when(alertGroupMapper.queryAllGroupList()).thenReturn(getList());
-        HashMap<String, Object> result = alertGroupService.queryAlertgroup();
+        Map<String, Object> result = alertGroupService.queryAlertgroup();
         logger.info(result.toString());
         List<AlertGroup> alertGroups = (List<AlertGroup>) 
result.get(Constants.DATA_LIST);
         Assert.assertTrue(CollectionUtils.isNotEmpty(alertGroups));
diff --git 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java
 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java
index ca6c721..259842e 100644
--- 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java
+++ 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java
@@ -22,6 +22,7 @@ import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.when;
 
 import org.apache.dolphinscheduler.api.enums.Status;
+import org.apache.dolphinscheduler.api.service.impl.UsersServiceImpl;
 import org.apache.dolphinscheduler.api.utils.PageInfo;
 import org.apache.dolphinscheduler.api.utils.Result;
 import org.apache.dolphinscheduler.common.Constants;
@@ -65,7 +66,7 @@ public class UsersServiceTest {
     private static final Logger logger = 
LoggerFactory.getLogger(UsersServiceTest.class);
 
     @InjectMocks
-    private UsersService usersService;
+    private UsersServiceImpl usersService;
     @Mock
     private UserMapper userMapper;
     @Mock
diff --git 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java
 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java
index 9edf793..0ca80b1 100644
--- 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java
+++ 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java
@@ -73,7 +73,7 @@ public class PropertyUtils {
     /**
      * @return judge whether resource upload startup
      */
-    public static Boolean getResUploadStartupState() {
+    public static boolean getResUploadStartupState() {
         String resUploadStartupType = 
PropertyUtils.getUpperCaseString(Constants.RESOURCE_STORAGE_TYPE);
         ResUploadType resUploadType = 
ResUploadType.valueOf(resUploadStartupType);
         return resUploadType == ResUploadType.HDFS || resUploadType == 
ResUploadType.S3;

Reply via email to