Search in sources :

Example 21 with MetricCriterion

use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion in project sonarqube by SonarSource.

the class ProjectMeasuresQueryFactory method processMetricCriterion.

private static void processMetricCriterion(Criterion criterion, ProjectMeasuresQuery query) {
    checkOperator(criterion);
    checkValue(criterion);
    query.addMetricCriterion(new MetricCriterion(criterion.getKey().toLowerCase(ENGLISH), criterion.getOperator(), parseValue(criterion.getValue())));
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion)

Example 22 with MetricCriterion

use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion 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

MetricCriterion (org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion)22 Test (org.junit.Test)20 ProjectMeasuresQuery (org.sonar.server.measure.index.ProjectMeasuresQuery)8 SearchOptions (org.sonar.server.es.SearchOptions)6 Facets (org.sonar.server.es.Facets)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Multimap (com.google.common.collect.Multimap)1 Collections.emptyList (java.util.Collections.emptyList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 IntStream (java.util.stream.IntStream)1 Nullable (javax.annotation.Nullable)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1