Search in sources :

Example 1 with FILTER_LANGUAGES

use of org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES in project sonarqube by SonarSource.

the class SearchProjectsAction method addFacets.

private static SearchProjectsWsResponse.Builder addFacets(SearchResults searchResults, SearchProjectsWsResponse.Builder wsResponse) {
    Facets esFacets = searchResults.facets;
    EsToWsFacet esToWsFacet = new EsToWsFacet();
    searchResults.query.getLanguages().ifPresent(languages -> addMandatoryValuesToFacet(esFacets, FILTER_LANGUAGES, languages));
    searchResults.query.getTags().ifPresent(tags -> addMandatoryValuesToFacet(esFacets, FILTER_TAGS, tags));
    Common.Facets wsFacets = esFacets.getAll().entrySet().stream().map(esToWsFacet).collect(Collector.of(Common.Facets::newBuilder, Common.Facets.Builder::addFacets, (result1, result2) -> {
        throw new IllegalStateException("Parallel execution forbidden");
    }, Common.Facets.Builder::build));
    wsResponse.setFacets(wsFacets);
    return wsResponse;
}
Also used : Facets(org.sonar.server.es.Facets) Collectors.toSet(org.sonar.core.util.stream.Collectors.toSet) DbSession(org.sonar.db.DbSession) Request(org.sonar.api.server.ws.Request) SUPPORTED_FACETS(org.sonar.server.measure.index.ProjectMeasuresIndex.SUPPORTED_FACETS) DEFAULT_PAGE_SIZE(org.sonarqube.ws.client.component.SearchProjectsRequest.DEFAULT_PAGE_SIZE) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) PropertyQuery(org.sonar.db.property.PropertyQuery) Map(java.util.Map) ProjectMeasuresQueryFactory.newProjectMeasuresQuery(org.sonar.server.component.ws.ProjectMeasuresQueryFactory.newProjectMeasuresQuery) WsUtils.checkFoundWithOptional(org.sonar.server.ws.WsUtils.checkFoundWithOptional) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) PARAM_FILTER(org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER) Collector(java.util.stream.Collector) OrganizationDto(org.sonar.db.organization.OrganizationDto) Criterion(org.sonar.server.component.ws.FilterParser.Criterion) FILTER_LANGUAGES(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES) ImmutableMap(com.google.common.collect.ImmutableMap) SearchIdResult(org.sonar.server.es.SearchIdResult) SORT_BY_NAME(org.sonar.server.measure.index.ProjectMeasuresQuery.SORT_BY_NAME) Set(java.util.Set) Collectors(org.sonar.core.util.stream.Collectors) SearchProjectsRequest(org.sonarqube.ws.client.component.SearchProjectsRequest) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) Common(org.sonarqube.ws.Common) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) Stream(java.util.stream.Stream) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) Entry(java.util.Map.Entry) Optional(java.util.Optional) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) FIELDS(org.sonar.api.server.ws.WebService.Param.FIELDS) MAX_PAGE_SIZE(org.sonarqube.ws.client.component.SearchProjectsRequest.MAX_PAGE_SIZE) PropertyDto(org.sonar.db.property.PropertyDto) WsUtils.writeProtobuf(org.sonar.server.ws.WsUtils.writeProtobuf) PARAM_ORGANIZATION(org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ORGANIZATION) SearchProjectsWsResponse(org.sonarqube.ws.WsComponents.SearchProjectsWsResponse) IS_FAVORITE_CRITERION(org.sonar.server.component.ws.ProjectMeasuresQueryFactory.IS_FAVORITE_CRITERION) Function(java.util.function.Function) LinkedHashMap(java.util.LinkedHashMap) ProjectMeasuresIndex(org.sonar.server.measure.index.ProjectMeasuresIndex) DateUtils(org.sonar.api.utils.DateUtils) Response(org.sonar.api.server.ws.Response) Nullable(javax.annotation.Nullable) Collections.emptyMap(java.util.Collections.emptyMap) Component(org.sonarqube.ws.WsComponents.Component) Ordering(com.google.common.collect.Ordering) Qualifiers(org.sonar.api.resources.Qualifiers) Change(org.sonar.api.server.ws.Change) UserSession(org.sonar.server.user.UserSession) NCLOC_KEY(org.sonar.api.measures.CoreMetrics.NCLOC_KEY) FILTER_TAGS(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS) SnapshotDto(org.sonar.db.component.SnapshotDto) Collections(java.util.Collections) Facets(org.sonar.server.es.Facets) Common(org.sonarqube.ws.Common)

Example 2 with FILTER_LANGUAGES

use of org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES in project sonarqube by SonarSource.

the class ProjectMeasuresIndex method createFilters.

