Search in sources :

Example 16 with QualityProfileDto

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

the class RuleActivator method cascadeActivation.

private List<ActiveRuleChange> cascadeActivation(DbSession session, RuleActivation activation, String profileKey) {
    List<ActiveRuleChange> changes = Lists.newArrayList();
    // get all inherited profiles
    List<QualityProfileDto> children = db.qualityProfileDao().selectChildren(session, profileKey);
    for (QualityProfileDto child : children) {
        RuleActivation childActivation = new RuleActivation(activation).setCascade(true);
        changes.addAll(activate(session, childActivation, child.getKey()));
    }
    return changes;
}
Also used : QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 17 with QualityProfileDto

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

the class RuleActivator method setParent.

public List<ActiveRuleChange> setParent(DbSession dbSession, String profileKey, @Nullable String parentKey) {
    QualityProfileDto profile = db.qualityProfileDao().selectOrFailByKey(dbSession, profileKey);
    List<ActiveRuleChange> changes = new ArrayList<>();
    if (parentKey == null) {
        // unset if parent is defined, else nothing to do
        changes.addAll(removeParent(dbSession, profile));
    } else if (profile.getParentKee() == null || !parentKey.equals(profile.getParentKee())) {
        QualityProfileDto parentProfile = db.qualityProfileDao().selectOrFailByKey(dbSession, parentKey);
        checkRequest(!isDescendant(dbSession, profile, parentProfile), "Descendant profile '%s' can not be selected as parent of '%s'", parentKey, profileKey);
        changes.addAll(removeParent(dbSession, profile));
        // set new parent
        profile.setParentKee(parentKey);
        db.qualityProfileDao().update(dbSession, profile);
        for (ActiveRuleDto parentActiveRule : db.activeRuleDao().selectByProfileKey(dbSession, parentKey)) {
            try {
                RuleActivation activation = new RuleActivation(parentActiveRule.getKey().ruleKey());
                changes.addAll(activate(dbSession, activation, profileKey));
            } catch (BadRequestException e) {
            // for example because rule status is REMOVED
            // TODO return errors
            }
        }
    }
    dbSession.commit();
    activeRuleIndexer.index(changes);
    return changes;
}
Also used : ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) BadRequestException(org.sonar.server.exceptions.BadRequestException) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 18 with QualityProfileDto

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

the class DeleteAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    qProfileWsSupport.checkQProfileAdminPermission();
    try (DbSession dbSession = dbClient.openSession(false)) {
        QualityProfileDto profile = profileFactory.find(dbSession, QProfileRef.from(request));
        profileFactory.delete(dbSession, profile.getKey(), false);
        dbSession.commit();
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 19 with QualityProfileDto

use of org.sonar.db.qualityprofile.QualityProfileDto 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_PROFILE_NAME);
    String language = request.mandatoryParam(PARAM_LANGUAGE);
    String exporterKey = exporters.exportersForLanguage(language).isEmpty() ? null : request.param(PARAM_FORMAT);
    QualityProfileDto profile = getProfile(name, language);
    writeResponse(profile, exporterKey, response);
}
Also used : QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 20 with QualityProfileDto

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

the class RuleQueryFactory method createRuleQuery.

/**
   * Create a {@link RuleQuery} from a {@link Request}.
   * When a profile key is set, the language of the profile is automatically set in the query
   */
public RuleQuery createRuleQuery(Request request) {
    RuleQuery ruleQuery = createRuleQuery(new RuleQuery(), request);
    String qProfileKey = ruleQuery.getQProfileKey();
    if (qProfileKey != null) {
        QualityProfileDto qProfile = getProfileByKey(qProfileKey);
        if (qProfile != null) {
            ruleQuery.setLanguages(ImmutableList.of(qProfile.getLanguage()));
        }
    }
    return ruleQuery;
}
Also used : RuleQuery(org.sonar.server.rule.index.RuleQuery) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Aggregations

QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)126 Test (org.junit.Test)76 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)37 RuleDto (org.sonar.db.rule.RuleDto)29 WsTester (org.sonar.server.ws.WsTester)21 RuleQuery (org.sonar.server.rule.index.RuleQuery)14 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)13 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)12 DbSession (org.sonar.db.DbSession)11 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)9 SearchOptions (org.sonar.server.es.SearchOptions)9 ComponentDto (org.sonar.db.component.ComponentDto)8 OrganizationDto (org.sonar.db.organization.OrganizationDto)7 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)6 Date (java.util.Date)5 QualityProfileTesting.newQualityProfileDto (org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto)5 RuleParamDto (org.sonar.db.rule.RuleParamDto)5 RulesProfile (org.sonar.api.profiles.RulesProfile)4 Language (org.sonar.api.resources.Language)4 RuleKey (org.sonar.api.rule.RuleKey)4