Search in sources :

Example 21 with MeasureDto

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());
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) MetricDto(org.sonar.db.metric.MetricDto) MeasureQuery(org.sonar.db.measure.MeasureQuery)

Example 22 with MeasureDto

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;
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) MetricDto(org.sonar.db.metric.MetricDto) MeasureQuery(org.sonar.db.measure.MeasureQuery)

Example 23 with MeasureDto

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();
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) MetricDto(org.sonar.db.metric.MetricDto) ComponentWsResponse(org.sonarqube.ws.WsMeasures.ComponentWsResponse) HashMap(java.util.HashMap)

Example 24 with MeasureDto

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

the class ComponentTreeDataLoader method searchMeasuresByComponentUuidAndMetric.

private Table<String, MetricDto, MeasureDto> searchMeasuresByComponentUuidAndMetric(DbSession dbSession, ComponentDto baseComponent, ComponentTreeQuery componentTreeQuery, List<ComponentDto> components, List<MetricDto> metrics, @Nullable Long developerId) {
    Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDto::getId);
    MeasureTreeQuery measureQuery = MeasureTreeQuery.builder().setStrategy(MeasureTreeQuery.Strategy.valueOf(componentTreeQuery.getStrategy().name())).setNameOrKeyQuery(componentTreeQuery.getNameOrKeyQuery()).setQualifiers(componentTreeQuery.getQualifiers()).setPersonId(developerId).setMetricIds(new ArrayList<>(metricsById.keySet())).build();
    List<MeasureDto> measureDtos = dbClient.measureDao().selectTreeByQuery(dbSession, baseComponent, measureQuery);
    Table<String, MetricDto, MeasureDto> measuresByComponentUuidAndMetric = HashBasedTable.create(components.size(), metrics.size());
    for (MeasureDto measureDto : measureDtos) {
        measuresByComponentUuidAndMetric.put(measureDto.getComponentUuid(), metricsById.get(measureDto.getMetricId()), measureDto);
    }
    addBestValuesToMeasures(measuresByComponentUuidAndMetric, components, metrics);
    return measuresByComponentUuidAndMetric;
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) MeasureTreeQuery(org.sonar.db.measure.MeasureTreeQuery) MetricDto(org.sonar.db.metric.MetricDto) ArrayList(java.util.ArrayList)

Example 25 with MeasureDto

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

the class ProjectStatusAction method getQualityGateDetailsMeasureData.

private Optional<String> getQualityGateDetailsMeasureData(DbSession dbSession, ComponentDto project) {
    MeasureQuery measureQuery = MeasureQuery.builder().setProjectUuids(singletonList(project.projectUuid())).setMetricKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY).build();
    List<MeasureDto> measures = dbClient.measureDao().selectByQuery(dbSession, measureQuery);
    return measures.isEmpty() ? Optional.absent() : Optional.fromNullable(measures.get(0).getData());
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) MeasureQuery(org.sonar.db.measure.MeasureQuery)

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