Search in sources :

Example 1 with QProfile

use of org.sonar.server.qualityprofile.QProfile 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)

Example 2 with QProfile

use of org.sonar.server.qualityprofile.QProfile in project sonarqube by SonarSource.

the class InheritanceAction method writeAncestors.

private void writeAncestors(JsonWriter json, List<QProfile> ancestors, Map<String, Multimap<String, FacetValue>> profileStats) {
    json.name("ancestors").beginArray();
    for (QProfile ancestor : ancestors) {
        String ancestorKey = ancestor.key();
        writeProfileAttributes(json, ancestorKey, ancestor.name(), ancestor.parent(), profileStats);
    }
    json.endArray();
}
Also used : QProfile(org.sonar.server.qualityprofile.QProfile)

Example 3 with QProfile

use of org.sonar.server.qualityprofile.QProfile in project sonarqube by SonarSource.

the class SearchAction method buildResponse.

private SearchWsResponse buildResponse(SearchData data) {
    List<QProfile> profiles = data.getProfiles();
    Map<String, QProfile> profilesByKey = profiles.stream().collect(Collectors.toMap(QProfile::key, identity()));
    SearchWsResponse.Builder response = SearchWsResponse.newBuilder();
    for (QProfile profile : profiles) {
        QualityProfile.Builder profileBuilder = response.addProfilesBuilder();
        String profileKey = profile.key();
        profileBuilder.setKey(profileKey);
        if (profile.name() != null) {
            profileBuilder.setName(profile.name());
        }
        if (profile.getRulesUpdatedAt() != null) {
            profileBuilder.setRulesUpdatedAt(profile.getRulesUpdatedAt());
        }
        if (profile.getLastUsed() != null) {
            profileBuilder.setLastUsed(formatDateTime(profile.getLastUsed()));
        }
        if (profile.getUserUpdatedAt() != null) {
            profileBuilder.setUserUpdatedAt(formatDateTime(profile.getUserUpdatedAt()));
        }
        profileBuilder.setActiveRuleCount(data.getActiveRuleCount(profileKey));
        profileBuilder.setActiveDeprecatedRuleCount(data.getActiveDeprecatedRuleCount(profileKey));
        if (!profile.isDefault()) {
            profileBuilder.setProjectCount(data.getProjectCount(profileKey));
        }
        writeLanguageFields(profileBuilder, profile);
        writeParentFields(profileBuilder, profile, profilesByKey);
        profileBuilder.setIsInherited(profile.isInherited());
        profileBuilder.setIsDefault(profile.isDefault());
    }
    return response.build();
}
Also used : QualityProfile(org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile) SearchWsResponse(org.sonarqube.ws.QualityProfiles.SearchWsResponse) QProfile(org.sonar.server.qualityprofile.QProfile)

Example 4 with QProfile

use of org.sonar.server.qualityprofile.QProfile in project sonarqube by SonarSource.

the class SearchAction method writeParentFields.

private static void writeParentFields(QualityProfile.Builder profileBuilder, QProfile profile, Map<String, QProfile> profilesByKey) {
    String parentKey = profile.parent();
    if (parentKey == null) {
        return;
    }
    profileBuilder.setParentKey(parentKey);
    QProfile parent = profilesByKey.get(parentKey);
    if (parent != null && parent.name() != null) {
        profileBuilder.setParentName(parent.name());
    }
}
Also used : QProfile(org.sonar.server.qualityprofile.QProfile)

Aggregations

QProfile (org.sonar.server.qualityprofile.QProfile)4 Multimap (com.google.common.collect.Multimap)1 DbSession (org.sonar.db.DbSession)1 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)1 SearchWsResponse (org.sonarqube.ws.QualityProfiles.SearchWsResponse)1 QualityProfile (org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile)1