aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorPierre Guillot <50145663+pierre-guillot-sonarsource@users.noreply.github.com>2020-02-14 17:09:57 +0100
committerSonarTech <sonartech@sonarsource.com>2020-02-20 20:46:18 +0100
commit531e52e6f1639bda8bdb83eea6a8155feef5be6d (patch)
treecc27523d745f0530eb7e9749a35924958b5e3ada /server/sonar-db-dao
parent9f796ca145a0a8169f4a319667100bd9dfc63b74 (diff)
downloadsonarqube-531e52e6f1639bda8bdb83eea6a8155feef5be6d.tar.gz
sonarqube-531e52e6f1639bda8bdb83eea6a8155feef5be6d.zip
SONAR-13003 display already imported BBS repos
Co-authored-by: Julien Lancelot <julien.lancelot@sonarsource.com>
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java10
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingMapper.java3
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/alm/setting/ProjectAlmSettingMapper.xml12
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl1
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java35
6 files changed, 61 insertions, 2 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java
index 570de28f18b..a5630c417c2 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java
@@ -73,7 +73,7 @@ public class AlmAppInstallDao implements Dao {
public List<AlmAppInstallDto> selectByOrganizations(DbSession dbSession, List<OrganizationDto> organizations) {
Set<String> organizationUuids = organizations.stream().map(OrganizationDto::getUuid).collect(Collectors.toSet());
- return executeLargeInputs(organizationUuids, uuids -> getMapper(dbSession).selectByOrganizationUuids(organizationUuids));
+ return executeLargeInputs(organizationUuids, uuids -> getMapper(dbSession).selectByOrganizationUuids(uuids));
}
public List<AlmAppInstallDto> selectUnboundByUserExternalId(DbSession dbSession, String userExternalId) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java
index d93d544c12d..a3d1b0e941d 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java
@@ -19,13 +19,20 @@
*/
package org.sonar.db.alm.setting;
+import java.util.List;
import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
import org.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
+import org.sonar.db.alm.AlmAppInstallDto;
+import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.project.ProjectDto;
+import static org.sonar.db.DatabaseUtils.executeLargeInputs;
+
public class ProjectAlmSettingDao implements Dao {
private final System2 system2;
@@ -73,4 +80,7 @@ public class ProjectAlmSettingDao implements Dao {
return dbSession.getMapper(ProjectAlmSettingMapper.class);
}
+ public List<ProjectAlmSettingDto> selectByAlmSettingAndSlugs(DbSession dbSession, AlmSettingDto almSettingDto, Set<String> almSlugs) {
+ return executeLargeInputs(almSlugs, slugs -> getMapper(dbSession).selectByAlmSettingAndSlugs(almSettingDto.getUuid(), slugs));
+ }
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingMapper.java
index 248756e81a1..a880721c126 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingMapper.java
@@ -19,6 +19,8 @@
*/
package org.sonar.db.alm.setting;
+import java.util.List;
+import java.util.Set;
import javax.annotation.CheckForNull;
import org.apache.ibatis.annotations.Param;
@@ -36,4 +38,5 @@ public interface ProjectAlmSettingMapper {
void deleteByProjectUuid(@Param("projectUuid") String projectUuid);
void deleteByAlmSettingUuid(@Param("almSettingUuid") String almSettingUuid);
+ List<ProjectAlmSettingDto> selectByAlmSettingAndSlugs(@Param("almSettingUuid") String almSettingUuid, @Param("slugs") List<String> slugs);
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/setting/ProjectAlmSettingMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/setting/ProjectAlmSettingMapper.xml
index 87848bac606..7b6a7f86262 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/setting/ProjectAlmSettingMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/setting/ProjectAlmSettingMapper.xml
@@ -21,6 +21,18 @@
p.project_uuid = #{projectUuid, jdbcType=VARCHAR}
</select>
+ <select id="selectByAlmSettingAndSlugs" parameterType="string" resultType="org.sonar.db.alm.setting.ProjectAlmSettingDto">
+ select <include refid="sqlColumns"/>
+ from
+ project_alm_settings p
+ where
+ alm_setting_uuid=#{almSettingUuid, jdbcType=VARCHAR}
+ and alm_slug in
+ <foreach collection="slugs" open="(" close=")" item="slug" separator=",">
+ #{slug, jdbcType=VARCHAR}
+ </foreach>
+ </select>
+
<insert id="insert" parameterType="Map" useGeneratedKeys="false">
INSERT INTO project_alm_settings
(
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index eb922de2031..17a3cd04dc3 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -636,6 +636,7 @@ CREATE TABLE "PROJECT_ALM_SETTINGS"(
ALTER TABLE "PROJECT_ALM_SETTINGS" ADD CONSTRAINT "PK_PROJECT_ALM_SETTINGS" PRIMARY KEY("UUID");
CREATE UNIQUE INDEX "UNIQ_PROJECT_ALM_SETTINGS" ON "PROJECT_ALM_SETTINGS"("PROJECT_UUID");
CREATE INDEX "PROJECT_ALM_SETTINGS_ALM" ON "PROJECT_ALM_SETTINGS"("ALM_SETTING_UUID");
+CREATE INDEX "PROJECT_ALM_SETTINGS_SLUG" ON "PROJECT_ALM_SETTINGS"("ALM_SLUG");
CREATE TABLE "PROJECT_BRANCHES"(
"UUID" VARCHAR(50) NOT NULL,
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java
index 474ac89f68f..cdbfa161c5d 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java
@@ -19,6 +19,8 @@
*/
package org.sonar.db.alm.setting;
+import java.util.HashSet;
+import java.util.Set;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -31,6 +33,7 @@ import org.sonar.db.project.ProjectDto;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.sonar.db.almsettings.AlmSettingsTesting.newBitbucketProjectAlmSettingDto;
import static org.sonar.db.almsettings.AlmSettingsTesting.newGithubProjectAlmSettingDto;
public class ProjectAlmSettingDaoTest {
@@ -50,7 +53,7 @@ public class ProjectAlmSettingDaoTest {
private ProjectAlmSettingDao underTest = new ProjectAlmSettingDao(system2, uuidFactory);
@Test
- public void selectByProject() {
+ public void select_by_project() {
when(uuidFactory.create()).thenReturn(A_UUID);
when(system2.now()).thenReturn(A_DATE);
AlmSettingDto githubAlmSettingDto = db.almSettings().insertGitHubAlmSetting();
@@ -71,6 +74,36 @@ public class ProjectAlmSettingDaoTest {
}
@Test
+ public void select_by_alm_setting_and_slugs() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+ when(system2.now()).thenReturn(A_DATE);
+ AlmSettingDto almSettingsDto = db.almSettings().insertBitbucketAlmSetting();
+ ProjectDto project = db.components().insertPrivateProjectDto();
+ ProjectAlmSettingDto githubProjectAlmSettingDto = newBitbucketProjectAlmSettingDto(almSettingsDto, project);
+ githubProjectAlmSettingDto.setAlmSlug("slug1");
+ underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto);
+ ProjectAlmSettingDto githubProjectAlmSettingDto2 = newBitbucketProjectAlmSettingDto(almSettingsDto, db.components().insertPrivateProjectDto());
+ githubProjectAlmSettingDto2.setAlmSlug("slug2");
+ when(uuidFactory.create()).thenReturn(A_UUID + 1);
+ underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto2);
+
+ Set<String> slugs = new HashSet<>();
+ slugs.add("slug1");
+ assertThat(underTest.selectByAlmSettingAndSlugs(dbSession, almSettingsDto, slugs))
+ .extracting(ProjectAlmSettingDto::getProjectUuid)
+ .containsExactly(project.getUuid());
+ }
+
+ @Test
+ public void select_with_no_slugs_return_empty() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+ when(system2.now()).thenReturn(A_DATE);
+ AlmSettingDto almSettingsDto = db.almSettings().insertBitbucketAlmSetting();
+
+ assertThat(underTest.selectByAlmSettingAndSlugs(dbSession, almSettingsDto, new HashSet<>())).isEmpty();
+ }
+
+ @Test
public void update_existing_binding() {
when(uuidFactory.create()).thenReturn(A_UUID);
when(system2.now()).thenReturn(A_DATE);