Search in sources :

Example 66 with QualityProfileDto

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

the class RuleActivatorContextFactory method create.

RuleActivatorContext create(String profileKey, RuleKey ruleKey, DbSession session) {
    RuleActivatorContext context = new RuleActivatorContext();
    QualityProfileDto profile = db.qualityProfileDao().selectByKey(session, profileKey);
    checkRequest(profile != null, "Quality profile not found: %s", profileKey);
    context.setProfile(profile);
    return create(ruleKey, session, context);
}
Also used : QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 67 with QualityProfileDto

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

the class RuleActivatorContextFactory method create.

RuleActivatorContext create(QProfileName profileName, RuleKey ruleKey, DbSession session) {
    RuleActivatorContext context = new RuleActivatorContext();
    QualityProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage(profileName.getName(), profileName.getLanguage(), session);
    checkRequest(profile != null, "Quality profile not found: %s", profileName);
    context.setProfile(profile);
    return create(ruleKey, session, context);
}
Also used : QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 68 with QualityProfileDto

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

the class BackupAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    Stream stream = response.stream();
    stream.setMediaType(MediaTypes.XML);
    try (OutputStreamWriter writer = new OutputStreamWriter(stream.output(), StandardCharsets.UTF_8);
        DbSession dbSession = dbClient.openSession(false)) {
        QualityProfileDto profile = profileFactory.find(dbSession, QProfileRef.from(request));
        response.setHeader("Content-Disposition", String.format("attachment; filename=%s.xml", profile.getKee()));
        backuper.backup(profile.getKee(), writer);
    }
}
Also used : DbSession(org.sonar.db.DbSession) Stream(org.sonar.api.server.ws.Response.Stream) OutputStreamWriter(java.io.OutputStreamWriter) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 69 with QualityProfileDto

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

the class ChangeParentAction 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));
        String parentKey = request.param(PARAM_PARENT_KEY);
        String parentName = request.param(PARAM_PARENT_NAME);
        if (isEmpty(parentKey) && isEmpty(parentName)) {
            ruleActivator.setParent(dbSession, profile.getKey(), null);
        } else {
            QProfileRef parentRef = QProfileRef.from(parentKey, request.param(QProfileRef.PARAM_LANGUAGE), parentName);
            QualityProfileDto parent = profileFactory.find(dbSession, parentRef);
            ruleActivator.setParent(dbSession, profile.getKey(), parent.getKey());
        }
        response.noContent();
    }
}
Also used : DbSession(org.sonar.db.DbSession) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) QProfileRef(org.sonar.server.qualityprofile.QProfileRef)

Example 70 with QualityProfileDto

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

the class QProfileBackuper method backup.

/**
   * @deprecated use {@link #backup(DbSession, QualityProfileDto, Writer)} instead
   */
@Deprecated
public void backup(String key, Writer writer) {
    try (DbSession dbSession = db.openSession(false)) {
        QualityProfileDto profile = db.qualityProfileDao().selectOrFailByKey(dbSession, key);
        backup(dbSession, profile, writer);
    }
}
Also used : DbSession(org.sonar.db.DbSession) 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