use of org.sonar.api.rules.RuleType in project sonarqube by SonarSource.
the class IssueCounter method addMeasuresByPeriod.
private void addMeasuresByPeriod(Component component) {
if (!periodHolder.hasPeriod()) {
return;
}
Double unresolvedVariations = (double) currentCounters.counterForPeriod().unresolved;
measureRepository.add(component, metricRepository.getByKey(NEW_VIOLATIONS_KEY), Measure.newMeasureBuilder().setVariation(unresolvedVariations).createNoValue());
for (Map.Entry<String, String> entry : SEVERITY_TO_NEW_METRIC_KEY.entrySet()) {
String severity = entry.getKey();
String metricKey = entry.getValue();
Multiset<String> bag = currentCounters.counterForPeriod().severityBag;
Metric metric = metricRepository.getByKey(metricKey);
measureRepository.add(component, metric, Measure.newMeasureBuilder().setVariation((double) bag.count(severity)).createNoValue());
}
// (see call currentCounters.counterForPeriod(period.getIndex()).xxx with xxx as severityBag or typeBag)
for (Map.Entry<RuleType, String> entry : TYPE_TO_NEW_METRIC_KEY.entrySet()) {
RuleType type = entry.getKey();
String metricKey = entry.getValue();
Multiset<RuleType> bag = currentCounters.counterForPeriod().typeBag;
Metric metric = metricRepository.getByKey(metricKey);
measureRepository.add(component, metric, Measure.newMeasureBuilder().setVariation((double) bag.count(type)).createNoValue());
}
}
use of org.sonar.api.rules.RuleType in project sonarqube by SonarSource.
the class RegisterRules method mergeRule.
private boolean mergeRule(RulesDefinition.Rule def, RuleDto dto) {
boolean changed = false;
if (!StringUtils.equals(dto.getName(), def.name())) {
dto.setName(def.name());
changed = true;
}
if (mergeDescription(def, dto)) {
changed = true;
}
if (!StringUtils.equals(dto.getConfigKey(), def.internalKey())) {
dto.setConfigKey(def.internalKey());
changed = true;
}
String severity = def.severity();
if (!ObjectUtils.equals(dto.getSeverityString(), severity)) {
dto.setSeverity(severity);
changed = true;
}
boolean isTemplate = def.template();
if (isTemplate != dto.isTemplate()) {
dto.setIsTemplate(isTemplate);
changed = true;
}
if (def.status() != dto.getStatus()) {
dto.setStatus(def.status());
changed = true;
}
if (!StringUtils.equals(dto.getLanguage(), def.repository().language())) {
dto.setLanguage(def.repository().language());
changed = true;
}
RuleType type = RuleType.valueOf(def.type().name());
if (!ObjectUtils.equals(dto.getType(), type.getDbConstant())) {
dto.setType(type);
changed = true;
}
return changed;
}
use of org.sonar.api.rules.RuleType in project sonarqube by SonarSource.
the class SetTypeAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
String issueKey = request.mandatoryParam(PARAM_ISSUE);
RuleType ruleType = RuleType.valueOf(request.mandatoryParam(PARAM_TYPE));
try (DbSession session = dbClient.openSession(false)) {
setType(session, issueKey, ruleType);
}
responseWriter.write(issueKey, request, response);
}