use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.
the class MeasureDtoToMeasureTest method toMeasure_maps_data_and_alert_properties_in_dto_for_Double_Metric.
@Test
public void toMeasure_maps_data_and_alert_properties_in_dto_for_Double_Metric() {
MeasureDto measureDto = new MeasureDto().setValue(10.6395d).setData(SOME_DATA).setAlertStatus(Level.OK.name()).setAlertText(SOME_ALERT_TEXT);
Optional<Measure> measure = underTest.toMeasure(measureDto, SOME_DOUBLE_METRIC);
assertThat(measure.isPresent()).isTrue();
assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.DOUBLE);
assertThat(measure.get().getDoubleValue()).isEqualTo(10.6395d);
assertThat(measure.get().getData()).isEqualTo(SOME_DATA);
assertThat(measure.get().getQualityGateStatus().getStatus()).isEqualTo(Level.OK);
assertThat(measure.get().getQualityGateStatus().getText()).isEqualTo(SOME_ALERT_TEXT);
}
use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.
the class MeasureToMeasureDtoTest method toMeasureDto_maps_value_to_1_or_0_and_data_from_data_field_for_BOOLEAN_metric.
@Test
public void toMeasureDto_maps_value_to_1_or_0_and_data_from_data_field_for_BOOLEAN_metric() {
MeasureDto trueMeasureDto = underTest.toMeasureDto(Measure.newMeasureBuilder().create(true, SOME_DATA), SOME_BOOLEAN_METRIC, SOME_COMPONENT);
assertThat(trueMeasureDto.getValue()).isEqualTo(1d);
assertThat(trueMeasureDto.getData()).isEqualTo(SOME_DATA);
MeasureDto falseMeasureDto = underTest.toMeasureDto(Measure.newMeasureBuilder().create(false, SOME_DATA), SOME_BOOLEAN_METRIC, SOME_COMPONENT);
assertThat(falseMeasureDto.getValue()).isEqualTo(0d);
assertThat(falseMeasureDto.getData()).isEqualTo(SOME_DATA);
}
use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.
the class AppAction method measuresByMetricKey.
private Map<String, MeasureDto> measuresByMetricKey(ComponentDto component, DbSession session) {
MeasureQuery query = MeasureQuery.builder().setComponentUuid(component.uuid()).setMetricKeys(METRIC_KEYS).build();
List<MeasureDto> measures = dbClient.measureDao().selectByQuery(session, query);
Set<Integer> metricIds = measures.stream().map(MeasureDto::getMetricId).collect(Collectors.toSet());
List<MetricDto> metrics = dbClient.metricDao().selectByIds(session, metricIds);
Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDto::getId);
return Maps.uniqueIndex(measures, m -> metricsById.get(m.getMetricId()).getKey());
}
use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.
the class ComponentAction method searchMeasures.
private List<MeasureDto> searchMeasures(DbSession dbSession, ComponentDto component, @Nullable SnapshotDto analysis, List<MetricDto> metrics, @Nullable Long developerId) {
if (analysis == null) {
return emptyList();
}
List<Integer> metricIds = Lists.transform(metrics, MetricDto::getId);
MeasureQuery query = MeasureQuery.builder().setPersonId(developerId).setMetricIds(metricIds).setComponentUuid(component.uuid()).build();
List<MeasureDto> measures = dbClient.measureDao().selectByQuery(dbSession, query);
addBestValuesToMeasures(measures, component, metrics);
return measures;
}
use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.
the class ComponentAction method buildResponse.
private static ComponentWsResponse buildResponse(ComponentWsRequest request, ComponentDto component, Optional<ComponentDto> refComponent, List<MeasureDto> measures, List<MetricDto> metrics, List<WsMeasures.Period> periods) {
ComponentWsResponse.Builder response = ComponentWsResponse.newBuilder();
Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDto::getId);
Map<MetricDto, MeasureDto> measuresByMetric = new HashMap<>();
for (MeasureDto measure : measures) {
MetricDto metric = metricsById.get(measure.getMetricId());
measuresByMetric.put(metric, measure);
}
if (refComponent.isPresent()) {
response.setComponent(componentDtoToWsComponent(component, measuresByMetric, singletonMap(refComponent.get().uuid(), refComponent.get())));
} else {
response.setComponent(componentDtoToWsComponent(component, measuresByMetric, emptyMap()));
}
List<String> additionalFields = request.getAdditionalFields();
if (additionalFields != null) {
if (additionalFields.contains(ADDITIONAL_METRICS)) {
for (MetricDto metric : metrics) {
response.getMetricsBuilder().addMetrics(metricDtoToWsMetric(metric));
}
}
if (additionalFields.contains(ADDITIONAL_PERIODS)) {
response.getPeriodsBuilder().addAllPeriods(periods);
}
}
return response.build();
}
Aggregations