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