Search in sources :

Example 1 with SnapshotDto

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

the class ProjectMeasuresIndexerIteratorTest method insertProjectAndMeasure.

private MeasureDto insertProjectAndMeasure(String projectUuid, MetricDto metric, String value) {
    ComponentDto project = newProjectDto(dbTester.getDefaultOrganization(), projectUuid);
    SnapshotDto analysis1 = dbTester.components().insertProjectAndSnapshot(project);
    return insertMeasure(project, analysis1, metric, value);
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto)

Example 2 with SnapshotDto

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

the class ProjectMeasuresIndexerIteratorTest method fail_when_measure_return_no_value.

@Test
public void fail_when_measure_return_no_value() throws Exception {
    MetricDto metric = insertIntMetric("new_lines");
    ComponentDto project = newProjectDto(dbTester.getDefaultOrganization());
    SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
    insertMeasure(project, analysis, metric, 10d);
    expectedException.expect(IllegalStateException.class);
    createResultSetAndReturnDocsById();
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 3 with SnapshotDto

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

the class SearchProjectsAction method searchData.

private SearchResults searchData(DbSession dbSession, SearchProjectsRequest request, @Nullable OrganizationDto organization) {
    Set<String> favoriteProjectUuids = loadFavoriteProjectUuids(dbSession);
    List<Criterion> criteria = FilterParser.parse(firstNonNull(request.getFilter(), ""));
    ProjectMeasuresQuery query = newProjectMeasuresQuery(criteria, hasFavoriteFilter(criteria) ? favoriteProjectUuids : null).setSort(request.getSort()).setAsc(request.getAsc());
    Optional.ofNullable(organization).map(OrganizationDto::getUuid).ifPresent(query::setOrganizationUuid);
    queryValidator.validate(dbSession, query);
    SearchIdResult<String> esResults = index.search(query, new SearchOptions().addFacets(request.getFacets()).setPage(request.getPage(), request.getPageSize()));
    List<String> projectUuids = esResults.getIds();
    Ordering<ComponentDto> ordering = Ordering.explicit(projectUuids).onResultOf(ComponentDto::uuid);
    List<ComponentDto> projects = ordering.immutableSortedCopy(dbClient.componentDao().selectByUuids(dbSession, projectUuids));
    Map<String, SnapshotDto> analysisByProjectUuid = getSnapshots(dbSession, request, projectUuids);
    return new SearchResults(projects, favoriteProjectUuids, esResults, analysisByProjectUuid, query);
}
Also used : ProjectMeasuresQueryFactory.newProjectMeasuresQuery(org.sonar.server.component.ws.ProjectMeasuresQueryFactory.newProjectMeasuresQuery) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Criterion(org.sonar.server.component.ws.FilterParser.Criterion)

Example 4 with SnapshotDto

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

the class PeriodResolver method findNearestSnapshotToTargetDate.

@CheckForNull
private static SnapshotDto findNearestSnapshotToTargetDate(List<SnapshotDto> snapshots, Long targetDate) {
    long bestDistance = Long.MAX_VALUE;
    SnapshotDto nearest = null;
    for (SnapshotDto snapshot : snapshots) {
        long distance = Math.abs(snapshot.getCreatedAt() - targetDate);
        if (distance <= bestDistance) {
            bestDistance = distance;
            nearest = snapshot;
        }
    }
    return nearest;
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) CheckForNull(javax.annotation.CheckForNull)

Example 5 with SnapshotDto

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

the class PeriodResolver method findByDays.

@CheckForNull
private Period findByDays(int days) {
    List<SnapshotDto> snapshots = dbClient.snapshotDao().selectAnalysesByQuery(session, createCommonQuery(projectUuid).setCreatedBefore(analysisDate).setSort(BY_DATE, ASC));
    long targetDate = DateUtils.addDays(new Date(analysisDate), -days).getTime();
    SnapshotDto snapshot = findNearestSnapshotToTargetDate(snapshots, targetDate);
    if (snapshot == null) {
        return null;
    }
    LOG.debug("Compare over {} days ({}, analysis of {})", String.valueOf(days), formatDate(targetDate), formatDate(snapshot.getCreatedAt()));
    return new Period(LEAK_PERIOD_MODE_DAYS, String.valueOf(days), snapshot.getCreatedAt(), snapshot.getUuid());
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) Period(org.sonar.server.computation.task.projectanalysis.period.Period) Date(java.util.Date) CheckForNull(javax.annotation.CheckForNull)

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