use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class SearchAction method doHandle.
private SearchWsResponse doHandle(SearchWsRequest searchWsRequest) {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto component = getComponentByUuidOrKey(dbSession, searchWsRequest);
List<ComponentLinkDto> links = dbClient.componentLinkDao().selectByComponentUuid(dbSession, component.uuid());
return buildResponse(links);
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class SetAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String projectKey = request.mandatoryParam(PARAM_PROJECT);
List<String> tags = request.mandatoryParamAsStrings(PARAM_TAGS).stream().filter(StringUtils::isNotBlank).map(t -> t.toLowerCase(Locale.ENGLISH)).map(SetAction::checkTag).distinct().collect(Collectors.toList());
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto project = componentFinder.getByKey(dbSession, projectKey);
checkRequest(project.isRootProject(), "Component must be a project");
userSession.checkComponentUuidPermission(UserRole.ADMIN, project.uuid());
project.setTags(tags);
dbClient.componentDao().updateTags(dbSession, project);
dbSession.commit();
indexers.forEach(i -> i.indexProject(project.uuid(), PROJECT_TAGS_UPDATE));
}
response.noContent();
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class BulkDeleteAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
List<String> uuids = request.paramAsStrings(PARAM_PROJECT_IDS);
List<String> keys = request.paramAsStrings(PARAM_PROJECTS);
String orgKey = request.param(ProjectsWsSupport.PARAM_ORGANIZATION);
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<OrganizationDto> org = loadOrganizationByKey(dbSession, orgKey);
List<ComponentDto> projects = searchProjects(dbSession, uuids, keys);
projects.stream().filter(p -> !org.isPresent() || org.get().getUuid().equals(p.getOrganizationUuid())).forEach(p -> componentCleanerService.delete(dbSession, p));
}
response.noContent();
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class CreateAction method doHandle.
private CreateWsResponse doHandle(CreateRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = support.getOrganization(dbSession, ofNullable(request.getOrganization()).orElseGet(defaultOrganizationProvider.get()::getKey));
userSession.checkPermission(PROVISION_PROJECTS, organization);
ComponentDto componentDto = componentUpdater.create(dbSession, newComponentBuilder().setOrganizationUuid(organization.getUuid()).setKey(request.getKey()).setName(request.getName()).setBranch(request.getBranch()).setQualifier(PROJECT).build(), userSession.isLoggedIn() ? userSession.getUserId() : null);
return toCreateResponse(componentDto);
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class QualityGates method delete.
public void delete(long idToDelete) {
checkIsSystemAdministrator();
QualityGateDto qGate = getNonNullQgate(idToDelete);
try (DbSession session = dbClient.openSession(false)) {
if (isDefault(qGate)) {
propertiesDao.deleteGlobalProperty(SONAR_QUALITYGATE_PROPERTY, session);
}
propertiesDao.deleteProjectProperties(SONAR_QUALITYGATE_PROPERTY, Long.toString(idToDelete), session);
dao.delete(qGate, session);
session.commit();
}
}
Aggregations