use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class ActiveRuleIndexerTest method indexAll_indexes_all_data.
@Test
public void indexAll_indexes_all_data() {
ActiveRuleDto activeRule = db.qualityProfiles().activateRule(profile1, rule1);
underTest.indexAll();
List<ActiveRuleDoc> docs = es.getDocuments(TYPE_ACTIVE_RULE, ActiveRuleDoc.class);
assertThat(docs).hasSize(1);
verify(docs.get(0), profile1, activeRule);
assertThatEsQueueTableIsEmpty();
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class ActiveRuleIndexerTest method commitDeletionOfProfiles.
@Test
public void commitDeletionOfProfiles() {
ActiveRuleDto ar1 = db.qualityProfiles().activateRule(profile1, rule1);
db.qualityProfiles().activateRule(profile2, rule1);
db.qualityProfiles().activateRule(profile2, rule2);
indexAll();
db.getDbClient().qualityProfileDao().deleteRulesProfilesByUuids(db.getSession(), singletonList(profile2.getRulesProfileUuid()));
underTest.commitDeletionOfProfiles(db.getSession(), singletonList(profile2));
verifyOnlyIndexed(ar1);
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class QProfileResetImpl method reset.
@Override
public BulkChangeResult reset(DbSession dbSession, QProfileDto profile, Collection<RuleActivation> activations) {
requireNonNull(profile.getRulesProfileUuid(), "Quality profile must be persisted");
checkArgument(!profile.isBuiltIn(), "Operation forbidden for built-in Quality Profile '%s'", profile.getKee());
BulkChangeResult result = new BulkChangeResult();
Set<String> rulesToBeDeactivated = new HashSet<>();
// Keep reference to all the activated rules before backup restore
for (ActiveRuleDto activeRuleDto : db.activeRuleDao().selectByProfile(dbSession, profile)) {
if (activeRuleDto.getInheritance() == null) {
// inherited rules can't be deactivated
rulesToBeDeactivated.add(activeRuleDto.getRuleUuid());
}
}
Set<String> ruleUuids = new HashSet<>(rulesToBeDeactivated.size() + activations.size());
ruleUuids.addAll(rulesToBeDeactivated);
activations.forEach(a -> ruleUuids.add(a.getRuleUuid()));
RuleActivationContext context = activator.createContextForUserProfile(dbSession, profile, ruleUuids);
for (RuleActivation activation : activations) {
try {
List<ActiveRuleChange> changes = activator.activate(dbSession, activation, context);
rulesToBeDeactivated.remove(activation.getRuleUuid());
result.incrementSucceeded();
result.addChanges(changes);
} catch (BadRequestException e) {
result.incrementFailed();
result.getErrors().addAll(e.errors());
}
}
List<ActiveRuleChange> changes = new ArrayList<>(result.getChanges());
for (String ruleUuid : rulesToBeDeactivated) {
try {
changes.addAll(activator.deactivate(dbSession, context, ruleUuid, false));
} catch (BadRequestException e) {
// ignore, probably a rule inherited from parent that can't be deactivated
}
}
qualityProfileChangeEventService.distributeRuleChangeEvent(List.of(profile), changes, profile.getLanguage());
activeRuleIndexer.commitAndIndex(dbSession, changes);
return result;
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class CompareAction method writeRules.
private void writeRules(JsonWriter json, Map<RuleKey, ActiveRuleDto> activeRules, Map<RuleKey, RuleDefinitionDto> rulesByKey, Map<String, RuleRepositoryDto> repositoriesByKey) {
json.beginArray();
for (Entry<RuleKey, ActiveRuleDto> activeRule : activeRules.entrySet()) {
RuleKey key = activeRule.getKey();
ActiveRuleDto value = activeRule.getValue();
json.beginObject();
RuleDefinitionDto 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.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class RuleActivator method getSeverityForNonBuiltInProfile.
private static String getSeverityForNonBuiltInProfile(RuleActivation request, RuleWrapper rule, @Nullable ActiveRuleWrapper activeRule, @Nullable ActiveRuleWrapper parentActiveRule) {
String severity;
if (activeRule != null) {
ActiveRuleDto activeRuleDto = activeRule.get();
// load severity from request, else keep existing one (if overridden), else from parent if rule inherited, else from default
severity = firstNonNull(request.getSeverity(), activeRuleDto.doesOverride() ? activeRuleDto.getSeverityString() : null, parentActiveRule != null ? parentActiveRule.get().getSeverityString() : activeRuleDto.getSeverityString(), rule.get().getSeverityString());
} else {
// load severity from request, else from parent, else from default
severity = firstNonNull(request.getSeverity(), parentActiveRule != null ? parentActiveRule.get().getSeverityString() : null, rule.get().getSeverityString());
}
return severity;
}
Aggregations