use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class ProvisionedAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
SearchOptions options = new SearchOptions().setPage(request.mandatoryParamAsInt(Param.PAGE), request.mandatoryParamAsInt(Param.PAGE_SIZE));
Set<String> desiredFields = desiredFields(request);
String query = request.param(Param.TEXT_QUERY);
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = support.getOrganization(dbSession, request.getParam(PARAM_ORGANIZATION).or(defaultOrganizationProvider.get()::getKey));
userSession.checkPermission(PROVISION_PROJECTS, organization);
RowBounds rowBounds = new RowBounds(options.getOffset(), options.getLimit());
List<ComponentDto> projects = dbClient.componentDao().selectProvisioned(dbSession, organization.getUuid(), query, QUALIFIERS_FILTER, rowBounds);
int nbOfProjects = dbClient.componentDao().countProvisioned(dbSession, organization.getUuid(), query, QUALIFIERS_FILTER);
JsonWriter json = response.newJsonWriter().beginObject();
writeProjects(projects, json, desiredFields);
options.writeJson(json, nbOfProjects);
json.endObject().close();
}
}
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)) {
OrganizationDto organization = support.getOrganization(dbSession, ofNullable(request.getOrganization()).orElseGet(defaultOrganizationProvider.get()::getKey));
userSession.checkPermission(OrganizationPermission.ADMINISTER, organization);
ComponentQuery query = buildQuery(request);
Paging paging = buildPaging(dbSession, request, organization, query);
List<ComponentDto> components = dbClient.componentDao().selectByQuery(dbSession, organization.getUuid(), query, paging.offset(), paging.pageSize());
return buildResponse(components, organization, paging);
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class SelectAction method doHandle.
private void doHandle(SelectWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
checkQualityGate(dbSession, request.getGateId());
ComponentDto project = getProject(dbSession, request.getProjectId(), request.getProjectKey());
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(SONAR_QUALITYGATE_PROPERTY).setResourceId(project.getId()).setValue(String.valueOf(request.getGateId())));
dbSession.commit();
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class CreateEventAction method doHandle.
private CreateEventResponse doHandle(CreateEventRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
SnapshotDto analysis = getAnalysis(dbSession, request);
checkExistingDbEvents(dbSession, request, analysis);
EventDto dbEvent = insertDbEvent(dbSession, request, analysis);
return toCreateEventResponse(dbEvent);
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class CreateAction method doHandle.
private CreateWsResponse doHandle(CreateWsRequest createWsRequest) {
validateRequest(createWsRequest);
String name = createWsRequest.getName();
String url = createWsRequest.getUrl();
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto component = getComponentByUuidOrKey(dbSession, createWsRequest);
userSession.checkComponentPermission(UserRole.ADMIN, component);
ComponentLinkDto link = new ComponentLinkDto().setComponentUuid(component.uuid()).setName(name).setHref(url).setType(nameToType(name));
dbClient.componentLinkDao().insert(dbSession, link);
dbSession.commit();
return buildResponse(link);
}
}
Aggregations