Search in sources :

Example 16 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class SearchUsersAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    SearchQualityProfileUsersRequest wsRequest = buildRequest(request);
    try (DbSession dbSession = dbClient.openSession(false)) {
        QProfileDto profile = wsSupport.getProfile(dbSession, wsRequest.getQualityProfile(), wsRequest.getLanguage());
        wsSupport.checkCanEdit(dbSession, profile);
        SearchQualityProfilePermissionQuery query = builder().setProfile(profile).setQuery(wsRequest.getQuery()).setMembership(MEMBERSHIP.get(fromParam(wsRequest.getSelected()))).build();
        int total = dbClient.qProfileEditUsersDao().countByQuery(dbSession, query);
        List<SearchUserMembershipDto> usersMembership = dbClient.qProfileEditUsersDao().selectByQuery(dbSession, query, forPage(wsRequest.getPage()).andSize(wsRequest.getPageSize()));
        Map<String, UserDto> usersById = dbClient.userDao().selectByUuids(dbSession, usersMembership.stream().map(SearchUserMembershipDto::getUserUuid).collect(toList())).stream().collect(uniqueIndex(UserDto::getUuid));
        writeProtobuf(SearchUsersResponse.newBuilder().addAllUsers(usersMembership.stream().map(userMembershipDto -> toUser(usersById.get(userMembershipDto.getUserUuid()), userMembershipDto.isSelected())).collect(toList())).setPaging(buildPaging(wsRequest, total)).build(), request, response);
    }
}
Also used : TEXT_QUERY(org.sonar.api.server.ws.WebService.Param.TEXT_QUERY) Arrays(java.util.Arrays) ACTION_SEARCH_USERS(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SEARCH_USERS) UserDto(org.sonar.db.user.UserDto) SELECTED(org.sonar.api.server.ws.WebService.Param.SELECTED) DbSession(org.sonar.db.DbSession) ALL(org.sonar.api.server.ws.WebService.SelectionMode.ALL) SearchUserMembershipDto(org.sonar.db.user.SearchUserMembershipDto) PAGE(org.sonar.api.server.ws.WebService.Param.PAGE) ANY(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.ANY) Request(org.sonar.api.server.ws.Request) Languages(org.sonar.api.resources.Languages) MoreCollectors.toSet(org.sonar.core.util.stream.MoreCollectors.toSet) WebService(org.sonar.api.server.ws.WebService) SelectionMode.fromParam(org.sonar.api.server.ws.WebService.SelectionMode.fromParam) PARAM_LANGUAGE(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE) Map(java.util.Map) Response(org.sonar.api.server.ws.Response) SelectionMode(org.sonar.api.server.ws.WebService.SelectionMode) Language(org.sonar.api.resources.Language) PARAM_QUALITY_PROFILE(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE) MoreCollectors.toList(org.sonar.core.util.stream.MoreCollectors.toList) Pagination.forPage(org.sonar.db.Pagination.forPage) ImmutableMap(com.google.common.collect.ImmutableMap) Optional.ofNullable(java.util.Optional.ofNullable) AvatarResolver(org.sonar.server.issue.AvatarResolver) Common(org.sonarqube.ws.Common) DbClient(org.sonar.db.DbClient) List(java.util.List) Strings.emptyToNull(com.google.common.base.Strings.emptyToNull) OUT(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.OUT) SearchQualityProfilePermissionQuery(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery) IN(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.IN) SearchUsersResponse(org.sonarqube.ws.Qualityprofiles.SearchUsersResponse) DESELECTED(org.sonar.api.server.ws.WebService.SelectionMode.DESELECTED) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) MoreCollectors.uniqueIndex(org.sonar.core.util.stream.MoreCollectors.uniqueIndex) PAGE_SIZE(org.sonar.api.server.ws.WebService.Param.PAGE_SIZE) SearchQualityProfilePermissionQuery.builder(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.builder) WsUtils.writeProtobuf(org.sonar.server.ws.WsUtils.writeProtobuf) DbSession(org.sonar.db.DbSession) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) UserDto(org.sonar.db.user.UserDto) SearchUserMembershipDto(org.sonar.db.user.SearchUserMembershipDto) SearchQualityProfilePermissionQuery(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery)