private Map<String, QueryBuilder> createFilters(ProjectMeasuresQuery query) {
    Map<String, QueryBuilder> filters = new HashMap<>();
    filters.put("__authorization", authorizationTypeSupport.createQueryFilter());
    Multimap<String, MetricCriterion> metricCriterionMultimap = ArrayListMultimap.create();
    query.getMetricCriteria().forEach(metricCriterion -> metricCriterionMultimap.put(metricCriterion.getMetricKey(), metricCriterion));
    metricCriterionMultimap.asMap().entrySet().forEach(entry -> {
        BoolQueryBuilder metricFilters = boolQuery();
        entry.getValue().stream().map(criterion -> nestedQuery(FIELD_MEASURES, boolQuery().filter(termQuery(FIELD_MEASURES_KEY, criterion.getMetricKey())).filter(toValueQuery(criterion)))).forEach(metricFilters::must);
        filters.put(entry.getKey(), metricFilters);
    });
    query.getQualityGateStatus().ifPresent(qualityGateStatus -> filters.put(ALERT_STATUS_KEY, termQuery(FIELD_QUALITY_GATE_STATUS, QUALITY_GATE_STATUS.get(qualityGateStatus.name()))));
    query.getProjectUuids().ifPresent(projectUuids -> filters.put("ids", termsQuery("_id", projectUuids)));
    query.getLanguages().ifPresent(languages -> filters.put(FILTER_LANGUAGES, termsQuery(FIELD_LANGUAGES, languages)));
    query.getOrganizationUuid().ifPresent(organizationUuid -> filters.put(FIELD_ORGANIZATION_UUID, termQuery(FIELD_ORGANIZATION_UUID, organizationUuid)));
    query.getTags().ifPresent(tags -> filters.put(FIELD_TAGS, termsQuery(FIELD_TAGS, tags)));
    createTextQueryFilter(query).ifPresent(queryBuilder -> filters.put("textQuery", queryBuilder));
    return filters;
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ComponentTextSearchFeature(org.sonar.server.es.textsearch.ComponentTextSearchFeature) QueryBuilders.nestedQuery(org.elasticsearch.index.query.QueryBuilders.nestedQuery) StickyFacetBuilder(org.sonar.server.es.StickyFacetBuilder) AuthorizationTypeSupport(org.sonar.server.permission.index.AuthorizationTypeSupport) EsClient(org.sonar.server.es.EsClient) DESC(org.elasticsearch.search.sort.SortOrder.DESC) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Bucket(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket) Map(java.util.Map) FIELD_LANGUAGES(org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_LANGUAGES) FILTER_LANGUAGES(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES) RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.RELIABILITY_RATING_KEY) FIELD_QUALITY_GATE_STATUS(org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_QUALITY_GATE_STATUS) QueryBuilders.boolQuery(org.elasticsearch.index.query.QueryBuilders.boolQuery) ImmutableMap(com.google.common.collect.ImmutableMap) SearchIdResult(org.sonar.server.es.SearchIdResult) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) Collections.emptyList(java.util.Collections.emptyList) SORT_BY_NAME(org.sonar.server.measure.index.ProjectMeasuresQuery.SORT_BY_NAME) Set(java.util.Set) Collectors(org.sonar.core.util.stream.Collectors) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) List(java.util.List) SearchOptions(org.sonar.server.es.SearchOptions) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) SQALE_RATING_KEY(org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY) Optional(java.util.Optional) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) IntStream(java.util.stream.IntStream) INDEX_TYPE_PROJECT_MEASURES(org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.INDEX_TYPE_PROJECT_MEASURES) TermsBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder) AbstractAggregationBuilder(org.elasticsearch.search.aggregations.AbstractAggregationBuilder) DefaultIndexSettingsElement(org.sonar.server.es.DefaultIndexSettingsElement) EsUtils.escapeSpecialRegexChars(org.sonar.server.es.EsUtils.escapeSpecialRegexChars) QueryBuilders.rangeQuery(org.elasticsearch.index.query.QueryBuilders.rangeQuery) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) ComponentTextSearchQueryFactory(org.sonar.server.es.textsearch.ComponentTextSearchQueryFactory) RangeBuilder(org.elasticsearch.search.aggregations.bucket.range.RangeBuilder) AggregationBuilders.filters(org.elasticsearch.search.aggregations.AggregationBuilders.filters) ImmutableList(com.google.common.collect.ImmutableList) FIELD_ORGANIZATION_UUID(org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_ORGANIZATION_UUID) Nullable(javax.annotation.Nullable) QueryBuilders.termsQuery(org.elasticsearch.index.query.QueryBuilders.termsQuery) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) FiltersAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder) SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.SECURITY_RATING_KEY) QueryBuilders.matchAllQuery(org.elasticsearch.index.query.QueryBuilders.matchAllQuery) DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY_KEY) FIELD_KEY(org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_KEY) FIELD_NAME(org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_NAME) AggregationBuilders(org.elasticsearch.search.aggregations.AggregationBuilders) MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) QUALITY_GATE_STATUS(org.sonar.server.measure.index.ProjectMeasuresDoc.QUALITY_GATE_STATUS) FIELD_MEASURES(org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_MEASURES) ASC(org.elasticsearch.search.sort.SortOrder.ASC) QueryBuilders.termQuery(org.elasticsearch.index.query.QueryBuilders.termQuery) COVERAGE_KEY(org.sonar.api.measures.CoreMetrics.COVERAGE_KEY) BaseIndex(org.sonar.server.es.BaseIndex) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) NCLOC_KEY(org.sonar.api.measures.CoreMetrics.NCLOC_KEY) FILTER_TAGS(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS) FIELD_TAGS(org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_TAGS) MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) HashMap(java.util.HashMap) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Nullable (javax.annotation.Nullable)2 ALERT_STATUS_KEY (org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY)2 NCLOC_KEY (org.sonar.api.measures.CoreMetrics.NCLOC_KEY)2 Collectors (org.sonar.core.util.stream.Collectors)2 SearchIdResult (org.sonar.server.es.SearchIdResult)2 SearchOptions (org.sonar.server.es.SearchOptions)2 SORT_BY_NAME (org.sonar.server.measure.index.ProjectMeasuresQuery.SORT_BY_NAME)2 FILTER_LANGUAGES (org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES)2 FILTER_TAGS (org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 Multimap (com.google.common.collect.Multimap)1 Ordering (com.google.common.collect.Ordering)1