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