]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5329 - Adding stats to ActiveRules for QProfile page
authorStephane Gamard <stephane.gamard@searchbox.com>
Thu, 12 Jun 2014 17:16:26 +0000 (19:16 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Thu, 12 Jun 2014 17:19:43 +0000 (19:19 +0200)
sonar-server/src/main/java/org/sonar/server/qualityprofile/ActiveRuleChange.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java
sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java

index 0126c0fe7914bb82a497c8bdd62f80d2ae66eb24..893a6009f6508af87e3eb58683dc281d01e38871 100644 (file)
@@ -120,6 +120,8 @@ public class ActiveRuleChange implements Loggable {
 
     if (this.getKey() != null) {
       details.put("key", this.getKey().toString());
+      details.put("ruleKey", this.getKey().ruleKey().toString());
+      details.put("profileKey", this.getKey().qProfile().toString());
     }
     return details.build();
   }
index a174f40ace3636d59ba0fce7632ca50adebfe66b..933cd4a7b6777615ba41bdc18d908e8947b7ca73 100644 (file)
@@ -176,4 +176,22 @@ public class ActiveRuleIndex extends BaseIndex<ActiveRule, ActiveRuleDto, Active
       .setRouting(key.toString());
     return request.get().getCount();
   }
+
+  public Map getStatsByProfileKey(QualityProfileKey... keys) {
+    // Get QProfiles keys as Strings
+    String[] stringKeys = new String[keys.length];
+    for(int i=0; i<keys.length; i++){
+      stringKeys[i]=keys[i].toString();
+    }
+
+//    getClient().prepareSearch(this.getIndexName())
+//      .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
+//        FilterBuilders.termsFilter(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field(), stringKeys)))
+//      .addAggregation(AggregationBuilders.terms("").)
+//      .setAggregations()
+//      .setRouting(key.toString());
+//    return request.get().getCount();
+
+    return null;
+  }
 }
index c7bb61746df0d8568d15e7f76f54055a69abc938..8809f2270a3e07b7547dc8949f4f253b072535a8 100644 (file)
@@ -260,7 +260,7 @@ public class ActiveRuleBackendMediumTest {
   }
 
   @Test
-  public void count_all_by_index_field() {
+    public void count_all_by_index_field() {
     QualityProfileDto profileDto1 = QualityProfileDto.createFor("p1", "java");
     QualityProfileDto profileDto2 = QualityProfileDto.createFor("p2", "java");
     db.qualityProfileDao().insert(dbSession, profileDto1, profileDto2);
@@ -284,6 +284,33 @@ public class ActiveRuleBackendMediumTest {
     assertThat(counts.keySet()).containsOnly(profileDto1.getKey().toString(), profileDto2.getKey().toString());
   }
 
+  @Test
+  public void stats_for_all() {
+    QualityProfileDto profileDto1 = QualityProfileDto.createFor("p1", "java");
+    QualityProfileDto profileDto2 = QualityProfileDto.createFor("p2", "java");
+    db.qualityProfileDao().insert(dbSession, profileDto1, profileDto2);
+
+    RuleDto ruleDto1 = newRuleDto(RuleKey.of("javascript", "S001"));
+    RuleDto ruleDto2 = newRuleDto(RuleKey.of("javascript", "S002"));
+    db.ruleDao().insert(dbSession, ruleDto1, ruleDto2);
+
+    db.activeRuleDao().insert(dbSession,
+      ActiveRuleDto.createFor(profileDto1, ruleDto1).setSeverity(Severity.BLOCKER),
+      ActiveRuleDto.createFor(profileDto2, ruleDto1).setSeverity(Severity.MINOR),
+      ActiveRuleDto.createFor(profileDto1, ruleDto2).setSeverity(Severity.MAJOR),
+      ActiveRuleDto.createFor(profileDto2, ruleDto2).setSeverity(Severity.BLOCKER)
+      );
+    dbSession.commit();
+
+    // 0. Test base case
+    assertThat(index.countAll()).isEqualTo(2);
+
+    // 1. Assert by term aggregation;
+    Map stats = index.getStatsByProfileKey(
+      profileDto1.getKey(),
+      profileDto2.getKey());
+  }
+
 
   private RuleDto newRuleDto(RuleKey ruleKey) {
     return new RuleDto()