public List<Integer> selectUserIdsByQuery(DbSession dbSession, PermissionQuery query) { return mapper(dbSession).selectUserIdsByQuery(query) .stream() // Pagination is done in Java because it's too complex to use SQL pagination in Oracle and MsSQL with the distinct .skip(query.getPageOffset()) .limit(query.getPageSize()) .collect(MoreCollectors.toArrayList()); }
/** * Returns the names of the groups that match the given query, for the given organization. * The virtual group "Anyone" may be returned as the value {@link DefaultGroups#ANYONE}. * @return group names, sorted in alphabetical order */ public List<String> selectGroupNamesByQuery(DbSession dbSession, PermissionQuery query) { return mapper(dbSession).selectGroupNamesByQuery(query, new RowBounds(query.getPageOffset(), query.getPageSize())); }
/** * @return a paginated list of user logins. */ public List<String> selectUserLoginsByQueryAndTemplate(DbSession session, PermissionQuery query, long templateId) { return mapper(session).selectUserLoginsByQueryAndTemplate(query, templateId, new RowBounds(query.getPageOffset(), query.getPageSize())); }
public List<String> selectGroupNamesByQueryAndTemplate(DbSession session, PermissionQuery query, long templateId) { return mapper(session).selectGroupNamesByQueryAndTemplate(templateId, query, new RowBounds(query.getPageOffset(), query.getPageSize())); }
@Test public void create_query_with_default_pagination() { PermissionQuery quey = PermissionQuery.builder() .setOrganizationUuid("ORGANIZATION_UUID") .build(); assertThat(quey.getPageOffset()).isEqualTo(0); assertThat(quey.getPageSize()).isEqualTo(20); }
@Test public void create_query_with_pagination() { PermissionQuery quey = PermissionQuery.builder() .setOrganizationUuid("ORGANIZATION_UUID") .setPageSize(10) .setPageIndex(5) .build(); assertThat(quey.getPageOffset()).isEqualTo(40); assertThat(quey.getPageSize()).isEqualTo(10); }
@Override public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto org = wsSupport.findOrganization(dbSession, request.param(PARAM_ORGANIZATION)); Optional<ProjectId> projectId = wsSupport.findProjectId(dbSession, request); checkProjectAdmin(userSession, org.getUuid(), projectId); PermissionQuery query = buildPermissionQuery(request, org, projectId); // TODO validatePermission(groupsRequest.getPermission(), wsProjectRef); List<GroupDto> groups = findGroups(dbSession, org, query); int total = dbClient.groupPermissionDao().countGroupsByQuery(dbSession, query); List<GroupPermissionDto> groupsWithPermission = findGroupPermissions(dbSession, org, groups, projectId); Paging paging = Paging.forPageIndex(request.mandatoryParamAsInt(Param.PAGE)).withPageSize(query.getPageSize()).andTotal(total); WsGroupsResponse groupsResponse = buildResponse(groups, groupsWithPermission, paging); writeProtobuf(groupsResponse, request, response); } }
@Override public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto org = wsSupport.findOrganization(dbSession, request.param(PARAM_ORGANIZATION)); Optional<ProjectId> projectId = wsSupport.findProjectId(dbSession, request); checkProjectAdmin(userSession, org.getUuid(), projectId); PermissionQuery query = buildPermissionQuery(request, org, projectId); List<UserDto> users = findUsers(dbSession, query); int total = dbClient.userPermissionDao().countUsersByQuery(dbSession, query); List<UserPermissionDto> userPermissions = findUserPermissions(dbSession, org, users, projectId); Paging paging = Paging.forPageIndex(request.mandatoryParamAsInt(Param.PAGE)).withPageSize(query.getPageSize()).andTotal(total); UsersWsResponse usersWsResponse = buildResponse(users, userPermissions, paging); writeProtobuf(usersWsResponse, request, response); } }
/** * List of user permissions ordered by alphabetical order of user names * * @param query non-null query including optional filters. * @param userLogins if null, then filter on all active users. If not null, then filter on logins, including disabled users. * Must not be empty. If not null then maximum size is {@link org.sonar.db.DatabaseUtils#PARTITION_SIZE_FOR_ORACLE}. */ public List<UserPermissionDto> select(DbSession dbSession, String organizationUuid, PermissionQuery query, @Nullable Collection<String> userLogins) { if (userLogins != null) { if (userLogins.isEmpty()) { return emptyList(); } checkArgument(userLogins.size() <= DatabaseUtils.PARTITION_SIZE_FOR_ORACLE, "Maximum 1'000 users are accepted"); } RowBounds rowBounds = new RowBounds(query.getPageOffset(), query.getPageSize()); return mapper(dbSession).selectByQuery(organizationUuid, query, userLogins, rowBounds); }
/** * Returns the names of the groups that match the given query, for the given organization. * The virtual group "Anyone" may be returned as the value {@link DefaultGroups#ANYONE}. * @return group names, sorted in alphabetical order */ public List<String> selectGroupNamesByQuery(DbSession dbSession, String organizationUuid, PermissionQuery query) { return mapper(dbSession).selectGroupNamesByQuery(organizationUuid, query, new RowBounds(query.getPageOffset(), query.getPageSize())); }
/** * @return a paginated list of user logins. */ public List<String> selectUserLoginsByQueryAndTemplate(DbSession session, PermissionQuery query, long templateId) { return mapper(session).selectUserLoginsByQueryAndTemplate(query, templateId, new RowBounds(query.getPageOffset(), query.getPageSize())); }
public List<String> selectGroupNamesByQueryAndTemplate(DbSession session, PermissionQuery query, String organizationUuid, long templateId) { return mapper(session).selectGroupNamesByQueryAndTemplate(organizationUuid, templateId, query, new RowBounds(query.getPageOffset(), query.getPageSize())); }
@Override public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto org = support.findOrganization(dbSession, request.param(PARAM_ORGANIZATION)); Optional<ProjectId> projectId = support.findProjectId(dbSession, request); checkProjectAdmin(userSession, org.getUuid(), projectId); PermissionQuery query = buildPermissionQuery(request, org, projectId); List<UserDto> users = findUsers(dbSession, query); int total = dbClient.userPermissionDao().countUsersByQuery(dbSession, query); List<UserPermissionDto> userPermissions = findUserPermissions(dbSession, org, users, projectId); Paging paging = Paging.forPageIndex(request.mandatoryParamAsInt(Param.PAGE)).withPageSize(query.getPageSize()).andTotal(total); UsersWsResponse usersWsResponse = buildResponse(users, userPermissions, paging); writeProtobuf(usersWsResponse, request, response); } }
@Override public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto org = support.findOrganization(dbSession, request.param(PARAM_ORGANIZATION)); Optional<ProjectId> projectId = support.findProjectId(dbSession, request); checkProjectAdmin(userSession, org.getUuid(), projectId); PermissionQuery query = buildPermissionQuery(request, org, projectId); // TODO validatePermission(groupsRequest.getPermission(), wsProjectRef); List<GroupDto> groups = findGroups(dbSession, org, query); int total = dbClient.groupPermissionDao().countGroupsByQuery(dbSession, query); List<GroupPermissionDto> groupsWithPermission = findGroupPermissions(dbSession, org, groups, projectId); Paging paging = Paging.forPageIndex(request.mandatoryParamAsInt(Param.PAGE)).withPageSize(query.getPageSize()).andTotal(total); WsGroupsResponse groupsResponse = buildResponse(groups, groupsWithPermission, paging); writeProtobuf(groupsResponse, request, response); } }