aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-02-10 16:16:40 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-02-10 18:29:38 +0100
commit04f7859ab0bcff24a9ab1d621c67d37ba44aa5bb (patch)
tree7a6b50a602b8adaf761714ab7647bf90237950e2 /sonar-db
parent539323544aeeb1796a615e43c18051447fdcc1d7 (diff)
downloadsonarqube-04f7859ab0bcff24a9ab1d621c67d37ba44aa5bb.tar.gz
sonarqube-04f7859ab0bcff24a9ab1d621c67d37ba44aa5bb.zip
SONAR-8752 support userId in OrganizationDto and OrganizationDao
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java14
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml3
-rw-r--r--sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java15
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoWithDuplicatedKeysTest/schema.sql1
4 files changed, 28 insertions, 5 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java b/sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java
index 96b55c80aca..79705021095 100644
--- a/sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java
+++ b/sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java
@@ -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 +
'}';
diff --git a/sonar-db/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml b/sonar-db/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
index fa7e3d41862..bd8039014c3 100644
--- a/sonar-db/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
@@ -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>
@@ -132,6 +133,7 @@
url,
avatar_url,
guarded,
+ user_id,
created_at,
updated_at
)
@@ -144,6 +146,7 @@
#{organization.url, jdbcType=VARCHAR},
#{organization.avatarUrl, jdbcType=VARCHAR},
#{organization.guarded, jdbcType=BOOLEAN},
+ #{organization.userId, jdbcType=INTEGER},
#{organization.createdAt, jdbcType=BIGINT},
#{organization.updatedAt, jdbcType=BIGINT}
)
diff --git a/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java
index 69e20a2527c..8a03cb98ad5 100644
--- a/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java
@@ -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\"" +
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoWithDuplicatedKeysTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoWithDuplicatedKeysTest/schema.sql
index dc2e084f3b9..f1420ae723a 100644
--- a/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoWithDuplicatedKeysTest/schema.sql
+++ b/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoWithDuplicatedKeysTest/schema.sql
@@ -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