use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class InheritanceAction method collectAncestors.
private void collectAncestors(QProfileDto profile, List<QProfileDto> ancestors, DbSession session) {
if (profile.getParentKee() == null) {
return;
}
QProfileDto parent = getParent(session, profile);
ancestors.add(parent);
collectAncestors(parent, ancestors, session);
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class InheritanceAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
QProfileReference reference = QProfileReference.fromName(request);
try (DbSession dbSession = dbClient.openSession(false)) {
QProfileDto profile = wsSupport.getProfile(dbSession, reference);
List<QProfileDto> ancestors = ancestors(profile, dbSession);
List<QProfileDto> children = dbClient.qualityProfileDao().selectChildren(dbSession, singleton(profile));
List<QProfileDto> allProfiles = new ArrayList<>();
allProfiles.add(profile);
allProfiles.addAll(ancestors);
allProfiles.addAll(children);
Statistics statistics = new Statistics(dbSession, allProfiles);
writeProtobuf(buildResponse(profile, ancestors, children, statistics), request, response);
}
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class RemoveProjectAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto project = loadProject(dbSession, request);
QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromName(request));
checkPermissions(dbSession, profile, project);
dbClient.qualityProfileDao().deleteProjectProfileAssociation(dbSession, project, profile);
dbSession.commit();
QProfileDto activatedProfile = null;
// publish change for rules in the default quality profile
QProfileDto defaultProfile = dbClient.qualityProfileDao().selectDefaultProfile(dbSession, profile.getLanguage());
if (defaultProfile != null) {
activatedProfile = defaultProfile;
}
qualityProfileChangeEventService.publishRuleActivationToSonarLintClients(project, activatedProfile, profile);
response.noContent();
}
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class ActiveRuleCompleter method writeActiveRules.
private Set<String> writeActiveRules(DbSession dbSession, SearchResponse.Builder response, RuleQuery query, List<RuleDto> rules) {
final Set<String> profileUuids = new HashSet<>();
Rules.Actives.Builder activesBuilder = response.getActivesBuilder();
QProfileDto profile = query.getQProfile();
if (profile != null) {
// Load details of active rules on the selected profile
List<OrgActiveRuleDto> activeRules = dbClient.activeRuleDao().selectByProfile(dbSession, profile);
Map<RuleKey, OrgActiveRuleDto> activeRuleByRuleKey = activeRules.stream().collect(uniqueIndex(ActiveRuleDto::getRuleKey));
ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = loadParams(dbSession, activeRules);
for (RuleDto rule : rules) {
OrgActiveRuleDto activeRule = activeRuleByRuleKey.get(rule.getKey());
if (activeRule != null) {
profileUuids.addAll(writeActiveRules(rule.getKey(), singletonList(activeRule), activeRuleParamsByActiveRuleKey, activesBuilder));
}
}
} else {
// Load details of all active rules
List<String> ruleUuids = Lists.transform(rules, RuleDto::getUuid);
List<OrgActiveRuleDto> activeRules = dbClient.activeRuleDao().selectByRuleUuids(dbSession, ruleUuids);
Multimap<RuleKey, OrgActiveRuleDto> activeRulesByRuleKey = activeRules.stream().collect(MoreCollectors.index(OrgActiveRuleDto::getRuleKey));
ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = loadParams(dbSession, activeRules);
rules.forEach(rule -> profileUuids.addAll(writeActiveRules(rule.getKey(), activeRulesByRuleKey.get(rule.getKey()), activeRuleParamsByActiveRuleKey, activesBuilder)));
}
response.setActives(activesBuilder);
return profileUuids;
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class RuleQueryFactory method setProfile.
private void setProfile(DbSession dbSession, RuleQuery query, Request request) {
String profileUuid = request.param(PARAM_QPROFILE);
if (profileUuid == null) {
return;
}
QProfileDto profileOptional = dbClient.qualityProfileDao().selectByUuid(dbSession, profileUuid);
QProfileDto profile = checkFound(profileOptional, "The specified qualityProfile '%s' does not exist", profileUuid);
query.setQProfile(profile);
}
Aggregations