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();
}
}
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;
}
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();
}
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());
}
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;
}
Aggregations