use of org.apache.cloudstack.acl.RolePermissionVO in project cloudstack by apache.
the class RolePermissionsDaoImpl method persist.
@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);
}
use of org.apache.cloudstack.acl.RolePermissionVO in project cloudstack by apache.
the class RolePermissionsDaoImpl method updateSortOrder.
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;
}
use of org.apache.cloudstack.acl.RolePermissionVO in project cloudstack by apache.
the class RolePermissionsDaoImpl method findAllByRoleIdSorted.
@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;
}
Aggregations