@Override public Role findRole(Long id) { if (id == null || id < 1L) { logger.trace(String.format("Role ID is invalid [%s]", id)); return null; } RoleVO role = roleDao.findById(id); if (role == null) { logger.trace(String.format("Role not found [id=%s]", id)); return null; } Account account = getCurrentAccount(); if (!accountManager.isRootAdmin(account.getId()) && RoleType.Admin == role.getRoleType()) { logger.debug(String.format("Role [id=%s, name=%s] is of 'Admin' type and is only visible to 'Root admins'.", id, role.getName())); return null; } return role; }
@Override public RoleVO doInTransaction(TransactionStatus status) { return roleDao.persist(new RoleVO(name, roleType, description)); } });
@Override @ActionEvent(eventType = EventTypes.EVENT_ROLE_UPDATE, eventDescription = "updating Role") public Role updateRole(final Role role, final String name, final RoleType roleType, final String description) { checkCallerAccess(); if (roleType != null && roleType == RoleType.Unknown) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unknown is not a valid role type"); } RoleVO roleVO = (RoleVO)role; if (!Strings.isNullOrEmpty(name)) { roleVO.setName(name); } if (roleType != null) { if (role.getId() <= RoleType.User.getId()) { throw new PermissionDeniedException("The role type of default roles cannot be changed"); } List<? extends Account> accounts = accountDao.findAccountsByRole(role.getId()); if (accounts == null || accounts.isEmpty()) { roleVO.setRoleType(roleType); } else { throw new PermissionDeniedException("Found accounts that have role in use, won't allow to change role type"); } } if (!Strings.isNullOrEmpty(description)) { roleVO.setDescription(description); } roleDao.update(role.getId(), roleVO); return role; }
@Override public Boolean doInTransaction(TransactionStatus status) { List<? extends RolePermission> rolePermissions = rolePermissionsDao.findAllByRoleIdSorted(role.getId()); if (rolePermissions != null && !rolePermissions.isEmpty()) { for (RolePermission rolePermission : rolePermissions) { rolePermissionsDao.remove(rolePermission.getId()); } } if (roleDao.remove(role.getId())) { RoleVO roleVO = roleDao.findByIdIncludingRemoved(role.getId()); roleVO.setName(null); return roleDao.update(role.getId(), roleVO); } return false; } });
public RoleDaoImpl() { super(); RoleByNameSearch = createSearchBuilder(); RoleByNameSearch.and("roleName", RoleByNameSearch.entity().getName(), SearchCriteria.Op.LIKE); RoleByNameSearch.done(); RoleByTypeSearch = createSearchBuilder(); RoleByTypeSearch.and("roleType", RoleByTypeSearch.entity().getRoleType(), SearchCriteria.Op.EQ); RoleByTypeSearch.done(); }