Search in sources :

Example 36 with DbSession

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);
    }
}
Also used : DbSession(org.sonar.db.DbSession) Issues(org.sonarqube.ws.Issues)

Example 37 with DbSession

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();
    }
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) MeasureDto(org.sonar.db.measure.MeasureDto) DbSession(org.sonar.db.DbSession) MetricDto(org.sonar.db.metric.MetricDto) ComponentTreeQuery(org.sonar.db.component.ComponentTreeQuery)

Example 38 with DbSession

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);
    }
}
Also used : DbSession(org.sonar.db.DbSession) SearchWsResponse(org.sonarqube.ws.WsMeasures.SearchWsResponse)

Example 39 with DbSession

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);
    }
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) DbSession(org.sonar.db.DbSession) MetricDto(org.sonar.db.metric.MetricDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto)

Example 40 with DbSession

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());
    }
}
Also used : DbSession(org.sonar.db.DbSession) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Aggregations

DbSession (org.sonar.db.DbSession)254 ComponentDto (org.sonar.db.component.ComponentDto)63 OrganizationDto (org.sonar.db.organization.OrganizationDto)30 JsonWriter (org.sonar.api.utils.text.JsonWriter)24 UserDto (org.sonar.db.user.UserDto)20 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)16 Test (org.junit.Test)13 MetricDto (org.sonar.db.metric.MetricDto)13 Paging (org.sonar.api.utils.Paging)12 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)10 CeQueueDto (org.sonar.db.ce.CeQueueDto)8 DepthTraversalTypeAwareCrawler (org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler)8 SearchOptions (org.sonar.server.es.SearchOptions)8 NotFoundException (org.sonar.server.exceptions.NotFoundException)8 List (java.util.List)7 SnapshotDto (org.sonar.db.component.SnapshotDto)7 GroupDto (org.sonar.db.user.GroupDto)7 DbClient (org.sonar.db.DbClient)6 ProjectId (org.sonar.server.permission.ProjectId)6 RuleKey (org.sonar.api.rule.RuleKey)5