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;
}
Aggregations