use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class ComponentTreeAction method searchMeasuresByComponentUuidAndMetric.
private Table<String, MetricDto, ComponentTreeData.Measure> searchMeasuresByComponentUuidAndMetric(DbSession dbSession, ComponentDto baseComponent, ComponentTreeQuery componentTreeQuery, List<ComponentDto> components, List<MetricDto> metrics) {
Map<String, MetricDto> metricsByUuid = Maps.uniqueIndex(metrics, MetricDto::getUuid);
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));
});
addBestValuesToMeasures(measuresByComponentUuidAndMetric, components, metrics);
return measuresByComponentUuidAndMetric;
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class ListAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String projectKey = request.mandatoryParam(PARAM_PROJECT);
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto project = componentFinder.getProjectOrApplicationByKey(dbSession, projectKey);
checkPermission(project);
List<BranchDto> pullRequests = dbClient.branchDao().selectByProject(dbSession, project).stream().filter(b -> b.getBranchType() == PULL_REQUEST).collect(toList());
List<String> pullRequestUuids = pullRequests.stream().map(BranchDto::getUuid).collect(toList());
Map<String, BranchDto> mergeBranchesByUuid = dbClient.branchDao().selectByUuids(dbSession, pullRequests.stream().map(BranchDto::getMergeBranchUuid).filter(Objects::nonNull).collect(toList())).stream().collect(uniqueIndex(BranchDto::getUuid));
Map<String, PrStatistics> branchStatisticsByBranchUuid = issueIndex.searchBranchStatistics(project.getUuid(), pullRequestUuids).stream().collect(uniqueIndex(PrStatistics::getBranchUuid, Function.identity()));
Map<String, LiveMeasureDto> qualityGateMeasuresByComponentUuids = dbClient.liveMeasureDao().selectByComponentUuidsAndMetricKeys(dbSession, pullRequestUuids, singletonList(ALERT_STATUS_KEY)).stream().collect(uniqueIndex(LiveMeasureDto::getComponentUuid));
Map<String, String> analysisDateByBranchUuid = dbClient.snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, pullRequestUuids).stream().collect(uniqueIndex(SnapshotDto::getComponentUuid, s -> formatDateTime(s.getCreatedAt())));
ProjectPullRequests.ListWsResponse.Builder protobufResponse = ProjectPullRequests.ListWsResponse.newBuilder();
pullRequests.forEach(b -> addPullRequest(protobufResponse, b, mergeBranchesByUuid, qualityGateMeasuresByComponentUuids.get(b.getUuid()), branchStatisticsByBranchUuid.get(b.getUuid()), analysisDateByBranchUuid.get(b.getUuid())));
writeProtobuf(protobufResponse.build(), request, response);
}
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class MeasureToMeasureDto method toLiveMeasureDto.
public LiveMeasureDto toLiveMeasureDto(Measure measure, Metric metric, Component component) {
LiveMeasureDto out = new LiveMeasureDto();
out.setMetricUuid(metric.getUuid());
out.setComponentUuid(component.getUuid());
out.setProjectUuid(treeRootHolder.getRoot().getUuid());
if (measure.hasVariation()) {
out.setVariation(measure.getVariation());
}
out.setValue(valueAsDouble(measure));
out.setData(data(measure));
return out;
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class LiveMeasureComputerImplTest method assertThatRatingMeasureHasValue.
private LiveMeasureDto assertThatRatingMeasureHasValue(ComponentDto component, Rating expectedRating) {
LiveMeasureDto measure = db.getDbClient().liveMeasureDao().selectMeasure(db.getSession(), component.uuid(), ratingMetric.getKey()).get();
assertThat(measure.getComponentUuid()).isEqualTo(component.uuid());
assertThat(measure.getProjectUuid()).isEqualTo(component.projectUuid());
assertThat(measure.getMetricUuid()).isEqualTo(ratingMetric.getUuid());
assertThat(measure.getValue()).isEqualTo(expectedRating.getIndex());
assertThat(measure.getDataAsString()).isEqualTo(expectedRating.name());
return measure;
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class LiveMeasureComputerImplTest method variation_is_refreshed_when_int_value_is_changed.
@Test
public void variation_is_refreshed_when_int_value_is_changed() {
markProjectAsAnalyzed(project);
// value is:
// 42 on last analysis
// 42-12=30 on beginning of leak period
db.measures().insertLiveMeasure(project, intMetric, m -> m.setValue(42.0).setVariation(12.0));
// new value is 44, so variation on leak period is 44-30=14
List<QGChangeEvent> result = run(file1, newIntConstantFormula(44.0));
LiveMeasureDto measure = assertThatIntMeasureHasValue(project, 44.0);
assertThat(measure.getVariation()).isEqualTo(14.0);
assertThatProjectChanged(result, project);
}
Aggregations