Example 17 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class ShowAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        QProfileDto profile = qProfileWsSupport.getProfile(dbSession, QProfileReference.fromKey(request.mandatoryParam(PARAM_KEY)));
        boolean isDefault = dbClient.defaultQProfileDao().isDefault(dbSession, profile.getKee());
        ActiveRuleCountQuery.Builder builder = ActiveRuleCountQuery.builder();
        long activeRuleCount = countActiveRulesByQuery(dbSession, profile, builder);
        long deprecatedActiveRuleCount = countActiveRulesByQuery(dbSession, profile, builder.setRuleStatus(DEPRECATED));
        long projectCount = countProjectsByProfiles(dbSession, profile);
        CompareToSonarWay compareToSonarWay = getSonarWay(request, dbSession, profile);
        writeProtobuf(buildResponse(profile, isDefault, getLanguage(profile), activeRuleCount, deprecatedActiveRuleCount, projectCount, compareToSonarWay), request, response);
    }
}
Also used : DbSession(org.sonar.db.DbSession) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) ActiveRuleCountQuery(org.sonar.db.qualityprofile.ActiveRuleCountQuery) CompareToSonarWay(org.sonarqube.ws.Qualityprofiles.ShowResponse.CompareToSonarWay)

Example 18 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class DeactivateRulesAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String qualityProfileKey = request.mandatoryParam(PARAM_TARGET_KEY);
    userSession.checkLoggedIn();
    BulkChangeResult result;
    try (DbSession dbSession = dbClient.openSession(false)) {
        QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(qualityProfileKey));
        wsSupport.checkCanEdit(dbSession, profile);
        RuleQuery ruleQuery = ruleQueryFactory.createRuleQuery(dbSession, request);
        ruleQuery.setIncludeExternal(false);
        result = ruleActivator.bulkDeactivateAndCommit(dbSession, profile, ruleQuery);
    }
    writeResponse(result, response);
}
Also used : DbSession(org.sonar.db.DbSession) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) BulkChangeResult(org.sonar.server.qualityprofile.BulkChangeResult) RuleQuery(org.sonar.server.rule.index.RuleQuery)

Example 19 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class ExportAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String name = request.param(PARAM_QUALITY_PROFILE);
    String language = request.mandatoryParam(PARAM_LANGUAGE);
    try (DbSession dbSession = dbClient.openSession(false)) {
        QProfileDto profile = loadProfile(dbSession, language, name);
        String exporterKey = exporters.exportersForLanguage(profile.getLanguage()).isEmpty() ? null : request.param(PARAM_EXPORTER_KEY);
        writeResponse(dbSession, profile, exporterKey, response);
    }
}
Also used : DbSession(org.sonar.db.DbSession) QProfileDto(org.sonar.db.qualityprofile.QProfileDto)

Example 20 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class ProjectsAction method loadAllProjects.

private List<ProjectQprofileAssociationDto> loadAllProjects(String profileKey, DbSession session, String selected, String query) {
    QProfileDto profile = dbClient.qualityProfileDao().selectByUuid(session, profileKey);
    if (profile == null) {
        throw new NotFoundException("Quality profile not found: " + profileKey);
    }
    List<ProjectQprofileAssociationDto> projects;
    SelectionMode selectionMode = SelectionMode.fromParam(selected);
    if (SelectionMode.SELECTED == selectionMode) {
        projects = dbClient.qualityProfileDao().selectSelectedProjects(session, profile, query);
    } else if (SelectionMode.DESELECTED == selectionMode) {
        projects = dbClient.qualityProfileDao().selectDeselectedProjects(session, profile, query);
    } else {
        projects = dbClient.qualityProfileDao().selectProjectAssociations(session, profile, query);
    }
    return projects;
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) NotFoundException(org.sonar.server.exceptions.NotFoundException) ProjectQprofileAssociationDto(org.sonar.db.qualityprofile.ProjectQprofileAssociationDto) SelectionMode(org.sonar.api.server.ws.WebService.SelectionMode)

Aggregations

QProfileDto (org.sonar.db.qualityprofile.QProfileDto)389 Test (org.junit.Test)329 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)139 UserDto (org.sonar.db.user.UserDto)72 DbSession (org.sonar.db.DbSession)38 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)38 ProjectDto (org.sonar.db.project.ProjectDto)36 RuleParamDto (org.sonar.db.rule.RuleParamDto)36 GroupDto (org.sonar.db.user.GroupDto)35 NotFoundException (org.sonar.server.exceptions.NotFoundException)31 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)23 TestRequest (org.sonar.server.ws.TestRequest)23 System2 (org.sonar.api.utils.System2)22 RuleQuery (org.sonar.server.rule.index.RuleQuery)22 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)21 DbTester (org.sonar.db.DbTester)21 BadRequestException (org.sonar.server.exceptions.BadRequestException)20 UserSessionRule (org.sonar.server.tester.UserSessionRule)20 List (java.util.List)19 Rule (org.junit.Rule)19