use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RegisterRules method processRemainingDbRules.
private List<RuleDto> processRemainingDbRules(Collection<RuleDto> existingRules, DbSession session) {
// custom rules check status of template, so they must be processed at the end
List<RuleDto> customRules = newArrayList();
List<RuleDto> removedRules = newArrayList();
for (RuleDto rule : existingRules) {
if (rule.getTemplateId() != null) {
customRules.add(rule);
} else if (rule.getStatus() != RuleStatus.REMOVED) {
removeRule(session, removedRules, rule);
}
}
for (RuleDto customRule : customRules) {
Integer templateId = customRule.getTemplateId();
checkNotNull(templateId, "Template id of the custom rule '%s' is null", customRule);
Optional<RuleDto> template = dbClient.ruleDao().selectById(templateId, session);
if (template.isPresent() && template.get().getStatus() != RuleStatus.REMOVED) {
if (updateCustomRuleFromTemplateRule(customRule, template.get())) {
update(session, customRule);
}
} else {
removeRule(session, removedRules, customRule);
}
}
session.commit();
return removedRules;
}
use of org.sonar.db.rule.RuleDto 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.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleCreator method createCustomRule.
private RuleKey createCustomRule(RuleKey ruleKey, NewCustomRule newRule, RuleDto templateRuleDto, DbSession dbSession) {
RuleDto ruleDto = RuleDto.createFor(ruleKey).setTemplateId(templateRuleDto.getId()).setConfigKey(templateRuleDto.getConfigKey()).setName(newRule.name()).setDescription(newRule.markdownDescription()).setDescriptionFormat(Format.MARKDOWN).setSeverity(newRule.severity()).setStatus(newRule.status()).setLanguage(templateRuleDto.getLanguage()).setDefaultRemediationFunction(templateRuleDto.getDefaultRemediationFunction()).setDefaultRemediationGapMultiplier(templateRuleDto.getDefaultRemediationGapMultiplier()).setDefaultRemediationBaseEffort(templateRuleDto.getDefaultRemediationBaseEffort()).setGapDescription(templateRuleDto.getGapDescription()).setTags(templateRuleDto.getTags()).setSystemTags(templateRuleDto.getSystemTags()).setType(templateRuleDto.getType()).setCreatedAt(system2.now()).setUpdatedAt(system2.now());
dbClient.ruleDao().insert(dbSession, ruleDto);
for (RuleParamDto templateRuleParamDto : dbClient.ruleDao().selectRuleParamsByRuleKey(dbSession, templateRuleDto.getKey())) {
String customRuleParamValue = Strings.emptyToNull(newRule.parameter(templateRuleParamDto.getName()));
createCustomRuleParams(customRuleParamValue, ruleDto, templateRuleParamDto, dbSession);
}
return ruleKey;
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleUpdater method updateParameters.
private void updateParameters(DbSession dbSession, RuleUpdate update, Context context) {
if (update.isChangeParameters() && update.isCustomRule()) {
RuleDto customRule = context.rule;
Integer templateId = customRule.getTemplateId();
checkNotNull(templateId, "Rule '%s' has no persisted template!", customRule);
Optional<RuleDto> templateRule = dbClient.ruleDao().selectById(templateId, dbSession);
if (!templateRule.isPresent()) {
throw new IllegalStateException(String.format("Template %s of rule %s does not exist", customRule.getTemplateId(), customRule.getKey()));
}
List<String> paramKeys = newArrayList();
// Load active rules and its parameters in cache
Multimap<ActiveRuleDto, ActiveRuleParamDto> activeRuleParamsByActiveRule = getActiveRuleParamsByActiveRule(dbSession, customRule);
// Browse custom rule parameters to create, update or delete them
deleteOrUpdateParameters(dbSession, update, customRule, paramKeys, activeRuleParamsByActiveRule);
}
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class ClearRulesOverloadedDebt method clearDebt.
private void clearDebt(DbSession session) {
int countClearedRules = 0;
for (RuleDto rule : dbClient.ruleDao().selectAll(session)) {
if (isDebtOverridden(rule)) {
rule.setRemediationFunction(null);
rule.setRemediationGapMultiplier(null);
rule.setRemediationBaseEffort(null);
rule.setUpdatedAt(system2.now());
dbClient.ruleDao().update(session, rule);
countClearedRules++;
}
}
if (countClearedRules > 0) {
LOG.warn("The SQALE model has been cleaned to remove any redundant data left over from previous migrations.");
LOG.warn("=> As a result, the technical debt of existing issues in your projects may change slightly when those projects are reanalyzed.");
}
}
Aggregations