use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class IssueQueryFactoryTest method new_code_period_does_not_rely_on_date_for_reference_branch.
@Test
public void new_code_period_does_not_rely_on_date_for_reference_branch() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
SnapshotDto analysis = db.components().insertSnapshot(project, s -> s.setPeriodMode(REFERENCE_BRANCH.name()).setPeriodParam("master"));
SearchRequest request = new SearchRequest().setComponentUuids(Collections.singletonList(file.uuid())).setOnComponentOnly(true).setInNewCodePeriod(true);
IssueQuery query = underTest.create(request);
assertThat(query.componentUuids()).containsOnly(file.uuid());
assertThat(query.newCodeOnReference()).isTrue();
assertThat(query.createdAfter()).isNull();
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class IssueQueryFactoryTest method leak_period_does_not_rely_on_date_for_reference_branch.
@Test
public void leak_period_does_not_rely_on_date_for_reference_branch() {
long leakPeriodStart = addDays(new Date(), -14).getTime();
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
SnapshotDto analysis = db.components().insertSnapshot(project, s -> s.setPeriodMode(REFERENCE_BRANCH.name()).setPeriodParam("master"));
SearchRequest request = new SearchRequest().setComponentUuids(Collections.singletonList(file.uuid())).setOnComponentOnly(true).setSinceLeakPeriod(true);
IssueQuery query = underTest.create(request);
assertThat(query.componentUuids()).containsOnly(file.uuid());
assertThat(query.newCodeOnReference()).isTrue();
assertThat(query.createdAfter()).isNull();
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ListAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String projectKey = request.mandatoryParam(PARAM_PROJECT);
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto projectOrApp = componentFinder.getProjectOrApplicationByKey(dbSession, projectKey);
checkPermission(projectOrApp);
Collection<BranchDto> branches = dbClient.branchDao().selectByProject(dbSession, projectOrApp).stream().filter(b -> b.getBranchType() == BRANCH).collect(toList());
List<String> branchUuids = branches.stream().map(BranchDto::getUuid).collect(toList());
Map<String, LiveMeasureDto> qualityGateMeasuresByComponentUuids = dbClient.liveMeasureDao().selectByComponentUuidsAndMetricKeys(dbSession, branchUuids, singletonList(ALERT_STATUS_KEY)).stream().collect(uniqueIndex(LiveMeasureDto::getComponentUuid));
Map<String, String> analysisDateByBranchUuid = dbClient.snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, branchUuids).stream().collect(uniqueIndex(SnapshotDto::getComponentUuid, s -> formatDateTime(s.getCreatedAt())));
ProjectBranches.ListWsResponse.Builder protobufResponse = ProjectBranches.ListWsResponse.newBuilder();
branches.forEach(b -> addBranch(protobufResponse, b, qualityGateMeasuresByComponentUuids.get(b.getUuid()), analysisDateByBranchUuid.get(b.getUuid())));
WsUtils.writeProtobuf(protobufResponse.build(), request, response);
}
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ComponentTreeAction method load.
private ComponentTreeData load(ComponentTreeRequest wsRequest) {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto baseComponent = loadComponent(dbSession, wsRequest);
checkPermissions(baseComponent);
Optional<SnapshotDto> baseSnapshot = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, baseComponent.projectUuid());
if (baseSnapshot.isEmpty()) {
return ComponentTreeData.builder().setBaseComponent(baseComponent).build();
}
Set<String> requestedMetricKeys = new HashSet<>(wsRequest.getMetricKeys());
Set<String> metricKeysToSearch = new HashSet<>(requestedMetricKeys);
boolean isPR = isPR(wsRequest.getPullRequest());
if (isPR) {
PrMeasureFix.addReplacementMetricKeys(metricKeysToSearch);
}
ComponentTreeQuery componentTreeQuery = toComponentTreeQuery(wsRequest, baseComponent);
List<ComponentDto> components = searchComponents(dbSession, componentTreeQuery);
List<MetricDto> metrics = searchMetrics(dbSession, metricKeysToSearch);
Table<String, MetricDto, ComponentTreeData.Measure> measuresByComponentUuidAndMetric = searchMeasuresByComponentUuidAndMetric(dbSession, baseComponent, componentTreeQuery, components, metrics);
if (isPR) {
PrMeasureFix.removeMetricsNotRequested(metrics, requestedMetricKeys);
PrMeasureFix.createReplacementMeasures(metrics, measuresByComponentUuidAndMetric, requestedMetricKeys);
}
components = filterComponents(components, measuresByComponentUuidAndMetric, metrics, wsRequest);
components = filterAuthorizedComponents(components);
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).setPeriod(snapshotToWsPeriods(baseSnapshot.get()).orElse(null)).setReferenceComponentsByUuid(searchReferenceComponentsById(dbSession, components)).build();
}
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class SearchAction method doHandle.
private SearchWsResponse doHandle(SearchRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
userSession.checkPermission(GlobalPermission.ADMINISTER);
ComponentQuery query = buildDbQuery(request);
Paging paging = buildPaging(dbSession, request, query);
List<ComponentDto> components = dbClient.componentDao().selectByQuery(dbSession, query, paging.offset(), paging.pageSize());
Set<String> componentUuids = components.stream().map(ComponentDto::uuid).collect(MoreCollectors.toHashSet(components.size()));
Map<String, Long> lastAnalysisDateByComponentUuid = dbClient.snapshotDao().selectLastAnalysisDateByProjects(dbSession, componentUuids).stream().collect(Collectors.toMap(ProjectLastAnalysisDateDto::getProjectUuid, ProjectLastAnalysisDateDto::getDate));
Map<String, SnapshotDto> snapshotsByComponentUuid = dbClient.snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, componentUuids).stream().collect(MoreCollectors.uniqueIndex(SnapshotDto::getComponentUuid, identity()));
return buildResponse(components, snapshotsByComponentUuid, lastAnalysisDateByComponentUuid, paging);
}
}
Aggregations