Search in sources :

Example 16 with Paging

use of org.sonar.api.utils.Paging in project sonarqube by SonarSource.

the class GroupsAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        Optional<ComponentDto> project = wsSupport.findProject(dbSession, request);
        wsSupport.checkPermissionManagementAccess(userSession, project.orElse(null));
        PermissionQuery query = buildPermissionQuery(request, project.orElse(null));
        List<GroupDto> groups = findGroups(dbSession, query);
        int total = dbClient.groupPermissionDao().countGroupsByQuery(dbSession, query);
        List<GroupPermissionDto> groupsWithPermission = findGroupPermissions(dbSession, groups, project.orElse(null));
        Paging paging = Paging.forPageIndex(request.mandatoryParamAsInt(Param.PAGE)).withPageSize(query.getPageSize()).andTotal(total);
        WsGroupsResponse groupsResponse = buildResponse(groups, groupsWithPermission, paging);
        writeProtobuf(groupsResponse, request, response);
    }
}
Also used : DbSession(org.sonar.db.DbSession) Paging(org.sonar.api.utils.Paging) ComponentDto(org.sonar.db.component.ComponentDto) GroupDto(org.sonar.db.user.GroupDto) WsGroupsResponse(org.sonarqube.ws.Permissions.WsGroupsResponse) PermissionQuery(org.sonar.db.permission.PermissionQuery) GroupPermissionDto(org.sonar.db.permission.GroupPermissionDto)

Example 17 with Paging

use of org.sonar.api.utils.Paging in project sonarqube by SonarSource.

the class SearchAction method searchHotspots.

private SearchResponseData searchHotspots(WsRequest wsRequest, DbSession dbSession, @Nullable ComponentDto project) {
    SearchResponse result = doIndexSearch(wsRequest, dbSession, project);
    List<String> issueKeys = Arrays.stream(result.getHits().getHits()).map(SearchHit::getId).collect(toList(result.getHits().getHits().length));
    List<IssueDto> hotspots = toIssueDtos(dbSession, issueKeys);
    Paging paging = forPageIndex(wsRequest.getPage()).withPageSize(wsRequest.getIndex()).andTotal((int) getTotalHits(result).value);
    return new SearchResponseData(paging, hotspots);
}
Also used : Paging(org.sonar.api.utils.Paging) IssueDto(org.sonar.db.issue.IssueDto) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 18 with Paging

use of org.sonar.api.utils.Paging in project sonarqube by SonarSource.

the class SearchAction method formatPaging.

private static void formatPaging(SearchResponseData searchResponseData, SearchWsResponse.Builder responseBuilder) {
    Paging paging = searchResponseData.getPaging();
    Common.Paging.Builder pagingBuilder = Common.Paging.newBuilder().setPageIndex(paging.pageIndex()).setPageSize(paging.pageSize()).setTotal(paging.total());
    responseBuilder.setPaging(pagingBuilder.build());
}
Also used : Paging(org.sonar.api.utils.Paging)

Example 19 with Paging

use of org.sonar.api.utils.Paging in project sonarqube by SonarSource.

the class SearchAction method toSearchResults.

private SearchResults toSearchResults(SearchRequest request) {
    userSession.checkLoggedIn();
    List<ComponentDto> authorizedFavorites = getAuthorizedFavorites();
    Paging paging = Paging.forPageIndex(Integer.parseInt(request.getP())).withPageSize(Integer.parseInt(request.getPs())).andTotal(authorizedFavorites.size());
    List<ComponentDto> displayedFavorites = authorizedFavorites.stream().skip(paging.offset()).limit(paging.pageSize()).collect(MoreCollectors.toList());
    return new SearchResults(paging, displayedFavorites);
}
Also used : Paging(org.sonar.api.utils.Paging) ComponentDto(org.sonar.db.component.ComponentDto)

Example 20 with Paging

use of org.sonar.api.utils.Paging in project sonarqube by SonarSource.

the class SearchAction method doHandle.

private Users.SearchWsResponse doHandle(SearchRequest request) {
    SearchOptions options = new SearchOptions().setPage(request.getPage(), request.getPageSize());
    SearchResult<UserDoc> result = userIndex.search(UserQuery.builder().setTextQuery(request.getQuery()).build(), options);
    try (DbSession dbSession = dbClient.openSession(false)) {
        List<String> logins = result.getDocs().stream().map(UserDoc::login).collect(toList());
        Multimap<String, String> groupsByLogin = dbClient.groupMembershipDao().selectGroupsByLogins(dbSession, logins);
        List<UserDto> users = dbClient.userDao().selectByOrderedLogins(dbSession, logins);
        Map<String, Integer> tokenCountsByLogin = dbClient.userTokenDao().countTokensByUsers(dbSession, users);
        Paging paging = forPageIndex(request.getPage()).withPageSize(request.getPageSize()).andTotal((int) result.getTotal());
        return buildResponse(users, groupsByLogin, tokenCountsByLogin, paging);
    }
}
Also used : DbSession(org.sonar.db.DbSession) UserDto(org.sonar.db.user.UserDto) Paging(org.sonar.api.utils.Paging) SearchOptions(org.sonar.server.es.SearchOptions) UserDoc(org.sonar.server.user.index.UserDoc)

Aggregations

Paging (org.sonar.api.utils.Paging)21 DbSession (org.sonar.db.DbSession)15 ComponentDto (org.sonar.db.component.ComponentDto)7 PermissionQuery (org.sonar.db.permission.PermissionQuery)4 UserDto (org.sonar.db.user.UserDto)4 SearchOptions (org.sonar.server.es.SearchOptions)4 ComponentQuery (org.sonar.db.component.ComponentQuery)3 OrganizationDto (org.sonar.db.organization.OrganizationDto)3 GroupDto (org.sonar.db.user.GroupDto)3 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 JsonWriter (org.sonar.api.utils.text.JsonWriter)2 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)2 ProjectQgateAssociationDto (org.sonar.db.qualitygate.ProjectQgateAssociationDto)2 Facets (org.sonar.server.es.Facets)2 UsersWsResponse (org.sonarqube.ws.Permissions.UsersWsResponse)2 Collection (java.util.Collection)1 Comparator.comparing (java.util.Comparator.comparing)1 List (java.util.List)1 Set (java.util.Set)1 Change (org.sonar.api.server.ws.Change)1