Search in sources :

Example 16 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class ComponentAction method handle.

@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto component = componentFinder.getByUuidOrKey(dbSession, wsRequest.param(PARAM_COMPONENT_ID), wsRequest.param(PARAM_COMPONENT_KEY), COMPONENT_ID_AND_KEY);
        userSession.checkComponentPermission(UserRole.USER, component);
        List<CeQueueDto> queueDtos = dbClient.ceQueueDao().selectByComponentUuid(dbSession, component.uuid());
        CeTaskQuery activityQuery = new CeTaskQuery().setComponentUuid(component.uuid()).setOnlyCurrents(true);
        List<CeActivityDto> activityDtos = dbClient.ceActivityDao().selectByQuery(dbSession, activityQuery, 0, 1);
        ProjectResponse.Builder wsResponseBuilder = ProjectResponse.newBuilder();
        wsResponseBuilder.addAllQueue(formatter.formatQueue(dbSession, queueDtos));
        if (activityDtos.size() == 1) {
            wsResponseBuilder.setCurrent(formatter.formatActivity(dbSession, activityDtos.get(0)));
        }
        writeProtobuf(wsResponseBuilder.build(), wsRequest, wsResponse);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ProjectResponse(org.sonarqube.ws.WsCe.ProjectResponse) CeActivityDto(org.sonar.db.ce.CeActivityDto) ComponentDto(org.sonar.db.component.ComponentDto) CeQueueDto(org.sonar.db.ce.CeQueueDto) CeTaskQuery(org.sonar.db.ce.CeTaskQuery)

Example 17 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class TaskAction method handle.

@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
    String taskUuid = wsRequest.mandatoryParam(PARAM_TASK_UUID);
    try (DbSession dbSession = dbClient.openSession(false)) {
        WsCe.TaskResponse.Builder wsTaskResponse = WsCe.TaskResponse.newBuilder();
        Optional<CeQueueDto> queueDto = dbClient.ceQueueDao().selectByUuid(dbSession, taskUuid);
        if (queueDto.isPresent()) {
            Optional<ComponentDto> component = loadComponent(dbSession, queueDto.get().getComponentUuid());
            checkPermission(component);
            wsTaskResponse.setTask(wsTaskFormatter.formatQueue(dbSession, queueDto.get(), component));
        } else {
            CeActivityDto ceActivityDto = WsUtils.checkFoundWithOptional(dbClient.ceActivityDao().selectByUuid(dbSession, taskUuid), "No activity found for task '%s'", taskUuid);
            Optional<ComponentDto> component = loadComponent(dbSession, ceActivityDto.getComponentUuid());
            checkPermission(component);
            Set<AdditionalField> additionalFields = AdditionalField.getFromRequest(wsRequest);
            maskErrorStacktrace(ceActivityDto, additionalFields);
            wsTaskResponse.setTask(wsTaskFormatter.formatActivity(dbSession, ceActivityDto, component, extractScannerContext(dbSession, ceActivityDto, additionalFields)));
        }
        writeProtobuf(wsTaskResponse.build(), wsRequest, wsResponse);
    }
}
Also used : DbSession(org.sonar.db.DbSession) CeActivityDto(org.sonar.db.ce.CeActivityDto) ComponentDto(org.sonar.db.component.ComponentDto) CeQueueDto(org.sonar.db.ce.CeQueueDto)

Example 18 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class SearchAction method doHandle.

private SearchWsResponse doHandle(SearchWsRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentQuery query = buildQuery(request);
        OrganizationDto organization = getOrganization(dbSession, request);
        Paging paging = buildPaging(dbSession, request, organization, query);
        List<ComponentDto> components = searchComponents(dbSession, organization, query, paging);
        return buildResponse(components, organization, paging);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentQuery(org.sonar.db.component.ComponentQuery) Paging(org.sonar.api.utils.Paging) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 19 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class MeasureRepositoryImpl method getBaseMeasure.

@Override
public Optional<Measure> getBaseMeasure(Component component, Metric metric) {
    // fail fast
    requireNonNull(component);
    requireNonNull(metric);
    try (DbSession dbSession = dbClient.openSession(false)) {
        MeasureQuery query = MeasureQuery.builder().setComponentUuid(component.getUuid()).setMetricKey(metric.getKey()).build();
        java.util.Optional<MeasureDto> measureDto = dbClient.measureDao().selectSingle(dbSession, query);
        if (measureDto.isPresent()) {
            return underTest.toMeasure(measureDto.get(), metric);
        }
        return Optional.absent();
    }
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) DbSession(org.sonar.db.DbSession) MeasureQuery(org.sonar.db.measure.MeasureQuery)

Example 20 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class MetricRepositoryImpl method start.

@Override
public void start() {
    DbSession dbSession = dbClient.openSession(false);
    try {
        List<MetricDto> metricList = dbClient.metricDao().selectEnabled(dbSession);
        this.metricsByKey = from(metricList).transform(MetricDtoToMetric.INSTANCE).uniqueIndex(MetricToKey.INSTANCE);
        this.metricsById = from(metricList).transform(MetricDtoToMetric.INSTANCE).uniqueIndex(MetricToId.INSTANCE);
    } finally {
        dbSession.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) MetricDto(org.sonar.db.metric.MetricDto)

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