Search in sources :

Example 71 with DbSession

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

Example 72 with DbSession

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();
}
Also used : PROJECT_TAGS_UPDATE(org.sonar.server.es.ProjectIndexer.Cause.PROJECT_TAGS_UPDATE) ComponentFinder(org.sonar.server.component.ComponentFinder) StringUtils(org.apache.commons.lang.StringUtils) Collectors(org.sonar.core.util.stream.Collectors) DbSession(org.sonar.db.DbSession) Request(org.sonar.api.server.ws.Request) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) UserRole(org.sonar.api.web.UserRole) WebService(org.sonar.api.server.ws.WebService) WsUtils.checkRequest(org.sonar.server.ws.WsUtils.checkRequest) Locale(java.util.Locale) Response(org.sonar.api.server.ws.Response) ProjectIndexer(org.sonar.server.es.ProjectIndexer) KEY_PROJECT_EXAMPLE_001(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001) UserSession(org.sonar.server.user.UserSession) DbSession(org.sonar.db.DbSession) StringUtils(org.apache.commons.lang.StringUtils) ComponentDto(org.sonar.db.component.ComponentDto)

Example 73 with DbSession

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();
}
Also used : ADMINISTER(org.sonar.db.permission.OrganizationPermission.ADMINISTER) DbSession(org.sonar.db.DbSession) Request(org.sonar.api.server.ws.Request) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) WebService(org.sonar.api.server.ws.WebService) Response(org.sonar.api.server.ws.Response) Optional(java.util.Optional) KEY_PROJECT_EXAMPLE_001(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001) OrganizationDto(org.sonar.db.organization.OrganizationDto) UserSession(org.sonar.server.user.UserSession) Nullable(javax.annotation.Nullable) ComponentCleanerService(org.sonar.server.component.ComponentCleanerService) DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 74 with DbSession

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

Example 75 with DbSession

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

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