summaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2013-12-05 17:16:52 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2013-12-05 17:21:09 +0100
commit50673979b7ce6b337e9b87d3a4e0cd74a5789bc6 (patch)
tree0c2827410dd4f0d218a3410df20d48a2db445e53 /sonar-core
parent0229a6a9e46062d0795e1086468b1d6e2d48c257 (diff)
downloadsonarqube-50673979b7ce6b337e9b87d3a4e0cd74a5789bc6.tar.gz
sonarqube-50673979b7ce6b337e9b87d3a4e0cd74a5789bc6.zip
SONAR-4941 Replace usage of template name by template key
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/permission/PermissionFacade.java8
-rw-r--r--sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDao.java19
-rw-r--r--sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateMapper.java6
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml10
-rw-r--r--sonar-core/src/test/java/org/sonar/core/permission/PermissionFacadeTest.java6
-rw-r--r--sonar-core/src/test/java/org/sonar/core/permission/PermissionTemplateDaoTest.java22
6 files changed, 16 insertions, 55 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionFacade.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionFacade.java
index 1391310b5c7..670a4db7385 100644
--- a/sonar-core/src/main/java/org/sonar/core/permission/PermissionFacade.java
+++ b/sonar-core/src/main/java/org/sonar/core/permission/PermissionFacade.java
@@ -30,11 +30,7 @@ import org.sonar.api.task.TaskComponent;
import org.sonar.core.persistence.MyBatis;
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceDto;
-import org.sonar.core.user.GroupDto;
-import org.sonar.core.user.GroupRoleDto;
-import org.sonar.core.user.RoleDao;
-import org.sonar.core.user.UserDao;
-import org.sonar.core.user.UserRoleDto;
+import org.sonar.core.user.*;
import javax.annotation.Nullable;
@@ -163,7 +159,7 @@ public class PermissionFacade implements TaskComponent, ServerComponent {
if (permissionTemplateDto == null) {
throw new IllegalArgumentException("Could not retrieve permission template with key " + templateKey);
}
- PermissionTemplateDto templateWithPermissions = permissionTemplateDao.selectPermissionTemplate(permissionTemplateDto.getName());
+ PermissionTemplateDto templateWithPermissions = permissionTemplateDao.selectPermissionTemplate(permissionTemplateDto.getKee());
if (templateWithPermissions == null) {
throw new IllegalArgumentException("Could not retrieve permissions for template with key " + templateKey);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDao.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDao.java
index 72262d4052b..300d7579fe7 100644
--- a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDao.java
@@ -75,17 +75,6 @@ public class PermissionTemplateDao implements TaskComponent, ServerComponent {
}
@CheckForNull
- public PermissionTemplateDto selectTemplateByName(String templateName) {
- SqlSession session = myBatis.openSession();
- try {
- PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
- return mapper.selectByName(templateName);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- @CheckForNull
public PermissionTemplateDto selectTemplateByKey(String templateKey) {
SqlSession session = myBatis.openSession();
try {
@@ -97,17 +86,17 @@ public class PermissionTemplateDao implements TaskComponent, ServerComponent {
}
@CheckForNull
- public PermissionTemplateDto selectPermissionTemplate(String templateName) {
+ public PermissionTemplateDto selectPermissionTemplate(String templateKey) {
PermissionTemplateDto permissionTemplate = null;
SqlSession session = myBatis.openSession();
try {
PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class);
- permissionTemplate = mapper.selectByName(templateName);
- PermissionTemplateDto templateUsersPermissions = mapper.selectTemplateUsersPermissions(templateName);
+ permissionTemplate = mapper.selectByKey(templateKey);
+ PermissionTemplateDto templateUsersPermissions = mapper.selectTemplateUsersPermissions(templateKey);
if (templateUsersPermissions != null) {
permissionTemplate.setUsersPermissions(templateUsersPermissions.getUsersPermissions());
}
- PermissionTemplateDto templateGroupsPermissions = mapper.selectTemplateGroupsPermissions(templateName);
+ PermissionTemplateDto templateGroupsPermissions = mapper.selectTemplateGroupsPermissions(templateKey);
if (templateGroupsPermissions != null) {
permissionTemplate.setGroupsByPermission(templateGroupsPermissions.getGroupsPermissions());
}
diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateMapper.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateMapper.java
index 68073023046..c115e289050 100644
--- a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateMapper.java
@@ -35,13 +35,11 @@ public interface PermissionTemplateMapper {
void deleteGroupsPermissions(Long templateId);
- PermissionTemplateDto selectByName(String templateName);
-
PermissionTemplateDto selectByKey(String templateKey);
- PermissionTemplateDto selectTemplateUsersPermissions(String templateName);
+ PermissionTemplateDto selectTemplateUsersPermissions(String templateKey);
- PermissionTemplateDto selectTemplateGroupsPermissions(String templateName);
+ PermissionTemplateDto selectTemplateGroupsPermissions(String templateKey);
void insertUserPermission(PermissionTemplateUserDto permissionTemplateUser);
diff --git a/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml b/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml
index 7cf029510c1..f6461371b30 100644
--- a/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml
@@ -89,12 +89,6 @@
WHERE kee = #{kee}
</select>
- <select id="selectByName" parameterType="String" resultType="PermissionTemplate">
- SELECT id, name, kee, description, key_pattern AS keyPattern, created_at AS createdAt, updated_at AS updatedAt
- FROM permission_templates
- WHERE name = #{templateName}
- </select>
-
<select id="selectAllPermissionTemplates" resultType="PermissionTemplate">
SELECT id, name, kee, description, key_pattern AS keyPattern, created_at AS createdAt, updated_at AS updatedAt
FROM permission_templates
@@ -115,7 +109,7 @@
FROM permission_templates pt
INNER JOIN perm_templates_users ptu ON ptu.template_id = pt.id
INNER JOIN users u ON u.id = ptu.user_id AND u.active = ${_true}
- WHERE pt.name = #{templateName}
+ WHERE pt.kee = #{templateKey}
</select>
<select id="selectTemplateGroupsPermissions" parameterType="String" resultMap="fullPermissionsTemplateResult">
@@ -132,7 +126,7 @@
FROM permission_templates pt
INNER JOIN perm_templates_groups ptg ON ptg.template_id = pt.id
LEFT OUTER JOIN groups g ON g.id = ptg.group_id
- WHERE pt.name = #{templateName}
+ WHERE pt.kee = #{templateKey}
AND (g.name IS NOT NULL OR ptg.group_id IS NULL)
</select>
diff --git a/sonar-core/src/test/java/org/sonar/core/permission/PermissionFacadeTest.java b/sonar-core/src/test/java/org/sonar/core/permission/PermissionFacadeTest.java
index c64e2bfedea..93bd6cfa44f 100644
--- a/sonar-core/src/test/java/org/sonar/core/permission/PermissionFacadeTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/permission/PermissionFacadeTest.java
@@ -160,11 +160,11 @@ public class PermissionFacadeTest extends AbstractDaoTestCase {
@Test
public void should_retrieve_permission_template() throws Exception {
- PermissionTemplateDto permissionTemplateDto = new PermissionTemplateDto().setName("Test template");
- PermissionTemplateDto templateWithPermissions = new PermissionTemplateDto();
+ PermissionTemplateDto permissionTemplateDto = new PermissionTemplateDto().setName("Test template").setKee("test_template");
+ PermissionTemplateDto templateWithPermissions = new PermissionTemplateDto().setKee("test_template");
permissionTemplateDao = mock(PermissionTemplateDao.class);
when(permissionTemplateDao.selectTemplateByKey("test_template")).thenReturn(permissionTemplateDto);
- when(permissionTemplateDao.selectPermissionTemplate("Test template")).thenReturn(templateWithPermissions);
+ when(permissionTemplateDao.selectPermissionTemplate("test_template")).thenReturn(templateWithPermissions);
permissionFacade = new PermissionFacade(null, null, null, null, permissionTemplateDao, null);
diff --git a/sonar-core/src/test/java/org/sonar/core/permission/PermissionTemplateDaoTest.java b/sonar-core/src/test/java/org/sonar/core/permission/PermissionTemplateDaoTest.java
index 652ecfca7d1..53daae1c564 100644
--- a/sonar-core/src/test/java/org/sonar/core/permission/PermissionTemplateDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/permission/PermissionTemplateDaoTest.java
@@ -33,10 +33,7 @@ import java.util.Date;
import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.stub;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
public class PermissionTemplateDaoTest extends AbstractDaoTestCase {
@@ -93,7 +90,7 @@ public class PermissionTemplateDaoTest extends AbstractDaoTestCase {
@Test
public void should_select_permission_template() throws Exception {
setupData("selectPermissionTemplate");
- PermissionTemplateDto permissionTemplate = permissionTemplateDao.selectPermissionTemplate("my template");
+ PermissionTemplateDto permissionTemplate = permissionTemplateDao.selectPermissionTemplate("my_template_20130102_030405");
assertThat(permissionTemplate).isNotNull();
assertThat(permissionTemplate.getName()).isEqualTo("my template");
@@ -113,7 +110,7 @@ public class PermissionTemplateDaoTest extends AbstractDaoTestCase {
@Test
public void should_select_empty_permission_template() throws Exception {
setupData("selectEmptyPermissionTemplate");
- PermissionTemplateDto permissionTemplate = permissionTemplateDao.selectPermissionTemplate("my template");
+ PermissionTemplateDto permissionTemplate = permissionTemplateDao.selectPermissionTemplate("my_template_20130102_030405");
assertThat(permissionTemplate).isNotNull();
assertThat(permissionTemplate.getName()).isEqualTo("my template");
@@ -123,19 +120,6 @@ public class PermissionTemplateDaoTest extends AbstractDaoTestCase {
}
@Test
- public void should_select_permission_template_by_name() throws Exception {
- setupData("selectPermissionTemplate");
-
- PermissionTemplateDto permissionTemplate = permissionTemplateDao.selectTemplateByName("my template");
-
- assertThat(permissionTemplate).isNotNull();
- assertThat(permissionTemplate.getId()).isEqualTo(1L);
- assertThat(permissionTemplate.getName()).isEqualTo("my template");
- assertThat(permissionTemplate.getKee()).isEqualTo("my_template_20130102_030405");
- assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
- }
-
- @Test
public void should_select_permission_template_by_key() throws Exception {
setupData("selectPermissionTemplate");