From 9cf53a057f8d0cb669d26e51df9b16249d543f3d Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Thu, 20 Aug 2015 16:49:52 +0200 Subject: Remove selectGroupByName methods from UserDao --- .../sonar/db/permission/PermissionRepository.java | 4 ++-- .../src/main/java/org/sonar/db/user/GroupDao.java | 6 ++--- .../src/main/java/org/sonar/db/user/UserDao.java | 26 ---------------------- .../test/java/org/sonar/db/user/GroupDaoTest.java | 2 +- .../test/java/org/sonar/db/user/UserDaoTest.java | 22 ------------------ 5 files changed, 6 insertions(+), 54 deletions(-) (limited to 'sonar-db/src') 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 f34ce6cc9f8..24d39bc3d41 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 @@ -98,7 +98,7 @@ public class PermissionRepository { if (DefaultGroups.isAnyone(groupName)) { insertGroupPermission(resourceId, (Long) null, permission, session); } else { - GroupDto group = dbClient.userDao().selectGroupByName(groupName, session); + GroupDto group = dbClient.groupDao().selectByName(session, groupName); if (group != null) { insertGroupPermission(resourceId, group.getId(), permission, session); } @@ -118,7 +118,7 @@ public class PermissionRepository { if (DefaultGroups.isAnyone(groupName)) { deleteGroupPermission(resourceId, (Long) null, permission, session); } else { - GroupDto group = dbClient.userDao().selectGroupByName(groupName, session); + GroupDto group = dbClient.groupDao().selectByName(session, groupName); if (group != null) { deleteGroupPermission(resourceId, group.getId(), permission, session); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/GroupDao.java b/sonar-db/src/main/java/org/sonar/db/user/GroupDao.java index cf2f1d1e4d1..2b316fec8b0 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/GroupDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/GroupDao.java @@ -40,8 +40,8 @@ public class GroupDao implements Dao { this.system = system; } - public GroupDto selectOrFailByKey(DbSession session, String key) { - GroupDto group = selectByKey(session, key); + public GroupDto selectOrFailByName(DbSession session, String key) { + GroupDto group = selectByName(session, key); if (group == null) { throw new RowNotFoundException(String.format("Could not find a group with name '%s'", key)); } @@ -49,7 +49,7 @@ public class GroupDao implements Dao { } @CheckForNull - public GroupDto selectByKey(DbSession session, String key) { + public GroupDto selectByName(DbSession session, String key) { return mapper(session).selectByKey(key); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/UserDao.java b/sonar-db/src/main/java/org/sonar/db/user/UserDao.java index 5c1e52d5f8c..451554b2a49 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/UserDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/UserDao.java @@ -158,32 +158,6 @@ public class UserDao implements Dao { } } - /** - * Search for group by name. - * - * @return the group, null if group not found - * - * TODO should be moved to GroupDao - */ - @CheckForNull - public GroupDto selectGroupByName(String name, DbSession session) { - UserMapper mapper = session.getMapper(UserMapper.class); - return mapper.selectGroupByName(name); - } - - /** - * TODO should be moved to GroupDao - */ - @CheckForNull - public GroupDto selectGroupByName(String name) { - DbSession session = mybatis.openSession(false); - try { - return selectGroupByName(name, session); - } finally { - MyBatis.closeQuietly(session); - } - } - @CheckForNull public UserDto selectByLogin(DbSession session, String login) { return mapper(session).selectByLogin(login); diff --git a/sonar-db/src/test/java/org/sonar/db/user/GroupDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/GroupDaoTest.java index 003f0a46ff0..c09cd3ff4af 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/GroupDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/user/GroupDaoTest.java @@ -62,7 +62,7 @@ public class GroupDaoTest { public void select_by_key() { dbTester.prepareDbUnit(getClass(), "select_by_key.xml"); - GroupDto group = new GroupDao(system2).selectOrFailByKey(session, "sonar-users"); + GroupDto group = new GroupDao(system2).selectOrFailByName(session, "sonar-users"); assertThat(group).isNotNull(); assertThat(group.getId()).isEqualTo(1L); assertThat(group.getName()).isEqualTo("sonar-users"); diff --git a/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java index 07fea9e3c47..d0fe4e7ee84 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java @@ -19,7 +19,6 @@ */ package org.sonar.db.user; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -162,27 +161,6 @@ public class UserDaoTest { assertThat(users).isEmpty(); } - @Test - public void selectGroupByName() { - db.prepareDbUnit(getClass(), "selectGroupByName.xml"); - - GroupDto group = underTest.selectGroupByName("sonar-users"); - assertThat(group).isNotNull(); - assertThat(group.getId()).isEqualTo(1L); - assertThat(group.getName()).isEqualTo("sonar-users"); - assertThat(group.getDescription()).isEqualTo("Sonar Users"); - assertThat(group.getCreatedAt()).isNotNull(); - assertThat(group.getUpdatedAt()).isNotNull(); - } - - @Test - public void selectGroupByName_not_found() { - db.prepareDbUnit(getClass(), "selectGroupByName.xml"); - - GroupDto group = underTest.selectGroupByName("not-found"); - assertThat(group).isNull(); - } - @Test public void insert_user() { Long date = DateUtils.parseDate("2014-06-20").getTime(); -- cgit v1.2.3