Search in sources :

Example 16 with UserInterfaceRbacErrorException

use of org.mx.comps.rbac.error.UserInterfaceRbacErrorException in project main by JohnPeng739.

the class RoleManageServiceCommonImpl method saveRole.

/**
 * {@inheritDoc}
 *
 * @see RoleManageService#saveRole(RoleInfo)
 */
@Override
public Role saveRole(RoleInfo roleInfo) {
    if (roleInfo == null) {
        throw new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM);
    }
    String id = roleInfo.getRoleId();
    Role role;
    if (!StringUtils.isBlank(id)) {
        role = accessor.getById(id, Role.class);
        if (role == null) {
            throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ROLE_NOT_FOUND);
        }
    } else {
        role = EntityFactory.createEntity(Role.class);
    }
    role.setCode(roleInfo.getCode());
    role.setName(roleInfo.getName());
    role.setDesc(roleInfo.getDesc());
    if (role.getAccounts() != null && !role.getAccounts().isEmpty()) {
        role.getAccounts().clear();
    }
    if (roleInfo.getAccountIds() != null && !roleInfo.getAccountIds().isEmpty()) {
        for (String accountId : roleInfo.getAccountIds()) {
            Account account = accessor.getById(accountId, Account.class);
            if (account == null) {
                throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_NOT_FOUND);
            }
            role.getAccounts().add(account);
        }
    }
    if (role.getPrivileges() != null && !role.getPrivileges().isEmpty()) {
        role.getPrivileges().clear();
        for (String privilegeId : roleInfo.getPrivilegeIds()) {
            Privilege privilege = accessor.getById(privilegeId, Privilege.class);
            if (privilege == null) {
                throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.PRIVILEGE_NOT_FOUND);
            }
            role.getPrivileges().add(privilege);
        }
    }
    role.setValid(roleInfo.isValid());
    role = this.save(role);
    if (operateLogService != null) {
        operateLogService.writeLog(String.format("保存角色[code=%s, name=%s]信息成功。", roleInfo.getCode(), roleInfo.getName()));
    }
    return role;
}
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) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) Privilege(org.mx.comps.rbac.dal.entity.Privilege)

Aggregations

UserInterfaceRbacErrorException (org.mx.comps.rbac.error.UserInterfaceRbacErrorException)16 Account (org.mx.comps.rbac.dal.entity.Account)12 UserInterfaceSystemErrorException (org.mx.error.UserInterfaceSystemErrorException)10 User (org.mx.comps.rbac.dal.entity.User)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 Date (java.util.Date)5 Role (org.mx.comps.rbac.dal.entity.Role)5 Test (org.junit.Test)3 Accredit (org.mx.comps.rbac.dal.entity.Accredit)3 LoginHistory (org.mx.comps.rbac.dal.entity.LoginHistory)3 AccountManageService (org.mx.comps.rbac.service.AccountManageService)3 UserManageService (org.mx.comps.rbac.service.UserManageService)3 GeneralDictAccessor (org.mx.dal.service.GeneralDictAccessor)3 Department (org.mx.comps.rbac.dal.entity.Department)2 GeneralAccessor (org.mx.dal.service.GeneralAccessor)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 Privilege (org.mx.comps.rbac.dal.entity.Privilege)1 AccreditManageService (org.mx.comps.rbac.service.AccreditManageService)1