use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class CompareAction method writeRules.
private void writeRules(JsonWriter json, Map<RuleKey, ActiveRuleDto> activeRules, Map<RuleKey, RuleDto> rulesByKey, Map<String, RuleRepositoryDto> repositoriesByKey) {
json.beginArray();
for (Entry<RuleKey, ActiveRuleDto> activeRule : activeRules.entrySet()) {
RuleKey key = activeRule.getKey();
ActiveRuleDto value = activeRule.getValue();
json.beginObject();
RuleDto rule = rulesByKey.get(key);
writeRule(json, rule, repositoriesByKey.get(rule.getRepositoryKey()));
json.prop(ATTRIBUTE_SEVERITY, value.getSeverityString());
json.endObject();
}
json.endArray();
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class RuleActivator method bulkDeactivate.
BulkChangeResult bulkDeactivate(RuleQuery ruleQuery, String profile) {
DbSession dbSession = db.openSession(false);
BulkChangeResult result = new BulkChangeResult();
try {
Iterator<RuleKey> rules = ruleIndex.searchAll(ruleQuery);
while (rules.hasNext()) {
try {
RuleKey ruleKey = rules.next();
ActiveRuleKey key = ActiveRuleKey.of(profile, ruleKey);
List<ActiveRuleChange> changes = deactivate(dbSession, key);
result.addChanges(changes);
if (!changes.isEmpty()) {
result.incrementSucceeded();
}
} catch (BadRequestException e) {
// other exceptions stop the bulk activation
result.incrementFailed();
result.getErrors().addAll(e.errors());
}
}
dbSession.commit();
activeRuleIndexer.index(result.getChanges());
return result;
} finally {
dbSession.close();
}
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class RuleActivationActions method activate.
private void activate(Request request, Response response) {
RuleKey ruleKey = readRuleKey(request);
RuleActivation activation = new RuleActivation(ruleKey);
activation.setSeverity(request.param(SEVERITY));
String params = request.param(PARAMS);
if (params != null) {
activation.setParameters(KeyValueFormat.parse(params));
}
activation.setReset(Boolean.TRUE.equals(request.paramAsBoolean(RESET)));
service.activate(request.mandatoryParam(PROFILE_KEY), activation);
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class RuleActivationActions method deactivate.
private void deactivate(Request request, Response response) {
RuleKey ruleKey = readRuleKey(request);
service.deactivate(ActiveRuleKey.of(request.mandatoryParam(PROFILE_KEY), ruleKey));
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class ShowAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
RuleKey key = RuleKey.parse(request.mandatoryParam(PARAM_KEY));
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<RuleDto> optionalRule = dbClient.ruleDao().selectByKey(dbSession, key);
checkFoundWithOptional(optionalRule, "Rule not found: " + key);
RuleDto rule = optionalRule.get();
List<RuleDto> templateRules = new ArrayList<>();
if (rule.getTemplateId() != null) {
Optional<RuleDto> templateRule = dbClient.ruleDao().selectById(rule.getTemplateId(), dbSession);
if (templateRule.isPresent()) {
templateRules.add(templateRule.get());
}
}
List<RuleParamDto> ruleParameters = dbClient.ruleDao().selectRuleParamsByRuleIds(dbSession, singletonList(rule.getId()));
ShowResponse showResponse = buildResponse(dbSession, request, new SearchAction.SearchResult().setRules(singletonList(rule)).setTemplateRules(templateRules).setRuleParameters(ruleParameters).setTotal(1L));
writeProtobuf(showResponse, request, response);
}
}
Aggregations