]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9616 Add project uuid routing when searching branch stats
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 30 Aug 2017 09:41:24 +0000 (11:41 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 12 Sep 2017 09:34:55 +0000 (11:34 +0200)
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java

index 78a7dc1a53c93861288169ccfd8f35e1f8b44b1f..107f49b3a8ae997d71c341c54a9eddc8227ab593 100644 (file)
@@ -707,12 +707,13 @@ public class IssueIndex {
       }).collect(MoreCollectors.toList(projectUuids.size()));
   }
 
-  public List<BranchStatistics> searchBranchStatistics(List<String> branchUuids) {
+  public List<BranchStatistics> searchBranchStatistics(String projectUuid, List<String> branchUuids) {
     if (branchUuids.isEmpty()) {
       return Collections.emptyList();
     }
 
     SearchRequestBuilder request = client.prepareSearch(IssueIndexDefinition.INDEX_TYPE_ISSUE)
+      .setRouting(projectUuid)
       .setQuery(
         boolQuery()
           .must(termsQuery(IssueIndexDefinition.FIELD_ISSUE_BRANCH_UUID, branchUuids))
index fd176f09b8ac94f6c3da665a66e0de5f4e755670..aeae39e6a6498a649e449a9b568b41c30d45cb8e 100644 (file)
@@ -106,7 +106,7 @@ public class ListAction implements BranchWsAction {
       Map<String, MeasureDto> qualityGateMeasuresByComponentUuids = dbClient.measureDao()
         .selectByComponentsAndMetrics(dbSession, branches.stream().map(BranchDto::getUuid).collect(toList()), singletonList(qualityGateMetric.getId()))
         .stream().collect(uniqueIndex(MeasureDto::getComponentUuid));
-      Map<String, BranchStatistics> branchStatisticsByBranchUuid = issueIndex.searchBranchStatistics(branches.stream()
+      Map<String, BranchStatistics> branchStatisticsByBranchUuid = issueIndex.searchBranchStatistics(project.uuid(), branches.stream()
         .filter(b -> b.getBranchType().equals(SHORT))
         .map(BranchDto::getUuid).collect(toList()))
         .stream().collect(uniqueIndex(BranchStatistics::getBranchUuid, Function.identity()));
index 939a8181059ad7e96a1da83b67c63704c3ed43d8..f11d9ab4c2bfdb8dc07226c13b296f95d31154f4 100644 (file)
@@ -1311,7 +1311,7 @@ public class IssueIndexTest {
       newDoc(branch1).setType(BUG), newDoc(branch1).setType(VULNERABILITY), newDoc(branch1).setType(CODE_SMELL),
       newDoc(branch3).setType(CODE_SMELL), newDoc(branch3).setType(CODE_SMELL), newDoc(fileOnBranch3).setType(CODE_SMELL));
 
-    List<BranchStatistics> branchStatistics = underTest.searchBranchStatistics(asList(branch1.uuid(), branch2.uuid(), branch3.uuid()));
+    List<BranchStatistics> branchStatistics = underTest.searchBranchStatistics(project.uuid(), asList(branch1.uuid(), branch2.uuid(), branch3.uuid()));
 
     assertThat(branchStatistics).extracting(BranchStatistics::getBranchUuid, BranchStatistics::getBugs, BranchStatistics::getVulnerabilities, BranchStatistics::getCodeSmells)
       .containsExactlyInAnyOrder(
@@ -1331,7 +1331,7 @@ public class IssueIndexTest {
       branchUuids.add(branch.uuid());
     });
 
-    List<BranchStatistics> branchStatistics = underTest.searchBranchStatistics(branchUuids);
+    List<BranchStatistics> branchStatistics = underTest.searchBranchStatistics(project.uuid(), branchUuids);
 
     assertThat(branchStatistics)
       .extracting(BranchStatistics::getBranchUuid, BranchStatistics::getBugs, BranchStatistics::getVulnerabilities, BranchStatistics::getCodeSmells)
@@ -1341,8 +1341,10 @@ public class IssueIndexTest {
 
   @Test
   public void searchBranchStatistics_on_empty_list() {
-    assertThat(underTest.searchBranchStatistics(emptyList())).isEmpty();
-    assertThat(underTest.searchBranchStatistics(singletonList("unknown"))).isEmpty();
+    ComponentDto project = db.components().insertMainBranch();
+
+    assertThat(underTest.searchBranchStatistics(project.uuid(), emptyList())).isEmpty();
+    assertThat(underTest.searchBranchStatistics(project.uuid(), singletonList("unknown"))).isEmpty();
   }
 
   private void addIssues(ComponentDto branch, int bugs, int vulnerabilities, int codeSmelles) {