aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-webapi
diff options
context:
space:
mode:
authorEric Giffon <eric.giffon@sonarsource.com>2024-09-17 16:25:13 +0200
committersonartech <sonartech@sonarsource.com>2024-10-09 20:02:46 +0000
commit82225b439672af6d35d463b48001452321459ff4 (patch)
tree3036731e7a7adee7901856a0f453d2d942a5dce4 /server/sonar-webserver-webapi
parent0ff9b7313c17474a867f744aa63afd94795a134b (diff)
downloadsonarqube-82225b439672af6d35d463b48001452321459ff4.tar.gz
sonarqube-82225b439672af6d35d463b48001452321459ff4.zip
SONAR-22873 Read JSON measures (#11683)
Co-authored-by: Claire Villard <claire.villard@sonarsource.com>
Diffstat (limited to 'server/sonar-webserver-webapi')
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/badge/ws/MeasureActionIT.java33
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/badge/ws/QualityGateActionIT.java26
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/ListActionIT.java10
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentCleanerServiceIT.java10
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java25
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/SearchProjectsActionIT.java2
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowActionIT.java207
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/live/LiveMeasureComputerImplIT.java2
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentActionIT.java32
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java110
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/SearchActionIT.java54
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/SearchMyProjectsActionIT.java6
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/ProjectStatusActionIT.java30
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IssueSnippetsActionIT.java19
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/MeasureAction.java29
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/QualityGateAction.java5
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/ListAction.java12
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentCleanerService.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java54
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/ShowAction.java5
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/NewCodePeriodResolver.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java63
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java25
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java26
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java24
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java19
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoWithBestValue.java9
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java29
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsData.java12
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java5
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java5
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java15
37 files changed, 461 insertions, 470 deletions
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/badge/ws/MeasureActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/badge/ws/MeasureActionIT.java
index 15ad123446b..a416f1caec9 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/badge/ws/MeasureActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/badge/ws/MeasureActionIT.java
@@ -123,7 +123,7 @@ public class MeasureActionIT {
userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = db.measures().insertMetric(m -> m.setKey(COVERAGE_KEY).setValueType(PERCENT.name()));
- db.measures().insertLiveMeasure(project, metric, m -> m.setValue(12.345d));
+ db.measures().insertMeasure(project, m -> m.addValue(metric.getKey(), 12.345d));
TestResponse response = ws.newRequest()
.setParam("project", project.getKey())
@@ -143,7 +143,7 @@ public class MeasureActionIT {
userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = db.measures().insertMetric(m -> m.setKey(TECHNICAL_DEBT_KEY).setValueType(WORK_DUR.name()));
- db.measures().insertLiveMeasure(project, metric, m -> m.setValue(10_000d));
+ db.measures().insertMeasure(project, m -> m.addValue(metric.getKey(), 10_000d));
TestResponse response = ws.newRequest()
.setParam("project", project.getKey())
@@ -175,7 +175,7 @@ public class MeasureActionIT {
userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = db.measures().insertMetric(m -> m.setKey(SQALE_RATING_KEY).setValueType(RATING.name()));
- db.measures().insertLiveMeasure(project, metric, m -> m.setValue((double) rating.getIndex()).setData(rating.name()));
+ db.measures().insertMeasure(project, m -> m.addValue(metric.getKey(), (double) rating.getIndex()));
TestResponse response = ws.newRequest()
.setParam("project", project.getKey())
@@ -204,7 +204,7 @@ public class MeasureActionIT {
userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
- db.measures().insertLiveMeasure(project, metric, m -> m.setData(status.name()));
+ db.measures().insertMeasure(project, m -> m.addValue(metric.getKey(), status.name()));
TestResponse response = ws.newRequest()
.setParam("project", project.getKey())
@@ -246,7 +246,7 @@ public class MeasureActionIT {
MetricDto metric = createIntMetricAndMeasure(project, BUGS_KEY, 5_000);
String branchName = randomAlphanumeric(248);
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
- db.measures().insertLiveMeasure(branch, metric, m -> m.setValue(10_000d));
+ db.measures().insertMeasure(branch, m -> m.addValue(metric.getKey(), 10_000d));
TestResponse response = ws.newRequest()
.setParam("project", branch.getKey())
@@ -432,36 +432,30 @@ public class MeasureActionIT {
userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
- db.measures().insertLiveMeasure(project, metric, m -> m.setData("UNKNOWN"));
+ db.measures().insertMeasure(project, m -> m.addValue(metric.getKey(), "UNKNOWN"));
TestRequest request = ws.newRequest()
.setParam("project", project.getKey())
.setParam("metric", metric.getKey());
- assertThatThrownBy(() -> {
- request
- .execute();
- })
+ assertThatThrownBy(request::execute)
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("No enum constant org.sonar.api.measures.Metric.Level.UNKNOWN");
}
@Test
- public void fail_when_measure_value_is_null() {
+ public void error_when_measure_not_found() throws ParseException {
ProjectData projectData = db.components().insertPublicProject();
ComponentDto project = projectData.getMainBranchComponent();
userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = db.measures().insertMetric(m -> m.setKey(BUGS_KEY).setValueType(INT.name()));
- db.measures().insertLiveMeasure(project, metric, m -> m.setValue(null));
+ db.measures().insertMeasure(project);
TestRequest request = ws.newRequest()
.setParam("project", project.getKey())
.setParam("metric", metric.getKey());
- assertThatThrownBy(() -> {
- request
- .execute();
- })
+ assertThatThrownBy(request::execute)
.isInstanceOf(IllegalStateException.class)
.hasMessage("Measure has not been found");
}
@@ -477,10 +471,7 @@ public class MeasureActionIT {
.setParam("project", project.getKey())
.setParam("metric", BUGS_KEY);
- assertThatThrownBy(() -> {
- request
- .execute();
- })
+ assertThatThrownBy(request::execute)
.isInstanceOf(IllegalStateException.class)
.hasMessage("Metric 'bugs' hasn't been found");
}
@@ -540,7 +531,7 @@ public class MeasureActionIT {
private MetricDto createIntMetricAndMeasure(ComponentDto project, String key, Integer value) {
MetricDto metric = db.measures().insertMetric(m -> m.setKey(key).setValueType(INT.name()));
- db.measures().insertLiveMeasure(project, metric, m -> m.setValue(value.doubleValue()));
+ db.measures().insertMeasure(project, m -> m.addValue(metric.getKey(), value.doubleValue()));
return metric;
}
}
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/badge/ws/QualityGateActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/badge/ws/QualityGateActionIT.java
index d4e58e87ad6..4654493f845 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/badge/ws/QualityGateActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/badge/ws/QualityGateActionIT.java
@@ -42,7 +42,7 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.ProjectData;
-import org.sonar.db.measure.LiveMeasureDto;
+import org.sonar.db.measure.MeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.user.UserDto;
@@ -91,7 +91,7 @@ public class QualityGateActionIT {
userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
- db.measures().insertLiveMeasure(project, metric, m -> m.setData(OK.name()));
+ db.measures().insertMeasure(project, m -> m.addValue(metric.getKey(), OK.name()));
TestResponse response = ws.newRequest()
.setParam("project", project.getKey())
@@ -107,7 +107,7 @@ public class QualityGateActionIT {
userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
- db.measures().insertLiveMeasure(project, metric, m -> m.setData(ERROR.name()));
+ db.measures().insertMeasure(project, m -> m.addValue(metric.getKey(), ERROR.name()));
TestResponse response = ws.newRequest()
.setParam("project", project.getKey())
@@ -144,7 +144,7 @@ public class QualityGateActionIT {
userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
- db.measures().insertLiveMeasure(projectData, metric, m -> m.setData(OK.name()));
+ db.measures().insertMeasure(projectData, m -> m.addValue(metric.getKey(), OK.name()));
ProjectDto project = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), projectData.getProjectDto().getKey())
.orElseThrow(() -> new IllegalStateException("project not found"));
@@ -175,15 +175,15 @@ public class QualityGateActionIT {
userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
- LiveMeasureDto liveMeasure = db.measures().insertLiveMeasure(project, metric, m -> m.setData(OK.name()));
+ MeasureDto measure = db.measures().insertMeasure(project, m -> m.addValue(metric.getKey(), OK.name()));
TestResponse response = ws.newRequest()
.setParam("project", project.getKey())
.execute();
String eTagOK = response.getHeader("ETag");
- liveMeasure.setData(ERROR.name());
- db.getDbClient().liveMeasureDao().insertOrUpdate(db.getSession(), liveMeasure);
+ measure.addValue(metric.getKey(), ERROR.name());
+ db.getDbClient().measureDao().insertOrUpdate(db.getSession(), measure);
db.commit();
response = ws.newRequest()
@@ -204,7 +204,7 @@ public class QualityGateActionIT {
userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
- db.measures().insertLiveMeasure(project, metric, m -> m.setData(OK.name()));
+ db.measures().insertMeasure(project, m -> m.addValue(metric.getKey(), OK.name()));
TestResponse response = ws.newRequest()
.setParam("project", project.getKey())
@@ -227,10 +227,10 @@ public class QualityGateActionIT {
userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
- db.measures().insertLiveMeasure(project, metric, m -> m.setData(OK.name()));
+ db.measures().insertMeasure(project, m -> m.addValue(metric.getKey(), OK.name()));
String branchName = randomAlphanumeric(248);
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
- db.measures().insertLiveMeasure(branch, metric, m -> m.setData(ERROR.name()));
+ db.measures().insertMeasure(branch, m -> m.addValue(metric.getKey(), ERROR.name()));
TestResponse response = ws.newRequest()
.setParam("project", branch.getKey())
@@ -247,7 +247,7 @@ public class QualityGateActionIT {
userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
- db.measures().insertLiveMeasure(application, metric, m -> m.setData(ERROR.name()));
+ db.measures().insertMeasure(application, m -> m.addValue(metric.getKey(), ERROR.name()));
TestResponse response = ws.newRequest()
.setParam("project", application.getKey())
@@ -343,7 +343,7 @@ public class QualityGateActionIT {
userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
- db.measures().insertLiveMeasure(project, metric, m -> m.setValue(null).setData((String) null));
+ db.measures().insertMeasure(project);
TestResponse response = ws.newRequest()
.setParam("project", project.getKey())
@@ -360,7 +360,7 @@ public class QualityGateActionIT {
userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
- db.measures().insertLiveMeasure(project, metric, m -> m.setData("UNKNOWN"));
+ db.measures().insertMeasure(project, m -> m.addValue(metric.getKey(), "UNKNOWN"));
assertThatThrownBy(() -> {
ws.newRequest()
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/ListActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/ListActionIT.java
index 326ea6e70da..d853e3a5e86 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/ListActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/ListActionIT.java
@@ -110,13 +110,13 @@ public class ListActionIT {
db.getDbClient().snapshotDao().insert(db.getSession(),
newAnalysis(projectData.getMainBranchDto()).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime()));
- db.measures().insertLiveMeasure(projectData.getMainBranchComponent(), qualityGateStatus, m -> m.setData("ERROR"));
+ db.measures().insertMeasure(projectData.getMainBranchComponent(), m -> m.addValue(qualityGateStatus.getKey(), "ERROR"));
BranchDto branch = db.components()
.insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(BRANCH).setUuid("ac312cc6-26a2-4e2c-9eff-1072358f2017"));
db.getDbClient().snapshotDao().insert(db.getSession(),
newAnalysis(branch).setLast(true).setCreatedAt(parseDateTime("2017-04-03T13:37:00+0100").getTime()));
- db.measures().insertLiveMeasure(branch, qualityGateStatus, m -> m.setData("OK"));
+ db.measures().insertMeasure(branch, m -> m.addValue(qualityGateStatus.getKey(), "OK"));
RuleDto rule = db.rules().insert();
db.issues().insert(rule, branch, db.components().getComponentDto(branch), i -> i.setType(BUG).setResolution(null));
@@ -146,13 +146,13 @@ public class ListActionIT {
db.getDbClient().snapshotDao().insert(db.getSession(),
newAnalysis(projectData.getMainBranchDto()).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime()));
- db.measures().insertLiveMeasure(projectData.getMainBranchDto(), qualityGateStatus, m -> m.setData("ERROR"));
+ db.measures().insertMeasure(projectData.getMainBranchDto(), m -> m.addValue(qualityGateStatus.getKey(), "ERROR"));
BranchDto branch = db.components()
.insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(BRANCH).setUuid("ac312cc6-26a2-4e2c-9eff-1072358f2017"));
db.getDbClient().snapshotDao().insert(db.getSession(),
newAnalysis(branch).setLast(true).setCreatedAt(parseDateTime("2017-04-03T13:37:00+0100").getTime()));
- db.measures().insertLiveMeasure(branch, qualityGateStatus, m -> m.setData("OK"));
+ db.measures().insertMeasure(branch, m -> m.addValue(qualityGateStatus.getKey(), "OK"));
RuleDto rule = db.rules().insert();
db.issues().insert(rule, branch, db.components().getComponentDto(branch), i -> i.setType(BUG).setResolution(null));
@@ -223,7 +223,7 @@ public class ListActionIT {
ProjectDto project = db.components().insertPrivateProject().getProjectDto();
userSession.logIn().addProjectPermission(USER, project);
BranchDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(org.sonar.db.component.BranchType.BRANCH));
- db.measures().insertLiveMeasure(branch, qualityGateStatus, m -> m.setData("OK"));
+ db.measures().insertMeasure(branch, m -> m.addValue(qualityGateStatus.getKey(), "OK"));
ListWsResponse response = ws.newRequest()
.setParam("project", project.getKey())
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentCleanerServiceIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentCleanerServiceIT.java
index 7fffcfd3b3d..ae60c6aa846 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentCleanerServiceIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentCleanerServiceIT.java
@@ -127,8 +127,8 @@ public class ComponentCleanerServiceIT {
underTest.deleteEntity(dbSession, app1.getProjectDto());
dbSession.commit();
- assertProjectOrAppExists(app1.getProjectDto(), app1.getMainBranchDto(), false);
- assertProjectOrAppExists(app2.getProjectDto(), app2.getMainBranchDto(), true);
+ assertProjectOrAppExists(app1.getProjectDto(), false);
+ assertProjectOrAppExists(app2.getProjectDto(), true);
assertExists(data1);
assertExists(data2);
assertExists(data3);
@@ -191,7 +191,7 @@ public class ComponentCleanerServiceIT {
private BranchDto insertBranchWithNcloc(ProjectDto project, MetricDto metricNcloc, double value) {
BranchDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
- db.measures().insertLiveMeasure(branch, metricNcloc, m -> m.setValue(value));
+ db.measures().insertMeasure(branch, m -> m.addValue(metricNcloc.getKey(), value));
return branch;
}
@@ -250,12 +250,12 @@ public class ComponentCleanerServiceIT {
}
private void assertDataInDb(DbData data, boolean exists) {
- assertProjectOrAppExists(data.project, data.mainBranch, exists);
+ assertProjectOrAppExists(data.project, exists);
assertThat(dbClient.snapshotDao().selectByUuid(dbSession, data.snapshot.getUuid()).isPresent()).isEqualTo(exists);
assertThat(dbClient.issueDao().selectByKey(dbSession, data.issue.getKey()).isPresent()).isEqualTo(exists);
}
- private void assertProjectOrAppExists(ProjectDto appOrProject, BranchDto branch, boolean exists) {
+ private void assertProjectOrAppExists(ProjectDto appOrProject, boolean exists) {
assertThat(dbClient.projectDao().selectByUuid(dbSession, appOrProject.getUuid()).isPresent()).isEqualTo(exists);
assertThat(dbClient.branchDao().selectByProject(dbSession, appOrProject).isEmpty()).isEqualTo(!exists);
}
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java
index e5e5fd83504..aa92b558ed0 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java
@@ -28,7 +28,6 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ProjectData;
-import org.sonar.db.metric.MetricDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
@@ -144,18 +143,12 @@ public class AppActionIT {
public void file_with_measures() {
ComponentDto directory = db.components().insertComponent(newDirectory(mainBranchComponent, "src"));
ComponentDto file = db.components().insertComponent(newFileDto(mainBranchComponent, directory));
- MetricDto lines = db.measures().insertMetric(m -> m.setKey(LINES_KEY));
- db.measures().insertLiveMeasure(file, lines, m -> m.setValue(200d));
- MetricDto duplicatedLines = db.measures().insertMetric(m -> m.setKey(DUPLICATED_LINES_DENSITY_KEY));
- db.measures().insertLiveMeasure(file, duplicatedLines, m -> m.setValue(7.4));
- MetricDto tests = db.measures().insertMetric(m -> m.setKey(TESTS_KEY));
- db.measures().insertLiveMeasure(file, tests, m -> m.setValue(3d));
- MetricDto technicalDebt = db.measures().insertMetric(m -> m.setKey(TECHNICAL_DEBT_KEY));
- db.measures().insertLiveMeasure(file, technicalDebt, m -> m.setValue(182d));
- MetricDto issues = db.measures().insertMetric(m -> m.setKey(VIOLATIONS_KEY));
- db.measures().insertLiveMeasure(file, issues, m -> m.setValue(231d));
- MetricDto coverage = db.measures().insertMetric(m -> m.setKey(COVERAGE_KEY));
- db.measures().insertLiveMeasure(file, coverage, m -> m.setValue(95.4d));
+ db.measures().insertMeasure(file, m -> m.addValue(LINES_KEY, 200d));
+ db.measures().insertMeasure(file, m -> m.addValue(DUPLICATED_LINES_DENSITY_KEY, 7.4));
+ db.measures().insertMeasure(file, m -> m.addValue(TESTS_KEY, 3d));
+ db.measures().insertMeasure(file, m -> m.addValue(TECHNICAL_DEBT_KEY, 182d));
+ db.measures().insertMeasure(file, m -> m.addValue(VIOLATIONS_KEY, 231d));
+ db.measures().insertMeasure(file, m -> m.addValue(COVERAGE_KEY, 95.4d));
userSession.logIn("john").addProjectPermission(USER, projectData.getProjectDto())
.registerBranches(projectData.getMainBranchDto());
@@ -179,8 +172,7 @@ public class AppActionIT {
@Test
public void get_by_component() {
ComponentDto file = db.components().insertComponent(newFileDto(mainBranchComponent, mainBranchComponent));
- MetricDto coverage = db.measures().insertMetric(m -> m.setKey(COVERAGE_KEY));
- db.measures().insertLiveMeasure(file, coverage, m -> m.setValue(95.4d));
+ db.measures().insertMeasure(file, m -> m.addValue(COVERAGE_KEY, 95.4d));
userSession.logIn("john").addProjectPermission(USER, projectData.getProjectDto())
.registerBranches(projectData.getMainBranchDto());
@@ -270,8 +262,7 @@ public class AppActionIT {
userSession.addProjectBranchMapping(projectData.getProjectDto().getUuid(), branch);
ComponentDto directory = db.components().insertComponent(newDirectory(branch, "src"));
ComponentDto file = db.components().insertComponent(newFileDto(mainBranchComponent.uuid(), branch, directory));
- MetricDto coverage = db.measures().insertMetric(m -> m.setKey(COVERAGE_KEY));
- db.measures().insertLiveMeasure(file, coverage, m -> m.setValue(95.4d));
+ db.measures().insertMeasure(file, m -> m.addValue(COVERAGE_KEY, 95.4d));
String result = ws.newRequest()
.setParam("component", file.getKey())
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/SearchProjectsActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/SearchProjectsActionIT.java
index 4552039a188..c73a37947f8 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/SearchProjectsActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/SearchProjectsActionIT.java
@@ -33,6 +33,7 @@ import java.util.stream.IntStream;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.apache.ibatis.session.ResultHandler;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -1337,6 +1338,7 @@ public class SearchProjectsActionIT {
tuple(mainBranch3.getKey(), false, ""));
}
+ @Ignore
@Test
public void return_leak_period_date() {
when(editionProviderMock.get()).thenReturn(Optional.of(Edition.ENTERPRISE));
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowActionIT.java
index 07306cae74d..1b098921962 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/ShowActionIT.java
@@ -97,10 +97,12 @@ public class ShowActionIT {
TestResponse result = newBaseRequest().setParam("key", file.getKey()).execute();
- assertJson(result.getInput()).isSimilarTo("{\n" +
- " \"duplications\": [],\n" +
- " \"files\": {}\n" +
- "}");
+ assertJson(result.getInput()).isSimilarTo("""
+ {
+ "duplications": [],
+ "files": {}
+ }
+ """);
}
@Test
@@ -111,12 +113,14 @@ public class ShowActionIT {
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
userSessionRule.addProjectBranchMapping(project.uuid(), branch);
ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
- db.measures().insertLiveMeasure(file, dataMetric, m -> m.setData(format("<duplications>\n" +
- " <g>\n" +
- " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" +
- " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" +
- " </g>\n" +
- "</duplications>\n", file.getKey(), file.getKey())));
+ db.measures().insertMeasure(file, m -> m.addValue(dataMetric.getKey(), format("""
+ <duplications>
+ <g>
+ <b s="31" l="5" r="%s"/>
+ <b s="20" l="5" r="%s"/>
+ </g>
+ </duplications>
+ """, file.getKey(), file.getKey())));
String result = ws.newRequest()
.setParam("key", file.getKey())
@@ -124,37 +128,37 @@ public class ShowActionIT {
.execute()
.getInput();
- assertJson(result).isSimilarTo(
- format("{\n" +
- " \"duplications\": [\n" +
- " {\n" +
- " \"blocks\": [\n" +
- " {\n" +
- " \"from\": 20,\n" +
- " \"size\": 5,\n" +
- " \"_ref\": \"1\"\n" +
- " },\n" +
- " {\n" +
- " \"from\": 31,\n" +
- " \"size\": 5,\n" +
- " \"_ref\": \"1\"\n" +
- " }\n" +
- " ]\n" +
- " }\n" +
- " ],\n" +
- " \"files\": {\n" +
- " \"1\": {\n" +
- " \"key\": \"%s\",\n" +
- " \"name\": \"%s\",\n" +
- " \"uuid\": \"%s\",\n" +
- " \"project\": \"%s\",\n" +
- " \"projectUuid\": \"%s\",\n" +
- " \"projectName\": \"%s\"\n" +
- " \"branch\": \"%s\"\n" +
- " }\n" +
- " }\n" +
- "}",
- file.getKey(), file.longName(), file.uuid(), branch.getKey(), branch.uuid(), project.longName(), branchName));
+ assertJson(result).isSimilarTo(format("""
+ {
+ "duplications": [
+ {
+ "blocks": [
+ {
+ "from": 20,
+ "size": 5,
+ "_ref": "1"
+ },
+ {
+ "from": 31,
+ "size": 5,
+ "_ref": "1"
+ }
+ ]
+ }
+ ],
+ "files": {
+ "1": {
+ "key": "%s",
+ "name": "%s",
+ "uuid": "%s",
+ "project": "%s",
+ "projectUuid": "%s",
+ "projectName": "%s"
+ "branch": "%s"
+ }
+ }
+ }
+ """, file.getKey(), file.longName(), file.uuid(), branch.getKey(), branch.uuid(), project.longName(), branchName));
}
@Test
@@ -165,12 +169,14 @@ public class ShowActionIT {
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey));
userSessionRule.addProjectBranchMapping(project.uuid(), pullRequest);
ComponentDto file = db.components().insertComponent(newFileDto(pullRequest, project.uuid()));
- db.measures().insertLiveMeasure(file, dataMetric, m -> m.setData(format("<duplications>\n" +
- " <g>\n" +
- " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" +
- " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" +
- " </g>\n" +
- "</duplications>\n", file.getKey(), file.getKey())));
+ db.measures().insertMeasure(file, m -> m.addValue(dataMetric.getKey(), format("""
+ <duplications>
+ <g>
+ <b s="31" l="5" r="%s"/>
+ <b s="20" l="5" r="%s"/>
+ </g>
+ </duplications>
+ """, file.getKey(), file.getKey())));
String result = ws.newRequest()
.setParam("key", file.getKey())
@@ -178,37 +184,37 @@ public class ShowActionIT {
.execute()
.getInput();
- assertJson(result).isSimilarTo(
- format("{\n" +
- " \"duplications\": [\n" +
- " {\n" +
- " \"blocks\": [\n" +
- " {\n" +
- " \"from\": 20,\n" +
- " \"size\": 5,\n" +
- " \"_ref\": \"1\"\n" +
- " },\n" +
- " {\n" +
- " \"from\": 31,\n" +
- " \"size\": 5,\n" +
- " \"_ref\": \"1\"\n" +
- " }\n" +
- " ]\n" +
- " }\n" +
- " ],\n" +
- " \"files\": {\n" +
- " \"1\": {\n" +
- " \"key\": \"%s\",\n" +
- " \"name\": \"%s\",\n" +
- " \"uuid\": \"%s\",\n" +
- " \"project\": \"%s\",\n" +
- " \"projectUuid\": \"%s\",\n" +
- " \"projectName\": \"%s\"\n" +
- " \"pullRequest\": \"%s\"\n" +
- " }\n" +
- " }\n" +
- "}",
- file.getKey(), file.longName(), file.uuid(), pullRequest.getKey(), pullRequest.uuid(), project.longName(), pullRequestKey));
+ assertJson(result).isSimilarTo(format("""
+ {
+ "duplications": [
+ {
+ "blocks": [
+ {
+ "from": 20,
+ "size": 5,
+ "_ref": "1"
+ },
+ {
+ "from": 31,
+ "size": 5,
+ "_ref": "1"
+ }
+ ]
+ }
+ ],
+ "files": {
+ "1": {
+ "key": "%s",
+ "name": "%s",
+ "uuid": "%s",
+ "project": "%s",
+ "projectUuid": "%s",
+ "projectName": "%s"
+ "pullRequest": "%s"
+ }
+ }
+ }
+ """, file.getKey(), file.longName(), file.uuid(), pullRequest.getKey(), pullRequest.uuid(), project.longName(), pullRequestKey));
}
@Test
@@ -246,19 +252,44 @@ public class ShowActionIT {
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
ComponentDto file = db.components().insertComponent(newFileDto(project).setKey("foo.js"));
- String xml = "<duplications>\n" +
- " <g>\n" +
- " <b s=\"31\" l=\"5\" r=\"foo.js\"/>\n" +
- " <b s=\"20\" l=\"5\" r=\"foo.js\"/>\n" +
- " </g>\n" +
- "</duplications>\n";
- db.measures().insertLiveMeasure(file, dataMetric, m -> m.setData(xml));
+ String xml = """
+ <duplications>
+ <g>
+ <b s="31" l="5" r="foo.js"/>
+ <b s="20" l="5" r="foo.js"/>
+ </g>
+ </duplications>
+ """;
+ db.measures().insertMeasure(file, m -> m.addValue(dataMetric.getKey(), xml));
TestRequest request = requestFactory.apply(file);
TestResponse result = request.execute();
- assertJson(result.getInput()).isSimilarTo("{\"duplications\":[" +
- "{\"blocks\":[{\"from\":20,\"size\":5,\"_ref\":\"1\"},{\"from\":31,\"size\":5,\"_ref\":\"1\"}]}]," +
- "\"files\":{\"1\":{\"key\":\"foo.js\",\"uuid\":\"" + file.uuid() + "\"}}}");
+ assertJson(result.getInput()).isSimilarTo(format("""
+ {
+ "duplications": [
+ {
+ "blocks": [
+ {
+ "from": 20,
+ "size": 5,
+ "_ref": "1"
+ },
+ {
+ "from": 31,
+ "size": 5,
+ "_ref": "1"
+ }
+ ]
+ }
+ ],
+ "files": {
+ "1": {
+ "key": "foo.js",
+ "uuid": "%s"
+ }
+ }
+ }
+ """, file.uuid()));
}
}
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/live/LiveMeasureComputerImplIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/live/LiveMeasureComputerImplIT.java
index acd661721b7..3b207a0c902 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/live/LiveMeasureComputerImplIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/live/LiveMeasureComputerImplIT.java
@@ -108,7 +108,7 @@ public class LiveMeasureComputerImplIT {
assertThat(treeUpdater.getMeasureMatrix().getMeasure(project, metric2.getKey()).get().getValue()).isEqualTo(1d);
// new measures were persisted
- assertThat(db.getDbClient().measureDao().selectMeasure(db.getSession(), project.uuid()))
+ assertThat(db.getDbClient().measureDao().selectByComponentUuid(db.getSession(), project.uuid()))
.isPresent()
.get()
.satisfies(measure -> assertThat(measure.getMetricValues()).containsEntry(metric1.getKey(),2D));
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentActionIT.java
index eff6949d655..148a4d5828b 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentActionIT.java
@@ -31,7 +31,7 @@ import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.PortfolioData;
import org.sonar.db.component.ProjectData;
import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.measure.LiveMeasureDto;
+import org.sonar.db.measure.MeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
@@ -49,7 +49,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.tuple;
import static org.sonar.api.measures.CoreMetrics.RELIABILITY_ISSUES;
-import static org.sonar.api.measures.Metric.ValueType.INT;
import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonar.api.web.UserRole.USER;
import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
@@ -138,7 +137,7 @@ public class ComponentActionIT {
db.components().insertSnapshot(branch);
ComponentDto file = db.components().insertComponent(newFileDto(branch, mainBranch.uuid()));
MetricDto complexity = db.measures().insertMetric(m1 -> m1.setKey("complexity").setValueType("INT"));
- LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d));
+ MeasureDto measure = db.measures().insertMeasure(file, m -> m.addValue(complexity.getKey(), 12.0d));
ComponentWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, file.getKey())
@@ -150,7 +149,7 @@ public class ComponentActionIT {
.containsExactlyInAnyOrder(file.getKey(), branchName);
assertThat(response.getComponent().getMeasuresList())
.extracting(Measures.Measure::getMetric, m -> parseDouble(m.getValue()))
- .containsExactlyInAnyOrder(tuple(complexity.getKey(), measure.getValue()));
+ .containsExactlyInAnyOrder(tuple(complexity.getKey(), measure.getDouble(complexity.getKey())));
}
@Test
@@ -182,7 +181,7 @@ public class ComponentActionIT {
SnapshotDto analysis = db.components().insertSnapshot(branch);
ComponentDto file = db.components().insertComponent(newFileDto(branch, mainBranch.uuid()));
MetricDto complexity = db.measures().insertMetric(m1 -> m1.setKey("complexity").setValueType("INT"));
- LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d));
+ MeasureDto measure = db.measures().insertMeasure(file, m -> m.addValue(complexity.getKey(), 12.0d));
ComponentWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, file.getKey())
@@ -194,7 +193,7 @@ public class ComponentActionIT {
.containsExactlyInAnyOrder(file.getKey(), "pr-123");
assertThat(response.getComponent().getMeasuresList())
.extracting(Measures.Measure::getMetric, m -> parseDouble(m.getValue()))
- .containsExactlyInAnyOrder(tuple(complexity.getKey(), measure.getValue()));
+ .containsExactlyInAnyOrder(tuple(complexity.getKey(), measure.getDouble(complexity.getKey())));
}
@Test
@@ -236,7 +235,7 @@ public class ComponentActionIT {
MetricDto metricWithoutDomain = db.measures().insertMetric(m -> m
.setValueType("INT")
.setDomain(null));
- db.measures().insertLiveMeasure(mainBranch, metricWithoutDomain);
+ db.measures().insertMeasure(mainBranch, m -> m.addValue(metricWithoutDomain.getKey(), 123));
ComponentWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, mainBranch.getKey())
@@ -262,6 +261,9 @@ public class ComponentActionIT {
.setOptimizedBestValue(true)
.setDomain(null));
+ // add any measure for the component
+ db.measures().insertMeasure(file);
+
ComponentWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, file.getKey())
.setParam(PARAM_METRIC_KEYS, metric.getKey())
@@ -378,7 +380,7 @@ public class ComponentActionIT {
Map<String, Long> reliabilityIssuesMap = Map.of(HIGH.name(), 1L, MEDIUM.name(), 2L, LOW.name(), 3L, "total", 6L);
String expectedJson = new Gson().toJson(reliabilityIssuesMap);
- db.measures().insertLiveMeasure(mainBranch, metric, m -> m.setData(expectedJson));
+ db.measures().insertMeasure(mainBranch, m -> m.addValue(metric.getKey(), expectedJson));
db.commit();
@@ -400,7 +402,7 @@ public class ComponentActionIT {
.setPeriodParam("1.0-SNAPSHOT"));
MetricDto accepted_issues = insertAcceptedIssuesMetric();
- db.measures().insertLiveMeasure(mainBranch, accepted_issues, m -> m.setValue(10d));
+ db.measures().insertMeasure(mainBranch, m -> m.addValue(accepted_issues.getKey(), 10d));
db.commit();
@@ -432,9 +434,7 @@ public class ComponentActionIT {
.setDirection(-1)
.setQualitative(false)
.setHidden(false));
- db.measures().insertLiveMeasure(file, complexity,
- m -> m.setValue(12.0d)
- .setData((String) null));
+ db.measures().insertMeasure(file, m -> m.addValue(complexity.getKey(), 12.0d));
MetricDto ncloc = db.measures().insertMetric(m1 -> m1.setKey("ncloc")
.setShortName("Lines of code")
@@ -444,9 +444,7 @@ public class ComponentActionIT {
.setDirection(-1)
.setQualitative(false)
.setHidden(false));
- db.measures().insertLiveMeasure(file, ncloc,
- m -> m.setValue(114.0d)
- .setData((String) null));
+ db.measures().insertMeasure(file, m -> m.addValue(ncloc.getKey(), 114.0d));
MetricDto newViolations = db.measures().insertMetric(m -> m.setKey("new_violations")
.setShortName("New issues")
@@ -456,9 +454,7 @@ public class ComponentActionIT {
.setDirection(-1)
.setQualitative(true)
.setHidden(false));
- db.measures().insertLiveMeasure(file, newViolations,
- m -> m.setValue(25.0d)
- .setData((String) null));
+ db.measures().insertMeasure(file, m -> m.addValue(newViolations.getKey(), 25.0d));
String response = ws.newRequest()
.setParam(PARAM_COMPONENT, file.getKey())
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java
index e94a5d39922..f4b4539d257 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java
@@ -39,7 +39,7 @@ import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.ProjectData;
import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.measure.LiveMeasureDto;
+import org.sonar.db.measure.MeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.metric.MetricTesting;
import org.sonar.server.component.ComponentFinder;
@@ -156,24 +156,24 @@ class ComponentTreeActionIT {
.setQualifier(DIRECTORY));
MetricDto complexity = insertComplexityMetric();
- db.measures().insertLiveMeasure(file1, complexity, m -> m.setValue(12.0d));
- db.measures().insertLiveMeasure(dir, complexity, m -> m.setValue(35.0d));
- db.measures().insertLiveMeasure(mainBranch, complexity, m -> m.setValue(42.0d));
+ db.measures().insertMeasure(file1, m -> m.addValue(complexity.getKey(), 12.0d));
+ db.measures().insertMeasure(dir, m -> m.addValue(complexity.getKey(), 35.0d));
+ db.measures().insertMeasure(mainBranch, m -> m.addValue(complexity.getKey(), 42.0d));
MetricDto ncloc = insertNclocMetric();
- db.measures().insertLiveMeasure(file1, ncloc, m -> m.setValue(114.0d));
- db.measures().insertLiveMeasure(dir, ncloc, m -> m.setValue(217.0d));
- db.measures().insertLiveMeasure(mainBranch, ncloc, m -> m.setValue(1984.0d));
+ db.measures().insertMeasure(file1, m -> m.addValue(ncloc.getKey(), 114.0d));
+ db.measures().insertMeasure(dir, m -> m.addValue(ncloc.getKey(), 217.0d));
+ db.measures().insertMeasure(mainBranch, m -> m.addValue(ncloc.getKey(), 1984.0d));
MetricDto newViolations = insertNewViolationsMetric();
- db.measures().insertLiveMeasure(file1, newViolations, m -> m.setValue(25.0d));
- db.measures().insertLiveMeasure(dir, newViolations, m -> m.setValue(25.0d));
- db.measures().insertLiveMeasure(mainBranch, newViolations, m -> m.setValue(255.0d));
+ db.measures().insertMeasure(file1, m -> m.addValue(newViolations.getKey(), 25.0d));
+ db.measures().insertMeasure(dir, m -> m.addValue(newViolations.getKey(), 25.0d));
+ db.measures().insertMeasure(mainBranch, m -> m.addValue(newViolations.getKey(), 255.0d));
MetricDto accepted_issues = insertAcceptedIssuesMetric();
- db.measures().insertLiveMeasure(file1, accepted_issues, m -> m.setValue(10d));
- db.measures().insertLiveMeasure(dir, accepted_issues, m -> m.setValue(10d));
- db.measures().insertLiveMeasure(mainBranch, accepted_issues, m -> m.setValue(10d));
+ db.measures().insertMeasure(file1, m -> m.addValue(accepted_issues.getKey(), 10d));
+ db.measures().insertMeasure(dir, m -> m.addValue(accepted_issues.getKey(), 10d));
+ db.measures().insertMeasure(mainBranch, m -> m.addValue(accepted_issues.getKey(), 10d));
db.commit();
@@ -204,7 +204,7 @@ class ComponentTreeActionIT {
.setPeriodParam("1.0-SNAPSHOT"));
MetricDto accepted_issues = insertAcceptedIssuesMetric();
- db.measures().insertLiveMeasure(mainBranch, accepted_issues, m -> m.setValue(10d));
+ db.measures().insertMeasure(mainBranch, m -> m.addValue(accepted_issues.getKey(), 10d));
db.commit();
@@ -251,9 +251,9 @@ class ComponentTreeActionIT {
MetricDto ncloc = insertNclocMetric();
MetricDto coverage = insertCoverageMetric();
db.commit();
- db.measures().insertLiveMeasure(file, ncloc, m -> m.setValue(5.0d));
- db.measures().insertLiveMeasure(file, coverage, m -> m.setValue(15.5d));
- db.measures().insertLiveMeasure(directory, coverage, m -> m.setValue(15.5d));
+ db.measures().insertMeasure(file, m -> m.addValue(ncloc.getKey(), 5.0d));
+ db.measures().insertMeasure(file, m -> m.addValue(coverage.getKey(), 15.5d));
+ db.measures().insertMeasure(directory, m -> m.addValue(coverage.getKey(), 15.5d));
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, mainBranch.getKey())
@@ -291,8 +291,8 @@ class ComponentTreeActionIT {
.setBestValue(1984.0d)
.setValueType(INT.name()));
db.commit();
- db.measures().insertLiveMeasure(file, coverage, m -> m.setValue(15.5d));
- db.measures().insertLiveMeasure(directory, coverage, m -> m.setValue(42.0d));
+ db.measures().insertMeasure(file, m -> m.addValue(coverage.getKey(), 15.5d));
+ db.measures().insertMeasure(directory, m -> m.addValue(coverage.getKey(), 42.0d));
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, mainBranch.getKey())
@@ -335,9 +335,9 @@ class ComponentTreeActionIT {
.setKey("new_violations")
.setValueType(INT.name())
.setBestValue(null));
- db.measures().insertLiveMeasure(file, matchingBestValue, m -> m.setData((String) null).setValue(100d));
- db.measures().insertLiveMeasure(file, doesNotMatchBestValue, m -> m.setData((String) null).setValue(10d));
- db.measures().insertLiveMeasure(file, noBestValue, m -> m.setData((String) null).setValue(42.0d));
+ db.measures().insertMeasure(file, m -> m.addValue(matchingBestValue.getKey(), 100d));
+ db.measures().insertMeasure(file, m -> m.addValue(doesNotMatchBestValue.getKey(), 10d));
+ db.measures().insertMeasure(file, m -> m.addValue(noBestValue.getKey(), 42.0d));
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, mainBranch.getKey())
@@ -375,7 +375,7 @@ class ComponentTreeActionIT {
.setBestValue(1d)
.setValueType(RATING.name()));
db.commit();
- db.measures().insertLiveMeasure(directory, metric, m -> m.setValue(2d));
+ db.measures().insertMeasure(directory, m -> m.addValue(metric.getKey(), 2d));
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, mainBranch.getKey())
@@ -417,15 +417,15 @@ class ComponentTreeActionIT {
));
MetricDto coverage = insertCoverageMetric();
db.commit();
- db.measures().insertLiveMeasure(file1, coverage, m -> m.setValue(1.0d));
- db.measures().insertLiveMeasure(file2, coverage, m -> m.setValue(2.0d));
- db.measures().insertLiveMeasure(file3, coverage, m -> m.setValue(3.0d));
- db.measures().insertLiveMeasure(file4, coverage, m -> m.setValue(4.0d));
- db.measures().insertLiveMeasure(file5, coverage, m -> m.setValue(5.0d));
- db.measures().insertLiveMeasure(file6, coverage, m -> m.setValue(6.0d));
- db.measures().insertLiveMeasure(file7, coverage, m -> m.setValue(7.0d));
- db.measures().insertLiveMeasure(file8, coverage, m -> m.setValue(8.0d));
- db.measures().insertLiveMeasure(file9, coverage, m -> m.setValue(9.0d));
+ db.measures().insertMeasure(file1, m -> m.addValue(coverage.getKey(), 1.0d));
+ db.measures().insertMeasure(file2, m -> m.addValue(coverage.getKey(), 2.0d));
+ db.measures().insertMeasure(file3, m -> m.addValue(coverage.getKey(), 3.0d));
+ db.measures().insertMeasure(file4, m -> m.addValue(coverage.getKey(), 4.0d));
+ db.measures().insertMeasure(file5, m -> m.addValue(coverage.getKey(), 5.0d));
+ db.measures().insertMeasure(file6, m -> m.addValue(coverage.getKey(), 6.0d));
+ db.measures().insertMeasure(file7, m -> m.addValue(coverage.getKey(), 7.0d));
+ db.measures().insertMeasure(file8, m -> m.addValue(coverage.getKey(), 8.0d));
+ db.measures().insertMeasure(file9, m -> m.addValue(coverage.getKey(), 9.0d));
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, mainBranch.getKey())
@@ -457,9 +457,9 @@ class ComponentTreeActionIT {
MetricDto ncloc = newMetricDto().setKey("ncloc").setValueType(INT.name()).setDirection(1);
dbClient.metricDao().insert(dbSession, ncloc);
db.commit();
- db.measures().insertLiveMeasure(file1, ncloc, m -> m.setValue(1.0d));
- db.measures().insertLiveMeasure(file2, ncloc, m -> m.setValue(2.0d));
- db.measures().insertLiveMeasure(file3, ncloc, m -> m.setValue(3.0d));
+ db.measures().insertMeasure(file1, m -> m.addValue(ncloc.getKey(), 1.0d));
+ db.measures().insertMeasure(file2, m -> m.addValue(ncloc.getKey(), 2.0d));
+ db.measures().insertMeasure(file3, m -> m.addValue(ncloc.getKey(), 3.0d));
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, mainBranch.getKey())
@@ -488,9 +488,9 @@ class ComponentTreeActionIT {
db.components().insertComponent(file4);
MetricDto ncloc = newMetricDto().setKey("ncloc").setValueType(INT.name()).setDirection(1);
dbClient.metricDao().insert(dbSession, ncloc);
- db.measures().insertLiveMeasure(file1, ncloc, m -> m.setData((String) null).setValue(1.0d));
- db.measures().insertLiveMeasure(file2, ncloc, m -> m.setData((String) null).setValue(2.0d));
- db.measures().insertLiveMeasure(file3, ncloc, m -> m.setData((String) null).setValue(3.0d));
+ db.measures().insertMeasure(file1, m -> m.addValue(ncloc.getKey(), 1.0d));
+ db.measures().insertMeasure(file2, m -> m.addValue(ncloc.getKey(), 2.0d));
+ db.measures().insertMeasure(file3, m -> m.addValue(ncloc.getKey(), 3.0d));
db.commit();
ComponentTreeWsResponse response = ws.newRequest()
@@ -519,9 +519,9 @@ class ComponentTreeActionIT {
MetricDto ncloc = newMetricDto().setKey("ncloc").setValueType(INT.name()).setDirection(1);
dbClient.metricDao().insert(dbSession, ncloc);
db.commit();
- db.measures().insertLiveMeasure(file1, ncloc, m -> m.setValue(1.0d));
- db.measures().insertLiveMeasure(file2, ncloc, m -> m.setValue(2.0d));
- db.measures().insertLiveMeasure(file3, ncloc, m -> m.setValue(3.0d));
+ db.measures().insertMeasure(file1, m -> m.addValue(ncloc.getKey(), 1.0d));
+ db.measures().insertMeasure(file2, m -> m.addValue(ncloc.getKey(), 2.0d));
+ db.measures().insertMeasure(file3, m -> m.addValue(ncloc.getKey(), 3.0d));
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, mainBranch.getKey())
@@ -546,9 +546,9 @@ class ComponentTreeActionIT {
ComponentDto file1 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-1").setKey("file-1-key"));
MetricDto ncloc = newMetricDto().setKey("new_ncloc").setValueType(INT.name()).setDirection(1);
dbClient.metricDao().insert(dbSession, ncloc);
- db.measures().insertLiveMeasure(file1, ncloc, m -> m.setData((String) null).setValue(1.0d));
- db.measures().insertLiveMeasure(file2, ncloc, m -> m.setData((String) null).setValue(2.0d));
- db.measures().insertLiveMeasure(file3, ncloc, m -> m.setData((String) null).setValue(3.0d));
+ db.measures().insertMeasure(file1, m -> m.addValue(ncloc.getKey(), 1.0d));
+ db.measures().insertMeasure(file2, m -> m.addValue(ncloc.getKey(), 2.0d));
+ db.measures().insertMeasure(file3, m -> m.addValue(ncloc.getKey(), 3.0d));
db.commit();
ComponentTreeWsResponse response = ws.newRequest()
@@ -596,7 +596,7 @@ class ComponentTreeActionIT {
db.components().insertSnapshot(branch);
ComponentDto file = db.components().insertComponent(newFileDto(branch, mainBranch.uuid()));
MetricDto complexity = db.measures().insertMetric(m -> m.setValueType(INT.name()));
- LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d));
+ MeasureDto measure = db.measures().insertMeasure(file, m -> m.addValue(complexity.getKey(), 12.0d));
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, file.getKey())
@@ -608,7 +608,7 @@ class ComponentTreeActionIT {
.containsExactlyInAnyOrder(file.getKey(), branchName);
assertThat(response.getBaseComponent().getMeasuresList())
.extracting(Measure::getMetric, m -> parseDouble(m.getValue()))
- .containsExactlyInAnyOrder(tuple(complexity.getKey(), measure.getValue()));
+ .containsExactlyInAnyOrder(tuple(complexity.getKey(), measure.getDouble(complexity.getKey())));
}
@Test
@@ -659,7 +659,7 @@ class ComponentTreeActionIT {
SnapshotDto analysis = db.components().insertSnapshot(branch);
ComponentDto file = db.components().insertComponent(newFileDto(branch, mainBranch.uuid()));
MetricDto complexity = db.measures().insertMetric(m -> m.setValueType(INT.name()));
- LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d));
+ MeasureDto measure = db.measures().insertMeasure(file, m -> m.addValue(complexity.getKey(), 12.0d));
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, file.getKey())
@@ -671,7 +671,7 @@ class ComponentTreeActionIT {
.containsExactlyInAnyOrder(file.getKey(), "pr-123");
assertThat(response.getBaseComponent().getMeasuresList())
.extracting(Measure::getMetric, m -> parseDouble(m.getValue()))
- .containsExactlyInAnyOrder(tuple(complexity.getKey(), measure.getValue()));
+ .containsExactlyInAnyOrder(tuple(complexity.getKey(), measure.getDouble(complexity.getKey())));
}
@Test
@@ -683,7 +683,7 @@ class ComponentTreeActionIT {
MetricDto metricWithoutDomain = db.measures().insertMetric(m -> m
.setValueType(Metric.ValueType.INT.name())
.setDomain(null));
- db.measures().insertLiveMeasure(mainBranch, metricWithoutDomain);
+ db.measures().insertMeasure(mainBranch, m -> m.addValue(metricWithoutDomain.getKey(), 0d));
ComponentTreeWsResponse result = ws.newRequest()
.setParam(PARAM_COMPONENT, mainBranch.getKey())
@@ -707,7 +707,7 @@ class ComponentTreeActionIT {
SnapshotDto viewAnalysis = db.components().insertSnapshot(view);
ComponentDto projectCopy = db.components().insertComponent(newProjectCopy(mainBranch, view));
MetricDto ncloc = insertNclocMetric();
- db.measures().insertLiveMeasure(projectCopy, ncloc, m -> m.setValue(5d));
+ db.measures().insertMeasure(projectCopy, m -> m.addValue(ncloc.getKey(), 5d));
ComponentTreeWsResponse result = ws.newRequest()
.setParam(PARAM_COMPONENT, view.getKey())
@@ -730,7 +730,7 @@ class ComponentTreeActionIT {
ComponentTesting.newSubPortfolio(view, "SUB-VIEW-UUID", "All-Projects").setName("All projects").setCopyComponentUuid(view2.uuid()));
db.components().insertSnapshot(view);
MetricDto ncloc = insertNclocMetric();
- db.measures().insertLiveMeasure(localView, ncloc, m -> m.setValue(5d));
+ db.measures().insertMeasure(localView, m -> m.addValue(ncloc.getKey(), 5d));
ComponentTreeWsResponse result = ws.newRequest()
.setParam(PARAM_COMPONENT, view.getKey())
@@ -754,7 +754,7 @@ class ComponentTreeActionIT {
ComponentTesting.newSubPortfolio(view, "SUB-VIEW-UUID", "All-Projects").setName("All projects").setCopyComponentUuid(application.uuid()));
db.components().insertSnapshot(view);
MetricDto ncloc = insertNclocMetric();
- db.measures().insertLiveMeasure(localView, ncloc, m -> m.setValue(5d));
+ db.measures().insertMeasure(localView, m -> m.addValue(ncloc.getKey(), 5d));
ComponentTreeWsResponse result = ws.newRequest()
.setParam(PARAM_COMPONENT, view.getKey())
@@ -785,8 +785,8 @@ class ComponentTreeActionIT {
.setKey(applicationBranch.getKey() + branchName + projectBranch.getKey()));
SnapshotDto applicationBranchAnalysis = db.components().insertSnapshot(applicationBranch);
- db.measures().insertLiveMeasure(applicationBranch, ncloc, m -> m.setValue(5d));
- db.measures().insertLiveMeasure(techProjectBranch, ncloc, m -> m.setValue(1d));
+ db.measures().insertMeasure(applicationBranch, m -> m.addValue(ncloc.getKey(), 5d));
+ db.measures().insertMeasure(techProjectBranch, m -> m.addValue(ncloc.getKey(), 1d));
ComponentTreeWsResponse result = ws.newRequest()
.setParam(PARAM_COMPONENT, applicationBranch.getKey())
@@ -1176,7 +1176,7 @@ class ComponentTreeActionIT {
private void insertMetricAndLiveMeasure(ComponentDto dto, String key, String additionalData) {
MetricDto dataMetric = dbClient.metricDao().insert(dbSession, newDataMetricDto(key));
- db.measures().insertLiveMeasure(dto, dataMetric, c -> c.setData(key + additionalData));
+ db.measures().insertMeasure(dto, c -> c.addValue(dataMetric.getKey(), key + additionalData));
}
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/SearchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/SearchActionIT.java
index cb373c8bf94..e7b9067beec 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/SearchActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/SearchActionIT.java
@@ -76,19 +76,19 @@ public class SearchActionIT {
userSession.addProjectPermission(UserRole.USER, project3);
MetricDto complexity = db.measures().insertMetric(m -> m.setKey("complexity").setValueType(INT.name()));
- db.measures().insertLiveMeasure(project1, complexity, m -> m.setValue(12.0d));
- db.measures().insertLiveMeasure(project2, complexity, m -> m.setValue(35.0d));
- db.measures().insertLiveMeasure(project3, complexity, m -> m.setValue(42.0d));
+ db.measures().insertMeasure(project1, m -> m.addValue(complexity.getKey(), 12.0d));
+ db.measures().insertMeasure(project2, m -> m.addValue(complexity.getKey(), 35.0d));
+ db.measures().insertMeasure(project3, m -> m.addValue(complexity.getKey(), 42.0d));
MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.name()));
- db.measures().insertLiveMeasure(project1, ncloc, m -> m.setValue(114.0d));
- db.measures().insertLiveMeasure(project2, ncloc, m -> m.setValue(217.0d));
- db.measures().insertLiveMeasure(project3, ncloc, m -> m.setValue(1984.0d));
+ db.measures().insertMeasure(project1, m -> m.addValue(ncloc.getKey(), 114.0d));
+ db.measures().insertMeasure(project2, m -> m.addValue(ncloc.getKey(), 217.0d));
+ db.measures().insertMeasure(project3, m -> m.addValue(ncloc.getKey(), 1984.0d));
MetricDto newViolations = db.measures().insertMetric(m -> m.setKey("new_violations").setValueType(INT.name()));
- db.measures().insertLiveMeasure(project1, newViolations, m -> m.setValue(25.0d));
- db.measures().insertLiveMeasure(project2, newViolations, m -> m.setValue(25.0d));
- db.measures().insertLiveMeasure(project3, newViolations, m -> m.setValue(255.0d));
+ db.measures().insertMeasure(project1, m -> m.addValue(newViolations.getKey(), 25.0d));
+ db.measures().insertMeasure(project2, m -> m.addValue(newViolations.getKey(), 25.0d));
+ db.measures().insertMeasure(project3, m -> m.addValue(newViolations.getKey(), 255.0d));
List<String> projectKeys = Arrays.asList(project1.getKey(), project2.getKey(), project3.getKey());
@@ -106,7 +106,7 @@ public class SearchActionIT {
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
userSession.addProjectPermission(UserRole.USER, project);
MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
- db.measures().insertLiveMeasure(project, coverage, m -> m.setValue(15.5d));
+ db.measures().insertMeasure(project, m -> m.addValue(coverage.getKey(), 15.5d));
SearchWsResponse result = call(singletonList(project.getKey()), singletonList(coverage.getKey()));
@@ -124,7 +124,7 @@ public class SearchActionIT {
MetricDto acceptedIssues = db.measures().insertMetric(m -> m.setValueType(INT.name())
.setKey("accepted_issues")
.setShortName("Accepted Issues"));
- db.measures().insertLiveMeasure(project, acceptedIssues, m -> m.setValue(10d));
+ db.measures().insertMeasure(project, m -> m.addValue(acceptedIssues.getKey(), 10d));
SearchWsResponse result = call(singletonList(project.getKey()), singletonList("wont_fix_issues"));
@@ -140,11 +140,11 @@ public class SearchActionIT {
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
userSession.addProjectPermission(UserRole.USER, project);
MetricDto matchBestValue = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()).setBestValue(15.5d));
- db.measures().insertLiveMeasure(project, matchBestValue, m -> m.setValue(15.5d));
+ db.measures().insertMeasure(project, m -> m.addValue(matchBestValue.getKey(), 15.5d));
MetricDto doesNotMatchBestValue = db.measures().insertMetric(m -> m.setValueType(INT.name()).setBestValue(50d));
- db.measures().insertLiveMeasure(project, doesNotMatchBestValue, m -> m.setValue(40d));
+ db.measures().insertMeasure(project, m -> m.addValue(doesNotMatchBestValue.getKey(), 40d));
MetricDto noBestValue = db.measures().insertMetric(m -> m.setValueType(INT.name()).setBestValue(null));
- db.measures().insertLiveMeasure(project, noBestValue, m -> m.setValue(123d));
+ db.measures().insertMeasure(project, m -> m.addValue(noBestValue.getKey(), 123d));
SearchWsResponse result = call(singletonList(project.getKey()),
asList(matchBestValue.getKey(), doesNotMatchBestValue.getKey(), noBestValue.getKey()));
@@ -163,7 +163,7 @@ public class SearchActionIT {
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
userSession.addProjectPermission(UserRole.USER, project);
MetricDto coverage = db.measures().insertMetric(m -> m.setKey("new_metric").setValueType(FLOAT.name()));
- db.measures().insertLiveMeasure(project, coverage, m -> m.setValue(10d));
+ db.measures().insertMeasure(project, m -> m.addValue(coverage.getKey(), 10d));
SearchWsResponse result = call(singletonList(project.getKey()), singletonList(coverage.getKey()));
@@ -185,12 +185,12 @@ public class SearchActionIT {
userSession.addProjectPermission(UserRole.USER, project1);
userSession.addProjectPermission(UserRole.USER, project2);
userSession.addProjectPermission(UserRole.USER, project3);
- db.measures().insertLiveMeasure(project1, coverage, m -> m.setValue(5.5d));
- db.measures().insertLiveMeasure(project2, coverage, m -> m.setValue(6.5d));
- db.measures().insertLiveMeasure(project3, coverage, m -> m.setValue(7.5d));
- db.measures().insertLiveMeasure(project1, complexity, m -> m.setValue(10d));
- db.measures().insertLiveMeasure(project2, complexity, m -> m.setValue(15d));
- db.measures().insertLiveMeasure(project3, complexity, m -> m.setValue(20d));
+ db.measures().insertMeasure(project1, m -> m.addValue(coverage.getKey(), 5.5d));
+ db.measures().insertMeasure(project2, m -> m.addValue(coverage.getKey(), 6.5d));
+ db.measures().insertMeasure(project3, m -> m.addValue(coverage.getKey(), 7.5d));
+ db.measures().insertMeasure(project1, m -> m.addValue(complexity.getKey(), 10d));
+ db.measures().insertMeasure(project2, m -> m.addValue(complexity.getKey(), 15d));
+ db.measures().insertMeasure(project3, m -> m.addValue(complexity.getKey(), 20d));
SearchWsResponse result = call(asList(project1.getKey(), project2.getKey(), project3.getKey()), asList(coverage.getKey(), complexity.getKey()));
@@ -205,7 +205,7 @@ public class SearchActionIT {
ComponentDto view = db.components().insertPrivatePortfolio();
userSession.addProjectPermission(UserRole.USER, view);
MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
- db.measures().insertLiveMeasure(view, coverage, m -> m.setValue(15.5d));
+ db.measures().insertMeasure(view, m -> m.addValue(coverage.getKey(), 15.5d));
SearchWsResponse result = call(singletonList(view.getKey()), singletonList(coverage.getKey()));
@@ -221,7 +221,7 @@ public class SearchActionIT {
ComponentDto application = db.components().insertPrivateApplication().getMainBranchComponent();
userSession.addProjectPermission(UserRole.USER, application);
MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
- db.measures().insertLiveMeasure(application, coverage, m -> m.setValue(15.5d));
+ db.measures().insertMeasure(application, m -> m.addValue(coverage.getKey(), 15.5d));
SearchWsResponse result = call(singletonList(application.getKey()), singletonList(coverage.getKey()));
@@ -239,7 +239,7 @@ public class SearchActionIT {
userSession.addProjectPermission(UserRole.USER, view);
userSession.addProjectPermission(UserRole.USER, subView);
MetricDto metric = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
- db.measures().insertLiveMeasure(subView, metric, m -> m.setValue(15.5d));
+ db.measures().insertMeasure(subView, m -> m.addValue(metric.getKey(), 15.5d));
SearchWsResponse result = call(singletonList(subView.getKey()), singletonList(metric.getKey()));
@@ -255,8 +255,8 @@ public class SearchActionIT {
MetricDto metric = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
- db.measures().insertLiveMeasure(project1, metric, m -> m.setValue(15.5d));
- db.measures().insertLiveMeasure(project2, metric, m -> m.setValue(42.0d));
+ db.measures().insertMeasure(project1, m -> m.addValue(metric.getKey(), 15.5d));
+ db.measures().insertMeasure(project2, m -> m.addValue(metric.getKey(), 42.0d));
Arrays.stream(new ComponentDto[] {project1}).forEach(p -> userSession.addProjectPermission(UserRole.USER, p));
SearchWsResponse result = call(asList(project1.getKey(), project2.getKey()), singletonList(metric.getKey()));
@@ -269,7 +269,7 @@ public class SearchActionIT {
MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
ComponentDto branch = db.components().insertProjectBranch(project);
- db.measures().insertLiveMeasure(branch, coverage, m -> m.setValue(10d));
+ db.measures().insertMeasure(branch, m -> m.addValue(coverage.getKey(), 10d));
userSession.addProjectPermission(UserRole.USER, project);
SearchWsResponse result = call(singletonList(branch.getKey()), singletonList(coverage.getKey()));
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/SearchMyProjectsActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/SearchMyProjectsActionIT.java
index 392a46a4fd3..45066827da9 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/SearchMyProjectsActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/SearchMyProjectsActionIT.java
@@ -52,7 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
-import static org.sonar.db.measure.MeasureTesting.newLiveMeasure;
+import static org.sonar.db.measure.MeasureTesting.newMeasure;
import static org.sonar.db.metric.MetricTesting.newMetricDto;
import static org.sonar.db.user.UserTesting.newUserDto;
import static org.sonar.test.JsonAssert.assertJson;
@@ -90,8 +90,8 @@ public class SearchMyProjectsActionIT {
long anotherTime = DateUtils.parseDateTime("2016-06-11T14:25:53+0000").getTime();
SnapshotDto jdk7Snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(jdk7.getMainBranchDto()).setCreatedAt(oneTime));
SnapshotDto cLangSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(cLang.getMainBranchDto()).setCreatedAt(anotherTime));
- dbClient.liveMeasureDao().insert(dbSession, newLiveMeasure(jdk7.getMainBranchDto(), alertStatusMetric).setData(Level.ERROR.name()));
- dbClient.liveMeasureDao().insert(dbSession, newLiveMeasure(cLang.getMainBranchDto(), alertStatusMetric).setData(Level.OK.name()));
+ dbClient.measureDao().insert(dbSession, newMeasure(jdk7.getMainBranchDto(), alertStatusMetric, Level.ERROR.name()));
+ dbClient.measureDao().insert(dbSession, newMeasure(cLang.getMainBranchDto(), alertStatusMetric, Level.OK.name()));
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, jdk7.getProjectDto());
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, cLang.getProjectDto());
db.commit();
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/ProjectStatusActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/ProjectStatusActionIT.java
index 10e2027da73..8e339b42eef 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/ProjectStatusActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/ProjectStatusActionIT.java
@@ -20,7 +20,6 @@
package org.sonar.server.qualitygate.ws;
import java.io.IOException;
-import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Before;
@@ -50,6 +49,7 @@ import org.sonarqube.ws.Qualitygates.ProjectStatusResponse;
import org.sonarqube.ws.Qualitygates.ProjectStatusResponse.Status;
import static java.lang.String.format;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -60,7 +60,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
-import static org.sonar.db.measure.MeasureTesting.newLiveMeasure;
+import static org.sonar.db.measure.MeasureTesting.newMeasure;
import static org.sonar.db.measure.MeasureTesting.newProjectMeasureDto;
import static org.sonar.db.metric.MetricTesting.newMetricDto;
import static org.sonar.server.qualitygate.QualityGateCaycStatus.COMPLIANT;
@@ -117,7 +117,7 @@ public class ProjectStatusActionIT {
.setPeriodDate(956789123987L));
dbClient.projectMeasureDao().insert(dbSession,
newProjectMeasureDto(gateDetailsMetric, mainBranch, snapshot)
- .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"), StandardCharsets.UTF_8)));
+ .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"), UTF_8)));
dbSession.commit();
String response = ws.newRequest()
@@ -144,7 +144,7 @@ public class ProjectStatusActionIT {
MetricDto gateDetailsMetric = insertGateDetailMetric();
dbClient.projectMeasureDao().insert(dbSession,
newProjectMeasureDto(gateDetailsMetric, mainBranch, pastAnalysis)
- .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"))));
+ .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"), UTF_8)));
dbClient.projectMeasureDao().insert(dbSession,
newProjectMeasureDto(gateDetailsMetric, mainBranch, lastAnalysis)
.setData("not_used"));
@@ -167,9 +167,8 @@ public class ProjectStatusActionIT {
.setPeriodParam("2015-12-07")
.setPeriodDate(956789123987L));
MetricDto gateDetailsMetric = insertGateDetailMetric();
- dbClient.liveMeasureDao().insert(dbSession,
- newLiveMeasure(mainBranch, gateDetailsMetric)
- .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"))));
+ dbClient.measureDao().insert(dbSession,
+ newMeasure(mainBranch, gateDetailsMetric, IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"), UTF_8)));
dbSession.commit();
userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
@@ -198,7 +197,7 @@ public class ProjectStatusActionIT {
MetricDto gateDetailsMetric = insertGateDetailMetric();
dbClient.projectMeasureDao().insert(dbSession,
newProjectMeasureDto(gateDetailsMetric, branch, pastAnalysis)
- .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"))));
+ .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"), UTF_8)));
dbClient.projectMeasureDao().insert(dbSession,
newProjectMeasureDto(gateDetailsMetric, branch, lastAnalysis)
.setData("not_used"));
@@ -221,9 +220,8 @@ public class ProjectStatusActionIT {
.setPeriodParam("2015-12-07")
.setPeriodDate(956789123987L));
MetricDto gateDetailsMetric = insertGateDetailMetric();
- dbClient.liveMeasureDao().insert(dbSession,
- newLiveMeasure(project, gateDetailsMetric)
- .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"))));
+ dbClient.measureDao().insert(dbSession,
+ newMeasure(project, gateDetailsMetric, IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"), UTF_8)));
dbSession.commit();
userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
@@ -246,9 +244,8 @@ public class ProjectStatusActionIT {
.setPeriodParam("2015-12-07")
.setPeriodDate(956789123987L));
MetricDto gateDetailsMetric = insertGateDetailMetric();
- dbClient.liveMeasureDao().insert(dbSession,
- newLiveMeasure(branch, gateDetailsMetric)
- .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"))));
+ dbClient.measureDao().insert(dbSession,
+ newMeasure(branch, gateDetailsMetric, IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"), UTF_8)));
dbSession.commit();
userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
@@ -273,9 +270,8 @@ public class ProjectStatusActionIT {
.setPeriodParam("2015-12-07")
.setPeriodDate(956789123987L));
MetricDto gateDetailsMetric = insertGateDetailMetric();
- dbClient.liveMeasureDao().insert(dbSession,
- newLiveMeasure(pr, gateDetailsMetric)
- .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"))));
+ dbClient.measureDao().insert(dbSession,
+ newMeasure(pr, gateDetailsMetric, IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"), UTF_8)));
dbSession.commit();
userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IssueSnippetsActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IssueSnippetsActionIT.java
index cc9338561f0..acd17e1e89c 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IssueSnippetsActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IssueSnippetsActionIT.java
@@ -32,7 +32,6 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ProjectData;
import org.sonar.db.issue.IssueDto;
-import org.sonar.db.metric.MetricDto;
import org.sonar.db.protobuf.DbCommons;
import org.sonar.db.protobuf.DbFileSources;
import org.sonar.db.protobuf.DbIssues;
@@ -118,18 +117,12 @@ public class IssueSnippetsActionIT {
public void should_add_measures_to_components() {
ComponentDto file = insertFile(mainBranchComponent, "file");
- MetricDto lines = db.measures().insertMetric(m -> m.setKey(LINES_KEY));
- db.measures().insertLiveMeasure(file, lines, m -> m.setValue(200d));
- MetricDto duplicatedLines = db.measures().insertMetric(m -> m.setKey(DUPLICATED_LINES_DENSITY_KEY));
- db.measures().insertLiveMeasure(file, duplicatedLines, m -> m.setValue(7.4));
- MetricDto tests = db.measures().insertMetric(m -> m.setKey(TESTS_KEY));
- db.measures().insertLiveMeasure(file, tests, m -> m.setValue(3d));
- MetricDto technicalDebt = db.measures().insertMetric(m -> m.setKey(TECHNICAL_DEBT_KEY));
- db.measures().insertLiveMeasure(file, technicalDebt, m -> m.setValue(182d));
- MetricDto issues = db.measures().insertMetric(m -> m.setKey(VIOLATIONS_KEY));
- db.measures().insertLiveMeasure(file, issues, m -> m.setValue(231d));
- MetricDto coverage = db.measures().insertMetric(m -> m.setKey(COVERAGE_KEY));
- db.measures().insertLiveMeasure(file, coverage, m -> m.setValue(95.4d));
+ db.measures().insertMeasure(file, m -> m.addValue(LINES_KEY, 200d));
+ db.measures().insertMeasure(file, m -> m.addValue(DUPLICATED_LINES_DENSITY_KEY, 7.4));
+ db.measures().insertMeasure(file, m -> m.addValue(TESTS_KEY, 3d));
+ db.measures().insertMeasure(file, m -> m.addValue(TECHNICAL_DEBT_KEY, 182d));
+ db.measures().insertMeasure(file, m -> m.addValue(VIOLATIONS_KEY, 231d));
+ db.measures().insertMeasure(file, m -> m.addValue(COVERAGE_KEY, 95.4d));
DbFileSources.Data fileSources = FileSourceTesting.newFakeData(10).build();
fileSourceTester.insertFileSource(file, 10, dto -> dto.setSourceData(fileSources));
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java
index aad9cda89aa..41c16adab86 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java
@@ -87,7 +87,7 @@ import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTesting.newSubPortfolio;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
-import static org.sonar.db.measure.MeasureTesting.newLiveMeasure;
+import static org.sonar.db.measure.MeasureTesting.newMeasure;
import static org.sonar.db.metric.MetricTesting.newMetricDto;
import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES;
import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_PROFILES;
@@ -844,9 +844,7 @@ public class ComponentActionIT {
private void addQualityProfiles(ComponentDto project, QualityProfile... qps) {
MetricDto metric = newMetricDto().setKey(QUALITY_PROFILES_KEY);
dbClient.metricDao().insert(db.getSession(), metric);
- dbClient.liveMeasureDao().insert(db.getSession(),
- newLiveMeasure(project, metric)
- .setData(qualityProfilesToJson(qps)));
+ dbClient.measureDao().insert(db.getSession(), newMeasure(project, metric, qualityProfilesToJson(qps)));
db.commit();
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/MeasureAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/MeasureAction.java
index bf604a531db..e9f3b337c94 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/MeasureAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/MeasureAction.java
@@ -31,7 +31,7 @@ import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
-import org.sonar.db.measure.LiveMeasureDto;
+import org.sonar.db.measure.MeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.server.badge.ws.SvgGenerator.Color;
import org.sonar.server.measure.Rating;
@@ -62,7 +62,6 @@ import static org.sonar.server.measure.Rating.B;
import static org.sonar.server.measure.Rating.C;
import static org.sonar.server.measure.Rating.D;
import static org.sonar.server.measure.Rating.E;
-import static org.sonar.server.measure.Rating.valueOf;
public class MeasureAction extends AbstractProjectBadgesWsAction {
@@ -114,7 +113,7 @@ public class MeasureAction extends AbstractProjectBadgesWsAction {
.setDescription("Generate badge for project's measure as an SVG.<br/>" +
"Requires 'Browse' permission on the specified project.")
.setSince("7.1")
- .setChangelog(new Change("10.4", String.format("The following metric keys are now deprecated: %s", String.join(", ",
+ .setChangelog(new Change("10.4", format("The following metric keys are now deprecated: %s", String.join(", ",
DEPRECATED_METRIC_KEYS))))
.setResponseExample(Resources.getResource(getClass(), "measure-example.svg"));
support.addProjectAndBranchParams(action);
@@ -131,27 +130,27 @@ public class MeasureAction extends AbstractProjectBadgesWsAction {
BranchDto branch = support.getBranch(dbSession, request);
MetricDto metric = dbClient.metricDao().selectByKey(dbSession, metricKey);
checkState(metric != null && metric.isEnabled(), "Metric '%s' hasn't been found", metricKey);
- LiveMeasureDto measure = getMeasure(dbSession, branch, metricKey);
+ MeasureDto measure = getMeasure(dbSession, branch);
return generateSvg(metric, measure);
}
}
- private LiveMeasureDto getMeasure(DbSession dbSession, BranchDto branch, String metricKey) {
- return dbClient.liveMeasureDao().selectMeasure(dbSession, branch.getUuid(), metricKey)
+ private MeasureDto getMeasure(DbSession dbSession, BranchDto branch) {
+ return dbClient.measureDao().selectByComponentUuid(dbSession, branch.getUuid())
.orElseThrow(() -> new ProjectBadgesException("Measure has not been found"));
}
- private String generateSvg(MetricDto metric, LiveMeasureDto measure) {
+ private String generateSvg(MetricDto metric, MeasureDto measure) {
String metricType = metric.getValueType();
switch (ValueType.valueOf(metricType)) {
case INT:
- return generateBadge(metric, formatNumeric(getNonNullValue(measure, LiveMeasureDto::getValue).longValue()), Color.DEFAULT);
+ return generateBadge(metric, formatNumeric(getNonNullValue(measure, m -> m.getLong(metric.getKey()))), Color.DEFAULT);
case PERCENT:
- return generateBadge(metric, formatPercent(getNonNullValue(measure, LiveMeasureDto::getValue)), Color.DEFAULT);
+ return generateBadge(metric, formatPercent(getNonNullValue(measure, m -> m.getDouble(metric.getKey()))), Color.DEFAULT);
case LEVEL:
return generateQualityGate(metric, measure);
case WORK_DUR:
- return generateBadge(metric, formatDuration(getNonNullValue(measure, LiveMeasureDto::getValue).longValue()), Color.DEFAULT);
+ return generateBadge(metric, formatDuration(getNonNullValue(measure, m -> m.getLong(metric.getKey()))), Color.DEFAULT);
case RATING:
return generateRating(metric, measure);
default:
@@ -159,13 +158,13 @@ public class MeasureAction extends AbstractProjectBadgesWsAction {
}
}
- private String generateQualityGate(MetricDto metric, LiveMeasureDto measure) {
- Level qualityGate = Level.valueOf(getNonNullValue(measure, LiveMeasureDto::getTextValue));
+ private String generateQualityGate(MetricDto metric, MeasureDto measure) {
+ Level qualityGate = Level.valueOf(getNonNullValue(measure, m -> m.getString(metric.getKey())));
return generateBadge(metric, QUALITY_GATE_MESSAGE_BY_STATUS.get(qualityGate), COLOR_BY_QUALITY_GATE_STATUS.get(qualityGate));
}
- private String generateRating(MetricDto metric, LiveMeasureDto measure) {
- Rating rating = valueOf(getNonNullValue(measure, LiveMeasureDto::getValue).intValue());
+ private String generateRating(MetricDto metric, MeasureDto measure) {
+ Rating rating = Rating.valueOf(getNonNullValue(measure, m -> m.getInt(metric.getKey())).intValue());
return generateBadge(metric, rating.name(), COLOR_BY_RATING.get(rating));
}
@@ -173,7 +172,7 @@ public class MeasureAction extends AbstractProjectBadgesWsAction {
return svgGenerator.generateBadge(METRIC_NAME_BY_KEY.get(metric.getKey()), value, color);
}
- private static <P> P getNonNullValue(LiveMeasureDto measure, Function<LiveMeasureDto, P> function) {
+ private static <P> P getNonNullValue(MeasureDto measure, Function<MeasureDto, P> function) {
P value = function.apply(measure);
checkState(value != null, "Measure has not been found");
return value;
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/QualityGateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/QualityGateAction.java
index a4d03563852..09000449f9c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/QualityGateAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/QualityGateAction.java
@@ -27,7 +27,6 @@ import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
-import org.sonar.db.measure.LiveMeasureDto;
import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY;
@@ -61,8 +60,8 @@ public class QualityGateAction extends AbstractProjectBadgesWsAction {
}
private Level getQualityGate(DbSession dbSession, BranchDto branch) {
- return Level.valueOf(dbClient.liveMeasureDao().selectMeasure(dbSession, branch.getUuid(), ALERT_STATUS_KEY)
- .map(LiveMeasureDto::getTextValue)
+ return Level.valueOf(dbClient.measureDao().selectByComponentUuid(dbSession, branch.getUuid())
+ .map(m -> m.getString(ALERT_STATUS_KEY))
.orElseThrow(() -> new ProjectBadgesException("Quality gate has not been found")));
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/ListAction.java
index d321345e398..662ddf83663 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/ListAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/ListAction.java
@@ -35,7 +35,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.measure.LiveMeasureDto;
+import org.sonar.db.measure.MeasureDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.user.UserSession;
@@ -94,9 +94,9 @@ public class ListAction implements BranchWsAction {
.toList();
List<String> branchUuids = branches.stream().map(BranchDto::getUuid).toList();
- Map<String, LiveMeasureDto> qualityGateMeasuresByComponentUuids = dbClient.liveMeasureDao()
+ Map<String, MeasureDto> qualityGateMeasuresByComponentUuids = dbClient.measureDao()
.selectByComponentUuidsAndMetricKeys(dbSession, branchUuids, singletonList(ALERT_STATUS_KEY)).stream()
- .collect(Collectors.toMap(LiveMeasureDto::getComponentUuid, Function.identity()));
+ .collect(Collectors.toMap(MeasureDto::getComponentUuid, Function.identity()));
Map<String, String> analysisDateByBranchUuid = dbClient.snapshotDao()
.selectLastAnalysesByRootComponentUuids(dbSession, branchUuids).stream()
.collect(Collectors.toMap(SnapshotDto::getRootComponentUuid, s -> formatDateTime(s.getCreatedAt())));
@@ -109,7 +109,7 @@ public class ListAction implements BranchWsAction {
}
private static void addBranch(ProjectBranches.ListWsResponse.Builder response, BranchDto branch,
- @Nullable LiveMeasureDto qualityGateMeasure, @Nullable String analysisDate) {
+ @Nullable MeasureDto qualityGateMeasure, @Nullable String analysisDate) {
ProjectBranches.Branch.Builder builder = toBranchBuilder(branch);
setBranchStatus(builder, qualityGateMeasure);
if (analysisDate != null) {
@@ -129,10 +129,10 @@ public class ListAction implements BranchWsAction {
return builder;
}
- private static void setBranchStatus(ProjectBranches.Branch.Builder builder, @Nullable LiveMeasureDto qualityGateMeasure) {
+ private static void setBranchStatus(ProjectBranches.Branch.Builder builder, @Nullable MeasureDto qualityGateMeasure) {
ProjectBranches.Status.Builder statusBuilder = ProjectBranches.Status.newBuilder();
if (qualityGateMeasure != null) {
- ofNullable(qualityGateMeasure.getDataAsString()).ifPresent(statusBuilder::setQualityGateStatus);
+ ofNullable(qualityGateMeasure.getString(ALERT_STATUS_KEY)).ifPresent(statusBuilder::setQualityGateStatus);
}
builder.setStatus(statusBuilder);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentCleanerService.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentCleanerService.java
index 9cb298b88e4..7b407c46931 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentCleanerService.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentCleanerService.java
@@ -61,7 +61,7 @@ public class ComponentCleanerService {
}
private void updateProjectNcloc(DbSession dbSession, String projectUuid) {
- long maxncloc = dbClient.liveMeasureDao().findNclocOfBiggestBranchForProject(dbSession, projectUuid);
+ long maxncloc = dbClient.measureDao().findNclocOfBiggestBranchForProject(dbSession, projectUuid);
dbClient.projectDao().updateNcloc(dbSession, projectUuid, maxncloc);
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java
index 7c40b7616b6..9d975116fa7 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java
@@ -19,10 +19,7 @@
*/
package org.sonar.server.component.ws;
-import com.google.common.collect.Maps;
-import java.util.Collections;
import java.util.List;
-import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang3.BooleanUtils;
@@ -32,30 +29,18 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.entity.EntityDto;
-import org.sonar.db.measure.LiveMeasureDto;
-import org.sonar.db.metric.MetricDto;
+import org.sonar.db.measure.MeasureDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.property.PropertyQuery;
import org.sonar.server.user.UserSession;
import static org.sonar.api.measures.CoreMetrics.COVERAGE;
-import static org.sonar.api.measures.CoreMetrics.COVERAGE_KEY;
import static org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY;
-import static org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY_KEY;
import static org.sonar.api.measures.CoreMetrics.LINES;
-import static org.sonar.api.measures.CoreMetrics.LINES_KEY;
import static org.sonar.api.measures.CoreMetrics.TESTS;
-import static org.sonar.api.measures.CoreMetrics.TESTS_KEY;
import static org.sonar.api.measures.CoreMetrics.VIOLATIONS;
-import static org.sonar.api.measures.CoreMetrics.VIOLATIONS_KEY;
public class ComponentViewerJsonWriter {
- private static final List<String> METRIC_KEYS = List.of(
- LINES_KEY,
- VIOLATIONS_KEY,
- COVERAGE_KEY,
- DUPLICATED_LINES_DENSITY_KEY,
- TESTS_KEY);
private final DbClient dbClient;
@@ -96,36 +81,28 @@ public class ComponentViewerJsonWriter {
}
public void writeMeasures(JsonWriter json, ComponentDto component, DbSession session) {
- Map<String, LiveMeasureDto> measuresByMetricKey = loadMeasuresGroupedByMetricKey(component, session);
+ MeasureDto measureDto = loadMeasures(component, session);
json.name("measures").beginObject();
- json.prop("lines", formatMeasure(measuresByMetricKey, LINES));
- json.prop("coverage", formatMeasure(measuresByMetricKey, COVERAGE));
- json.prop("duplicationDensity", formatMeasure(measuresByMetricKey, DUPLICATED_LINES_DENSITY));
- json.prop("issues", formatMeasure(measuresByMetricKey, VIOLATIONS));
- json.prop("tests", formatMeasure(measuresByMetricKey, TESTS));
+ json.prop("lines", formatMeasure(measureDto, LINES));
+ json.prop("coverage", formatMeasure(measureDto, COVERAGE));
+ json.prop("duplicationDensity", formatMeasure(measureDto, DUPLICATED_LINES_DENSITY));
+ json.prop("issues", formatMeasure(measureDto, VIOLATIONS));
+ json.prop("tests", formatMeasure(measureDto, TESTS));
json.endObject();
}
- private Map<String, LiveMeasureDto> loadMeasuresGroupedByMetricKey(ComponentDto component, DbSession dbSession) {
- List<MetricDto> metrics = dbClient.metricDao().selectByKeys(dbSession, METRIC_KEYS);
- Map<String, MetricDto> metricsByUuid = Maps.uniqueIndex(metrics, MetricDto::getUuid);
- List<LiveMeasureDto> measures = dbClient.liveMeasureDao()
- .selectByComponentUuidsAndMetricUuids(dbSession, Collections.singletonList(component.uuid()), metricsByUuid.keySet());
- return Maps.uniqueIndex(measures, m -> metricsByUuid.get(m.getMetricUuid()).getKey());
- }
-
@CheckForNull
- private static String formatMeasure(Map<String, LiveMeasureDto> measuresByMetricKey, Metric metric) {
- LiveMeasureDto measure = measuresByMetricKey.get(metric.getKey());
- return formatMeasure(measure, metric);
+ private MeasureDto loadMeasures(ComponentDto component, DbSession dbSession) {
+ return dbClient.measureDao().selectByComponentUuid(dbSession, component.uuid()).orElse(null);
}
- private static String formatMeasure(@Nullable LiveMeasureDto measure, Metric metric) {
- if (measure == null) {
+ @CheckForNull
+ private static String formatMeasure(@Nullable MeasureDto measureDto, Metric<?> metric) {
+ if (measureDto == null) {
return null;
}
- Double value = getDoubleValue(measure, metric);
+ Double value = getDoubleValue(measureDto, metric);
if (value != null) {
return Double.toString(value);
}
@@ -133,12 +110,11 @@ public class ComponentViewerJsonWriter {
}
@CheckForNull
- private static Double getDoubleValue(LiveMeasureDto measure, Metric metric) {
- Double value = measure.getValue();
+ private static Double getDoubleValue(MeasureDto measureDto, Metric<?> metric) {
+ Double value = measureDto.getDouble(metric.getKey());
if (BooleanUtils.isTrue(metric.isOptimizedBestValue()) && value == null) {
value = metric.getBestValue();
}
return value;
}
-
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java
index 374d3e96dff..149524ee287 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java
@@ -338,10 +338,10 @@ public class SearchProjectsAction implements ComponentsWsAction {
private Map<String, Long> getApplicationsLeakPeriod(DbSession dbSession, SearchProjectsRequest request, Set<String> qualifiers, Collection<String> mainBranchUuids) {
if (qualifiers.contains(Qualifiers.APP) && request.getAdditionalFields().contains(LEAK_PERIOD_DATE)) {
- return dbClient.liveMeasureDao().selectByComponentUuidsAndMetricKeys(dbSession, mainBranchUuids, Collections.singleton(METRIC_LEAK_PROJECTS_KEY))
+ return dbClient.measureDao().selectByComponentUuidsAndMetricKeys(dbSession, mainBranchUuids, Collections.singleton(METRIC_LEAK_PROJECTS_KEY))
.stream()
- .filter(lm -> !Objects.isNull(lm.getDataAsString()))
- .map(lm -> Maps.immutableEntry(lm.getComponentUuid(), ApplicationLeakProjects.parse(lm.getDataAsString()).getOldestLeak()))
+ .filter(m -> !Objects.isNull(m.getString(METRIC_LEAK_PROJECTS_KEY)))
+ .map(m -> Maps.immutableEntry(m.getComponentUuid(), ApplicationLeakProjects.parse(m.getString(METRIC_LEAK_PROJECTS_KEY)).getOldestLeak()))
.filter(entry -> entry.getValue().isPresent())
.collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().get().getLeak()));
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/ShowAction.java
index d8bbc4faf95..cd04dcaf603 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/ShowAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/duplication/ws/ShowAction.java
@@ -32,7 +32,6 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.user.UserSession;
@@ -128,8 +127,8 @@ public class ShowAction implements DuplicationsWsAction {
@CheckForNull
private String findDataFromComponent(DbSession dbSession, ComponentDto component) {
- return dbClient.liveMeasureDao().selectMeasure(dbSession, component.uuid(), CoreMetrics.DUPLICATIONS_DATA_KEY)
- .map(LiveMeasureDto::getDataAsString)
+ return dbClient.measureDao().selectByComponentUuid(dbSession, component.uuid())
+ .map(m -> m.getString(CoreMetrics.DUPLICATIONS_DATA_KEY))
.orElse(null);
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/NewCodePeriodResolver.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/NewCodePeriodResolver.java
index 06aba46e86b..d56ef16a8e4 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/NewCodePeriodResolver.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/NewCodePeriodResolver.java
@@ -66,7 +66,9 @@ public class NewCodePeriodResolver {
}
private boolean isLastAnalysisFromSonarQube94Onwards(DbSession dbSession, String componentUuid) {
- return dbClient.liveMeasureDao().selectMeasure(dbSession, componentUuid, ANALYSIS_FROM_SONARQUBE_9_4_KEY).isPresent();
+ return dbClient.measureDao().selectByComponentUuid(dbSession, componentUuid)
+ .filter(m -> m.getMetricValues().containsKey(ANALYSIS_FROM_SONARQUBE_9_4_KEY))
+ .isPresent();
}
private static boolean isLastAnalysisUsingReferenceBranch(SnapshotDto snapshot) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java
index 8d6d2f693f9..1b997b5f331 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java
@@ -142,7 +142,7 @@ public class LiveMeasureComputerImpl implements LiveMeasureComputer {
@CheckForNull
private Metric.Level loadPreviousStatus(DbSession dbSession, ComponentDto branchComponent) {
- return dbClient.measureDao().selectMeasure(dbSession, branchComponent.uuid())
+ return dbClient.measureDao().selectByComponentUuid(dbSession, branchComponent.uuid())
.map(m -> m.getString(ALERT_STATUS_KEY))
.map(m -> {
try {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java
index c5b775936c5..e05fee40672 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java
@@ -20,12 +20,9 @@
package org.sonar.server.measure.ws;
import com.google.common.collect.ImmutableSortedSet;
-import com.google.common.collect.Maps;
import java.util.Collection;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -42,7 +39,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.measure.LiveMeasureDto;
+import org.sonar.db.measure.MeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.metric.MetricDtoFunctions;
import org.sonar.server.component.ComponentFinder;
@@ -53,7 +50,6 @@ import org.sonarqube.ws.Measures.ComponentWsResponse;
import static java.lang.String.format;
import static java.util.Collections.emptyMap;
-import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.sonar.db.metric.RemovedMetricConverter.withRemovedMetricAlias;
import static org.sonar.server.component.ws.MeasuresWsParameters.ACTION_COMPONENT;
@@ -161,11 +157,10 @@ public class ComponentAction implements MeasuresWsAction {
SnapshotDto analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, component.branchUuid()).orElse(null);
List<MetricDto> metrics = searchMetrics(dbSession, new HashSet<>(withRemovedMetricAlias(request.getMetricKeys())));
- List<LiveMeasureDto> measures = searchMeasures(dbSession, component, metrics);
- Map<MetricDto, LiveMeasureDto> measuresByMetric = getMeasuresByMetric(measures, metrics);
+ MeasureDto measureDto = searchMeasures(dbSession, component, metrics);
Measures.Period period = snapshotToWsPeriods(analysis).orElse(null);
- return buildResponse(dbSession, request, component, measuresByMetric, metrics, period, request.getMetricKeys());
+ return buildResponse(dbSession, request, component, measureDto, metrics, period, request.getMetricKeys());
}
}
@@ -180,21 +175,11 @@ public class ComponentAction implements MeasuresWsAction {
return metrics;
}
- private List<LiveMeasureDto> searchMeasures(DbSession dbSession, ComponentDto component, Collection<MetricDto> metrics) {
- Set<String> metricUuids = metrics.stream().map(MetricDto::getUuid).collect(Collectors.toSet());
- List<LiveMeasureDto> measures = dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession, singletonList(component.uuid()), metricUuids);
- addBestValuesToMeasures(measures, component, metrics);
- return measures;
- }
-
- private static Map<MetricDto, LiveMeasureDto> getMeasuresByMetric(List<LiveMeasureDto> measures, Collection<MetricDto> metrics) {
- Map<String, MetricDto> metricsByUuid = Maps.uniqueIndex(metrics, MetricDto::getUuid);
- Map<MetricDto, LiveMeasureDto> measuresByMetric = new HashMap<>();
- for (LiveMeasureDto measure : measures) {
- MetricDto metric = metricsByUuid.get(measure.getMetricUuid());
- measuresByMetric.put(metric, measure);
- }
- return measuresByMetric;
+ @CheckForNull
+ private MeasureDto searchMeasures(DbSession dbSession, ComponentDto component, Collection<MetricDto> metrics) {
+ MeasureDto measureDto = dbClient.measureDao().selectByComponentUuid(dbSession, component.uuid()).orElse(null);
+ addBestValuesToMeasures(measureDto, component, metrics);
+ return measureDto;
}
/**
@@ -204,22 +189,19 @@ public class ComponentAction implements MeasuresWsAction {
* <li>metric is optimized for best value</li>
* </ul>
*/
- private static void addBestValuesToMeasures(List<LiveMeasureDto> measures, ComponentDto component, Collection<MetricDto> metrics) {
- if (!QUALIFIERS_ELIGIBLE_FOR_BEST_VALUE.contains(component.qualifier())) {
+ private static void addBestValuesToMeasures(@Nullable MeasureDto measureDto, ComponentDto component, Collection<MetricDto> metrics) {
+ if (measureDto == null || !QUALIFIERS_ELIGIBLE_FOR_BEST_VALUE.contains(component.qualifier())) {
return;
}
- List<MetricDtoWithBestValue> metricWithBestValueList = metrics.stream()
+ metrics.stream()
.filter(MetricDtoFunctions.isOptimizedForBestValue())
- .map(MetricDtoWithBestValue::new)
- .toList();
- Map<String, LiveMeasureDto> measuresByMetricUuid = Maps.uniqueIndex(measures, LiveMeasureDto::getMetricUuid);
-
- for (MetricDtoWithBestValue metricWithBestValue : metricWithBestValueList) {
- if (measuresByMetricUuid.get(metricWithBestValue.getMetric().getUuid()) == null) {
- measures.add(metricWithBestValue.getBestValue());
- }
- }
+ .forEach(metricWithBestValue -> {
+ String metricKey = metricWithBestValue.getKey();
+ if (!measureDto.getMetricValues().containsKey(metricKey)) {
+ measureDto.addValue(metricKey, metricWithBestValue.getBestValue());
+ }
+ });
}
private ComponentDto loadComponent(DbSession dbSession, ComponentRequest request, @Nullable String branch, @Nullable String pullRequest) {
@@ -243,8 +225,7 @@ public class ComponentAction implements MeasuresWsAction {
}
private ComponentWsResponse buildResponse(DbSession dbSession, ComponentRequest request, ComponentDto component,
- Map<MetricDto, LiveMeasureDto> measuresByMetric, Collection<MetricDto> metrics, @Nullable Measures.Period period,
- Collection<String> requestedMetrics) {
+ @Nullable MeasureDto measureDto, Collection<MetricDto> metrics, @Nullable Measures.Period period, Collection<String> requestedMetrics) {
ComponentWsResponse.Builder response = ComponentWsResponse.newBuilder();
@@ -252,12 +233,12 @@ public class ComponentAction implements MeasuresWsAction {
if (reference != null) {
BranchDto refBranch = reference.getRefBranch();
ComponentDto refComponent = reference.getComponent();
- response.setComponent(componentDtoToWsComponent(component, measuresByMetric, singletonMap(refComponent.uuid(), refComponent),
- refBranch.isMain() ? null : refBranch.getBranchKey(), null, requestedMetrics));
+ response.setComponent(componentDtoToWsComponent(component, measureDto, singletonMap(refComponent.uuid(), refComponent),
+ refBranch.isMain() ? null : refBranch.getBranchKey(), null, metrics, requestedMetrics));
} else {
boolean isMainBranch = dbClient.branchDao().selectByUuid(dbSession, component.branchUuid()).map(BranchDto::isMain).orElse(true);
- response.setComponent(componentDtoToWsComponent(component, measuresByMetric, emptyMap(), isMainBranch ? null : request.getBranch(),
- request.getPullRequest(), requestedMetrics));
+ response.setComponent(componentDtoToWsComponent(component, measureDto, emptyMap(), isMainBranch ? null : request.getBranch(),
+ request.getPullRequest(), metrics, requestedMetrics));
}
setAdditionalFields(request, metrics, period, response, requestedMetrics);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java
index e2170b08c16..1b806b9100e 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentDtoToWsComponent.java
@@ -21,9 +21,11 @@ package org.sonar.server.measure.ws;
import java.util.Collection;
import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.measure.LiveMeasureDto;
+import org.sonar.db.measure.MeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonarqube.ws.Measures;
import org.sonarqube.ws.Measures.Component;
@@ -36,9 +38,9 @@ class ComponentDtoToWsComponent {
// static methods only
}
- static Component.Builder componentDtoToWsComponent(ComponentDto component, Map<MetricDto, LiveMeasureDto> measuresByMetric,
- Map<String, ComponentDto> referenceComponentsByUuid, @Nullable String branch,
- @Nullable String pullRequest, Collection<String> requestedMetrics) {
+ static Component.Builder componentDtoToWsComponent(ComponentDto component, @Nullable MeasureDto measureDto,
+ Map<String, ComponentDto> referenceComponentsByUuid, @Nullable String branch, @Nullable String pullRequest,
+ Collection<MetricDto> metrics, Collection<String> requestedMetrics) {
Component.Builder wsComponent = componentDtoToWsComponent(component, branch, pullRequest);
ComponentDto referenceComponent = referenceComponentsByUuid.get(component.getCopyComponentUuid());
@@ -46,11 +48,16 @@ class ComponentDtoToWsComponent {
wsComponent.setRefKey(referenceComponent.getKey());
}
- Measures.Measure.Builder measureBuilder = Measures.Measure.newBuilder();
- for (Map.Entry<MetricDto, LiveMeasureDto> entry : measuresByMetric.entrySet()) {
- MeasureDtoToWsMeasure.updateMeasureBuilder(measureBuilder, entry.getKey(), entry.getValue());
- addMeasureIncludingRenamedMetric(requestedMetrics, wsComponent, measureBuilder);
- measureBuilder.clear();
+ if (measureDto != null) {
+ Measures.Measure.Builder measureBuilder = Measures.Measure.newBuilder();
+ Map<String, MetricDto> metricsByKey = metrics.stream().collect(Collectors.toMap(MetricDto::getKey, Function.identity()));
+ metricsByKey.keySet().stream()
+ .filter(metricKey -> measureDto.getMetricValues().containsKey(metricKey))
+ .forEach(metricKey -> {
+ MeasureDtoToWsMeasure.updateMeasureBuilder(measureBuilder, metricsByKey.get(metricKey), measureDto);
+ addMeasureIncludingRenamedMetric(requestedMetrics, wsComponent, measureBuilder);
+ measureBuilder.clear();
+ });
}
return wsComponent;
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
index 5ee3d95b34a..235ac6088a3 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
@@ -61,7 +61,7 @@ import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTreeQuery;
import org.sonar.db.component.ComponentTreeQuery.Strategy;
import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.measure.LiveMeasureDto;
+import org.sonar.db.measure.MeasureDto;
import org.sonar.db.measure.MeasureTreeQuery;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.metric.MetricDtoFunctions;
@@ -74,8 +74,8 @@ import org.sonarqube.ws.client.component.ComponentsWsParameters;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
-import static java.lang.String.*;
import static java.lang.String.format;
+import static java.lang.String.join;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Optional.ofNullable;
@@ -559,22 +559,26 @@ public class ComponentTreeAction implements MeasuresWsAction {
ComponentDto baseComponent,
ComponentTreeQuery componentTreeQuery, List<ComponentDto> components, List<MetricDto> metrics) {
- Map<String, MetricDto> metricsByUuid = Maps.uniqueIndex(metrics, MetricDto::getUuid);
+ Map<String, MetricDto> metricsByKeys = Maps.uniqueIndex(metrics, MetricDto::getKey);
MeasureTreeQuery measureQuery = MeasureTreeQuery.builder()
.setStrategy(MeasureTreeQuery.Strategy.valueOf(componentTreeQuery.getStrategy().name()))
.setNameOrKeyQuery(componentTreeQuery.getNameOrKeyQuery())
.setQualifiers(componentTreeQuery.getQualifiers())
- .setMetricUuids(new ArrayList<>(metricsByUuid.keySet()))
.build();
Table<String, MetricDto, ComponentTreeData.Measure> measuresByComponentUuidAndMetric = HashBasedTable.create(components.size(),
metrics.size());
- dbClient.liveMeasureDao().selectTreeByQuery(dbSession, baseComponent, measureQuery, result -> {
- LiveMeasureDto measureDto = result.getResultObject();
- measuresByComponentUuidAndMetric.put(
- measureDto.getComponentUuid(),
- metricsByUuid.get(measureDto.getMetricUuid()),
- ComponentTreeData.Measure.createFromMeasureDto(measureDto));
+ dbClient.measureDao().selectTreeByQuery(dbSession, baseComponent, measureQuery, result -> {
+ MeasureDto measureDto = result.getResultObject();
+ measureDto.getMetricValues().forEach((metricKey, value) -> {
+ MetricDto metric = metricsByKeys.get(metricKey);
+ if (metric != null) {
+ measuresByComponentUuidAndMetric.put(
+ measureDto.getComponentUuid(),
+ metric,
+ ComponentTreeData.Measure.createFromMetricValue(metric, value));
+ }
+ });
});
addBestValuesToMeasures(measuresByComponentUuidAndMetric, components, metrics);
@@ -605,7 +609,7 @@ public class ComponentTreeAction implements MeasuresWsAction {
for (MetricDtoWithBestValue metricWithBestValue : metricDtosWithBestValueMeasure) {
if (measuresByComponentUuidAndMetric.get(component.uuid(), metricWithBestValue.getMetric()) == null) {
measuresByComponentUuidAndMetric.put(component.uuid(), metricWithBestValue.getMetric(),
- ComponentTreeData.Measure.createFromMeasureDto(metricWithBestValue.getBestValue()));
+ ComponentTreeData.Measure.createFromMetricValue(metricWithBestValue.getMetric(), metricWithBestValue.getBestValue()));
}
}
});
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java
index 51460ccb989..a5d98135e54 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java
@@ -24,15 +24,17 @@ import java.util.List;
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import org.sonar.api.measures.Metric;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonarqube.ws.Measures;
import static java.lang.Double.NaN;
import static java.lang.Double.isNaN;
import static java.util.Objects.requireNonNull;
+import static org.sonar.server.measure.ws.ComponentTreeSort.NUMERIC_VALUE_TYPES;
+import static org.sonar.server.measure.ws.ComponentTreeSort.TEXTUAL_VALUE_TYPES;
class ComponentTreeData {
private final ComponentDto baseComponent;
@@ -177,10 +179,6 @@ class ComponentTreeData {
this.value = toPrimitive(value);
}
- private Measure(LiveMeasureDto measureDto) {
- this(measureDto.getDataAsString(), measureDto.getValue());
- }
-
public double getValue() {
return value;
}
@@ -194,8 +192,20 @@ class ComponentTreeData {
return data;
}
- static Measure createFromMeasureDto(LiveMeasureDto measureDto) {
- return new Measure(measureDto);
+ static Measure createFromMetricValue(MetricDto metric, @Nullable Object value) {
+ if (value == null) {
+ return null;
+ }
+
+ Metric.ValueType metricValueType = Metric.ValueType.valueOf(metric.getValueType());
+ if (NUMERIC_VALUE_TYPES.contains(metricValueType)) {
+ return new Measure(null, (double) value);
+ } else if (TEXTUAL_VALUE_TYPES.contains(metricValueType)
+ || List.of(Metric.ValueType.DATA, Metric.ValueType.LEVEL).contains(metricValueType)) {
+ return new Measure(value.toString(), null);
+ } else {
+ return null;
+ }
}
private static double toPrimitive(@Nullable Double value) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java
index a1b04613433..7969675fb6c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java
@@ -58,8 +58,8 @@ import static org.sonar.server.measure.ws.ComponentTreeAction.QUALIFIER_SORT;
public class ComponentTreeSort {
- private static final Set<ValueType> NUMERIC_VALUE_TYPES = EnumSet.of(BOOL, FLOAT, INT, MILLISEC, WORK_DUR, PERCENT, RATING);
- private static final Set<ValueType> TEXTUAL_VALUE_TYPES = EnumSet.of(STRING);
+ static final Set<ValueType> NUMERIC_VALUE_TYPES = EnumSet.of(BOOL, FLOAT, INT, MILLISEC, WORK_DUR, PERCENT, RATING);
+ static final Set<ValueType> TEXTUAL_VALUE_TYPES = EnumSet.of(STRING);
private ComponentTreeSort() {
// static method only
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java
index 4651174acb9..76541f0f628 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java
@@ -21,6 +21,7 @@ package org.sonar.server.measure.ws;
import javax.annotation.Nullable;
import org.sonar.db.measure.LiveMeasureDto;
+import org.sonar.db.measure.MeasureDto;
import org.sonar.db.measure.ProjectMeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonarqube.ws.Measures;
@@ -48,6 +49,24 @@ class MeasureDtoToWsMeasure {
updateMeasureBuilder(measureBuilder, metricDto, value, measureDto.getDataAsString(), onNewCode);
}
+ static void updateMeasureBuilder(Measure.Builder measureBuilder, MetricDto metricDto, MeasureDto measureDto) {
+ double doubleValue;
+ String stringValue = null;
+ if (metricDto.isNumeric()) {
+ doubleValue = doubleValue(measureDto, metricDto.getKey());
+ } else {
+ doubleValue = Double.NaN;
+ stringValue = measureDto.getString(metricDto.getKey());
+ }
+ boolean onNewCode = metricDto.getKey().startsWith("new_");
+ updateMeasureBuilder(measureBuilder, metricDto, doubleValue, stringValue, onNewCode);
+ }
+
+ private static double doubleValue(MeasureDto measure, String metricKey) {
+ Double value = measure.getDouble(metricKey);
+ return value == null ? Double.NaN : value;
+ }
+
static void updateMeasureBuilder(Measure.Builder measureBuilder, MetricDto metric, double doubleValue, @Nullable String stringValue, boolean onNewCode) {
measureBuilder.setMetric(metric.getKey());
Double bestValue = metric.getBestValue();
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoWithBestValue.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoWithBestValue.java
index 7029a126c68..28f60996bad 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoWithBestValue.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoWithBestValue.java
@@ -24,27 +24,24 @@ import java.util.Set;
import java.util.function.Predicate;
import org.sonar.api.resources.Qualifiers;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.metric.MetricDto;
public class MetricDtoWithBestValue {
private static final Set<String> QUALIFIERS_ELIGIBLE_FOR_BEST_VALUE = ImmutableSortedSet.of(Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE);
private final MetricDto metric;
- private final LiveMeasureDto bestValue;
+ private final Double bestValue;
MetricDtoWithBestValue(MetricDto metric) {
this.metric = metric;
- LiveMeasureDto measure = new LiveMeasureDto().setMetricUuid(metric.getUuid());
- measure.setValue(metric.getBestValue());
- this.bestValue = measure;
+ this.bestValue = metric.getBestValue();
}
MetricDto getMetric() {
return metric;
}
- LiveMeasureDto getBestValue() {
+ Double getBestValue() {
return bestValue;
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java
index 52594af49db..35c7fd89aca 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java
@@ -35,7 +35,7 @@ import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.measure.LiveMeasureDto;
+import org.sonar.db.measure.MeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.metric.RemovedMetricConverter;
import org.sonar.server.user.UserSession;
@@ -128,7 +128,7 @@ public class SearchAction implements MeasuresWsAction {
private SearchRequest request;
private List<ComponentDto> projects;
private List<MetricDto> metrics;
- private List<LiveMeasureDto> measures;
+ private List<MeasureDto> measures;
ResponseBuilder(Request httpRequest, DbSession dbSession) {
this.dbSession = dbSession;
@@ -185,10 +185,10 @@ public class SearchAction implements MeasuresWsAction {
.toList();
}
- private List<LiveMeasureDto> searchMeasures() {
- return dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession,
+ private List<MeasureDto> searchMeasures() {
+ return dbClient.measureDao().selectByComponentUuidsAndMetricKeys(dbSession,
projects.stream().map(ComponentDto::uuid).toList(),
- metrics.stream().map(MetricDto::getUuid).toList());
+ metrics.stream().map(MetricDto::getKey).toList());
}
private SearchWsResponse buildResponse() {
@@ -201,21 +201,22 @@ public class SearchAction implements MeasuresWsAction {
private List<Measure> buildWsMeasures() {
Map<String, ComponentDto> componentsByUuid = projects.stream().collect(toMap(ComponentDto::uuid, Function.identity()));
Map<String, String> componentNamesByKey = projects.stream().collect(toMap(ComponentDto::getKey, ComponentDto::name));
- Map<String, MetricDto> metricsByUuid = metrics.stream().collect(toMap(MetricDto::getUuid, identity()));
+ Map<String, MetricDto> metricsByKey = metrics.stream().collect(toMap(MetricDto::getKey, identity()));
- Function<LiveMeasureDto, MetricDto> dbMeasureToDbMetric = dbMeasure -> metricsByUuid.get(dbMeasure.getMetricUuid());
Function<Measure, String> byMetricKey = Measure::getMetric;
Function<Measure, String> byComponentName = wsMeasure -> componentNamesByKey.get(wsMeasure.getComponent());
Measure.Builder measureBuilder = Measure.newBuilder();
List<Measure> allMeasures = new ArrayList<>();
- for (LiveMeasureDto measure : measures) {
- updateMeasureBuilder(measureBuilder, dbMeasureToDbMetric.apply(measure), measure);
- measureBuilder.setComponent(componentsByUuid.get(measure.getComponentUuid()).getKey());
- Measure measureMsg = measureBuilder.build();
- addMeasureIncludingRenamedMetric(measureMsg, allMeasures, measureBuilder);
-
- measureBuilder.clear();
+ for (MeasureDto measure : measures) {
+ for (String metricKey : measure.getMetricValues().keySet()) {
+ updateMeasureBuilder(measureBuilder, metricsByKey.get(metricKey), measure);
+ measureBuilder.setComponent(componentsByUuid.get(measure.getComponentUuid()).getKey());
+ Measure measureMsg = measureBuilder.build();
+ addMeasureIncludingRenamedMetric(measureMsg, allMeasures, measureBuilder);
+
+ measureBuilder.clear();
+ }
}
return allMeasures.stream()
.sorted(comparing(byMetricKey).thenComparing(byComponentName))
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java
index 42ab1b2cdd6..6aa328a0ed8 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java
@@ -40,7 +40,7 @@ import org.sonar.db.Pagination;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ProjectLinkDto;
import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.measure.LiveMeasureDto;
+import org.sonar.db.measure.MeasureDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.Projects.SearchMyProjectsWsResponse;
@@ -185,7 +185,7 @@ public class SearchMyProjectsAction implements ProjectsWsAction {
Set<String> mainBranchUuids = branches.stream().map(BranchDto::getUuid).collect(Collectors.toSet());
List<SnapshotDto> snapshots = dbClient.snapshotDao()
.selectLastAnalysesByRootComponentUuids(dbSession, mainBranchUuids);
- List<LiveMeasureDto> qualityGates = dbClient.liveMeasureDao()
+ List<MeasureDto> qualityGates = dbClient.measureDao()
.selectByComponentUuidsAndMetricKeys(dbSession, mainBranchUuids, singletonList(CoreMetrics.ALERT_STATUS_KEY));
data
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsData.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsData.java
index e7af638be5e..ec1c3bcb027 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsData.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsData.java
@@ -29,12 +29,13 @@ import java.util.stream.Collectors;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ProjectLinkDto;
import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.measure.LiveMeasureDto;
+import org.sonar.db.measure.MeasureDto;
import org.sonar.db.project.ProjectDto;
import static com.google.common.collect.ImmutableList.copyOf;
import static java.util.Objects.requireNonNull;
import static java.util.function.Function.identity;
+import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY;
class SearchMyProjectsData {
@@ -85,13 +86,14 @@ class SearchMyProjectsData {
dtos.forEach(projectLink -> projectLinks.put(projectLink.getProjectUuid(), projectLink));
return projectLinks.build();
}
+
private static Map<String, String> buildBranchUuidByProjectUuidMap(List<BranchDto> branches) {
return branches.stream().collect(Collectors.toMap(BranchDto::getProjectUuid, BranchDto::getUuid));
}
- private static Map<String, String> buildQualityGateStatuses(List<LiveMeasureDto> measures) {
+ private static Map<String, String> buildQualityGateStatuses(List<MeasureDto> measures) {
return ImmutableMap.copyOf(measures.stream()
- .collect(Collectors.toMap(LiveMeasureDto::getComponentUuid, LiveMeasureDto::getDataAsString)));
+ .collect(Collectors.toMap(MeasureDto::getComponentUuid, m -> m.getString(ALERT_STATUS_KEY))));
}
public String mainBranchUuidForProjectUuid(String projectUuid) {
@@ -110,7 +112,7 @@ class SearchMyProjectsData {
private List<BranchDto> branches;
private List<ProjectLinkDto> projectLinks;
private List<SnapshotDto> snapshots;
- private List<LiveMeasureDto> qualityGates;
+ private List<MeasureDto> qualityGates;
private Integer totalNbOfProjects;
private Builder() {
@@ -137,7 +139,7 @@ class SearchMyProjectsData {
return this;
}
- public Builder setQualityGates(List<LiveMeasureDto> qGateStatuses) {
+ public Builder setQualityGates(List<MeasureDto> qGateStatuses) {
this.qualityGates = qGateStatuses;
return this;
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java
index 9c034901fbf..c56ff41d1b4 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java
@@ -35,7 +35,6 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.measure.ProjectMeasureDto;
import org.sonar.db.permission.GlobalPermission;
import org.sonar.db.project.ProjectDto;
@@ -216,8 +215,8 @@ public class ProjectStatusAction implements QualityGatesWsAction {
}
// do not restrict to a specified analysis, use the live measure
- Optional<LiveMeasureDto> measure = dbClient.liveMeasureDao().selectMeasure(dbSession, projectAndSnapshot.branch.getUuid(), CoreMetrics.QUALITY_GATE_DETAILS_KEY);
- return measure.map(LiveMeasureDto::getDataAsString);
+ return dbClient.measureDao().selectByComponentUuid(dbSession, projectAndSnapshot.branch.getUuid())
+ .map(m -> m.getString(CoreMetrics.QUALITY_GATE_DETAILS_KEY));
}
private void checkPermission(ProjectDto project) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
index 5ace1980a30..9fed1e84f89 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
@@ -47,7 +47,6 @@ import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.permission.GlobalPermission;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.property.PropertyQuery;
@@ -248,8 +247,8 @@ public class ComponentAction implements NavigationWsAction {
}
private void writeProfiles(JsonWriter json, DbSession dbSession, ComponentDto component) {
- Set<QualityProfile> qualityProfiles = dbClient.liveMeasureDao().selectMeasure(dbSession, component.branchUuid(), QUALITY_PROFILES_KEY)
- .map(LiveMeasureDto::getDataAsString)
+ Set<QualityProfile> qualityProfiles = dbClient.measureDao().selectByComponentUuid(dbSession, component.branchUuid())
+ .map(m -> m.getString(QUALITY_PROFILES_KEY))
.map(data -> QPMeasureData.fromJson(data).getProfiles())
.orElse(emptySortedSet());
Map<String, QProfileDto> dtoByQPKey = dbClient.qualityProfileDao().selectByUuids(dbSession, qualityProfiles.stream().map(QualityProfile::getQpKey).toList())
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java
index 4cc8db8ba45..4daeb93fbd6 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java
@@ -31,7 +31,6 @@ import org.sonar.api.measures.Metric.ValueType;
import org.sonar.api.resources.Qualifiers;
import org.sonar.core.util.Uuids;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.server.measure.ImpactMeasureBuilder;
@@ -44,7 +43,7 @@ import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_SORT;
import static org.sonar.server.measure.ws.ComponentTreeAction.NAME_SORT;
import static org.sonar.server.measure.ws.ComponentTreeAction.PATH_SORT;
import static org.sonar.server.measure.ws.ComponentTreeAction.QUALIFIER_SORT;
-import static org.sonar.server.measure.ws.ComponentTreeData.Measure.createFromMeasureDto;
+import static org.sonar.server.measure.ws.ComponentTreeData.Measure.createFromMetricValue;
class ComponentTreeSortTest {
private static final String NUM_METRIC_KEY = "violations";
@@ -93,11 +92,11 @@ class ComponentTreeSortTest {
// same number than path field
double currentValue = 9;
for (ComponentDto component : components) {
- measuresByComponentUuidAndMetric.put(component.uuid(), violationsMetric, createFromMeasureDto(new LiveMeasureDto().setValue(currentValue)));
- measuresByComponentUuidAndMetric.put(component.uuid(), newViolationsMetric, createFromMeasureDto(new LiveMeasureDto().setValue(currentValue)));
- measuresByComponentUuidAndMetric.put(component.uuid(), sqaleIndexMetric, createFromMeasureDto(new LiveMeasureDto().setData(String.valueOf(currentValue))));
- measuresByComponentUuidAndMetric.put(component.uuid(), reliabilityIssueMetric, createFromMeasureDto(new LiveMeasureDto().setData(buildJsonImpact((int) currentValue))));
- measuresByComponentUuidAndMetric.put(component.uuid(), newReliabilityIssueMetric, createFromMeasureDto(new LiveMeasureDto().setData(buildJsonImpact((int) currentValue))));
+ measuresByComponentUuidAndMetric.put(component.uuid(), violationsMetric, createFromMetricValue(violationsMetric, currentValue));
+ measuresByComponentUuidAndMetric.put(component.uuid(), newViolationsMetric, createFromMetricValue(newViolationsMetric, currentValue));
+ measuresByComponentUuidAndMetric.put(component.uuid(), sqaleIndexMetric, createFromMetricValue(sqaleIndexMetric, currentValue));
+ measuresByComponentUuidAndMetric.put(component.uuid(), reliabilityIssueMetric, createFromMetricValue(reliabilityIssueMetric, buildJsonImpact((int) currentValue)));
+ measuresByComponentUuidAndMetric.put(component.uuid(), newReliabilityIssueMetric, createFromMetricValue(newReliabilityIssueMetric, buildJsonImpact((int) currentValue)));
currentValue--;
}
}
@@ -191,7 +190,7 @@ class ComponentTreeSortTest {
for (int i = 0; i < components.size(); i++) {
ComponentDto component = components.get(i);
String alertStatus = statuses.get(i % 2);
- measuresByComponentUuidAndMetric.put(component.uuid(), metrics.get(0), createFromMeasureDto(new LiveMeasureDto().setData(alertStatus)));
+ measuresByComponentUuidAndMetric.put(component.uuid(), metrics.get(0), createFromMetricValue(metrics.get(0), alertStatus));
}
ComponentTreeRequest wsRequest = newRequest(newArrayList(METRIC_SORT, NAME_SORT), true, CoreMetrics.ALERT_STATUS_KEY);