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);
}
}
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());
}
}
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);
}
}
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);
}
}
Aggregations