Search in sources :

Example 11 with QualityProfileDto

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

the class InheritanceAction method writeChildren.

private void writeChildren(JsonWriter json, List<QualityProfileDto> children, Map<String, Multimap<String, FacetValue>> profileStats) {
    json.name("children").beginArray();
    for (QualityProfileDto child : children) {
        String childKey = child.getKey();
        writeProfileAttributes(json, childKey, child.getName(), null, profileStats);
    }
    json.endArray();
}
Also used : QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 12 with QualityProfileDto

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

the class OldRestoreAction method writeResponse.

private void writeResponse(JsonWriter json, BulkChangeResult result) {
    QualityProfileDto profile = result.profile();
    if (profile != null) {
        String languageKey = profile.getLanguage();
        Language language = languages.get(languageKey);
        JsonWriter jsonProfile = json.beginObject().name("profile").beginObject();
        jsonProfile.prop("key", profile.getKey()).prop("name", profile.getName()).prop("language", languageKey).prop("isDefault", false).prop("isInherited", false);
        if (language != null) {
            jsonProfile.prop("languageName", language.getName());
        }
        jsonProfile.endObject();
    }
    json.prop("ruleSuccesses", result.countSucceeded());
    json.prop("ruleFailures", result.countFailed());
    json.endObject().close();
}
Also used : Language(org.sonar.api.resources.Language) JsonWriter(org.sonar.api.utils.text.JsonWriter) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 13 with QualityProfileDto

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

the class RegisterQualityProfiles method setDefault.

private void setDefault(String language, List<RulesProfile> profileDefs, DbSession session) {
    QualityProfileDto currentDefault = dbClient.qualityProfileDao().selectDefaultProfile(session, language);
    if (currentDefault == null) {
        String defaultProfileName = nameOfDefaultProfile(profileDefs);
        LOGGER.info("Set default " + language + " profile: " + defaultProfileName);
        QualityProfileDto newDefaultProfile = dbClient.qualityProfileDao().selectByNameAndLanguage(defaultProfileName, language, session);
        if (newDefaultProfile == null) {
            // Must not happen, we just registered it
            throw new IllegalStateException("Could not find declared default profile '%s' for language '%s'");
        } else {
            dbClient.qualityProfileDao().update(session, newDefaultProfile.setDefault(true));
        }
    }
}
Also used : QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 14 with QualityProfileDto

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

the class RuleActivator method cascadeDeactivation.

private List<ActiveRuleChange> cascadeDeactivation(ActiveRuleKey key, DbSession dbSession, boolean isCascade, boolean force) {
    List<ActiveRuleChange> changes = Lists.newArrayList();
    RuleActivatorContext context = contextFactory.create(key.qProfile(), key.ruleKey(), dbSession);
    ActiveRuleChange change;
    ActiveRuleDto activeRuleDto = context.activeRule();
    if (activeRuleDto == null) {
        return changes;
    }
    checkRequest(force || isCascade || activeRuleDto.getInheritance() == null, "Cannot deactivate inherited rule '%s'", key.ruleKey());
    change = ActiveRuleChange.createFor(ActiveRuleChange.Type.DEACTIVATED, key);
    changes.add(change);
    persist(change, context, dbSession);
    // get all inherited profiles
    List<QualityProfileDto> profiles = db.qualityProfileDao().selectChildren(dbSession, key.qProfile());
    for (QualityProfileDto profile : profiles) {
        ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), key.ruleKey());
        changes.addAll(cascadeDeactivation(activeRuleKey, dbSession, true, force));
    }
    if (!changes.isEmpty()) {
        updateProfileDates(dbSession, context);
    }
    return changes;
}
Also used : ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 15 with QualityProfileDto

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

the class RestoreAction method writeResponse.

private void writeResponse(JsonWriter json, BulkChangeResult result) {
    QualityProfileDto profile = result.profile();
    if (profile != null) {
        String languageKey = profile.getLanguage();
        Language language = languages.get(languageKey);
        JsonWriter jsonProfile = json.beginObject().name("profile").beginObject();
        jsonProfile.prop("key", profile.getKey()).prop("name", profile.getName()).prop("language", languageKey).prop("isDefault", false).prop("isInherited", false);
        if (language != null) {
            jsonProfile.prop("languageName", language.getName());
        }
        jsonProfile.endObject();
    }
    json.prop("ruleSuccesses", result.countSucceeded());
    json.prop("ruleFailures", result.countFailed());
    json.endObject().close();
}
Also used : Language(org.sonar.api.resources.Language) JsonWriter(org.sonar.api.utils.text.JsonWriter) 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