aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-05-05 11:53:04 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-05-05 20:14:53 +0200
commit933ac80b9ec0f39468624016fda7de6ed6bb1c3a (patch)
tree31f855d32ddd2bc9ff3437ba17503faa3b9eaffd
parent9aa35c6e74e737fc5874cd10be6d72f2b60afe5c (diff)
downloadsonarqube-933ac80b9ec0f39468624016fda7de6ed6bb1c3a.tar.gz
sonarqube-933ac80b9ec0f39468624016fda7de6ed6bb1c3a.zip
Added ActiveRuleKey to ActiveRuleDao with BaseDao extension.
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule2/ActiveRuleDao.java46
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule2/ActiveRuleDaoTest.java6
2 files changed, 42 insertions, 10 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/ActiveRuleDao.java b/sonar-server/src/main/java/org/sonar/server/rule2/ActiveRuleDao.java
index b4c9df5f7f8..9be275fb594 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule2/ActiveRuleDao.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule2/ActiveRuleDao.java
@@ -30,7 +30,11 @@ import org.sonar.core.qualityprofile.db.ActiveRuleDto;
import org.sonar.core.qualityprofile.db.ActiveRuleKey;
import org.sonar.core.qualityprofile.db.ActiveRuleMapper;
import org.sonar.core.qualityprofile.db.ActiveRuleParamDto;
+import org.sonar.core.qualityprofile.db.QualityProfileDao;
+import org.sonar.core.qualityprofile.db.QualityProfileDto;
+import org.sonar.core.qualityprofile.db.QualityProfileKey;
import org.sonar.core.rule.RuleConstants;
+import org.sonar.core.rule.RuleDto;
import org.sonar.server.db.BaseDao;
import javax.annotation.CheckForNull;
@@ -43,8 +47,14 @@ import static com.google.common.collect.Lists.newArrayList;
public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, ActiveRuleKey>
implements ServerComponent {
- public ActiveRuleDao(MyBatis mybatis) {
+ /** this is temporary to build RuleKey and QProfileKey */
+ private RuleDao ruleDao;
+ private QualityProfileDao qDao;
+
+ public ActiveRuleDao(MyBatis mybatis, QualityProfileDao qDao, RuleDao ruleDao) {
super(ActiveRuleMapper.class, mybatis);
+ this.ruleDao = ruleDao;
+ this.qDao = qDao;
}
@Override
@@ -59,8 +69,9 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti
@Override
protected ActiveRuleDto doGetByKey(ActiveRuleKey key, DbSession session) {
- //return getMapper(session).selectByKey(key);
- throw new NotYetImplementedException("Need to implement ActiveRuleDto.doGetByKey() method");
+ QualityProfileDto qDto = qDao.selectByNameAndLanguage(key.qProfile().name(), key.qProfile().lang(), session);
+ RuleDto ruleDto = ruleDao.selectByKey(key.ruleKey());
+ return this.selectByProfileAndRule(qDto.getId(), ruleDto.getId(), session);
}
@Override
@@ -85,6 +96,23 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti
throw new NotYetImplementedException("Need to implement ActiveRuleDto.doDeleteByKey() method");
}
+ /** Helper methods to get the RuleKey and QualityProfileKey -- Temporary */
+
+ private ActiveRuleDto setActiveRuleKey(ActiveRuleDto dto){
+ RuleDto ruleDto = ruleDao.selectById(dto.getId());
+ QualityProfileDto qDto = qDao.selectById(dto.getId());
+ if(qDto != null && ruleDto != null) {
+ dto.setKey(QualityProfileKey.of(qDto.getName(), qDto.getLanguage()), ruleDto.getKey());
+ }
+ return dto;
+ }
+
+ private List<ActiveRuleDto> setActiveRuleKey(List<ActiveRuleDto> dtos){
+ for(ActiveRuleDto dto:dtos) {
+ setActiveRuleKey(dto);
+ }
+ return dtos;
+ }
public void delete(int activeRuleId, SqlSession session) {
@@ -148,7 +176,7 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti
List<ActiveRuleDto> dtos = session.selectList("org.sonar.core.qualityprofile.db.ActiveRuleMapper.selectByIds", newArrayList(idsPartition));
dtosList.addAll(dtos);
}
- return dtosList;
+ return setActiveRuleKey(dtosList);
}
public List<ActiveRuleDto> selectAll() {
@@ -161,7 +189,7 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti
}
public List<ActiveRuleDto> selectAll(SqlSession session) {
- return session.getMapper(ActiveRuleMapper.class).selectAll();
+ return setActiveRuleKey(session.getMapper(ActiveRuleMapper.class).selectAll());
}
public List<ActiveRuleDto> selectByRuleId(int ruleId) {
@@ -174,7 +202,7 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti
}
public List<ActiveRuleDto> selectByRuleId(int ruleId, SqlSession session) {
- return session.getMapper(ActiveRuleMapper.class).selectByRuleId(ruleId);
+ return setActiveRuleKey(session.getMapper(ActiveRuleMapper.class).selectByRuleId(ruleId));
}
public List<ActiveRuleDto> selectByProfileId(int profileId) {
@@ -187,7 +215,7 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti
}
public List<ActiveRuleDto> selectByProfileId(int profileId, SqlSession session) {
- return session.getMapper(ActiveRuleMapper.class).selectByProfileId(profileId);
+ return setActiveRuleKey(session.getMapper(ActiveRuleMapper.class).selectByProfileId(profileId));
}
@@ -203,7 +231,7 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti
@CheckForNull
public ActiveRuleDto selectById(int id, SqlSession session) {
- return session.getMapper(ActiveRuleMapper.class).selectById(id);
+ return setActiveRuleKey(session.getMapper(ActiveRuleMapper.class).selectById(id));
}
@CheckForNull
@@ -218,7 +246,7 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti
@CheckForNull
public ActiveRuleDto selectByProfileAndRule(int profileId, int ruleId, SqlSession session) {
- return session.getMapper(ActiveRuleMapper.class).selectByProfileAndRule(profileId, ruleId);
+ return setActiveRuleKey(session.getMapper(ActiveRuleMapper.class).selectByProfileAndRule(profileId, ruleId));
}
public void insert(ActiveRuleParamDto dto, SqlSession session) {
diff --git a/sonar-server/src/test/java/org/sonar/server/rule2/ActiveRuleDaoTest.java b/sonar-server/src/test/java/org/sonar/server/rule2/ActiveRuleDaoTest.java
index 50a0e9403d8..f826be582f7 100644
--- a/sonar-server/src/test/java/org/sonar/server/rule2/ActiveRuleDaoTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rule2/ActiveRuleDaoTest.java
@@ -30,6 +30,7 @@ import org.sonar.api.utils.DateUtils;
import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.qualityprofile.db.ActiveRuleDto;
import org.sonar.core.qualityprofile.db.ActiveRuleParamDto;
+import org.sonar.core.qualityprofile.db.QualityProfileDao;
import java.util.List;
@@ -41,7 +42,10 @@ public class ActiveRuleDaoTest extends AbstractDaoTestCase {
@Before
public void createDao() {
- dao = new ActiveRuleDao(getMyBatis());
+
+ RuleDao ruleDao = new RuleDao(getMyBatis());
+ QualityProfileDao qDao = new QualityProfileDao(getMyBatis());
+ dao = new ActiveRuleDao(getMyBatis(), qDao, ruleDao);
}
@Test