Search in sources :

Example 1 with ComponentIndexQuery

use of org.sonar.server.component.index.ComponentIndexQuery in project sonarqube by SonarSource.

the class SuggestionsAction method getResultsOfAllQualifiers.

private List<Qualifier> getResultsOfAllQualifiers(String query) {
    ComponentIndexQuery componentIndexQuery = new ComponentIndexQuery(query).setQualifiers(Arrays.asList(QUALIFIERS)).setLimit(NUMBER_OF_RESULTS_PER_QUALIFIER);
    List<ComponentsPerQualifier> componentsPerQualifiers = searchInIndex(componentIndexQuery);
    if (componentsPerQualifiers.isEmpty()) {
        return Collections.emptyList();
    }
    try (DbSession dbSession = dbClient.openSession(false)) {
        return componentsPerQualifiers.stream().map(qualifier -> {
            List<String> uuids = qualifier.getComponentUuids();
            List<ComponentDto> componentDtos = dbClient.componentDao().selectByUuids(dbSession, uuids);
            List<ComponentDto> sortedComponentDtos = Ordering.explicit(uuids).onResultOf(ComponentDto::uuid).immutableSortedCopy(componentDtos);
            Map<String, String> organizationKeyByUuids = getOrganizationKeys(dbSession, componentDtos);
            List<Component> results = sortedComponentDtos.stream().map(dto -> dtoToComponent(dto, organizationKeyByUuids)).collect(Collectors.toList());
            return Qualifier.newBuilder().setQ(qualifier.getQualifier()).addAllItems(results).build();
        }).collect(Collectors.toList());
    }
}
Also used : Arrays(java.util.Arrays) Qualifier(org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Qualifier) DbSession(org.sonar.db.DbSession) ACTION_SUGGESTIONS(org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SUGGESTIONS) Request(org.sonar.api.server.ws.Request) WebService(org.sonar.api.server.ws.WebService) ComponentIndexQuery(org.sonar.server.component.index.ComponentIndexQuery) Map(java.util.Map) Response(org.sonar.api.server.ws.Response) OrganizationDto(org.sonar.db.organization.OrganizationDto) SuggestionsWsResponse(org.sonarqube.ws.WsComponents.SuggestionsWsResponse) Resources(com.google.common.io.Resources) Collectors(org.sonar.core.util.stream.Collectors) Component(org.sonarqube.ws.WsComponents.Component) NewAction(org.sonar.api.server.ws.WebService.NewAction) Preconditions.checkState(com.google.common.base.Preconditions.checkState) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Ordering(com.google.common.collect.Ordering) Qualifiers(org.sonar.api.resources.Qualifiers) ComponentIndex(org.sonar.server.component.index.ComponentIndex) ComponentsPerQualifier(org.sonar.server.component.index.ComponentsPerQualifier) Collections(java.util.Collections) WsUtils.writeProtobuf(org.sonar.server.ws.WsUtils.writeProtobuf) DbSession(org.sonar.db.DbSession) ComponentsPerQualifier(org.sonar.server.component.index.ComponentsPerQualifier) ComponentDto(org.sonar.db.component.ComponentDto) ComponentIndexQuery(org.sonar.server.component.index.ComponentIndexQuery) List(java.util.List) Map(java.util.Map)

Aggregations

Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Ordering (com.google.common.collect.Ordering)1 Resources (com.google.common.io.Resources)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Qualifiers (org.sonar.api.resources.Qualifiers)1 Request (org.sonar.api.server.ws.Request)1 Response (org.sonar.api.server.ws.Response)1 WebService (org.sonar.api.server.ws.WebService)1 NewAction (org.sonar.api.server.ws.WebService.NewAction)1 Collectors (org.sonar.core.util.stream.Collectors)1 DbClient (org.sonar.db.DbClient)1 DbSession (org.sonar.db.DbSession)1 ComponentDto (org.sonar.db.component.ComponentDto)1 OrganizationDto (org.sonar.db.organization.OrganizationDto)1 ComponentIndex (org.sonar.server.component.index.ComponentIndex)1 ComponentIndexQuery (org.sonar.server.component.index.ComponentIndexQuery)1 ComponentsPerQualifier (org.sonar.server.component.index.ComponentsPerQualifier)1