aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-10-25 15:43:48 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-10-25 15:57:17 +0200
commit5f0f8f48729b4091048416f5c043d0076318f26b (patch)
treeb0bc213844f6fe5ebd22ca07d15ae55aa9f6dbb5 /server/sonar-server
parent8836dd4591462784a67c9adc77764ca2b876f241 (diff)
downloadsonarqube-5f0f8f48729b4091048416f5c043d0076318f26b.tar.gz
sonarqube-5f0f8f48729b4091048416f5c043d0076318f26b.zip
SONAR-8120 Replace component uuid by component key in measures list
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/measure/ws/SearchAction.java7
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/measure/ws/search-example.json40
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java32
4 files changed, 57 insertions, 27 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java
index ab09564a5d1..0e16688d17a 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.measure.ws;
+import org.sonar.db.component.ComponentDto;
import org.sonar.db.measure.MeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonarqube.ws.WsMeasures;
@@ -38,8 +39,8 @@ class MeasureDtoToWsMeasure {
* add component uuid to the WS Measure object
*
*/
- static Measure dbToWsMeasure(MeasureDto dbMeasure, MetricDto dbMetric) {
- return map(dbMetric, dbMeasure).setComponent(dbMeasure.getComponentUuid()).build();
+ static Measure dbToWsMeasure(MeasureDto dbMeasure, MetricDto dbMetric, ComponentDto componentDto) {
+ return map(dbMetric, dbMeasure).setComponent(componentDto.getKey()).build();
}
static Measure measureDtoToWsMeasure(MetricDto metricDto, MeasureDto measureDto) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/SearchAction.java
index 99fb6524764..6a06d9fb518 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/SearchAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/SearchAction.java
@@ -230,16 +230,17 @@ public class SearchAction implements MeasuresWsAction {
}
private List<Measure> buildWsMeasures() {
- Map<String, String> componentNamesByUuid = components.stream().collect(toMap(ComponentDto::uuid, ComponentDto::name));
+ Map<String, ComponentDto> componentsByUuid = components.stream().collect(toMap(ComponentDto::uuid, Function.identity()));
+ Map<String, String> componentNamesByKey = components.stream().collect(toMap(ComponentDto::key, ComponentDto::name));
Map<Integer, MetricDto> metricsById = metrics.stream().collect(toMap(MetricDto::getId, identity()));
Function<MeasureDto, MetricDto> dbMeasureToDbMetric = dbMeasure -> metricsById.get(dbMeasure.getMetricId());
Function<Measure, String> byMetricKey = Measure::getMetric;
- Function<Measure, String> byComponentName = wsMeasure -> componentNamesByUuid.get(wsMeasure.getComponent());
+ Function<Measure, String> byComponentName = wsMeasure -> componentNamesByKey.get(wsMeasure.getComponent());
return Stream
.concat(measures.stream(), buildBestMeasures().stream())
- .map(dbMeasure -> dbToWsMeasure(dbMeasure, dbMeasureToDbMetric.apply(dbMeasure)))
+ .map(dbMeasure -> dbToWsMeasure(dbMeasure, dbMeasureToDbMetric.apply(dbMeasure), componentsByUuid.get(dbMeasure.getComponentUuid())))
.sorted(comparing(byMetricKey).thenComparing(byComponentName))
.collect(toList());
}
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/measure/ws/search-example.json b/server/sonar-server/src/main/resources/org/sonar/server/measure/ws/search-example.json
index 803f4aec91a..fa2017ec0e1 100644
--- a/server/sonar-server/src/main/resources/org/sonar/server/measure/ws/search-example.json
+++ b/server/sonar-server/src/main/resources/org/sonar/server/measure/ws/search-example.json
@@ -2,49 +2,48 @@
"measures": [
{
"metric": "complexity",
- "component": "AVIwDXE-bJbJqrw6wFv5",
- "value": "12"
+ "value": "12",
+ "component": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/ElementImpl.java"
},
{
"metric": "complexity",
- "component": "project-id",
- "value": "42"
+ "value": "42",
+ "component": "MY_PROJECT"
},
{
"metric": "complexity",
- "component": "AVIwDXE-bJbJqrw6wFv8",
"value": "35",
"periods": [
{
"index": 2,
"value": "0"
}
- ]
+ ],
+ "component": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl"
},
{
"metric": "ncloc",
- "component": "AVIwDXE-bJbJqrw6wFv5",
- "value": "114"
+ "value": "114",
+ "component": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/ElementImpl.java"
},
{
"metric": "ncloc",
- "component": "project-id",
- "value": "1984"
+ "value": "1984",
+ "component": "MY_PROJECT"
},
{
"metric": "ncloc",
- "component": "AVIwDXE-bJbJqrw6wFv8",
"value": "217",
"periods": [
{
"index": 2,
"value": "0"
}
- ]
+ ],
+ "component": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl"
},
{
"metric": "new_violations",
- "component": "AVIwDXE-bJbJqrw6wFv5",
"periods": [
{
"index": 1,
@@ -58,11 +57,11 @@
"index": 3,
"value": "25"
}
- ]
+ ],
+ "component": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/ElementImpl.java"
},
{
"metric": "new_violations",
- "component": "AVIwDXE_bJbJqrw6wFwJ",
"periods": [
{
"index": 1,
@@ -76,11 +75,11 @@
"index": 3,
"value": "0"
}
- ]
+ ],
+ "component": "com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java"
},
{
"metric": "new_violations",
- "component": "project-id",
"periods": [
{
"index": 1,
@@ -94,11 +93,11 @@
"index": 3,
"value": "255"
}
- ]
+ ],
+ "component": "MY_PROJECT"
},
{
"metric": "new_violations",
- "component": "AVIwDXE-bJbJqrw6wFv8",
"periods": [
{
"index": 1,
@@ -112,7 +111,8 @@
"index": 3,
"value": "25"
}
- ]
+ ],
+ "component": "com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl"
}
],
"components": [
diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java
index 082db028f88..520c790d707 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java
@@ -209,16 +209,44 @@ public class SearchActionTest {
// directory is not eligible for best value
assertThat(result.getMeasuresList().stream()
- .filter(measure -> directoryDto.uuid().equals(measure.getComponent()))
+ .filter(measure -> directoryDto.key().equals(measure.getComponent()))
.map(Measure::getMetric))
.containsOnly("coverage");
// file measures
- List<Measure> fileMeasures = result.getMeasuresList().stream().filter(measure -> file.uuid().equals(measure.getComponent())).collect(Collectors.toList());
+ List<Measure> fileMeasures = result.getMeasuresList().stream().filter(measure -> file.key().equals(measure.getComponent())).collect(Collectors.toList());
assertThat(fileMeasures).extracting(Measure::getMetric).containsOnly("ncloc", "coverage", "new_violations");
assertThat(fileMeasures).extracting(Measure::getValue).containsOnly("100", "15.5", "");
}
@Test
+ public void sort_by_metric_key_then_component_name() throws Exception {
+ MetricDto coverage = insertCoverageMetric();
+ MetricDto complexity = insertComplexityMetric();
+ ComponentDto project = newProjectDto();
+ SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
+ setBrowsePermissionOnUser(project);
+ ComponentDto file1 = componentDb.insertComponent(newFileDto(project).setName("C"));
+ ComponentDto file2 = componentDb.insertComponent(newFileDto(project).setName("A"));
+ ComponentDto file3 = componentDb.insertComponent(newFileDto(project).setName("B"));
+ dbClient.measureDao().insert(dbSession, newMeasureDto(coverage, file1, projectSnapshot).setValue(5.5d));
+ dbClient.measureDao().insert(dbSession, newMeasureDto(coverage, file2, projectSnapshot).setValue(6.5d));
+ dbClient.measureDao().insert(dbSession, newMeasureDto(coverage, file3, projectSnapshot).setValue(7.5d));
+ dbClient.measureDao().insert(dbSession, newMeasureDto(complexity, file1, projectSnapshot).setValue(10d));
+ dbClient.measureDao().insert(dbSession, newMeasureDto(complexity, file2, projectSnapshot).setValue(15d));
+ dbClient.measureDao().insert(dbSession, newMeasureDto(complexity, file3, projectSnapshot).setValue(20d));
+ db.commit();
+
+ SearchWsResponse result = call(asList(file1.key(), file2.key(), file3.key()), asList("coverage", "complexity"));
+
+ assertThat(result.getMeasuresList()).extracting(Measure::getMetric, Measure::getComponent)
+ .containsExactly(
+ tuple("complexity", file2.key()), tuple("complexity", file3.key()), tuple("complexity", file1.key()),
+ tuple("coverage", file2.key()), tuple("coverage", file3.key()), tuple("coverage", file1.key())
+ );
+ assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(file2.key(), file3.key(), file1.key());
+ }
+
+ @Test
public void only_returns_authorized_components() {
insertComplexityMetric();
ComponentDto project1 = componentDb.insertProject();