Search in sources :

Example 6 with User

use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.

the class AccountManageServiceCommonImpl method saveAccount.

/**
 * {@inheritDoc}
 *
 * @see AccountManageService#saveAccount(AccountInfo)
 */
@Override
public Account saveAccount(AccountInfo accountInfo) {
    if (accountInfo == null) {
        throw new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM);
    }
    try {
        String accountId = accountInfo.getAccountId();
        Account account;
        if (!StringUtils.isBlank(accountId)) {
            account = accessor.getById(accountId, Account.class);
            if (account == null) {
                if (logger.isErrorEnabled()) {
                    logger.error(String.format("The Account entity[%s] not found.", accountId));
                }
                throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_NOT_FOUND);
            }
        // 这里不允许修改密码,密码必须通过另外途径进行修改
        } else {
            String password = accountInfo.getPassword();
            if (StringUtils.isBlank(password)) {
                password = "ds110119";
            }
            account = EntityFactory.createEntity(Account.class);
            account.setPassword(DigestUtils.md5(password));
        }
        account.setCode(accountInfo.getCode());
        if (StringUtils.isBlank(accountInfo.getOwnerId())) {
            if (!"admin".equals(accountInfo.getCode())) {
                throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_NOALLOCATE_USER);
            }
        } else {
            User owner = accessor.getById(accountInfo.getOwnerId(), User.class);
            if (owner == null) {
                throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.USER_NOT_FOUND);
            }
            account.setOwner(owner);
            account.setName(owner.getFullName());
        }
        account.setDesc(accountInfo.getDesc());
        if (account.getRoles() != null && !account.getRoles().isEmpty()) {
            account.getRoles().clear();
        }
        for (String roleId : accountInfo.getRoleIds()) {
            Role role = accessor.getById(roleId, Role.class);
            if (role == null) {
                throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ROLE_NOT_FOUND);
            }
            account.getRoles().add(role);
        }
        account.setValid(accountInfo.isValid());
        account = this.save(account);
        if (operateLogService != null) {
            operateLogService.writeLog(String.format("保存账户[code=%s, name=%s]成功。", account.getCode(), account.getName()));
        }
        return account;
    } catch (UserInterfaceDalErrorException ex) {
        if (logger.isErrorEnabled()) {
            logger.error(ex);
        }
        throw new UserInterfaceDalErrorException(UserInterfaceDalErrorException.DalErrors.DB_OPERATE_FAIL);
    } catch (NoSuchAlgorithmException ex) {
        if (logger.isErrorEnabled()) {
            logger.error(ex);
        }
        throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_DIGEST_PASSWORD_FAIL);
    }
}
Also used : Role(org.mx.comps.rbac.dal.entity.Role) Account(org.mx.comps.rbac.dal.entity.Account) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException) User(org.mx.comps.rbac.dal.entity.User) UserInterfaceDalErrorException(org.mx.dal.error.UserInterfaceDalErrorException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 7 with User

use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.

the class UserManageServiceCommonImpl method allocateAccount.

/**
 * {@inheritDoc}
 *
 * @see UserManageService#allocateAccount(AccountManageService.AccountInfo)
 */
@Override
public Account allocateAccount(AccountManageService.AccountInfo accountInfo) {
    if (accountInfo == null || StringUtils.isBlank(accountInfo.getOwnerId()) || StringUtils.isBlank(accountInfo.getCode())) {
        throw new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM);
    }
    User user = accessor.getById(accountInfo.getOwnerId(), User.class);
    if (user == null) {
        throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.USER_NOT_FOUND);
    }
    Account account = accessor.getByCode(accountInfo.getCode(), Account.class);
    if (account != null) {
        throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_HAS_EXIST);
    }
    account = accountManageService.saveAccount(accountInfo);
    if (operateLogService != null) {
        operateLogService.writeLog(String.format("为用户[%s]分配账户[%s]成功。", user.getFullName(), account.getCode()));
    }
    return account;
}
Also used : Account(org.mx.comps.rbac.dal.entity.Account) User(org.mx.comps.rbac.dal.entity.User) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException)

Example 8 with User

use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.

the class UserManageServiceCommonImpl method saveUser.

/**
 * {@inheritDoc}
 *
 * @see UserManageService#saveUser(UserInfo)
 */
