Search in sources :

Example 1 with Paging

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);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentQuery(org.sonar.db.component.ComponentQuery) Paging(org.sonar.api.utils.Paging) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 2 with 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);
    }
}
Also used : DbSession(org.sonar.db.DbSession) Paging(org.sonar.api.utils.Paging) OrganizationQuery(org.sonar.db.organization.OrganizationQuery) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 3 with Paging

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);
}
Also used : IssueDoc(org.sonar.server.issue.index.IssueDoc) Facets(org.sonar.server.es.Facets) Paging(org.sonar.api.utils.Paging) SearchOptions(org.sonar.server.es.SearchOptions) IssueQuery(org.sonar.server.issue.IssueQuery)

Example 4 with Paging

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();
}
Also used : Project(org.sonarqube.ws.WsPermissions.SearchProjectPermissionsWsResponse.Project) SearchProjectPermissionsWsResponse(org.sonarqube.ws.WsPermissions.SearchProjectPermissionsWsResponse) Paging(org.sonar.api.utils.Paging) Permission(org.sonarqube.ws.WsPermissions.Permission) ComponentDto(org.sonar.db.component.ComponentDto)

Example 5 with Paging

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);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentQuery(org.sonar.db.component.ComponentQuery) Paging(org.sonar.api.utils.Paging) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

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