]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5973 Display selected items in facet values (even when ES gives 0 result)
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 22 Jan 2015 14:16:47 +0000 (15:16 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 22 Jan 2015 14:57:30 +0000 (15:57 +0100)
server/sonar-server/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java
server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java

index 8191bc1142928b563ceca7608461cd1972a72085..c0d0d57256f5d6f025f9ac82ad03afea717318ca 100644 (file)
@@ -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<String, QualityProfileDto> 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();
index f5f24a581ef8e170b5e9b83db0bacd0f6578c824..384503263f48993388f2a90340c6bf2c29858e86 100644 (file)
@@ -297,8 +297,12 @@ public class SearchAction extends SearchRequestHandler<RuleQuery, Rule> 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);
   }
 }