use of org.sonar.db.qualityprofile.OrgActiveRuleDto in project sonarqube by SonarSource.
the class QProfileRuleImplTest method assertThatRuleIsActivated.
private void assertThatRuleIsActivated(QProfileDto profile, RuleDefinitionDto rule, @Nullable List<ActiveRuleChange> changes, String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map<String, String> expectedParams) {
OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile).stream().filter(ar -> ar.getRuleKey().equals(rule.getKey())).findFirst().orElseThrow(IllegalStateException::new);
assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity);
assertThat(activeRule.getInheritance()).isEqualTo(expectedInheritance != null ? expectedInheritance.name() : null);
List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid());
assertThat(params).hasSize(expectedParams.size());
if (changes != null) {
ActiveRuleChange change = changes.stream().filter(c -> c.getActiveRule().getUuid().equals(activeRule.getUuid())).findFirst().orElseThrow(IllegalStateException::new);
assertThat(change.getInheritance()).isEqualTo(expectedInheritance);
assertThat(change.getSeverity()).isEqualTo(expectedSeverity);
assertThat(change.getType()).isEqualTo(ActiveRuleChange.Type.ACTIVATED);
}
}
use of org.sonar.db.qualityprofile.OrgActiveRuleDto in project sonarqube by SonarSource.
the class QProfileRuleImplTest method assertThatRuleIsUpdated.
private void assertThatRuleIsUpdated(QProfileDto profile, RuleDefinitionDto rule, String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map<String, String> expectedParams) {
OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile).stream().filter(ar -> ar.getRuleKey().equals(rule.getKey())).findFirst().orElseThrow(IllegalStateException::new);
assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity);
assertThat(activeRule.getInheritance()).isEqualTo(expectedInheritance != null ? expectedInheritance.name() : null);
List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid());
assertThat(params).hasSize(expectedParams.size());
}
use of org.sonar.db.qualityprofile.OrgActiveRuleDto in project sonarqube by SonarSource.
the class ActiveRuleCompleter method loadParams.
private ListMultimap<ActiveRuleKey, ActiveRuleParamDto> loadParams(DbSession dbSession, List<OrgActiveRuleDto> activeRules) {
Map<String, ActiveRuleKey> activeRuleUuidsByKey = new HashMap<>();
for (OrgActiveRuleDto activeRule : activeRules) {
activeRuleUuidsByKey.put(activeRule.getUuid(), activeRule.getKey());
}
List<ActiveRuleParamDto> activeRuleParams = dbClient.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, Lists.transform(activeRules, ActiveRuleDto::getUuid));
ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = ArrayListMultimap.create(activeRules.size(), 10);
for (ActiveRuleParamDto activeRuleParam : activeRuleParams) {
ActiveRuleKey activeRuleKey = activeRuleUuidsByKey.get(activeRuleParam.getActiveRuleUuid());
activeRuleParamsByActiveRuleKey.put(activeRuleKey, activeRuleParam);
}
return activeRuleParamsByActiveRuleKey;
}
use of org.sonar.db.qualityprofile.OrgActiveRuleDto in project sonarqube by SonarSource.
the class QProfileTreeImpl method removeParent.
private List<ActiveRuleChange> removeParent(DbSession dbSession, QProfileDto profile) {
List<ActiveRuleChange> changes = new ArrayList<>();
if (profile.getParentKee() == null) {
return changes;
}
profile.setParentKee(null);
db.qualityProfileDao().update(dbSession, profile);
List<OrgActiveRuleDto> activeRules = db.activeRuleDao().selectByProfile(dbSession, profile);
Collection<String> ruleUuids = activeRules.stream().map(ActiveRuleDto::getRuleUuid).collect(MoreCollectors.toArrayList());
RuleActivationContext context = ruleActivator.createContextForUserProfile(dbSession, profile, ruleUuids);
for (OrgActiveRuleDto activeRule : activeRules) {
if (ActiveRuleDto.INHERITED.equals(activeRule.getInheritance())) {
changes.addAll(ruleActivator.deactivate(dbSession, context, activeRule.getRuleUuid(), true));
} else if (ActiveRuleDto.OVERRIDES.equals(activeRule.getInheritance())) {
context.reset(activeRule.getRuleUuid());
activeRule.setInheritance(null);
activeRule.setUpdatedAt(system2.now());
db.activeRuleDao().update(dbSession, activeRule);
changes.add(new ActiveRuleChange(ActiveRuleChange.Type.UPDATED, activeRule, context.getRule().get()).setInheritance(null));
}
}
qualityProfileChangeEventService.distributeRuleChangeEvent(List.of(profile), changes, profile.getLanguage());
return changes;
}
use of org.sonar.db.qualityprofile.OrgActiveRuleDto in project sonarqube by SonarSource.
the class ChangeParentActionTest method change_parent_with_no_parent_before.
@Test
public void change_parent_with_no_parent_before() {
QProfileDto parent1 = createProfile();
QProfileDto child = createProfile();
RuleDefinitionDto rule1 = createRule();
createActiveRule(rule1, parent1);
ruleIndexer.commitAndIndex(dbSession, rule1.getUuid());
activeRuleIndexer.indexAll();
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty();
// Set parent
ws.newRequest().setMethod("POST").setParam(PARAM_LANGUAGE, child.getLanguage()).setParam(PARAM_QUALITY_PROFILE, child.getName()).setParam(PARAM_PARENT_QUALITY_PROFILE, parent1.getName()).execute();
// Check rule 1 enabled
List<OrgActiveRuleDto> activeRules1 = dbClient.activeRuleDao().selectByProfile(dbSession, child);
assertThat(activeRules1).hasSize(1);
assertThat(activeRules1.get(0).getKey().getRuleKey().rule()).isEqualTo(rule1.getRuleKey());
assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getUuids()).hasSize(1);
}
Aggregations