aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-04-13 09:31:35 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-04-27 14:25:54 +0200
commitc3db4556be6503b693d0942718180406bfcc3aec (patch)
tree7d9e1634ff79ca061c5cdd9021982e6f27efe25a /server/sonar-db-dao
parentf803b905445daccf3f23c25356be5c21054d8a8f (diff)
downloadsonarqube-c3db4556be6503b693d0942718180406bfcc3aec.tar.gz
sonarqube-c3db4556be6503b693d0942718180406bfcc3aec.zip
SONAR-9087 add ComponentDao#setPrivateForRootComponentUuid
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml8
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java51
4 files changed, 65 insertions, 0 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 87678ede9b3..be316cb26e9 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
@@ -342,6 +342,10 @@ public class ComponentDao implements Dao {
mapper(session).resetBChangedForRootComponentUuid(projectUuid);
}
+ public void setPrivateForRootComponentUuid(DbSession session, String projectUuid, boolean isPrivate) {
+ mapper(session).setPrivateForRootComponentUuid(projectUuid, isPrivate);
+ }
+
public void delete(DbSession session, long componentId) {
mapper(session).delete(componentId);
}
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 6a609e37f26..319d594dc83 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
@@ -142,6 +142,8 @@ public interface ComponentMapper {
void resetBChangedForRootComponentUuid(@Param("projectUuid") String projectUuid);
+ void setPrivateForRootComponentUuid(@Param("projectUuid") String projectUuid, @Param("isPrivate") boolean isPrivate);
+
void delete(long componentId);
void updateTags(ComponentDto component);
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 1a461df3c41..1c4920b51e3 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
@@ -616,6 +616,14 @@
b_changed = ${_true}
</update>
+ <update id="setPrivateForRootComponentUuid" parameterType="map" >
+ update projects set
+ private = #{isPrivate,jdbcType=BOOLEAN}
+ where
+ project_uuid = #{projectUuid,jdbcType=VARCHAR}
+ and private &lt;&gt; #{isPrivate,jdbcType=BOOLEAN}
+ </update>
+
<delete id="delete" parameterType="long">
DELETE FROM projects WHERE id=#{id,jdbcType=BIGINT}
</delete>
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
index eb6e051d2fd..b82b94c10da 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
@@ -1143,4 +1143,55 @@ public class ComponentDaoTest {
assertThat(underTest.selectProjectsByNameQuery(dbSession, "1", true)).extracting(ComponentDto::uuid).containsOnly(project1.uuid(), module1.uuid(), subModule1.uuid());
assertThat(underTest.selectProjectsByNameQuery(dbSession, "unknown", true)).extracting(ComponentDto::uuid).isEmpty();
}
+
+ @Test
+ public void setPrivateForRootComponentUuid_updates_private_column_to_specified_value_for_all_rows_with_specified_projectUuid() {
+ String uuid1 = "uuid1";
+ String uuid2 = "uuid2";
+
+ OrganizationDto organizationDto = db.organizations().insert();
+ String[] uuids = {
+ db.components().insertComponent(newProjectDto(organizationDto).setProjectUuid(uuid1).setPrivate(true)).uuid(),
+ db.components().insertComponent(newProjectDto(organizationDto).setProjectUuid(uuid1).setPrivate(false)).uuid(),
+ db.components().insertComponent(newProjectDto(organizationDto).setProjectUuid(uuid2).setPrivate(true)).uuid(),
+ db.components().insertComponent(newProjectDto(organizationDto).setProjectUuid(uuid2).setPrivate(false)).uuid(),
+ db.components().insertComponent(newProjectDto(organizationDto).setRootUuid(uuid1).setProjectUuid("foo").setPrivate(false)).uuid(),
+ };
+
+ underTest.setPrivateForRootComponentUuid(db.getSession(), uuid1, true);
+
+ assertThat(privateFlagOfUuid(uuids[0])).isTrue();
+ assertThat(privateFlagOfUuid(uuids[1])).isTrue();
+ assertThat(privateFlagOfUuid(uuids[2])).isTrue();
+ assertThat(privateFlagOfUuid(uuids[3])).isFalse();
+ assertThat(privateFlagOfUuid(uuids[4])).isFalse();
+
+ underTest.setPrivateForRootComponentUuid(db.getSession(), uuid1, false);
+
+ assertThat(privateFlagOfUuid(uuids[0])).isFalse();
+ assertThat(privateFlagOfUuid(uuids[1])).isFalse();
+ assertThat(privateFlagOfUuid(uuids[2])).isTrue();
+ assertThat(privateFlagOfUuid(uuids[3])).isFalse();
+ assertThat(privateFlagOfUuid(uuids[4])).isFalse();
+
+ underTest.setPrivateForRootComponentUuid(db.getSession(), uuid2, false);
+
+ assertThat(privateFlagOfUuid(uuids[0])).isFalse();
+ assertThat(privateFlagOfUuid(uuids[1])).isFalse();
+ assertThat(privateFlagOfUuid(uuids[2])).isFalse();
+ assertThat(privateFlagOfUuid(uuids[3])).isFalse();
+ assertThat(privateFlagOfUuid(uuids[4])).isFalse();
+
+ underTest.setPrivateForRootComponentUuid(db.getSession(), uuid2, true);
+
+ assertThat(privateFlagOfUuid(uuids[0])).isFalse();
+ assertThat(privateFlagOfUuid(uuids[1])).isFalse();
+ assertThat(privateFlagOfUuid(uuids[2])).isTrue();
+ assertThat(privateFlagOfUuid(uuids[3])).isTrue();
+ assertThat(privateFlagOfUuid(uuids[4])).isFalse();
+ }
+
+ private boolean privateFlagOfUuid(String uuid) {
+ return underTest.selectByUuid(db.getSession(), uuid).get().isPrivate();
+ }
}