use of org.sonar.db.measure.MeasureDto 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.MeasureDto in project sonarqube by SonarSource.
the class MeasureToMeasureDto method toMeasureDto.
@Nonnull
public MeasureDto toMeasureDto(Measure measure, Metric metric, Component component) {
MeasureDto out = new MeasureDto();
out.setMetricId(metric.getId());
out.setComponentUuid(component.getUuid());
out.setAnalysisUuid(analysisMetadataHolder.getUuid());
if (measure.hasVariation()) {
out.setVariation(measure.getVariation());
}
if (measure.hasQualityGateStatus()) {
setAlert(out, measure.getQualityGateStatus());
}
Developer developer = measure.getDeveloper();
if (developer != null) {
out.setDeveloperId(dbIdsRepository.getDeveloperId(developer));
}
out.setDescription(measure.getDescription());
out.setValue(valueAsDouble(measure));
out.setData(data(measure));
return out;
}
use of org.sonar.db.measure.MeasureDto 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.MeasureDto in project sonarqube by SonarSource.
the class ComponentTreeDataLoader method load.
ComponentTreeData load(ComponentTreeWsRequest wsRequest) {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto baseComponent = componentFinder.getByUuidOrKey(dbSession, wsRequest.getBaseComponentId(), wsRequest.getBaseComponentKey(), BASE_COMPONENT_ID_AND_KEY);
checkPermissions(baseComponent);
Optional<SnapshotDto> baseSnapshot = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, baseComponent.projectUuid());
if (!baseSnapshot.isPresent()) {
return ComponentTreeData.builder().setBaseComponent(baseComponent).build();
}
Long developerId = searchDeveloperId(dbSession, wsRequest);
ComponentTreeQuery componentTreeQuery = toComponentTreeQuery(wsRequest, baseComponent);
List<ComponentDto> components = searchComponents(dbSession, componentTreeQuery);
List<MetricDto> metrics = searchMetrics(dbSession, wsRequest);
Table<String, MetricDto, MeasureDto> measuresByComponentUuidAndMetric = searchMeasuresByComponentUuidAndMetric(dbSession, baseComponent, componentTreeQuery, components, metrics, developerId);
components = filterComponents(components, measuresByComponentUuidAndMetric, metrics, wsRequest);
components = sortComponents(components, wsRequest, metrics, measuresByComponentUuidAndMetric);
int componentCount = components.size();
components = paginateComponents(components, wsRequest);
return ComponentTreeData.builder().setBaseComponent(baseComponent).setComponentsFromDb(components).setComponentCount(componentCount).setMeasuresByComponentUuidAndMetric(measuresByComponentUuidAndMetric).setMetrics(metrics).setPeriods(snapshotToWsPeriods(baseSnapshot.get())).setReferenceComponentsByUuid(searchReferenceComponentsById(dbSession, components)).build();
}
}
use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.
the class ComponentAction method doHandle.
private ComponentWsResponse doHandle(ComponentWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.getComponentId(), request.getComponentKey(), COMPONENT_ID_AND_KEY);
Long developerId = searchDeveloperId(dbSession, request);
Optional<ComponentDto> refComponent = getReferenceComponent(dbSession, component);
checkPermissions(component);
SnapshotDto analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, component.projectUuid()).orElse(null);
List<MetricDto> metrics = searchMetrics(dbSession, request);
List<WsMeasures.Period> periods = snapshotToWsPeriods(analysis);
List<MeasureDto> measures = searchMeasures(dbSession, component, analysis, metrics, developerId);
return buildResponse(request, component, refComponent, measures, metrics, periods);
}
}
Aggregations