aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-09-07 17:22:32 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-09-28 16:34:54 +0200
commit180c6958395b8f7bd82aa3d9aa641f2e89e58f26 (patch)
tree21434ad50dded01ee343898615571f46454dfa17 /sonar-db
parentae64fe3edb2f5e96a2d40c8bce24bae4fa7fd4a2 (diff)
downloadsonarqube-180c6958395b8f7bd82aa3d9aa641f2e89e58f26.tar.gz
sonarqube-180c6958395b8f7bd82aa3d9aa641f2e89e58f26.zip
Deprecate kee accessors in favor of uuid accessors in PermissionTemplateDto
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/permission/PermissionRepository.java2
-rw-r--r--sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java2
-rw-r--r--sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDto.java33
-rw-r--r--sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java31
-rw-r--r--sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateTesting.java2
5 files changed, 24 insertions, 46 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/PermissionRepository.java b/sonar-db/src/main/java/org/sonar/db/permission/PermissionRepository.java
index 0c7bfacd237..9986a04ce81 100644
--- a/sonar-db/src/main/java/org/sonar/db/permission/PermissionRepository.java
+++ b/sonar-db/src/main/java/org/sonar/db/permission/PermissionRepository.java
@@ -176,7 +176,7 @@ public class PermissionRepository {
}
checkAtMostOneMatchForComponentKey(componentKey, matchingTemplates);
if (matchingTemplates.size() == 1) {
- return matchingTemplates.get(0).getKee();
+ return matchingTemplates.get(0).getUuid();
}
String qualifierTemplateKey = settings.getString("sonar.permission.template." + qualifier + ".default");
if (!StringUtils.isBlank(qualifierTemplateKey)) {
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java
index f01ebe05665..1df1e9be5a2 100644
--- a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java
@@ -384,7 +384,7 @@ public class PermissionTemplateDao implements Dao {
if (permissionTemplateDto == null) {
throw new IllegalArgumentException("Could not retrieve permission template with uuid " + templateUuid);
}
- PermissionTemplateDto templateWithPermissions = selectByUuidWithUserAndGroupPermissions(session, permissionTemplateDto.getKee());
+ PermissionTemplateDto templateWithPermissions = selectByUuidWithUserAndGroupPermissions(session, permissionTemplateDto.getUuid());
if (templateWithPermissions == null) {
throw new IllegalArgumentException("Could not retrieve permissions for template with uuid " + templateUuid);
}
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDto.java b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDto.java
index e79376bd24c..1fc13fb8bd2 100644
--- a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDto.java
+++ b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDto.java
@@ -27,16 +27,9 @@ import javax.annotation.Nullable;
public class PermissionTemplateDto {
- public static final PermissionTemplateDto DEFAULT = new PermissionTemplateDto()
- .setName("Default template")
- .setKee("default_template")
- .setDescription("This permission template will be used as default when no other permission configuration is available")
- .setCreatedAt(new Date())
- .setUpdatedAt(new Date());
-
private Long id;
private String name;
- private String kee;
+ private String uuid;
private String description;
private String keyPattern;
private List<PermissionTemplateUserDto> usersPermissions;
@@ -62,27 +55,35 @@ public class PermissionTemplateDto {
return this;
}
+ /**
+ * @deprecated since 5.2 use {@link #getUuid()}
+ */
+ @Deprecated
public String getKee() {
- return kee;
+ return uuid;
}
/**
- * @since 5.2 the kee column is a proper uuid. Before that it was build on the name + timestamp
+ * @deprecated since 5.2 use {@link #setUuid(String)}
*/
- public String getUuid() {
- return kee;
- }
-
+ @Deprecated
public PermissionTemplateDto setKee(String kee) {
- this.kee = kee;
+ this.uuid = kee;
return this;
}
/**
+ * @since 5.2 the kee column is a proper uuid. Before that it was build on the name + timestamp
+ */
+ public String getUuid() {
+ return uuid;
+ }
+
+ /**
* @since 5.2 the kee column is a proper uuid. Before it was build on the name + timestamp
*/
public PermissionTemplateDto setUuid(String uuid) {
- this.kee = uuid;
+ this.uuid = uuid;
return this;
}
diff --git a/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java
index be7ccfcc78b..bdfeb62d8dd 100644
--- a/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java
@@ -37,14 +37,12 @@ import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
-import org.sonar.db.MyBatis;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import org.sonar.test.DbTests;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.sonar.api.web.UserRole.ADMIN;
import static org.sonar.api.web.UserRole.CODEVIEWER;
@@ -87,27 +85,6 @@ public class PermissionTemplateDaoTest {
}
@Test
- public void should_skip_key_normalization_on_default_template() {
- db.truncateTables();
-
- PermissionTemplateMapper mapper = mock(PermissionTemplateMapper.class);
-
- DbSession session = mock(DbSession.class);
- when(session.getMapper(PermissionTemplateMapper.class)).thenReturn(mapper);
-
- MyBatis myBatis = mock(MyBatis.class);
- when(myBatis.openSession(false)).thenReturn(session);
-
- underTest = new PermissionTemplateDao(myBatis, system);
- PermissionTemplateDto permissionTemplate = underTest.insert(session, PermissionTemplateDto.DEFAULT);
-
- verify(mapper).insert(permissionTemplate);
- verify(session).commit();
-
- assertThat(permissionTemplate.getKee()).isEqualTo(PermissionTemplateDto.DEFAULT.getKee());
- }
-
- @Test
public void should_select_permission_template() {
db.prepareDbUnit(getClass(), "selectPermissionTemplate.xml");
@@ -115,7 +92,7 @@ public class PermissionTemplateDaoTest {
assertThat(permissionTemplate).isNotNull();
assertThat(permissionTemplate.getName()).isEqualTo("my template");
- assertThat(permissionTemplate.getKee()).isEqualTo("my_template_20130102_030405");
+ assertThat(permissionTemplate.getUuid()).isEqualTo("my_template_20130102_030405");
assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
assertThat(permissionTemplate.getUsersPermissions()).hasSize(3);
assertThat(permissionTemplate.getUsersPermissions()).extracting("userId").containsOnly(1L, 2L, 1L);
@@ -150,7 +127,7 @@ public class PermissionTemplateDaoTest {
assertThat(permissionTemplate).isNotNull();
assertThat(permissionTemplate.getId()).isEqualTo(1L);
assertThat(permissionTemplate.getName()).isEqualTo("my template");
- assertThat(permissionTemplate.getKee()).isEqualTo("my_template_20130102_030405");
+ assertThat(permissionTemplate.getUuid()).isEqualTo("my_template_20130102_030405");
assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
}
@@ -255,8 +232,8 @@ public class PermissionTemplateDaoTest {
public void should_retrieve_permission_template() {
db.truncateTables();
- PermissionTemplateDto permissionTemplateDto = new PermissionTemplateDto().setName("Test template").setKee("test_template");
- PermissionTemplateDto templateWithPermissions = new PermissionTemplateDto().setKee("test_template");
+ PermissionTemplateDto permissionTemplateDto = new PermissionTemplateDto().setName("Test template").setUuid("test_template");
+ PermissionTemplateDto templateWithPermissions = new PermissionTemplateDto().setUuid("test_template");
underTest = mock(PermissionTemplateDao.class);
when(underTest.selectByUuid(db.getSession(), "test_template")).thenReturn(permissionTemplateDto);
when(underTest.selectByUuidWithUserAndGroupPermissions(db.getSession(), "test_template")).thenReturn(templateWithPermissions);
diff --git a/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateTesting.java b/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateTesting.java
index c8f35799c4c..fa9a0f66074 100644
--- a/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateTesting.java
+++ b/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateTesting.java
@@ -31,7 +31,7 @@ public class PermissionTemplateTesting {
return new PermissionTemplateDto()
.setName(randomAlphanumeric(60))
.setDescription(randomAscii(500))
- .setKee(Uuids.create())
+ .setUuid(Uuids.create())
.setCreatedAt(new Date())
.setUpdatedAt(new Date());
}