use of org.sonar.api.utils.Paging in project sonarqube by SonarSource.
the class SearchAction method doHandle.
private SearchWsResponse doHandle(SearchWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentQuery query = buildQuery(request);
OrganizationDto organization = getOrganization(dbSession, request);
Paging paging = buildPaging(dbSession, request, organization, query);
List<ComponentDto> components = searchComponents(dbSession, organization, query, paging);
return buildResponse(components, organization, paging);
}
}
use of org.sonar.api.utils.Paging in project sonarqube by SonarSource.
the class SearchAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
Paging paging = Paging.forPageIndex(request.mandatoryParamAsInt(Param.PAGE)).withPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE)).andTotal(0);
OrganizationQuery organizationQuery = newOrganizationQueryBuilder().setKeys(request.paramAsStrings(PARAM_ORGANIZATIONS)).build();
List<OrganizationDto> dtos = dbClient.organizationDao().selectByQuery(dbSession, organizationQuery, paging.offset(), paging.pageSize());
writeResponse(request, response, dtos);
}
}
use of org.sonar.api.utils.Paging in project sonarqube by SonarSource.
the class SearchAction method doHandle.
private SearchWsResponse doHandle(SearchWsRequest request, Request wsRequest) {
// prepare the Elasticsearch request
SearchOptions options = createSearchOptionsFromRequest(request);
EnumSet<SearchAdditionalField> additionalFields = SearchAdditionalField.getFromRequest(request);
IssueQuery query = issueQueryService.createFromRequest(request);
// execute request
SearchResult<IssueDoc> result = issueIndex.search(query, options);
List<String> issueKeys = from(result.getDocs()).transform(IssueDocToKey.INSTANCE).toList();
// load the additional information to be returned in response
SearchResponseLoader.Collector collector = new SearchResponseLoader.Collector(additionalFields, issueKeys);
collectLoggedInUser(collector);
collectRequestParams(collector, request);
Facets facets = null;
if (!options.getFacets().isEmpty()) {
facets = result.getFacets();
// add missing values to facets. For example if assignee "john" and facet on "assignees" are requested, then
// "john" should always be listed in the facet. If it is not present, then it is added with value zero.
// This is a constraint from webapp UX.
completeFacets(facets, request, wsRequest);
collectFacets(collector, facets);
}
SearchResponseData data = searchResponseLoader.load(collector, facets);
// format response
// Filter and reorder facets according to the requested ordered names.
// Must be done after loading of data as the "hidden" facet "debt"
// can be used to get total debt.
facets = reorderFacets(facets, options.getFacets());
// FIXME allow long in Paging
Paging paging = forPageIndex(options.getPage()).withPageSize(options.getLimit()).andTotal((int) result.getTotal());
return searchResponseFormat.formatSearch(additionalFields, data, paging, facets);
}
use of org.sonar.api.utils.Paging in project sonarqube by SonarSource.
the class SearchProjectPermissionsAction method buildResponse.
private SearchProjectPermissionsWsResponse buildResponse(SearchProjectPermissionsData data) {
SearchProjectPermissionsWsResponse.Builder response = SearchProjectPermissionsWsResponse.newBuilder();
Permission.Builder permissionResponse = Permission.newBuilder();
Project.Builder rootComponentBuilder = Project.newBuilder();
for (ComponentDto rootComponent : data.rootComponents()) {
rootComponentBuilder.clear().setId(rootComponent.uuid()).setKey(rootComponent.key()).setQualifier(rootComponent.qualifier()).setName(rootComponent.name());
for (String permission : data.permissions(rootComponent.getId())) {
rootComponentBuilder.addPermissions(permissionResponse.clear().setKey(permission).setUsersCount(data.userCount(rootComponent.getId(), permission)).setGroupsCount(data.groupCount(rootComponent.getId(), permission)));
}
response.addProjects(rootComponentBuilder);
}
for (String permissionKey : ProjectPermissions.ALL) {
response.addPermissions(permissionResponse.clear().setKey(permissionKey).setName(i18nName(permissionKey)).setDescription(i18nDescriptionMessage(permissionKey)));
}
Paging paging = data.paging();
response.setPaging(Common.Paging.newBuilder().setPageIndex(paging.pageIndex()).setPageSize(paging.pageSize()).setTotal(paging.total()));
return response.build();
}
use of org.sonar.api.utils.Paging in project sonarqube by SonarSource.
the class SearchAction method doHandle.
private SearchWsResponse doHandle(SearchWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = support.getOrganization(dbSession, ofNullable(request.getOrganization()).orElseGet(defaultOrganizationProvider.get()::getKey));
userSession.checkPermission(OrganizationPermission.ADMINISTER, organization);
ComponentQuery query = buildQuery(request);
Paging paging = buildPaging(dbSession, request, organization, query);
List<ComponentDto> components = dbClient.componentDao().selectByQuery(dbSession, organization.getUuid(), query, paging.offset(), paging.pageSize());
return buildResponse(components, organization, paging);
}
}
Aggregations