Search in sources :

Example 51 with DbSession

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

the class DeleteAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn().checkIsSystemAdministrator();
    try (DbSession dbSession = dbClient.openSession(false)) {
        List<Integer> ids = loadIds(dbSession, request);
        dbClient.metricDao().disableCustomByIds(dbSession, ids);
        dbClient.customMeasureDao().deleteByMetricIds(dbSession, ids);
        dbSession.commit();
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession)

Example 52 with DbSession

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

the class AutoDbMigration method installH2.

@VisibleForTesting
void installH2() {
    Connection connection = null;
    try (DbSession session = dbClient.openSession(false)) {
        connection = session.getConnection();
        createH2Schema(connection, dbClient.getDatabase().getDialect().getId());
    } finally {
        DbUtils.closeQuietly(connection);
    }
}
Also used : DbSession(org.sonar.db.DbSession) Connection(java.sql.Connection) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 53 with DbSession

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

the class RemoveGroupFromTemplateAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        String permission = request.mandatoryParam(PARAM_PERMISSION);
        PermissionTemplateDto template = wsSupport.findTemplate(dbSession, WsTemplateRef.fromRequest(request));
        checkGlobalAdmin(userSession, template.getOrganizationUuid());
        GroupIdOrAnyone groupId = wsSupport.findGroup(dbSession, request);
        checkArgument(groupId.getOrganizationUuid().equals(template.getOrganizationUuid()), "Group and template are on different organizations");
        dbClient.permissionTemplateDao().deleteGroupPermission(dbSession, template.getId(), groupId.getId(), permission);
        dbSession.commit();
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) GroupIdOrAnyone(org.sonar.server.usergroups.ws.GroupIdOrAnyone)

Example 54 with DbSession

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

the class SetDefaultTemplateAction method doHandle.

private void doHandle(SetDefaultTemplateWsRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        String qualifier = request.getQualifier();
        PermissionTemplateDto template = findTemplate(dbSession, request);
        checkGlobalAdmin(userSession, template.getOrganizationUuid());
        validateQualifier(qualifier, resourceTypes);
        setDefaultTemplateUuid(dbSession, template, qualifier);
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto)

Example 55 with DbSession

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

the class TemplateUsersAction method handle.

@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        WsTemplateRef templateRef = WsTemplateRef.fromRequest(wsRequest);
        PermissionTemplateDto template = support.findTemplate(dbSession, templateRef);
        checkGlobalAdmin(userSession, template.getOrganizationUuid());
        PermissionQuery query = buildQuery(wsRequest, template);
        int total = dbClient.permissionTemplateDao().countUserLoginsByQueryAndTemplate(dbSession, query, template.getId());
        Paging paging = Paging.forPageIndex(wsRequest.mandatoryParamAsInt(PAGE)).withPageSize(wsRequest.mandatoryParamAsInt(PAGE_SIZE)).andTotal(total);
        List<UserDto> users = findUsers(dbSession, query, template);
        List<PermissionTemplateUserDto> permissionTemplateUsers = dbClient.permissionTemplateDao().selectUserPermissionsByTemplateIdAndUserLogins(dbSession, template.getId(), users.stream().map(UserDto::getLogin).collect(Collectors.toList()));
        WsPermissions.UsersWsResponse templateUsersResponse = buildResponse(users, permissionTemplateUsers, paging);
        writeProtobuf(templateUsersResponse, wsRequest, wsResponse);
    }
}
Also used : DbSession(org.sonar.db.DbSession) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) UsersWsResponse(org.sonarqube.ws.WsPermissions.UsersWsResponse) PermissionTemplateUserDto(org.sonar.db.permission.template.PermissionTemplateUserDto) Paging(org.sonar.api.utils.Paging) UserDto(org.sonar.db.user.UserDto) PermissionTemplateUserDto(org.sonar.db.permission.template.PermissionTemplateUserDto) WsPermissions(org.sonarqube.ws.WsPermissions) PermissionQuery(org.sonar.db.permission.PermissionQuery)

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