aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2017-08-30 11:41:24 +0200
committerJanos Gyerik <janos.gyerik@sonarsource.com>2017-09-12 11:34:55 +0200
commit208d1e47d12f0fc58e22c1b97cd66d2d4fe0c4dd (patch)
tree249d39f3e77bd9f7145b75fb3119e732e0a6c5e5 /server
parent96d5f10d52e6e72123c0ff13f44cef23d623b546 (diff)
downloadsonarqube-208d1e47d12f0fc58e22c1b97cd66d2d4fe0c4dd.tar.gz
sonarqube-208d1e47d12f0fc58e22c1b97cd66d2d4fe0c4dd.zip
SONAR-9616 Add project uuid routing when searching branch stats
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java10
3 files changed, 9 insertions, 6 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
index 78a7dc1a53c..107f49b3a8a 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
@@ -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))
diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java
index fd176f09b8a..aeae39e6a64 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java
@@ -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()));
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
index 939a8181059..f11d9ab4c2b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
@@ -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) {