use of org.sonar.db.qualityprofile.ActiveRuleParamDto in project sonarqube by SonarSource.
the class QProfileBackuper method writeXml.
private void writeXml(DbSession dbSession, Writer writer, QualityProfileDto profile, Iterator<ActiveRuleDto> activeRules) {
XmlWriter xml = XmlWriter.of(writer).declaration();
xml.begin("profile");
xml.prop("name", profile.getName());
xml.prop("language", profile.getLanguage());
xml.begin("rules");
while (activeRules.hasNext()) {
ActiveRuleDto activeRule = activeRules.next();
xml.begin("rule");
xml.prop("repositoryKey", activeRule.getKey().ruleKey().repository());
xml.prop("key", activeRule.getKey().ruleKey().rule());
xml.prop("priority", activeRule.getSeverityString());
xml.begin("parameters");
for (ActiveRuleParamDto param : db.activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRule.getId())) {
xml.begin("parameter").prop("key", param.getKey()).prop("value", param.getValue()).end();
}
xml.end("parameters");
xml.end("rule");
}
xml.end("rules").end("profile").close();
}
use of org.sonar.db.qualityprofile.ActiveRuleParamDto in project sonarqube by SonarSource.
the class QProfileExporters method wrap.
private RulesProfile wrap(QualityProfileDto profile) {
try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfile target = new RulesProfile(profile.getName(), profile.getLanguage());
List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByProfileKey(dbSession, profile.getKey());
List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, Lists.transform(activeRuleDtos, ActiveRuleDto::getId));
ListMultimap<Integer, ActiveRuleParamDto> activeRuleParamsByActiveRuleId = FluentIterable.from(activeRuleParamDtos).index(ActiveRuleParamDto::getActiveRuleId);
for (ActiveRuleDto activeRule : activeRuleDtos) {
// TODO all rules should be loaded by using one query with all active rule keys as parameter
Rule rule = ruleFinder.findByKey(activeRule.getKey().ruleKey());
org.sonar.api.rules.ActiveRule wrappedActiveRule = target.activateRule(rule, RulePriority.valueOf(activeRule.getSeverityString()));
List<ActiveRuleParamDto> paramDtos = activeRuleParamsByActiveRuleId.get(activeRule.getId());
for (ActiveRuleParamDto activeRuleParamDto : paramDtos) {
wrappedActiveRule.setParameter(activeRuleParamDto.getKey(), activeRuleParamDto.getValue());
}
}
return target;
}
}
use of org.sonar.db.qualityprofile.ActiveRuleParamDto in project sonarqube by SonarSource.
the class ActiveRuleCompleter method completeShow.
void completeShow(DbSession dbSession, RuleDto rule, ShowResponse.Builder response) {
List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRuleId(dbSession, rule.getId());
Map<Integer, ActiveRuleKey> activeRuleIdsByKey = new HashMap<>();
for (ActiveRuleDto activeRuleDto : activeRuleDtos) {
activeRuleIdsByKey.put(activeRuleDto.getId(), activeRuleDto.getKey());
}
List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, Lists.transform(activeRuleDtos, ActiveRuleDto::getId));
ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = ArrayListMultimap.create(activeRuleDtos.size(), 10);
for (ActiveRuleParamDto activeRuleParamDto : activeRuleParamDtos) {
ActiveRuleKey activeRuleKey = activeRuleIdsByKey.get(activeRuleParamDto.getActiveRuleId());
activeRuleParamsByActiveRuleKey.put(activeRuleKey, activeRuleParamDto);
}
for (ActiveRuleDto activeRule : activeRuleDtos) {
response.addActives(buildActiveRuleResponse(activeRule, activeRuleParamsByActiveRuleKey.get(activeRule.getKey())));
}
}
use of org.sonar.db.qualityprofile.ActiveRuleParamDto in project sonarqube by SonarSource.
the class ActiveRuleCompleter method writeActiveRules.
private Collection<String> writeActiveRules(DbSession dbSession, SearchResponse.Builder response, RuleQuery query, List<RuleDto> rules) {
Collection<String> qProfileKeys = newHashSet();
Rules.Actives.Builder activesBuilder = response.getActivesBuilder();
String profileKey = query.getQProfileKey();
if (profileKey != null) {
// Load details of active rules on the selected profile
List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByProfileKey(dbSession, profileKey);
Map<RuleKey, ActiveRuleDto> activeRuleByRuleKey = from(activeRuleDtos).uniqueIndex(ActiveRuleToRuleKey.INSTANCE);
ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = activeRuleDtosToActiveRuleParamDtos(dbSession, activeRuleDtos);
for (RuleDto rule : rules) {
ActiveRuleDto activeRule = activeRuleByRuleKey.get(rule.getKey());
if (activeRule != null) {
qProfileKeys = writeActiveRules(rule.getKey(), singletonList(activeRule), activeRuleParamsByActiveRuleKey, activesBuilder);
}
}
} else {
// Load details of all active rules
List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRuleIds(dbSession, Lists.transform(rules, RuleDto::getId));
Multimap<RuleKey, ActiveRuleDto> activeRulesByRuleKey = from(activeRuleDtos).index(ActiveRuleToRuleKey.INSTANCE);
ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = activeRuleDtosToActiveRuleParamDtos(dbSession, activeRuleDtos);
for (RuleDto rule : rules) {
qProfileKeys = writeActiveRules(rule.getKey(), activeRulesByRuleKey.get(rule.getKey()), activeRuleParamsByActiveRuleKey, activesBuilder);
}
}
response.setActives(activesBuilder);
return qProfileKeys;
}
use of org.sonar.db.qualityprofile.ActiveRuleParamDto in project sonarqube by SonarSource.
the class RuleActivator method doInsert.
private ActiveRuleDto doInsert(ActiveRuleChange change, RuleActivatorContext context, DbSession dbSession) {
ActiveRuleDto activeRule;
ActiveRuleDao dao = db.activeRuleDao();
activeRule = ActiveRuleDto.createFor(context.profile(), context.rule());
String severity = change.getSeverity();
if (severity != null) {
activeRule.setSeverity(severity);
}
ActiveRule.Inheritance inheritance = change.getInheritance();
if (inheritance != null) {
activeRule.setInheritance(inheritance.name());
}
activeRule.setUpdatedAt(system2.now());
activeRule.setCreatedAt(system2.now());
dao.insert(dbSession, activeRule);
for (Map.Entry<String, String> param : change.getParameters().entrySet()) {
if (param.getValue() != null) {
ActiveRuleParamDto paramDto = ActiveRuleParamDto.createFor(context.ruleParamsByKeys().get(param.getKey()));
paramDto.setValue(param.getValue());
dao.insertParam(dbSession, activeRule, paramDto);
}
}
return activeRule;
}
Aggregations