]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8752 support userId in OrganizationDto and OrganizationDao
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 10 Feb 2017 15:16:40 +0000 (16:16 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 10 Feb 2017 17:29:38 +0000 (18:29 +0100)
sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java
sonar-db/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java
sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoWithDuplicatedKeysTest/schema.sql

index 96b55c80acaea4684510c389dd3260b872bf772e..797050210958b5576b79bcd77866aa50e302f008 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.db.organization;
 
+import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 
 public class OrganizationDto {
@@ -38,6 +39,8 @@ public class OrganizationDto {
    * Flag indicated whether being root is required to be able to delete this organization.
    */
   private boolean guarded = false;
+  /** If of the user for whom the organization was created, can be null. */
+  private Long userId;
   private long createdAt;
   private long updatedAt;
 
@@ -104,6 +107,16 @@ public class OrganizationDto {
     return this;
   }
 
+  @CheckForNull
+  public Long getUserId() {
+    return userId;
+  }
+
+  public OrganizationDto setUserId(@Nullable Long userId) {
+    this.userId = userId;
+    return this;
+  }
+
   public long getCreatedAt() {
     return createdAt;
   }
@@ -132,6 +145,7 @@ public class OrganizationDto {
       ", url='" + url + '\'' +
       ", avatarUrl='" + avatarUrl + '\'' +
       ", guarded=" + guarded +
+      ", userId=" + userId +
       ", createdAt=" + createdAt +
       ", updatedAt=" + updatedAt +
       '}';
index fa7e3d41862264fbd1e4e9a3cf56b37f1eb29f74..bd8039014c3980244c52bdb4d8f1ce1510e03fd9 100644 (file)
@@ -10,6 +10,7 @@
     org.url as "url",
     org.avatar_url as "avatarUrl",
     org.guarded as "guarded",
+    org.user_id as "userId",
     org.created_at as "createdAt",
     org.updated_at as "updatedAt"
   </sql>
       url,
       avatar_url,
       guarded,
+      user_id,
       created_at,
       updated_at
     )
       #{organization.url, jdbcType=VARCHAR},
       #{organization.avatarUrl, jdbcType=VARCHAR},
       #{organization.guarded, jdbcType=BOOLEAN},
+      #{organization.userId, jdbcType=INTEGER},
       #{organization.createdAt, jdbcType=BIGINT},
       #{organization.updatedAt, jdbcType=BIGINT}
     )
index 69e20a2527c8a1c5e05bec167d43ee5c5ea76024..8a03cb98ad5eb440ae43a85e8bf9313d5d755c29 100644 (file)
@@ -65,7 +65,8 @@ public class OrganizationDaoTest {
     .setDescription("the description 1")
     .setUrl("the url 1")
     .setAvatarUrl("the avatar url 1")
-    .setGuarded(false);
+    .setGuarded(false)
+    .setUserId(1_000L);
   private static final OrganizationDto ORGANIZATION_DTO_2 = new OrganizationDto()
     .setUuid("uuid 2")
     .setKey("the_key 2")
@@ -73,7 +74,8 @@ public class OrganizationDaoTest {
     .setDescription("the description 2")
     .setUrl("the url 2")
     .setAvatarUrl("the avatar url 2")
-    .setGuarded(true);
+    .setGuarded(true)
+    .setUserId(2_000L);
   private static final String PERMISSION_1 = "foo";
   private static final String PERMISSION_2 = "bar";
 
@@ -136,9 +138,9 @@ public class OrganizationDaoTest {
   }
 
   @Test
-  public void description_url_and_avatarUrl_are_optional() {
+  public void description_url_avatarUrl_and_userId_are_optional() {
     when(system2.now()).thenReturn(SOME_DATE);
-    insertOrganization(copyOf(ORGANIZATION_DTO_1).setDescription(null).setUrl(null).setAvatarUrl(null));
+    insertOrganization(copyOf(ORGANIZATION_DTO_1).setDescription(null).setUrl(null).setAvatarUrl(null).setUserId(null));
 
     Map<String, Object> row = selectSingleRow();
     assertThat(row.get("uuid")).isEqualTo(ORGANIZATION_DTO_1.getUuid());
@@ -148,6 +150,7 @@ public class OrganizationDaoTest {
     assertThat(row.get("url")).isNull();
     assertThat(row.get("avatarUrl")).isNull();
     assertThat(row.get("guarded")).isEqualTo(toBool(ORGANIZATION_DTO_1.isGuarded()));
+    assertThat(row.get("userId")).isNull();
     assertThat(row.get("createdAt")).isEqualTo(SOME_DATE);
     assertThat(row.get("updatedAt")).isEqualTo(SOME_DATE);
     assertThat(row.get("defaultTemplate")).isNull();
@@ -905,6 +908,7 @@ public class OrganizationDaoTest {
     assertThat(dto.getUrl()).isEqualTo(ORGANIZATION_DTO_1.getUrl());
     assertThat(dto.isGuarded()).isEqualTo(ORGANIZATION_DTO_1.isGuarded());
     assertThat(dto.getAvatarUrl()).isEqualTo(ORGANIZATION_DTO_1.getAvatarUrl());
+    assertThat(dto.getUserId()).isEqualTo(ORGANIZATION_DTO_1.getUserId());
     assertThat(dto.getCreatedAt()).isEqualTo(ORGANIZATION_DTO_1.getCreatedAt());
     assertThat(dto.getUpdatedAt()).isEqualTo(ORGANIZATION_DTO_1.getUpdatedAt());
   }
@@ -916,6 +920,7 @@ public class OrganizationDaoTest {
     assertThat(dto.getDescription()).isEqualTo(expected.getDescription());
     assertThat(dto.getUrl()).isEqualTo(expected.getUrl());
     assertThat(dto.isGuarded()).isEqualTo(expected.isGuarded());
+    assertThat(dto.getUserId()).isEqualTo(expected.getUserId());
     assertThat(dto.getAvatarUrl()).isEqualTo(expected.getAvatarUrl());
     assertThat(dto.getCreatedAt()).isEqualTo(expected.getCreatedAt());
     assertThat(dto.getUpdatedAt()).isEqualTo(expected.getUpdatedAt());
@@ -924,7 +929,7 @@ public class OrganizationDaoTest {
   private Map<String, Object> selectSingleRow() {
     List<Map<String, Object>> rows = dbTester.select("select" +
       " uuid as \"uuid\", kee as \"key\", name as \"name\",  description as \"description\", url as \"url\", avatar_url as \"avatarUrl\"," +
-      " guarded as \"guarded\"," +
+      " guarded as \"guarded\", user_id as \"userId\"," +
       " created_at as \"createdAt\", updated_at as \"updatedAt\"," +
       " default_perm_template_project as \"projectDefaultPermTemplate\"," +
       " default_perm_template_view as \"viewDefaultPermTemplate\"" +
index dc2e084f3b97e92ce7a8920028ae3ef383b8d59d..f1420ae723a254d64e8d545302e395247a228ab8 100644 (file)
@@ -5,6 +5,7 @@ CREATE TABLE "ORGANIZATIONS" (
   "DESCRIPTION" VARCHAR(256),
   "URL" VARCHAR(256),
   "AVATAR_URL" VARCHAR(256),
+  "USER_ID" BIGINT,
   "GUARDED" BOOLEAN NOT NULL,
   "CREATED_AT" BIGINT NOT NULL,
   "UPDATED_AT" BIGINT NOT NULL