From 2eeb32a24807ccad91edfb862a1428fd01224075 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Thu, 22 Jan 2015 15:16:47 +0100 Subject: [PATCH] SONAR-5973 Display selected items in facet values (even when ES gives 0 result) --- .../org/sonar/server/rule/ws/ActiveRuleCompleter.java | 11 +++++++++-- .../java/org/sonar/server/rule/ws/SearchAction.java | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java index 8191bc11429..c0d0d57256f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java @@ -35,6 +35,8 @@ import org.sonar.server.qualityprofile.QProfileLoader; import org.sonar.server.rule.Rule; import org.sonar.server.rule.index.RuleQuery; +import javax.annotation.CheckForNull; + import java.util.Arrays; import java.util.Collection; import java.util.Map; @@ -132,7 +134,7 @@ public class ActiveRuleCompleter implements ServerComponent { Map qProfilesByKey = Maps.newHashMap(); for (String qProfileKey : harvestedProfileKeys) { if (!qProfilesByKey.containsKey(qProfileKey)) { - QualityProfileDto profile = loader.getByKey(qProfileKey); + QualityProfileDto profile = loadProfile(qProfileKey); if (profile == null) { LOG.warn("Could not find quality profile with key " + qProfileKey); continue; @@ -140,7 +142,7 @@ public class ActiveRuleCompleter implements ServerComponent { qProfilesByKey.put(qProfileKey, profile); String parentKee = profile.getParentKee(); if (parentKee != null && !qProfilesByKey.containsKey(parentKee)) { - qProfilesByKey.put(parentKee, loader.getByKey(parentKee)); + qProfilesByKey.put(parentKee, loadProfile(parentKee)); } } } @@ -151,6 +153,11 @@ public class ActiveRuleCompleter implements ServerComponent { json.endObject(); } + @CheckForNull + QualityProfileDto loadProfile(String qProfileKey) { + return loader.getByKey(qProfileKey); + } + private void writeProfile(JsonWriter json, QualityProfileDto profile) { Language language = languages.get(profile.getLanguage()); String langName = language == null ? profile.getLanguage() : language.getName(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java index f5f24a581ef..384503263f4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java @@ -297,8 +297,12 @@ public class SearchAction extends SearchRequestHandler implemen @Override protected void writeFacets(Request request, QueryContext context, Result results, JsonWriter json) { + addMandatoryFacetValues(results, RuleIndex.FACET_DEBT_CHARACTERISTICS, request.paramAsStrings(PARAM_SEVERITIES)); + addMandatoryFacetValues(results, RuleIndex.FACET_LANGUAGES, request.paramAsStrings(PARAM_LANGUAGES)); + addMandatoryFacetValues(results, RuleIndex.FACET_REPOSITORIES, request.paramAsStrings(PARAM_REPOSITORIES)); addMandatoryFacetValues(results, RuleIndex.FACET_STATUSES, RuleIndex.ALL_STATUSES_EXCEPT_REMOVED); addMandatoryFacetValues(results, RuleIndex.FACET_SEVERITIES, Severity.ALL); + addMandatoryFacetValues(results, RuleIndex.FACET_TAGS, request.paramAsStrings(PARAM_TAGS)); super.writeFacets(request, context, results, json); } } -- 2.39.5