use of org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_RESOLUTION in project sonarqube by SonarSource.
the class IssueIndex method searchProjectStatistics.
public List<ProjectStatistics> searchProjectStatistics(List<String> projectUuids, List<Long> froms, @Nullable String assigneeUuid) {
checkState(projectUuids.size() == froms.size(), "Expected same size for projectUuids (had size %s) and froms (had size %s)", projectUuids.size(), froms.size());
if (projectUuids.isEmpty()) {
return Collections.emptyList();
}
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder().query(boolQuery().mustNot(existsQuery(FIELD_ISSUE_RESOLUTION)).filter(termQuery(FIELD_ISSUE_ASSIGNEE_UUID, assigneeUuid)).mustNot(termQuery(FIELD_ISSUE_TYPE, SECURITY_HOTSPOT.name()))).size(0);
IntStream.range(0, projectUuids.size()).forEach(i -> {
String projectUuid = projectUuids.get(i);
long from = froms.get(i);
sourceBuilder.aggregation(AggregationBuilders.filter(projectUuid, boolQuery().filter(termQuery(FIELD_ISSUE_PROJECT_UUID, projectUuid)).filter(rangeQuery(FIELD_ISSUE_FUNC_CREATED_AT).gte(epochMillisToEpochSeconds(from)))).subAggregation(AggregationBuilders.terms("branchUuid").field(FIELD_ISSUE_BRANCH_UUID).subAggregation(AggregationBuilders.count(AGG_COUNT).field(FIELD_ISSUE_KEY)).subAggregation(AggregationBuilders.max("maxFuncCreatedAt").field(FIELD_ISSUE_FUNC_CREATED_AT))));
});
SearchRequest requestBuilder = EsClient.prepareSearch(TYPE_ISSUE.getMainType());
requestBuilder.source(sourceBuilder);
SearchResponse response = client.search(requestBuilder);
return response.getAggregations().asList().stream().map(x -> (ParsedFilter) x).flatMap(projectBucket -> ((ParsedStringTerms) projectBucket.getAggregations().get("branchUuid")).getBuckets().stream().flatMap(branchBucket -> {
long count = ((ParsedValueCount) branchBucket.getAggregations().get(AGG_COUNT)).getValue();
if (count < 1L) {
return Stream.empty();
}
long lastIssueDate = (long) ((ParsedMax) branchBucket.getAggregations().get("maxFuncCreatedAt")).getValue();
return Stream.of(new ProjectStatistics(branchBucket.getKeyAsString(), count, lastIssueDate));
})).collect(MoreCollectors.toList(projectUuids.size()));
}
use of org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_RESOLUTION in project sonarqube by SonarSource.
the class IssueIndex method searchBranchStatistics.
public List<PrStatistics> searchBranchStatistics(String projectUuid, List<String> branchUuids) {
if (branchUuids.isEmpty()) {
return Collections.emptyList();
}
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder().query(boolQuery().must(termsQuery(FIELD_ISSUE_BRANCH_UUID, branchUuids)).mustNot(existsQuery(FIELD_ISSUE_RESOLUTION)).must(termQuery(FIELD_ISSUE_IS_MAIN_BRANCH, Boolean.toString(false)))).size(0).aggregation(AggregationBuilders.terms("branchUuids").field(FIELD_ISSUE_BRANCH_UUID).size(branchUuids.size()).subAggregation(AggregationBuilders.terms("types").field(FIELD_ISSUE_TYPE)));
SearchRequest requestBuilder = EsClient.prepareSearch(TYPE_ISSUE.getMainType()).routing(AuthorizationDoc.idOf(projectUuid));
requestBuilder.source(sourceBuilder);
SearchResponse response = client.search(requestBuilder);
return ((ParsedStringTerms) response.getAggregations().get("branchUuids")).getBuckets().stream().map(bucket -> new PrStatistics(bucket.getKeyAsString(), ((ParsedStringTerms) bucket.getAggregations().get("types")).getBuckets().stream().collect(uniqueIndex(MultiBucketsAggregation.Bucket::getKeyAsString, MultiBucketsAggregation.Bucket::getDocCount)))).collect(MoreCollectors.toList(branchUuids.size()));
}
Aggregations