use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class QProfilesWsMediumTest method bulk_deactivate_rule_not_all.
@Test
public void bulk_deactivate_rule_not_all() throws Exception {
QualityProfileDto profile = createProfile("java");
QualityProfileDto php = createProfile("php");
RuleDto rule0 = createRule(profile.getLanguage(), "toto1");
RuleDto rule1 = createRule(profile.getLanguage(), "toto2");
createActiveRule(rule0, profile);
createActiveRule(rule1, profile);
createActiveRule(rule0, php);
createActiveRule(rule1, php);
session.commit();
ruIndexer.index();
activeRuIndexer.index();
// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(2);
// 1. Deactivate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_DEACTIVATE_ACTION);
request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
WsTester.Result result = request.execute();
session.clearCache();
// 2. Assert ActiveRule in DAO
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(0);
assertThat(db.activeRuleDao().selectByProfileKey(session, php.getKey())).hasSize(2);
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class QProfilesWsMediumTest method activate_rule_override_severity.
@Test
public void activate_rule_override_severity() throws Exception {
QualityProfileDto profile = createProfile("java");
RuleDto rule = createRule(profile.getLanguage(), "toto");
session.commit();
ruIndexer.index();
// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, RuleActivationActions.ACTIVATE_ACTION);
request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
request.setParam(RuleActivationActions.RULE_KEY, rule.getKey().toString());
request.setParam(RuleActivationActions.SEVERITY, "MINOR");
WsTester.Result result = request.execute();
session.clearCache();
// 2. Assert ActiveRule in DAO
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), rule.getKey());
assertThat(db.activeRuleDao().selectOrFailByKey(session, activeRuleKey).getSeverityString()).isEqualTo("MINOR");
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class QProfileReset method resetLanguage.
/**
* Reset built-in profiles for the given language. Missing profiles are created and
* existing ones are updated.
*/
public void resetLanguage(String language) {
DbSession dbSession = db.openSession(false);
try {
ListMultimap<QProfileName, RulesProfile> profilesByName = loadDefinitionsGroupedByName(language);
for (Map.Entry<QProfileName, Collection<RulesProfile>> entry : profilesByName.asMap().entrySet()) {
QProfileName profileName = entry.getKey();
QualityProfileDto profile = factory.getOrCreate(dbSession, profileName);
List<RuleActivation> activations = Lists.newArrayList();
for (RulesProfile def : entry.getValue()) {
for (ActiveRule activeRule : def.getActiveRules()) {
RuleActivation activation = new RuleActivation(RuleKey.of(activeRule.getRepositoryKey(), activeRule.getRuleKey()));
activation.setSeverity(activeRule.getSeverity().name());
if (!activeRule.getActiveRuleParams().isEmpty()) {
for (ActiveRuleParam param : activeRule.getActiveRuleParams()) {
activation.setParameter(param.getParamKey(), param.getValue());
}
} else {
for (RuleParamDto param : db.ruleDao().selectRuleParamsByRuleKey(dbSession, activeRule.getRule().ruleKey())) {
activation.setParameter(param.getName(), param.getDefaultValue());
}
}
activations.add(activation);
}
}
doReset(dbSession, profile, activations);
}
} finally {
dbSession.close();
}
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class RegisterQualityProfiles method register.
private List<ActiveRuleChange> register(QProfileName name, Collection<RulesProfile> profiles, DbSession session) {
LOGGER.info("Register profile " + name);
List<ActiveRuleChange> changes = new ArrayList<>();
QualityProfileDto profileDto = dbClient.qualityProfileDao().selectByNameAndLanguage(name.getName(), name.getLanguage(), session);
if (profileDto != null) {
changes.addAll(profileFactory.delete(session, profileDto.getKey(), true));
}
profileFactory.create(session, name);
for (RulesProfile profile : profiles) {
for (org.sonar.api.rules.ActiveRule activeRule : profile.getActiveRules()) {
RuleKey ruleKey = RuleKey.of(activeRule.getRepositoryKey(), activeRule.getRuleKey());
RuleActivation activation = new RuleActivation(ruleKey);
activation.setSeverity(activeRule.getSeverity() != null ? activeRule.getSeverity().name() : null);
for (ActiveRuleParam param : activeRule.getActiveRuleParams()) {
activation.setParameter(param.getKey(), param.getValue());
}
changes.addAll(ruleActivator.activate(session, activation, name));
}
}
LoadedTemplateDto template = new LoadedTemplateDto(templateKey(name), LoadedTemplateDto.QUALITY_PROFILE_TYPE);
dbClient.loadedTemplateDao().insert(template, session);
session.commit();
return changes;
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class RuleActivator method updateProfileDates.
private void updateProfileDates(DbSession dbSession, RuleActivatorContext context) {
QualityProfileDto profile = context.profile();
profile.setRulesUpdatedAtAsDate(context.getInitDate());
if (userSession.isLoggedIn()) {
profile.setUserUpdatedAt(context.getInitDate().getTime());
}
db.qualityProfileDao().update(dbSession, profile);
}
Aggregations