Search in sources :

Example 1 with MeasureDto

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

Example 2 with MeasureDto

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;
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) Developer(org.sonar.server.computation.task.projectanalysis.component.Developer) Nonnull(javax.annotation.Nonnull)

Example 3 with MeasureDto

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

Example 4 with MeasureDto

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();
    }
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) MeasureDto(org.sonar.db.measure.MeasureDto) DbSession(org.sonar.db.DbSession) MetricDto(org.sonar.db.metric.MetricDto) ComponentTreeQuery(org.sonar.db.component.ComponentTreeQuery)

Example 5 with MeasureDto

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

Aggregations

MeasureDto (org.sonar.db.measure.MeasureDto)67 Test (org.junit.Test)51 LiveMeasureDto (org.sonar.db.measure.LiveMeasureDto)15 SnapshotDto (org.sonar.db.component.SnapshotDto)12 MetricDto (org.sonar.db.metric.MetricDto)12 ComponentDto (org.sonar.db.component.ComponentDto)8 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)7 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)6 DbSession (org.sonar.db.DbSession)6 MeasureQuery (org.sonar.db.measure.MeasureQuery)6 ProjectDump (com.sonarsource.governance.projectdump.protobuf.ProjectDump)3 Double.parseDouble (java.lang.Double.parseDouble)2 String.format (java.lang.String.format)2 Arrays.asList (java.util.Arrays.asList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Optional.ofNullable (java.util.Optional.ofNullable)2 LongStream (java.util.stream.LongStream)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2