use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class BulkChangeAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
try (DbSession dbSession = dbClient.openSession(false)) {
Issues.BulkChangeWsResponse wsResponse = Stream.of(request).map(loadData(dbSession)).map(executeBulkChange()).map(toWsResponse()).collect(Collectors.toOneElement());
writeProtobuf(wsResponse, request, response);
}
}
use of org.sonar.db.DbSession 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.DbSession in project sonarqube by SonarSource.
the class SearchAction method handle.
@Override
public void handle(Request httpRequest, Response httpResponse) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
SearchWsResponse response = new ResponseBuilder(httpRequest, dbSession).build();
writeProtobuf(response, httpRequest, httpResponse);
}
}
use of org.sonar.db.DbSession 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.DbSession in project sonarqube by SonarSource.
the class DefaultOrganizationProviderImpl method getDefaultOrganization.
private static DefaultOrganization getDefaultOrganization(DbClient dbClient) {
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<String> uuid = dbClient.internalPropertiesDao().selectByKey(dbSession, InternalProperties.DEFAULT_ORGANIZATION);
checkState(uuid.isPresent() && !uuid.get().isEmpty(), "No Default organization uuid configured");
Optional<OrganizationDto> dto = dbClient.organizationDao().selectByUuid(dbSession, uuid.get());
checkState(dto.isPresent(), "Default organization with uuid '%s' does not exist", uuid.get());
return toDefaultOrganization(dto.get());
}
}
Aggregations