@Override
public User saveUser(UserInfo userInfo) {
    if (userInfo == null) {
        throw new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM);
    }
    String userId = userInfo.getUserId();
    User user;
    if (!StringUtils.isBlank(userId)) {
        user = accessor.getById(userId, User.class);
        if (user == null) {
            if (logger.isErrorEnabled()) {
                logger.error(String.format("The User entity[%s] not found.", userId));
            }
            throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.USER_NOT_FOUND);
        }
    } else {
        user = EntityFactory.createEntity(User.class);
    }
    if (!StringUtils.isBlank(userInfo.getDepartId())) {
        Department depart = accessor.getById(userInfo.getDepartId(), Department.class);
        if (depart == null) {
            throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.DEPARTMENT_NOT_FOUND);
        }
        user.setDepartment(depart);
    } else {
        user.setDepartment(null);
    }
    long birthday = userInfo.getBirthday();
    if (birthday > 0) {
        user.setBirthday(new Date(birthday));
    }
    user.setDesc(userInfo.getDesc());
    user.setFirstName(userInfo.getFirstName());
    user.setMiddleName(userInfo.getMiddleName());
    user.setLastName(userInfo.getLastName());
    user.setSex(userInfo.getSex());
    user.setStation(userInfo.getStation());
    user.setValid(userInfo.isValid());
    user = this.save(user);
    if (operateLogService != null) {
        operateLogService.writeLog(String.format("保存用户[name=%s]信息成功。", user.getFullName()));
    }
    return user;
}
Also used : Department(org.mx.comps.rbac.dal.entity.Department) User(org.mx.comps.rbac.dal.entity.User) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) Date(java.util.Date)

Example 9 with User

use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.

the class UserManageResource method listUsersPagination.

@Path("users")
@POST
@AuthenticateAround(returnValueClass = PaginationDataVO.class)
public PaginationDataVO<List<UserVO>> listUsersPagination(Pagination pagination) {
    if (pagination == null) {
        pagination = new Pagination();
    }
    try {
        List<User> users = accessor.list(pagination, User.class);
        List<UserVO> userVOs = UserVO.transform(users);
        return new PaginationDataVO<>(pagination, userVOs);
    } catch (UserInterfaceException ex) {
        return new PaginationDataVO<>(ex);
    } catch (Exception ex) {
        if (logger.isErrorEnabled()) {
            logger.error("List users fail.", ex);
        }
        return new PaginationDataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
    }
}
Also used : Pagination(org.mx.dal.Pagination) User(org.mx.comps.rbac.dal.entity.User) PaginationDataVO(org.mx.service.rest.vo.PaginationDataVO) UserVO(org.mx.comps.rbac.rest.vo.UserVO) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) AuthenticateAround(org.mx.comps.jwt.AuthenticateAround)

Example 10 with User

use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.

the class UserManageResource method newUser.

@Path("users/new")
@POST
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<UserVO> newUser(@QueryParam("userCode") String userCode, UserInfoVO userInfoVO) {
    sessionDataStore.setCurrentUserCode(userCode);
    try {
        userInfoVO.setId(null);
        User user = userManageService.saveUser(userInfoVO.getUserInfo());
        UserVO userVO = UserVO.transform(user);
        sessionDataStore.removeCurrentUserCode();
        return new DataVO<>(userVO);
    } catch (UserInterfaceException ex) {
        return new DataVO<>(ex);
    } catch (Exception ex) {
        if (logger.isErrorEnabled()) {
            logger.error("Create a user fail.", ex);
        }
        return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
    }
}
Also used : User(org.mx.comps.rbac.dal.entity.User) UserVO(org.mx.comps.rbac.rest.vo.UserVO) DataVO(org.mx.service.rest.vo.DataVO) PaginationDataVO(org.mx.service.rest.vo.PaginationDataVO) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) AuthenticateAround(org.mx.comps.jwt.AuthenticateAround)

Aggregations

User (org.mx.comps.rbac.dal.entity.User)19 UserInterfaceSystemErrorException (org.mx.error.UserInterfaceSystemErrorException)9 UserInterfaceRbacErrorException (org.mx.comps.rbac.error.UserInterfaceRbacErrorException)6 AuthenticateAround (org.mx.comps.jwt.AuthenticateAround)5 Account (org.mx.comps.rbac.dal.entity.Account)5 UserVO (org.mx.comps.rbac.rest.vo.UserVO)5 UserManageService (org.mx.comps.rbac.service.UserManageService)5 UserInterfaceException (org.mx.error.UserInterfaceException)5 PaginationDataVO (org.mx.service.rest.vo.PaginationDataVO)5 Department (org.mx.comps.rbac.dal.entity.Department)4 DataVO (org.mx.service.rest.vo.DataVO)4 Test (org.junit.Test)3 AccountManageService (org.mx.comps.rbac.service.AccountManageService)3 GeneralDictAccessor (org.mx.dal.service.GeneralDictAccessor)3 ParseException (java.text.ParseException)2 DepartmentManageService (org.mx.comps.rbac.service.DepartmentManageService)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1