diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-11-07 10:28:39 +0100 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-11-07 10:29:39 +0100 |
commit | e740448d7406693436d5d232d65b569ed72e0811 (patch) | |
tree | 6f31b88c0c30c1f353591430a58e98a343985af7 | |
parent | c8813d7afbf9f3250e39da36714d78bdbbce5788 (diff) | |
download | sonarqube-e740448d7406693436d5d232d65b569ed72e0811.tar.gz sonarqube-e740448d7406693436d5d232d65b569ed72e0811.zip |
SONAR-5805 Add "Not planned" item to action plans facet
4 files changed, 44 insertions, 4 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java index 7bb3da31505..edc88e1de61 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java @@ -344,8 +344,6 @@ public class IssueIndex extends BaseIndex<Issue, IssueDto, String> { addSimpleStickyFacetIfNeeded(options, stickyFacetBuilder, esSearch, IssueFilterParameters.STATUSES, IssueNormalizer.IssueField.STATUS.field(), Issue.STATUSES.toArray()); addSimpleStickyFacetIfNeeded(options, stickyFacetBuilder, esSearch, - IssueFilterParameters.ACTION_PLANS, IssueNormalizer.IssueField.ACTION_PLAN.field(), query.actionPlans().toArray()); - addSimpleStickyFacetIfNeeded(options, stickyFacetBuilder, esSearch, IssueFilterParameters.COMPONENT_UUIDS, IssueNormalizer.IssueField.COMPONENT.field(), query.componentUuids().toArray()); addSimpleStickyFacetIfNeeded(options, stickyFacetBuilder, esSearch, IssueFilterParameters.PROJECT_UUIDS, IssueNormalizer.IssueField.PROJECT.field(), query.projectUuids().toArray()); @@ -362,6 +360,9 @@ public class IssueIndex extends BaseIndex<Issue, IssueDto, String> { if (options.facets().contains(IssueFilterParameters.ASSIGNEES)) { esSearch.addAggregation(getAssigneesFacet(query, options, filters, esQuery)); } + if (options.facets().contains(IssueFilterParameters.ACTION_PLANS)) { + esSearch.addAggregation(getActionPlansFacet(query, options, filters, esQuery)); + } } } @@ -428,6 +429,31 @@ public class IssueIndex extends BaseIndex<Issue, IssueDto, String> { .subAggregation(facetTopAggregation); } + private AggregationBuilder getActionPlansFacet(IssueQuery query, QueryContext options, Map<String, FilterBuilder> filters, QueryBuilder esQuery) { + String fieldName = IssueNormalizer.IssueField.ACTION_PLAN.field(); + String facetName = IssueFilterParameters.ACTION_PLANS; + + // Same as in super.stickyFacetBuilder + Map<String, FilterBuilder> actionPlanFilters = Maps.newHashMap(filters); + actionPlanFilters.remove("__isPlanned"); + actionPlanFilters.remove(fieldName); + StickyFacetBuilder actionPlanFacetBuilder = new StickyFacetBuilder(esQuery, actionPlanFilters); + BoolFilterBuilder facetFilter = actionPlanFacetBuilder.getStickyFacetFilter(fieldName); + FilterAggregationBuilder facetTopAggregation = actionPlanFacetBuilder.buildTopFacetAggregation(fieldName, facetName, facetFilter, DEFAULT_ISSUE_FACET_SIZE); + facetTopAggregation = actionPlanFacetBuilder.addSelectedItemsToFacet(fieldName, facetName, facetTopAggregation, query.actionPlans().toArray()); + + // Add missing facet for unresolved issues + facetTopAggregation.subAggregation( + AggregationBuilders + .missing(facetName + "_missing") + .field(fieldName) + ); + + return AggregationBuilders + .global(facetName) + .subAggregation(facetTopAggregation); + } + private void setSorting(IssueQuery query, SearchRequestBuilder esSearch) { String sortField = query.sort(); if (sortField != null) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java index 0e3ed206298..452280a2cf8 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java @@ -376,7 +376,12 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> { addMandatoryFacetValues(results, IssueFilterParameters.REPORTERS, request.paramAsStrings(IssueFilterParameters.REPORTERS)); addMandatoryFacetValues(results, IssueFilterParameters.RULES, request.paramAsStrings(IssueFilterParameters.RULES)); addMandatoryFacetValues(results, IssueFilterParameters.LANGUAGES, request.paramAsStrings(IssueFilterParameters.LANGUAGES)); - addMandatoryFacetValues(results, IssueFilterParameters.ACTION_PLANS, request.paramAsStrings(IssueFilterParameters.ACTION_PLANS)); + List<String> actionPlans = Lists.newArrayList(""); + List<String> actionPlansFromRequest = request.paramAsStrings(IssueFilterParameters.ACTION_PLANS); + if (actionPlansFromRequest != null) { + actionPlans.addAll(actionPlansFromRequest); + } + addMandatoryFacetValues(results, IssueFilterParameters.ACTION_PLANS, actionPlans); addMandatoryFacetValues(results, IssueFilterParameters.COMPONENT_UUIDS, request.paramAsStrings(IssueFilterParameters.COMPONENT_UUIDS)); super.writeFacets(request, context, results, json); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java index 58b57a54c50..4643bb6f69d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java @@ -378,7 +378,7 @@ public class SearchActionMediumTest { WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION) .setParam("resolved", "false") - .setParam(SearchAction.PARAM_FACETS, "statuses,severities,resolutions,projectUuids,rules,componentUuids,assignees,languages") + .setParam(SearchAction.PARAM_FACETS, "statuses,severities,resolutions,projectUuids,rules,componentUuids,assignees,languages,actionPlans") .execute(); result.assertJson(this.getClass(), "display_facets.json", false); } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/display_facets.json b/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/display_facets.json index 30aa15ce419..3560bf84625 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/display_facets.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/display_facets.json @@ -131,5 +131,14 @@ "count": 1 } ] + }, + { + "property": "actionPlans", + "values": [ + { + "val": "", + "count": 1 + } + ] } ]} |