Search in sources :

Example 6 with QualityProfileDto

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

the class QProfileProjectOperations method removeProject.

public void removeProject(DbSession dbSession, String profileKey, ComponentDto project) {
    checkAdminOnProject(project);
    QualityProfileDto qualityProfile = selectProfileByKey(dbSession, profileKey);
    db.qualityProfileDao().deleteProjectProfileAssociation(project.uuid(), qualityProfile.getKey(), dbSession);
    dbSession.commit();
}
Also used : QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 7 with QualityProfileDto

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

the class QProfileProjectOperations method addProject.

public void addProject(DbSession dbSession, String profileKey, ComponentDto project) {
    checkAdminOnProject(project);
    QualityProfileDto qualityProfile = selectProfileByKey(dbSession, profileKey);
    QualityProfileDto currentProfile = db.qualityProfileDao().selectByProjectAndLanguage(dbSession, project.key(), qualityProfile.getLanguage());
    boolean updated = false;
    if (currentProfile == null) {
        db.qualityProfileDao().insertProjectProfileAssociation(project.uuid(), qualityProfile.getKey(), dbSession);
        updated = true;
    } else if (!profileKey.equals(currentProfile.getKey())) {
        db.qualityProfileDao().updateProjectProfileAssociation(project.uuid(), profileKey, currentProfile.getKey(), dbSession);
        updated = true;
    }
    if (updated) {
        dbSession.commit();
    }
}
Also used : QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 8 with QualityProfileDto

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

the class ActiveRuleCompleter method buildQProfiles.

private Rules.QProfiles.Builder buildQProfiles(DbSession dbSession, Collection<String> harvestedProfileKeys) {
    Map<String, QualityProfileDto> qProfilesByKey = Maps.newHashMap();
    for (String qProfileKey : harvestedProfileKeys) {
        if (!qProfilesByKey.containsKey(qProfileKey)) {
            QualityProfileDto profile = loadProfile(dbSession, qProfileKey);
            if (profile == null) {
                LOG.warn("Could not find quality profile with key " + qProfileKey);
                continue;
            }
            qProfilesByKey.put(qProfileKey, profile);
            String parentKee = profile.getParentKee();
            if (parentKee != null && !qProfilesByKey.containsKey(parentKee)) {
                qProfilesByKey.put(parentKee, loadProfile(dbSession, parentKee));
            }
        }
    }
    Rules.QProfiles.Builder qProfilesResponse = Rules.QProfiles.newBuilder();
    Map<String, Rules.QProfile> qProfilesMapResponse = qProfilesResponse.getMutableQProfiles();
    for (QualityProfileDto profile : qProfilesByKey.values()) {
        writeProfile(qProfilesMapResponse, profile);
    }
    return qProfilesResponse;
}
Also used : QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 9 with QualityProfileDto

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

the class ChangelogAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        QualityProfileDto profile = profileFactory.find(dbSession, QProfileRef.from(request));
        QProfileChangeQuery query = new QProfileChangeQuery(profile.getKey());
        Date since = parseStartingDateOrDateTime(request.param(PARAM_SINCE));
        if (since != null) {
            query.setFromIncluded(since.getTime());
        }
        Date to = parseEndingDateOrDateTime(request.param(PARAM_TO));
        if (to != null) {
            query.setToExcluded(to.getTime());
        }
        int page = request.mandatoryParamAsInt(Param.PAGE);
        int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE);
        query.setPage(page, pageSize);
        ChangelogLoader.Changelog changelog = changelogLoader.load(dbSession, query);
        writeResponse(response.newJsonWriter(), page, pageSize, changelog);
    }
}
Also used : DbSession(org.sonar.db.DbSession) QProfileChangeQuery(org.sonar.db.qualityprofile.QProfileChangeQuery) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Date(java.util.Date)

Example 10 with QualityProfileDto

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

the class InheritanceAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    DbSession dbSession = dbClient.openSession(false);
    try {
        QualityProfileDto profile = profileFactory.find(dbSession, QProfileRef.from(request));
        List<QProfile> ancestors = profileLookup.ancestors(profile, dbSession);
        List<QualityProfileDto> children = dbClient.qualityProfileDao().selectChildren(dbSession, profile.getKey());
        Map<String, Multimap<String, FacetValue>> profileStats = profileLoader.getAllProfileStats();
        writeResponse(response.newJsonWriter(), profile, ancestors, children, profileStats);
    } finally {
        dbSession.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) Multimap(com.google.common.collect.Multimap) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) QProfile(org.sonar.server.qualityprofile.QProfile)

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