Search in sources :

Example 6 with MeasureDto

use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.

the class ComponentDtoToWsComponent method componentDtoToWsComponent.

static Component.Builder componentDtoToWsComponent(ComponentDto component, Map<MetricDto, MeasureDto> measuresByMetric, Map<String, ComponentDto> referenceComponentsByUuid) {
    Component.Builder wsComponent = componentDtoToWsComponent(component);
    ComponentDto referenceComponent = referenceComponentsByUuid.get(component.getCopyResourceUuid());
    if (referenceComponent != null) {
        wsComponent.setRefId(referenceComponent.uuid());
        wsComponent.setRefKey(referenceComponent.key());
    }
    for (Map.Entry<MetricDto, MeasureDto> entry : measuresByMetric.entrySet()) {
        wsComponent.addMeasures(measureDtoToWsMeasure(entry.getKey(), entry.getValue()));
    }
    return wsComponent;
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) MetricDto(org.sonar.db.metric.MetricDto) ComponentDto(org.sonar.db.component.ComponentDto) Component(org.sonarqube.ws.WsMeasures.Component) Map(java.util.Map)

Example 7 with MeasureDto

use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.

the class SearchMyProjectsDataLoader method load.

SearchMyProjectsData load(DbSession dbSession, SearchMyProjectsRequest request) {
    SearchMyProjectsData.Builder data = builder();
    ProjectsResult searchResult = searchProjects(dbSession, request);
    List<ComponentDto> projects = searchResult.projects;
    List<String> projectUuids = Lists.transform(projects, ComponentDto::projectUuid);
    List<ComponentLinkDto> projectLinks = dbClient.componentLinkDao().selectByComponentUuids(dbSession, projectUuids);
    List<SnapshotDto> snapshots = dbClient.snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, projectUuids);
    MetricDto gateStatusMetric = dbClient.metricDao().selectOrFailByKey(dbSession, CoreMetrics.ALERT_STATUS_KEY);
    MeasureQuery measureQuery = MeasureQuery.builder().setProjectUuids(projectUuids).setMetricId(gateStatusMetric.getId()).build();
    List<MeasureDto> qualityGates = dbClient.measureDao().selectByQuery(dbSession, measureQuery);
    data.setProjects(projects).setProjectLinks(projectLinks).setSnapshots(snapshots).setQualityGates(qualityGates).setTotalNbOfProjects(searchResult.total);
    return data.build();
}
Also used : ComponentLinkDto(org.sonar.db.component.ComponentLinkDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) MeasureDto(org.sonar.db.measure.MeasureDto) MetricDto(org.sonar.db.metric.MetricDto) MeasureQuery(org.sonar.db.measure.MeasureQuery)

Example 8 with MeasureDto

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_Long_Metric.

@Test
public void toMeasure_maps_data_and_alert_properties_in_dto_for_Long_Metric() {
    MeasureDto measureDto = new MeasureDto().setValue(10d).setData(SOME_DATA).setAlertStatus(Level.OK.name()).setAlertText(SOME_ALERT_TEXT);
    Optional<Measure> measure = underTest.toMeasure(measureDto, SOME_LONG_METRIC);
    assertThat(measure.isPresent()).isTrue();
    assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LONG);
    assertThat(measure.get().getLongValue()).isEqualTo(10);
    assertThat(measure.get().getData()).isEqualTo(SOME_DATA);
    assertThat(measure.get().getQualityGateStatus().getStatus()).isEqualTo(Level.OK);
    assertThat(measure.get().getQualityGateStatus().getText()).isEqualTo(SOME_ALERT_TEXT);
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) Test(org.junit.Test)

Example 9 with MeasureDto

use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.

the class MeasureDtoToMeasureTest method toMeasure_creates_MeasureVariation_and_maps_the_right_one.

@Test
public void toMeasure_creates_MeasureVariation_and_maps_the_right_one() {
    MeasureDto measureDto = new MeasureDto().setData("1").setVariation(2d);
    Optional<Measure> measure = underTest.toMeasure(measureDto, SOME_STRING_METRIC);
    assertThat(measure.get().getVariation()).isEqualTo(2);
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) Test(org.junit.Test)

Example 10 with MeasureDto

use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.

the class MeasureToMeasureDtoTest method toMeasureDto_returns_Dto_without_any_variation_if_Measure_has_no_MeasureVariations.

@Test
@UseDataProvider("all_types_Measures")
public void toMeasureDto_returns_Dto_without_any_variation_if_Measure_has_no_MeasureVariations(Measure measure, Metric metric) {
    MeasureDto measureDto = underTest.toMeasureDto(measure, metric, SOME_COMPONENT);
    assertThat(measureDto.getVariation()).isNull();
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

MeasureDto (org.sonar.db.measure.MeasureDto)36 Test (org.junit.Test)21 MetricDto (org.sonar.db.metric.MetricDto)9 ComponentDto (org.sonar.db.component.ComponentDto)7 MeasureQuery (org.sonar.db.measure.MeasureQuery)6 DbSession (org.sonar.db.DbSession)4 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3 SnapshotDto (org.sonar.db.component.SnapshotDto)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CheckForNull (javax.annotation.CheckForNull)1 Nonnull (javax.annotation.Nonnull)1 Before (org.junit.Before)1 JsonWriter (org.sonar.api.utils.text.JsonWriter)1 ComponentLinkDto (org.sonar.db.component.ComponentLinkDto)1 ComponentTreeQuery (org.sonar.db.component.ComponentTreeQuery)1 MeasureTreeQuery (org.sonar.db.measure.MeasureTreeQuery)1 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)1 Developer (org.sonar.server.computation.task.projectanalysis.component.Developer)1