*/
public List<ActiveRuleChange> deactivate(DbSession dbSession, RuleDto ruleDto) {
List<ActiveRuleChange> changes = Lists.newArrayList();
- List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByRule(dbSession, ruleDto);
+ List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByRuleId(dbSession, ruleDto.getId());
for (ActiveRuleDto activeRule : activeRules) {
changes.addAll(deactivate(dbSession, activeRule.getKey(), true));
}
for (RuleParamDto paramDto : paramDtos) {
RulesDefinition.Param paramDef = ruleDef.param(paramDto.getName());
if (paramDef == null) {
- dbClient.activeRuleDao().deleteParamsByRuleParam(session, rule, paramDto.getName());
+ dbClient.activeRuleDao().deleteParamsByRuleParam(session, rule.getId(), paramDto.getName());
dbClient.ruleDao().deleteRuleParam(session, paramDto.getId());
} else {
if (mergeParam(paramDto, paramDef)) {
dbClient.ruleDao().insertRuleParam(session, rule, paramDto);
if (!StringUtils.isEmpty(param.defaultValue())) {
// Propagate the default value to existing active rule parameters
- for (ActiveRuleDto activeRule : dbClient.activeRuleDao().selectByRule(session, rule)) {
+ for (ActiveRuleDto activeRule : dbClient.activeRuleDao().selectByRuleId(session, rule.getId())) {
ActiveRuleParamDto activeParam = ActiveRuleParamDto.createFor(paramDto).setValue(param.defaultValue());
dbClient.activeRuleDao().insertParam(session, activeRule, activeParam);
}
}
private Multimap<ActiveRuleDto, ActiveRuleParamDto> getActiveRuleParamsByActiveRule(DbSession dbSession, RuleDto customRule) {
- List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRule(dbSession, customRule);
+ List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRuleId(dbSession, customRule.getId());
Map<Integer, ActiveRuleDto> activeRuleById = from(activeRuleDtos).uniqueIndex(ActiveRuleDtoToId.INSTANCE);
List<Integer> activeRuleIds = from(activeRuleDtos)
.transform(ActiveRuleDtoToId.INSTANCE)
}
void completeShow(DbSession dbSession, RuleDto rule, ShowResponse.Builder response) {
- List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRule(dbSession, rule);
+ List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRuleId(dbSession, rule.getId());
Map<Integer, ActiveRuleKey> activeRuleIdsByKey = new HashMap<>();
for (ActiveRuleDto activeRuleDto : activeRuleDtos) {
activeRuleIdsByKey.put(activeRuleDto.getId(), activeRuleDto.getKey());
session.commit();
// 2. Assert ActiveRule with MINOR severity
- assertThat(tester.get(ActiveRuleDao.class).selectByRule(session, rule0).get(0).getSeverityString()).isEqualTo("MINOR");
+ assertThat(tester.get(ActiveRuleDao.class).selectByRuleId(session, rule0.getId()).get(0).getSeverityString()).isEqualTo("MINOR");
assertThat(tester.get(RuleIndex.class).searchAll(new RuleQuery()
.setQProfileKey(profile.getKey())
.setKey(rule0.getKey().toString())
import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbSession;
import org.sonar.db.RowNotFoundException;
-import org.sonar.db.rule.RuleDto;
public class ActiveRuleDao implements Dao {
return DatabaseUtils.executeLargeInputs(keys, new KeyToDto(mapper(dbSession)));
}
- public List<ActiveRuleDto> selectByRule(DbSession dbSession, RuleDto rule) {
- Preconditions.checkNotNull(rule.getId(), RULE_IS_NOT_PERSISTED);
- return mapper(dbSession).selectByRuleId(rule.getId());
+ public List<ActiveRuleDto> selectByRuleId(DbSession dbSession, int ruleId) {
+ return mapper(dbSession).selectByRuleId(ruleId);
}
public List<ActiveRuleDto> selectByRuleIds(DbSession dbSession, List<Integer> ids) {
}
}
- public void deleteParamsByRuleParam(DbSession dbSession, RuleDto rule, String paramKey) {
- List<ActiveRuleDto> activeRules = selectByRule(dbSession, rule);
+ public void deleteParamsByRuleParam(DbSession dbSession, int ruleId, String paramKey) {
+ List<ActiveRuleDto> activeRules = selectByRuleId(dbSession, ruleId);
for (ActiveRuleDto activeRule : activeRules) {
for (ActiveRuleParamDto activeParam : selectParamsByActiveRuleId(dbSession, activeRule.getId())) {
if (activeParam.getKey().equals(paramKey)) {
underTest.insert(dbTester.getSession(), activeRule2);
dbSession.commit();
- assertThat(underTest.selectByRule(dbSession, rule1)).extracting("key").containsOnly(activeRule1.getKey(), activeRule2.getKey());
- assertThat(underTest.selectByRule(dbSession, rule3)).isEmpty();
+ assertThat(underTest.selectByRuleId(dbSession, rule1.getId())).extracting("key").containsOnly(activeRule1.getKey(), activeRule2.getKey());
+ assertThat(underTest.selectByRuleId(dbSession, rule3.getId())).isEmpty();
}
@Test
dbSession.commit();
- underTest.deleteParamsByRuleParam(dbSession, rule1, rule1Param1.getName());
+ underTest.deleteParamsByRuleParam(dbSession, rule1.getId(), rule1Param1.getName());
dbSession.commit();
assertThat(underTest.selectParamByKeyAndName(activeRule1.getKey(), activeRuleParam1.getKey(), dbSession)).isNull();
dbSession.commit();
- underTest.deleteParamsByRuleParam(dbSession, rule1, "unknown");
+ underTest.deleteParamsByRuleParam(dbSession, rule1.getId(), "unknown");
}
}