@Override public RolePermission findRolePermission(final Long id) { if (id == null) { return null; } return rolePermissionsDao.findById(id); }
@Override public RolePermission findRolePermissionByUuid(final String uuid) { if (Strings.isNullOrEmpty(uuid)) { return null; } return rolePermissionsDao.findByUuid(uuid); }
@Override public List<RolePermission> findAllPermissionsBy(final Long roleId) { List<? extends RolePermission> permissions = rolePermissionsDao.findAllByRoleIdSorted(roleId); if (permissions != null) { return new ArrayList<>(permissions); } return Collections.emptyList(); }
@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; } });
@Override public boolean update(Role role, RolePermission rolePermission, Permission permission) { if (role == null || rolePermission == null || permission == null) { return false; } RolePermissionVO rolePermissionVO = findById(rolePermission.getId()); if (rolePermissionVO == null || role.getId() != rolePermission.getRoleId() || rolePermissionVO.getId() != rolePermission.getId()) { return false; } rolePermissionVO.setPermission(permission); return update(rolePermission.getId(), rolePermissionVO); }
private boolean updateSortOrder(final RolePermissionVO permissionBeingMoved, final RolePermissionVO parentPermission) { if (parentPermission != null && permissionBeingMoved.getId() == parentPermission.getId()) { return true; } final List<RolePermissionVO> newOrderedPermissionsList = new ArrayList<>(); // Null parent implies item needs to move to the top if (parentPermission == null) { newOrderedPermissionsList.add(permissionBeingMoved); } for (final RolePermissionVO permission : findAllByRoleIdSorted(permissionBeingMoved.getRoleId())) { if (permission.getId() == permissionBeingMoved.getId()) { continue; } newOrderedPermissionsList.add(permission); if (parentPermission != null && permission.getId() == parentPermission.getId()) { newOrderedPermissionsList.add(permissionBeingMoved); } } long sortOrder = 0L; for (final RolePermissionVO permission : newOrderedPermissionsList) { permission.setSortOrder(sortOrder++); if (!update(permission.getId(), permission)) { LOGGER.warn("Failed to update item's sort order with id:" + permission.getId() + " while moving permission with id:" + permissionBeingMoved.getId() + " to a new position"); return false; } } return true; }
@Override public boolean updateRolePermission(Role role, RolePermission rolePermission, RolePermission.Permission permission) { checkCallerAccess(); return role != null && rolePermissionsDao.update(role, rolePermission, permission); }
@Override public List<RoleVO> findAllByName(final String roleName) { SearchCriteria<RoleVO> sc = RoleByNameSearch.create(); sc.setParameters("roleName", "%" + roleName + "%"); return listBy(sc); }
@Override public RoleVO doInTransaction(TransactionStatus status) { return roleDao.persist(new RoleVO(name, roleType, description)); } });
@Override public List<Role> listRoles() { List<? extends Role> roles = roleDao.listAll(); removeRootAdminRolesIfNeeded(roles); return ListUtils.toListOfInterface(roles); }
@Override public List<Role> findRolesByName(String name) { List<? extends Role> roles = null; if (StringUtils.isNotBlank(name)) { roles = roleDao.findAllByName(name); } removeRootAdminRolesIfNeeded(roles); return ListUtils.toListOfInterface(roles); }
@Override public List<RolePermissionVO> findAllByRoleIdSorted(final Long roleId) { final SearchCriteria<RolePermissionVO> sc = RolePermissionsSearch.create(); if (roleId != null && roleId > 0L) { sc.setParameters("roleId", roleId); } final Filter searchBySorted = new Filter(RolePermissionVO.class, "sortOrder", true, null, null); final List<RolePermissionVO> rolePermissionList = listBy(sc, searchBySorted); if (rolePermissionList == null) { return Collections.emptyList(); } return rolePermissionList; } }
@Override public RolePermissionVO persist(final RolePermissionVO item) { item.setSortOrder(0); final List<RolePermissionVO> permissionsList = findAllByRoleIdSorted(item.getRoleId()); if (permissionsList != null && permissionsList.size() > 0) { RolePermission lastRule = permissionsList.get(permissionsList.size() - 1); item.setSortOrder(lastRule.getSortOrder() + 1); } return super.persist(item); }
@Override public RolePermissionVO doInTransaction(TransactionStatus status) { return rolePermissionsDao.persist(new RolePermissionVO(role.getId(), rule.toString(), permission, description)); } });
@Override @ActionEvent(eventType = EventTypes.EVENT_ROLE_PERMISSION_DELETE, eventDescription = "deleting Role Permission") public boolean deleteRolePermission(final RolePermission rolePermission) { checkCallerAccess(); return rolePermission != null && rolePermissionsDao.remove(rolePermission.getId()); }
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(); }
@Override public List<Role> findRolesByType(RoleType roleType) { if (roleType == null || RoleType.Admin == roleType && !accountManager.isRootAdmin(getCurrentAccount().getId())) { return Collections.emptyList(); } List<? extends Role> roles = roleDao.findAllByRoleType(roleType); return ListUtils.toListOfInterface(roles); }
public RolePermissionsDaoImpl() { super(); RolePermissionsSearch = createSearchBuilder(); RolePermissionsSearch.and("uuid", RolePermissionsSearch.entity().getUuid(), SearchCriteria.Op.EQ); RolePermissionsSearch.and("roleId", RolePermissionsSearch.entity().getRoleId(), SearchCriteria.Op.EQ); RolePermissionsSearch.and("sortOrder", RolePermissionsSearch.entity().getSortOrder(), SearchCriteria.Op.EQ); RolePermissionsSearch.done(); sortOrderAttribute = _allAttributes.get("sortOrder"); assert (sortOrderAttribute != null) : "Couldn't find one of these attributes"; }
@Override @ActionEvent(eventType = EventTypes.EVENT_ROLE_PERMISSION_UPDATE, eventDescription = "updating Role Permission order") public boolean updateRolePermission(final Role role, final List<RolePermission> newOrder) { checkCallerAccess(); return role != null && newOrder != null && rolePermissionsDao.update(role, newOrder); }
@Override public List<RoleVO> findAllByRoleType(final RoleType type) { SearchCriteria<RoleVO> sc = RoleByTypeSearch.create(); sc.setParameters("roleType", type); return listBy(sc); } }