From 47ef3bd0dc6610d0034f1753e06e8ac467eb906b Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 10 Aug 2017 13:36:54 +0200 Subject: SONAR-9616 Support branch in api/issues/search --- .../java/org/sonar/db/component/ComponentDao.java | 9 +- .../org/sonar/db/component/ComponentMapper.java | 2 + .../org/sonar/db/component/ComponentMapper.xml | 12 ++ .../org/sonar/db/component/ComponentDaoTest.java | 18 +++ .../org/sonar/db/component/ComponentDbTester.java | 2 +- .../java/org/sonar/server/issue/IssueQuery.java | 13 ++ .../org/sonar/server/issue/IssueQueryFactory.java | 144 +++++++++++---------- .../org/sonar/server/issue/index/IssueIndex.java | 5 +- .../org/sonar/server/issue/ws/SearchAction.java | 11 +- .../sonar/server/batch/ProjectDataLoaderTest.java | 6 +- .../org/sonar/server/issue/IssueDocTesting.java | 31 +++-- .../sonar/server/issue/IssueQueryFactoryTest.java | 109 ++++++++++++++-- .../org/sonar/server/issue/IssueQueryTest.java | 7 + .../sonar/server/issue/index/IssueIndexTest.java | 96 ++++++++++---- .../sonar/server/issue/index/IssueIndexerTest.java | 2 +- .../issue/ws/SearchActionComponentsTest.java | 107 ++++++++++++--- .../sonar/server/issue/ws/SearchActionTest.java | 12 +- .../ws/client/issue/IssuesWsParameters.java | 1 + .../sonarqube/ws/client/issue/SearchWsRequest.java | 11 ++ 19 files changed, 452 insertions(+), 146 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java index f12e59a954c..b6456c4e12d 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java @@ -35,6 +35,7 @@ import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; import org.sonar.api.resources.Qualifiers; import org.sonar.api.resources.Scopes; +import org.sonar.core.util.stream.MoreCollectors; import org.sonar.db.Dao; import org.sonar.db.DbSession; import org.sonar.db.RowNotFoundException; @@ -47,6 +48,7 @@ import static org.sonar.db.DaoDatabaseUtils.buildLikeValue; import static org.sonar.db.DatabaseUtils.executeLargeInputs; import static org.sonar.db.DatabaseUtils.executeLargeUpdates; import static org.sonar.db.WildcardPosition.BEFORE_AND_AFTER; +import static org.sonar.db.component.ComponentDto.generateBranchKey; public class ComponentDao implements Dao { @@ -169,6 +171,11 @@ public class ComponentDao implements Dao { return executeLargeInputs(keys, mapper(session)::selectByKeys); } + public List selectByKeysAndBranch(DbSession session, Collection keys, String branch) { + List dbKeys = keys.stream().map(k -> generateBranchKey(k, branch)).collect(MoreCollectors.toList()); + return executeLargeInputs(dbKeys, mapper(session)::selectByDbKeys); + } + public List selectComponentsHavingSameKeyOrderedById(DbSession session, String key) { return mapper(session).selectComponentsHavingSameKeyOrderedById(key); } @@ -215,7 +222,7 @@ public class ComponentDao implements Dao { } public java.util.Optional selectByKeyAndBranch(DbSession session, String key, String branch) { - return java.util.Optional.ofNullable(mapper(session).selectByDbKey(ComponentDto.generateBranchKey(key, branch))); + return java.util.Optional.ofNullable(mapper(session).selectByDbKey(generateBranchKey(key, branch))); } public List selectAllViewsAndSubViews(DbSession session) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java index 692948c085c..0f3f5d74c33 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java @@ -52,6 +52,8 @@ public interface ComponentMapper { List selectByKeys(@Param("keys") Collection keys); + List selectByDbKeys(@Param("keys") Collection keys); + List selectByIds(@Param("ids") Collection ids); List selectByUuids(@Param("uuids") Collection uuids); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml index 0409bbd1f62..d7079ac7a10 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -89,6 +89,18 @@ + +