Search in sources :

Example 1 with MeasureQuery

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

the class MeasureRepositoryImpl method getBaseMeasure.

@Override
public Optional<Measure> getBaseMeasure(Component component, Metric metric) {
    // fail fast
    requireNonNull(component);
    requireNonNull(metric);
    try (DbSession dbSession = dbClient.openSession(false)) {
        MeasureQuery query = MeasureQuery.builder().setComponentUuid(component.getUuid()).setMetricKey(metric.getKey()).build();
        java.util.Optional<MeasureDto> measureDto = dbClient.measureDao().selectSingle(dbSession, query);
        if (measureDto.isPresent()) {
            return underTest.toMeasure(measureDto.get(), metric);
        }
        return Optional.absent();
    }
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) DbSession(org.sonar.db.DbSession) MeasureQuery(org.sonar.db.measure.MeasureQuery)

Example 2 with MeasureQuery

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

the class ShowAction method findDataFromComponent.

@CheckForNull
private String findDataFromComponent(DbSession dbSession, ComponentDto component) {
    MeasureQuery query = MeasureQuery.builder().setComponentUuid(component.uuid()).setMetricKey(CoreMetrics.DUPLICATIONS_DATA_KEY).build();
    Optional<MeasureDto> measure = dbClient.measureDao().selectSingle(dbSession, query);
    return measure.isPresent() ? measure.get().getData() : null;
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) MeasureQuery(org.sonar.db.measure.MeasureQuery) CheckForNull(javax.annotation.CheckForNull)

Example 3 with MeasureQuery

use of org.sonar.db.measure.MeasureQuery 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 4 with MeasureQuery

use of org.sonar.db.measure.MeasureQuery 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 5 with MeasureQuery

use of org.sonar.db.measure.MeasureQuery 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)

Aggregations

MeasureDto (org.sonar.db.measure.MeasureDto)6 MeasureQuery (org.sonar.db.measure.MeasureQuery)6 MetricDto (org.sonar.db.metric.MetricDto)3 CheckForNull (javax.annotation.CheckForNull)1 DbSession (org.sonar.db.DbSession)1 ComponentDto (org.sonar.db.component.ComponentDto)1 ComponentLinkDto (org.sonar.db.component.ComponentLinkDto)1 SnapshotDto (org.sonar.db.component.SnapshotDto)1