]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9087 add ComponentDao#setPrivateForRootComponentUuid
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 13 Apr 2017 07:31:35 +0000 (09:31 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 27 Apr 2017 12:25:54 +0000 (14:25 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java

index 87678ede9b3a637969006a6bd2e6a14cf4e94186..be316cb26e96320d76280d536c3c9ab07076adeb 100644 (file)
@@ -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);
   }
index 6a609e37f2687f8d36bca59cead9d692eddddef1..319d594dc8314df746708de2246b9a9951356ed3 100644 (file)
@@ -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);
index 1a461df3c41a7eb71613674daf85b90a04475455..1c4920b51e3d846491064c19d0199ad89636b627 100644 (file)
     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>
index eb6e051d2fd4b46fcc03cd69e14c12d11e671cd2..b82b94c10dacecdf794e9f681029f9f755cd371f 100644 (file)
@@ -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();
+  }
 }