]> source.dussan.org Git - sonarqube.git/commitdiff
Revert "SONAR-5844 Profile inheritance is always displaying '0 rules' whatever the...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 8 Dec 2014 17:26:00 +0000 (18:26 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 8 Dec 2014 17:26:00 +0000 (18:26 +0100)
This reverts commit a060b930acec945a80cbecbba92db66e5f859a91.

server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterFactory.java
server/sonar-server/src/test/java/org/sonar/server/measure/MeasureFilterFactoryTest.java

index d572a320bfada730895cc42bce49debaf63e91c2..bb6dcdda810598b6d8584fcbd34bd7c62a413b41 100644 (file)
@@ -123,7 +123,7 @@ public class MeasureFilterFactory implements ServerComponent {
     }
   }
 
-  private List<String> sortFieldLabels() {
+  private List<String> sortFieldLabels(){
     return newArrayList(Iterables.transform(Arrays.asList(MeasureFilterSort.Field.values()), new Function<MeasureFilterSort.Field, String>() {
       @Override
       public String apply(@Nullable MeasureFilterSort.Field input) {
@@ -155,23 +155,22 @@ public class MeasureFilterFactory implements ServerComponent {
     if (alertLevels == null || alertLevels.isEmpty()) {
       return null;
     }
-    final List<String> availableLevels = Lists.transform(Arrays.asList(Metric.Level.values()), new Function<Metric.Level, String>() {
-      @Override
-      public String apply(@Nullable Metric.Level input) {
-        return input != null ? input.name() : null;
-      }
-    });
-
+    MeasureFilterCondition condition = null;
+    String metricKey = CoreMetrics.ALERT_STATUS_KEY;
+    String op = "in";
     List<String> alertLevelsUppercase = Lists.transform(alertLevels, new Function<String, String>() {
       @Override
       public String apply(@Nullable String input) {
-        return input != null && availableLevels.contains(input.toUpperCase()) ? input.toUpperCase() : null;
+        return input != null ? input.toUpperCase() : "";
       }
     });
-    String val = "('" + Joiner.on("', '").skipNulls().join(alertLevelsUppercase) + "')";
-    Metric metric = metricFinder.findByKey(CoreMetrics.ALERT_STATUS_KEY);
-    MeasureFilterCondition.Operator operator = MeasureFilterCondition.Operator.fromCode("in");
-    return new MeasureFilterCondition(metric, operator, val);
+    String val = "('" + Joiner.on("', '").join(alertLevelsUppercase) + "')";
+    if (!Strings.isNullOrEmpty(metricKey) && !Strings.isNullOrEmpty(op) && !Strings.isNullOrEmpty(val)) {
+      Metric metric = metricFinder.findByKey(metricKey);
+      MeasureFilterCondition.Operator operator = MeasureFilterCondition.Operator.fromCode(op);
+      condition = new MeasureFilterCondition(metric, operator, val);
+    }
+    return condition;
   }
 
   private List<String> toList(@Nullable Object obj) {
index cd2b01ea4a9061f09a92fd904baed0be59e3249e..20cc5872beeeeaa70c916a781b08b0a3cc0f2337 100644 (file)
@@ -195,7 +195,7 @@ public class MeasureFilterFactoryTest {
   public void alert_level_condition() {
     MeasureFilterFactory factory = new MeasureFilterFactory(newMetricFinder(), system);
     Map<String, Object> props = ImmutableMap.<String, Object>of(
-      "alertLevels", Arrays.asList("error", "warn", "unknown")
+      "alertLevels", Arrays.asList("error", "warn")
     );
     MeasureFilter filter = factory.create(props);