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);
}
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();
}
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);
}
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;
}
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());
}
Aggregations