Search in sources :

Example 11 with Paging

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

the class TemplateGroupsAction method handle.

@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        WsTemplateRef templateRef = WsTemplateRef.fromRequest(wsRequest);
        PermissionTemplateDto template = support.findTemplate(dbSession, templateRef);
        checkGlobalAdmin(userSession, template.getOrganizationUuid());
        PermissionQuery query = buildPermissionQuery(wsRequest);
        int total = dbClient.permissionTemplateDao().countGroupNamesByQueryAndTemplate(dbSession, query, template.getOrganizationUuid(), template.getId());
        Paging paging = Paging.forPageIndex(wsRequest.mandatoryParamAsInt(PAGE)).withPageSize(wsRequest.mandatoryParamAsInt(PAGE_SIZE)).andTotal(total);
        List<GroupDto> groups = findGroups(dbSession, query, template);
        List<PermissionTemplateGroupDto> groupPermissions = findGroupPermissions(dbSession, groups, template);
        WsPermissions.WsGroupsResponse groupsResponse = buildResponse(groups, groupPermissions, paging);
        writeProtobuf(groupsResponse, wsRequest, wsResponse);
    }
}
Also used : DbSession(org.sonar.db.DbSession) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) Paging(org.sonar.api.utils.Paging) PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) GroupDto(org.sonar.db.user.GroupDto) WsPermissions(org.sonarqube.ws.WsPermissions) PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) PermissionQuery(org.sonar.db.permission.PermissionQuery)

Example 12 with Paging

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

the class QgateProjectFinder method find.

public Association find(ProjectQgateAssociationQuery query) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        getQualityGateId(dbSession, query.gateId());
        List<ProjectQgateAssociationDto> projects = associationDao.selectProjects(dbSession, query);
        List<ProjectQgateAssociationDto> authorizedProjects = keepAuthorizedProjects(dbSession, projects);
        Paging paging = forPageIndex(query.pageIndex()).withPageSize(query.pageSize()).andTotal(authorizedProjects.size());
        return new Association(toProjectAssociations(getPaginatedProjects(authorizedProjects, paging)), paging.hasNextPage());
    }
}
Also used : DbSession(org.sonar.db.DbSession) ProjectQgateAssociation(org.sonar.db.qualitygate.ProjectQgateAssociation) Paging(org.sonar.api.utils.Paging) ProjectQgateAssociationDto(org.sonar.db.qualitygate.ProjectQgateAssociationDto)

Example 13 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();
    try (DbSession dbSession = dbClient.openSession(false)) {
        List<ComponentDto> authorizedFavorites = favoriteFinder.list().stream().filter(isAuthorized(dbSession)).collect(Collectors.toList());
        Paging paging = Paging.forPageIndex(request.getPage()).withPageSize(request.getPageSize()).andTotal(authorizedFavorites.size());
        List<ComponentDto> displayedFavorites = authorizedFavorites.stream().skip(paging.offset()).limit(paging.pageSize()).collect(Collectors.toList());
        Map<String, OrganizationDto> organizationsByUuid = getOrganizationsOfComponents(dbSession, displayedFavorites);
        return new SearchResults(paging, displayedFavorites, organizationsByUuid);
    }
}
Also used : DbSession(org.sonar.db.DbSession) Paging(org.sonar.api.utils.Paging) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 14 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)) {
        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, projectId);
        // TODO validatePermission(groupsRequest.getPermission(), wsProjectRef);
        List<GroupDto> groups = findGroups(dbSession, org, query);
        int total = dbClient.groupPermissionDao().countGroupsByQuery(dbSession, org.getUuid(), 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);
    }
}
Also used : DbSession(org.sonar.db.DbSession) Paging(org.sonar.api.utils.Paging) ProjectId(org.sonar.server.permission.ProjectId) GroupDto(org.sonar.db.user.GroupDto) WsGroupsResponse(org.sonarqube.ws.WsPermissions.WsGroupsResponse) OrganizationDto(org.sonar.db.organization.OrganizationDto) PermissionQuery(org.sonar.db.permission.PermissionQuery) GroupPermissionDto(org.sonar.db.permission.GroupPermissionDto)

Aggregations

Paging (org.sonar.api.utils.Paging)14 DbSession (org.sonar.db.DbSession)12 OrganizationDto (org.sonar.db.organization.OrganizationDto)6 ComponentDto (org.sonar.db.component.ComponentDto)4 PermissionQuery (org.sonar.db.permission.PermissionQuery)4 UserDto (org.sonar.db.user.UserDto)3 JsonWriter (org.sonar.api.utils.text.JsonWriter)2 ComponentQuery (org.sonar.db.component.ComponentQuery)2 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)2 GroupDto (org.sonar.db.user.GroupDto)2 ProjectId (org.sonar.server.permission.ProjectId)2 WsPermissions (org.sonarqube.ws.WsPermissions)2 UsersWsResponse (org.sonarqube.ws.WsPermissions.UsersWsResponse)2 CompareToBuilder (org.apache.commons.lang.builder.CompareToBuilder)1 OrganizationQuery (org.sonar.db.organization.OrganizationQuery)1 GroupPermissionDto (org.sonar.db.permission.GroupPermissionDto)1 UserPermissionDto (org.sonar.db.permission.UserPermissionDto)1 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)1 PermissionTemplateUserDto (org.sonar.db.permission.template.PermissionTemplateUserDto)1 ProjectQgateAssociation (org.sonar.db.qualitygate.ProjectQgateAssociation)1