From bcb302279d4dead246126e46ec8ea9d6b9d15c77 Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Tue, 1 Jul 2014 16:24:22 +0200 Subject: [PATCH] fix quality flaw --- .../qualityprofile/db/ActiveRuleDao.java | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/db/ActiveRuleDao.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/db/ActiveRuleDao.java index 243d969508f..b8c49eae83d 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/db/ActiveRuleDao.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/db/ActiveRuleDao.java @@ -47,6 +47,16 @@ import java.util.Map; public class ActiveRuleDao extends BaseDao { + private static final String QUALITY_PROFILE_IS_NOT_PERSISTED = "Quality profile is not persisted (missing id)"; + private static final String RULE_IS_NOT_PERSISTED = "Rule is not persisted"; + private static final String RULE_PARAM_IS_NOT_PERSISTED = "Rule param is not persisted"; + private static final String ACTIVE_RULE_KEY_CANNOT_BE_NULL = "ActiveRuleKey cannot be null"; + private static final String ACTIVE_RULE_IS_NOT_PERSISTED = "ActiveRule is not persisted"; + private static final String ACTIVE_RULE_IS_ALREADY_PERSISTED = "ActiveRule is already persisted"; + private static final String ACTIVE_RULE_PARAM_IS_NOT_PERSISTED = "ActiveRuleParam is not persisted"; + private static final String ACTIVE_RULE_PARAM_IS_ALREADY_PERSISTED = "ActiveRuleParam is already persisted"; + private static final String PARAMETER_NAME_CANNOT_BE_NULL = "ParameterName cannot be null"; + //TODO remove once key is finalized (used only to get id for SQL statement) private final RuleDao ruleDao; private final QualityProfileDao profileDao; @@ -101,18 +111,18 @@ public class ActiveRuleDao extends BaseDao findByRule(DbSession dbSession, RuleDto rule) { - Preconditions.checkNotNull(rule.getId(), "Rule is not persisted"); + Preconditions.checkNotNull(rule.getId(), RULE_IS_NOT_PERSISTED); return mapper(dbSession).selectByRuleId(rule.getId()); } @@ -146,9 +156,9 @@ public class ActiveRuleDao extends BaseDao findParamsByActiveRuleKey(DbSession session, ActiveRuleKey key) { - Preconditions.checkNotNull(key, "ActiveRuleKey cannot be null"); + Preconditions.checkNotNull(key, ACTIVE_RULE_KEY_CANNOT_BE_NULL); ActiveRuleDto activeRule = this.getByKey(session, key); return mapper(session).selectParamsByActiveRuleId(activeRule.getId()); } public ActiveRuleParamDto getParamByKeyAndName(ActiveRuleKey key, String name, DbSession session) { - Preconditions.checkNotNull(key, "ActiveRuleKey cannot be null"); - Preconditions.checkNotNull(name, "ParameterName cannot be null"); + Preconditions.checkNotNull(key, ACTIVE_RULE_KEY_CANNOT_BE_NULL); + Preconditions.checkNotNull(name, PARAMETER_NAME_CANNOT_BE_NULL); ActiveRuleDto activeRule = getNullableByKey(session, key); return mapper(session).selectParamByActiveRuleAndKey(activeRule.getId(), name); } -- 2.39.5