Search in sources :

Example 26 with QProfileDto

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

the class InheritanceAction method collectAncestors.

private void collectAncestors(QProfileDto profile, List<QProfileDto> ancestors, DbSession session) {
    if (profile.getParentKee() == null) {
        return;
    }
    QProfileDto parent = getParent(session, profile);
    ancestors.add(parent);
    collectAncestors(parent, ancestors, session);
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto)

Example 27 with QProfileDto

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

the class InheritanceAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    QProfileReference reference = QProfileReference.fromName(request);
    try (DbSession dbSession = dbClient.openSession(false)) {
        QProfileDto profile = wsSupport.getProfile(dbSession, reference);
        List<QProfileDto> ancestors = ancestors(profile, dbSession);
        List<QProfileDto> children = dbClient.qualityProfileDao().selectChildren(dbSession, singleton(profile));
        List<QProfileDto> allProfiles = new ArrayList<>();
        allProfiles.add(profile);
        allProfiles.addAll(ancestors);
        allProfiles.addAll(children);
        Statistics statistics = new Statistics(dbSession, allProfiles);
        writeProtobuf(buildResponse(profile, ancestors, children, statistics), request, response);
    }
}
Also used : DbSession(org.sonar.db.DbSession) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) ArrayList(java.util.ArrayList)

Example 28 with QProfileDto

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

the class RemoveProjectAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn();
    try (DbSession dbSession = dbClient.openSession(false)) {
        ProjectDto project = loadProject(dbSession, request);
        QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromName(request));
        checkPermissions(dbSession, profile, project);
        dbClient.qualityProfileDao().deleteProjectProfileAssociation(dbSession, project, profile);
        dbSession.commit();
        QProfileDto activatedProfile = null;
        // publish change for rules in the default quality profile
        QProfileDto defaultProfile = dbClient.qualityProfileDao().selectDefaultProfile(dbSession, profile.getLanguage());
        if (defaultProfile != null) {
            activatedProfile = defaultProfile;
        }
        qualityProfileChangeEventService.publishRuleActivationToSonarLintClients(project, activatedProfile, profile);
        response.noContent();
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) DbSession(org.sonar.db.DbSession) QProfileDto(org.sonar.db.qualityprofile.QProfileDto)

Example 29 with QProfileDto

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

the class ActiveRuleCompleter method writeActiveRules.

private Set<String> writeActiveRules(DbSession dbSession, SearchResponse.Builder response, RuleQuery query, List<RuleDto> rules) {
    final Set<String> profileUuids = new HashSet<>();
    Rules.Actives.Builder activesBuilder = response.getActivesBuilder();
    QProfileDto profile = query.getQProfile();
    if (profile != null) {
        // Load details of active rules on the selected profile
        List<OrgActiveRuleDto> activeRules = dbClient.activeRuleDao().selectByProfile(dbSession, profile);
        Map<RuleKey, OrgActiveRuleDto> activeRuleByRuleKey = activeRules.stream().collect(uniqueIndex(ActiveRuleDto::getRuleKey));
        ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = loadParams(dbSession, activeRules);
        for (RuleDto rule : rules) {
            OrgActiveRuleDto activeRule = activeRuleByRuleKey.get(rule.getKey());
            if (activeRule != null) {
                profileUuids.addAll(writeActiveRules(rule.getKey(), singletonList(activeRule), activeRuleParamsByActiveRuleKey, activesBuilder));
            }
        }
    } else {
        // Load details of all active rules
        List<String> ruleUuids = Lists.transform(rules, RuleDto::getUuid);
        List<OrgActiveRuleDto> activeRules = dbClient.activeRuleDao().selectByRuleUuids(dbSession, ruleUuids);
        Multimap<RuleKey, OrgActiveRuleDto> activeRulesByRuleKey = activeRules.stream().collect(MoreCollectors.index(OrgActiveRuleDto::getRuleKey));
        ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = loadParams(dbSession, activeRules);
        rules.forEach(rule -> profileUuids.addAll(writeActiveRules(rule.getKey(), activeRulesByRuleKey.get(rule.getKey()), activeRuleParamsByActiveRuleKey, activesBuilder)));
    }
    response.setActives(activesBuilder);
    return profileUuids;
}
Also used : ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) RuleKey(org.sonar.api.rule.RuleKey) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) OrgActiveRuleDto(org.sonar.db.qualityprofile.OrgActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) OrgActiveRuleDto(org.sonar.db.qualityprofile.OrgActiveRuleDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) HashSet(java.util.HashSet)

Example 30 with QProfileDto

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

the class RuleQueryFactory method setProfile.

private void setProfile(DbSession dbSession, RuleQuery query, Request request) {
    String profileUuid = request.param(PARAM_QPROFILE);
    if (profileUuid == null) {
        return;
    }
    QProfileDto profileOptional = dbClient.qualityProfileDao().selectByUuid(dbSession, profileUuid);
    QProfileDto profile = checkFound(profileOptional, "The specified qualityProfile '%s' does not exist", profileUuid);
    query.setQProfile(profile);
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto)

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