use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class ComponentAction method doHandle.
private ComponentWsResponse doHandle(ComponentRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
String branch = request.getBranch();
String pullRequest = request.getPullRequest();
ComponentDto component = loadComponent(dbSession, request, branch, pullRequest);
checkPermissions(component);
SnapshotDto analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, component.projectUuid()).orElse(null);
boolean isPR = isPR(pullRequest);
Set<String> metricKeysToRequest = new HashSet<>(request.metricKeys);
if (isPR) {
PrMeasureFix.addReplacementMetricKeys(metricKeysToRequest);
}
List<MetricDto> metrics = searchMetrics(dbSession, metricKeysToRequest);
List<LiveMeasureDto> measures = searchMeasures(dbSession, component, metrics);
Map<MetricDto, LiveMeasureDto> measuresByMetric = getMeasuresByMetric(measures, metrics);
if (isPR) {
Set<String> originalMetricKeys = new HashSet<>(request.metricKeys);
PrMeasureFix.createReplacementMeasures(metrics, measuresByMetric, originalMetricKeys);
PrMeasureFix.removeMetricsNotRequested(metrics, originalMetricKeys);
}
Optional<Measures.Period> period = snapshotToWsPeriods(analysis);
Optional<ComponentDto> refComponent = getReferenceComponent(dbSession, component);
return buildResponse(request, component, refComponent, measuresByMetric, metrics, period);
}
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class PrMeasureFix method createReplacementMeasures.
static void createReplacementMeasures(List<MetricDto> metrics, Map<MetricDto, LiveMeasureDto> measuresByMetric, Set<String> requestedMetricKeys) {
Map<String, MetricDto> metricByKey = Maps.uniqueIndex(metrics, MetricDto::getKey);
Map<MetricDto, LiveMeasureDto> newEntries = new HashMap<>();
for (Map.Entry<MetricDto, LiveMeasureDto> e : measuresByMetric.entrySet()) {
String originalKey = METRICS.inverse().get(e.getKey().getKey());
if (originalKey != null && requestedMetricKeys.contains(originalKey)) {
MetricDto metricDto = metricByKey.get(originalKey);
newEntries.put(metricDto, copyMeasureToVariation(e.getValue(), metricDto.getUuid()));
}
}
measuresByMetric.entrySet().removeIf(e -> !requestedMetricKeys.contains(e.getKey().getKey()));
measuresByMetric.putAll(newEntries);
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class PrMeasureFix method copyMeasureToVariation.
private static LiveMeasureDto copyMeasureToVariation(LiveMeasureDto dto, String metricUuid) {
LiveMeasureDto copy = new LiveMeasureDto();
copy.setVariation(dto.getValue());
copy.setProjectUuid(dto.getProjectUuid());
copy.setComponentUuid(dto.getComponentUuid());
copy.setMetricUuid(metricUuid);
return copy;
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class LiveQualityGateComputerImpl method refreshGateStatus.
@Override
public EvaluatedQualityGate refreshGateStatus(ComponentDto project, QualityGate gate, MeasureMatrix measureMatrix, Configuration configuration) {
QualityGateEvaluator.Measures measures = metricKey -> {
Optional<LiveMeasureDto> liveMeasureDto = measureMatrix.getMeasure(project, metricKey);
if (!liveMeasureDto.isPresent()) {
return Optional.empty();
}
MetricDto metric = measureMatrix.getMetricByUuid(liveMeasureDto.get().getMetricUuid());
return Optional.of(new LiveMeasure(liveMeasureDto.get(), metric));
};
EvaluatedQualityGate evaluatedGate = evaluator.evaluate(gate, measures, configuration);
measureMatrix.setValue(project, CoreMetrics.ALERT_STATUS_KEY, evaluatedGate.getStatus().name());
measureMatrix.setValue(project, CoreMetrics.QUALITY_GATE_DETAILS_KEY, QualityGateConverter.toJson(evaluatedGate));
return evaluatedGate;
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class ComponentDtoToWsComponent method componentDtoToWsComponent.
static Component.Builder componentDtoToWsComponent(ComponentDto component, Map<MetricDto, LiveMeasureDto> measuresByMetric, Map<String, ComponentDto> referenceComponentsByUuid) {
Component.Builder wsComponent = componentDtoToWsComponent(component);
ComponentDto referenceComponent = referenceComponentsByUuid.get(component.getCopyComponentUuid());
if (referenceComponent != null) {
wsComponent.setRefKey(referenceComponent.getDbKey());
}
Measures.Measure.Builder measureBuilder = Measures.Measure.newBuilder();
for (Map.Entry<MetricDto, LiveMeasureDto> entry : measuresByMetric.entrySet()) {
MeasureDtoToWsMeasure.updateMeasureBuilder(measureBuilder, entry.getKey(), entry.getValue());
wsComponent.addMeasures(measureBuilder);
measureBuilder.clear();
}
return wsComponent;
}
Aggregations