Search in sources :

Example 6 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class PeriodResolver method findByVersion.

@CheckForNull
private Period findByVersion(String version) {
    SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectUuid).setVersion(version).setSort(BY_DATE, DESC));
    if (snapshot == null) {
        return null;
    }
    LOG.debug("Compare to version ({}) ({})", version, formatDate(snapshot.getCreatedAt()));
    return new Period(LEAK_PERIOD_MODE_VERSION, version, snapshot.getCreatedAt(), snapshot.getUuid());
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) Period(org.sonar.server.computation.task.projectanalysis.period.Period) CheckForNull(javax.annotation.CheckForNull)

Example 7 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class IssueQueryService method findCreatedAfterFromComponentUuid.

@CheckForNull
private Date findCreatedAfterFromComponentUuid(DbSession dbSession, String uuid) {
    ComponentDto component = checkFoundWithOptional(dbClient.componentDao().selectByUuid(dbSession, uuid), "Component with id '%s' not found", uuid);
    Optional<SnapshotDto> snapshot = dbClient.snapshotDao().selectLastAnalysisByComponentUuid(dbSession, component.uuid());
    if (snapshot.isPresent()) {
        return longToDate(snapshot.get().getPeriodDate());
    }
    return null;
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) CheckForNull(javax.annotation.CheckForNull)

Example 8 with SnapshotDto

use of org.sonar.db.component.SnapshotDto 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 9 with SnapshotDto

use of org.sonar.db.component.SnapshotDto 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)

Example 10 with SnapshotDto

use of org.sonar.db.component.SnapshotDto 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)

Aggregations

SnapshotDto (org.sonar.db.component.SnapshotDto)326 Test (org.junit.Test)257 ComponentDto (org.sonar.db.component.ComponentDto)219 MetricDto (org.sonar.db.metric.MetricDto)54 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)31 EventDto (org.sonar.db.event.EventDto)30 ProjectDto (org.sonar.db.project.ProjectDto)27 DbSession (org.sonar.db.DbSession)26 SnapshotTesting.newAnalysis (org.sonar.db.component.SnapshotTesting.newAnalysis)21 BranchDto (org.sonar.db.component.BranchDto)20 SearchEventsWsResponse (org.sonarqube.ws.Developers.SearchEventsWsResponse)20 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)17 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)14 DbClient (org.sonar.db.DbClient)14 NotFoundException (org.sonar.server.exceptions.NotFoundException)14 List (java.util.List)13 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 Rule (org.junit.Rule)13 UserRole (org.sonar.api.web.UserRole)13 DbTester (org.sonar.db.DbTester)13