]> source.dussan.org Git - sonarqube.git/commitdiff
Move permissions template classes and resources to a specific package in sonar-db
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 5 Jul 2016 13:04:54 +0000 (15:04 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Tue, 12 Jul 2016 08:16:53 +0000 (10:16 +0200)
131 files changed:
server/sonar-server/src/main/java/org/sonar/server/permission/DefaultPermissionTemplates.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/DeleteTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionDependenciesFinder.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/TemplateGroupsAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/TemplateUsersAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/AddGroupToTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/AddProjectCreatorToTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/AddUserToTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/ApplyTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/BulkApplyTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/CreateTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/PermissionTemplateDtoBuilder.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/PermissionTemplateDtoToPermissionTemplateResponse.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/RemoveProjectCreatorFromTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesData.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesDataLoader.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/SetDefaultTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/UpdateTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/startup/RegisterPermissionTemplates.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ApplyPermissionsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/TemplateGroupsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/TemplateUsersActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddGroupToTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddProjectCreatorToTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddUserToTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/CreateTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/DeleteTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveProjectCreatorFromTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesDataTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SetDefaultTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/UpdateTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/startup/RegisterPermissionTemplatesTest.java
server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java
sonar-db/src/main/java/org/sonar/db/DaoModule.java
sonar-db/src/main/java/org/sonar/db/DbClient.java
sonar-db/src/main/java/org/sonar/db/MyBatis.java
sonar-db/src/main/java/org/sonar/db/permission/CountByTemplateAndPermissionDto.java [deleted file]
sonar-db/src/main/java/org/sonar/db/permission/PermissionRepository.java
sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplate.java [deleted file]
sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java [deleted file]
sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDto.java [deleted file]
sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateGroupDto.java [deleted file]
sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateMapper.java [deleted file]
sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateUserDto.java [deleted file]
sonar-db/src/main/java/org/sonar/db/permission/template/CountByTemplateAndPermissionDto.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplate.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateDto.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateUserDto.java [new file with mode: 0644]
sonar-db/src/main/resources/org/sonar/db/permission/PermissionTemplateMapper.xml [deleted file]
sonar-db/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/permission/GroupWithPermissionTemplateDaoTest.java [deleted file]
sonar-db/src/test/java/org/sonar/db/permission/PermissionRepositoryTest.java
sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java [deleted file]
sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateTesting.java [deleted file]
sonar-db/src/test/java/org/sonar/db/permission/UserWithPermissionTemplateDaoTest.java [deleted file]
sonar-db/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java
sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateTesting.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest.java [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/GroupWithPermissionTemplateDaoTest/groups_with_permissions.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/GroupWithPermissionTemplateDaoTest/groups_with_permissions_should_be_sorted_by_group_name.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addGroupPermissionToTemplate-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addGroupPermissionToTemplate.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addNullGroupPermissionToTemplate-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addNullGroupPermissionToTemplate.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addUserPermissionToTemplate-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addUserPermissionToTemplate.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/createNonAsciiPermissionTemplate-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/createNonAsciiPermissionTemplate.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/createPermissionTemplate-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/createPermissionTemplate.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/deletePermissionTemplate-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/deletePermissionTemplate.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeGroupPermissionFromTemplate-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeGroupPermissionFromTemplate.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeNullGroupPermissionFromTemplate-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeNullGroupPermissionFromTemplate.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeUserPermissionFromTemplate-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeUserPermissionFromTemplate.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/remove_by_group-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/remove_by_group.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/selectAllPermissionTemplates.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/selectEmptyPermissionTemplate.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/selectPermissionTemplate.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/updatePermissionTemplate-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/updatePermissionTemplate.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/UserWithPermissionTemplateDaoTest/select_only_enable_users.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/UserWithPermissionTemplateDaoTest/users_with_permissions.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest/groups_with_permissions.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest/groups_with_permissions_should_be_sorted_by_group_name.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addGroupPermissionToTemplate-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addGroupPermissionToTemplate.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addNullGroupPermissionToTemplate-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addNullGroupPermissionToTemplate.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addUserPermissionToTemplate-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addUserPermissionToTemplate.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/createNonAsciiPermissionTemplate-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/createNonAsciiPermissionTemplate.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/createPermissionTemplate-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/createPermissionTemplate.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/deletePermissionTemplate-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/deletePermissionTemplate.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeGroupPermissionFromTemplate-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeGroupPermissionFromTemplate.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeNullGroupPermissionFromTemplate-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeNullGroupPermissionFromTemplate.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeUserPermissionFromTemplate-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeUserPermissionFromTemplate.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/remove_by_group-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/remove_by_group.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/selectAllPermissionTemplates.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/selectEmptyPermissionTemplate.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/selectPermissionTemplate.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/updatePermissionTemplate-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/updatePermissionTemplate.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/select_only_enable_users.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml [new file with mode: 0644]

index b7441cf84cbb87260bb3263a118d3c160e63e669..1192531d8b96c5bb4bdbe3ef704bbd934b080c13 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.server.permission;
 
 import java.util.Date;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 
 import static java.lang.String.format;
 
index 7e5b5f56fde60fb7e0d6932ce02d5df0c5f676d3..225ea07770f475864cd588deca679c422cae15d8 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.server.permission.ws.template.DefaultPermissionTemplateFinder;
 import org.sonar.server.user.UserSession;
 import org.sonarqube.ws.client.permission.DeleteTemplateWsRequest;
index 8a31e9f5c529e8d8745cdb4de6a2d2ea00695e12..1e13e40517ef5f4c7d4fc1269359c61b9a66b32d 100644 (file)
@@ -25,7 +25,7 @@ import org.sonar.api.resources.ResourceTypes;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.component.ComponentFinder;
index 5e92540405f6c3966424acc05965ef01b6a3c768..7f013d4597ef8169b30b8ed4f6be3b98fb55d5cc 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.permission.GroupWithPermissionDto;
 import org.sonar.db.permission.OldPermissionQuery;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.server.user.UserSession;
 import org.sonarqube.ws.WsPermissions.Group;
 import org.sonarqube.ws.WsPermissions.WsGroupsResponse;
index b115ad453f03fa13502d5a2b708b0c44159248da..7925b46542911a58808ae063b971438207139e1e 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.api.server.ws.WebService.SelectionMode;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.permission.OldPermissionQuery;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.UserWithPermissionDto;
 import org.sonar.server.user.UserSession;
 import org.sonarqube.ws.WsPermissions;
index ceddba001b5060bcfd5a381b3a298d8fad11074a..ab48e14b2e8cce8b396ffabf6d5308905f165f08 100644 (file)
@@ -26,7 +26,7 @@ import org.sonar.api.server.ws.WebService;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.permission.OldPermissionQuery;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.server.permission.ws.PermissionDependenciesFinder;
 import org.sonar.server.permission.ws.PermissionsWsAction;
index dccc5589008b3fc33cddbd29e02121daa7e47d68..40bc126ce94e131030be4b0b97f752bf20890138 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicDto;
 import org.sonar.server.permission.ws.PermissionDependenciesFinder;
 import org.sonar.server.permission.ws.PermissionsWsAction;
index c0da46c091158622d4c11e23e2796845396e666e..45cf262a4577e38f99f4855b8d9ec85870a37732 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.server.ws.WebService;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.permission.OldPermissionQuery;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.UserWithPermissionDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.permission.ws.PermissionDependenciesFinder;
index 64e1bebba966c047c6bc5cdc038a46e579ce14cf..b729a5fc3981ac7c3fdfe4fcdec8e09f20820917 100644 (file)
@@ -25,7 +25,7 @@ import org.sonar.api.server.ws.WebService;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.server.permission.ApplyPermissionTemplateQuery;
 import org.sonar.server.permission.PermissionService;
 import org.sonar.server.permission.ws.PermissionDependenciesFinder;
index 8381bddfca797cdd4332951cd08d91632773643b..36d5ff72f5cf31013b6f584e12ec932b9e6e4efb 100644 (file)
@@ -44,7 +44,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentDtoFunctions;
 import org.sonar.db.component.ComponentQuery;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.server.permission.ApplyPermissionTemplateQuery;
 import org.sonar.server.permission.PermissionService;
 import org.sonar.server.permission.ws.PermissionDependenciesFinder;
index 0512ed69af4c783bf07b8e532ab11db434b6d8a4..462c839db99b93d0d32fd4222beaa51913156b72 100644 (file)
@@ -25,7 +25,7 @@ import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.server.permission.ws.PermissionsWsAction;
 import org.sonar.server.user.UserSession;
 import org.sonarqube.ws.WsPermissions.CreateTemplateWsResponse;
index cf25d8d7da0e2cd183de566ba89f79d8879ebd7a..b3e931e5bb9194feadb5a988094080c8c8e58a27 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.permission.ws.template;
 import java.util.Date;
 import org.sonar.api.utils.System2;
 import org.sonar.core.util.Uuids;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 
 public class PermissionTemplateDtoBuilder {
   private final System2 system;
index 156c1b31385a9cb3c345e485bc1b3a8d78c5c877..df92a7607c3fe4f9da2cba8335e2491b2570857d 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.permission.ws.template;
 import com.google.common.base.Function;
 import javax.annotation.Nonnull;
 import org.sonar.api.utils.DateUtils;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonarqube.ws.WsPermissions.PermissionTemplate;
 
 public class PermissionTemplateDtoToPermissionTemplateResponse {
index 207f863b471408f3d08211cf7ecc0c4dfd9d056f..cf5d1561f81c6f997cbc32dc7116e0ceee1e1f19 100644 (file)
@@ -24,7 +24,7 @@ import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.server.permission.ws.PermissionDependenciesFinder;
 import org.sonar.server.permission.ws.PermissionsWsAction;
index 6ef24c64afef0b7d851dc489e7d0754195c76c4b..8af7bd53f963a5e940772bb78acadc608272c584 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicDao;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicDto;
 import org.sonar.server.permission.ws.PermissionDependenciesFinder;
index 5b2f926d1f5b4c039305655930f673fcfd29c97f..026e86e6e664992554b35b6859797cfdee0e1985 100644 (file)
@@ -24,7 +24,7 @@ import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.permission.ws.PermissionDependenciesFinder;
 import org.sonar.server.permission.ws.PermissionsWsAction;
index 17b9727d37f3b55ec2de9bf0ad194e1916d1a918..021bfe1d234a39d677efdf0ca9d03063d8ed2302 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.core.permission.ProjectPermissions;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.server.permission.ws.PermissionsWsAction;
 import org.sonar.server.user.UserSession;
 import org.sonarqube.ws.WsPermissions;
index e5ae45ff506f606de947d9940861068d24aa4364..abe58c471d476d78f6423bfa99000eb818048a72 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.server.permission.ws.template;
 
 import com.google.common.collect.Table;
 import java.util.List;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.server.permission.ws.template.DefaultPermissionTemplateFinder.TemplateUuidQualifier;
 
 import static com.google.common.base.MoreObjects.firstNonNull;
index 1a08a623e523a84a2c845a30c25e4472f009fab5..4935153a2eac4303092667816d38b5cb59d6d62f 100644 (file)
@@ -25,8 +25,8 @@ import com.google.common.collect.TreeBasedTable;
 import java.util.List;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.permission.CountByTemplateAndPermissionDto;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.CountByTemplateAndPermissionDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicDto;
 import org.sonar.server.permission.ws.template.DefaultPermissionTemplateFinder.TemplateUuidQualifier;
 import org.sonarqube.ws.client.permission.SearchTemplatesWsRequest;
index 0f8e2702a9af0be89da93a620eba44e3299279e2..fbef6541c27c9dd4547ef506e82f09ad8991d53b 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.server.permission.ws.PermissionDependenciesFinder;
 import org.sonar.server.permission.ws.PermissionsWsAction;
 import org.sonar.server.platform.PersistentSettings;
index 979147722e12f3f78c82505895858dd05d49e716..7e751eaaccf2915e56b84106c7131e5452aa0723 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.server.permission.ws.PermissionDependenciesFinder;
 import org.sonar.server.permission.ws.PermissionsWsAction;
 import org.sonar.server.permission.ws.WsTemplateRef;
index 670a94433937b89e61a337a72e62924393418454..102d4104d52d02dbfeafa63631ec73cb42aa9b87 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.api.web.UserRole;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.loadedtemplate.LoadedTemplateDto;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.server.permission.DefaultPermissionTemplates;
 import org.sonar.server.platform.PersistentSettings;
index 112e46168f1e0488499565b60e46e51dec21f4f6..c38db74bef6c26274e860e8c3fd4a684c9d66fde 100644 (file)
@@ -36,7 +36,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.permission.PermissionRepository;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.user.GroupRoleDto;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
@@ -49,7 +49,7 @@ import org.sonar.server.issue.index.IssueIndexDefinition;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.db.component.ComponentTesting.newView;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
 import static org.sonar.server.computation.component.Component.Type.PROJECT;
 import static org.sonar.server.computation.component.Component.Type.VIEW;
 
index 73649de6322b8da3acf4e86fe5949e9e0f94febc..89d4e47685f13a8249c50763829742b4ecdd0947 100644 (file)
@@ -36,8 +36,8 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ResourceTypesRule;
-import org.sonar.db.permission.PermissionTemplateDto;
-import org.sonar.db.permission.PermissionTemplateGroupDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateGroupDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.exceptions.BadRequestException;
@@ -56,8 +56,8 @@ import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
 import static org.sonar.api.server.ws.WebService.Param.SELECTED;
 import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
 import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateGroupDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto;
 import static org.sonar.db.user.GroupTesting.newGroupDto;
 import static org.sonar.test.JsonAssert.assertJson;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
index 701fc6ac60ab46c29ddb3d612cb8b4fd959977a8..d0f12b2c021f716373f0e858388de18e81ee5f75 100644 (file)
@@ -35,8 +35,8 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ResourceTypesRule;
-import org.sonar.db.permission.PermissionTemplateDto;
-import org.sonar.db.permission.PermissionTemplateUserDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateUserDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.exceptions.BadRequestException;
@@ -52,8 +52,8 @@ import org.sonarqube.ws.WsPermissions.UsersWsResponse;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.api.web.UserRole.ADMIN;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateUserDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateUserDto;
 import static org.sonar.test.JsonAssert.assertJson;
 import static org.sonarqube.ws.MediaTypes.PROTOBUF;
 import static org.sonarqube.ws.WsPermissions.UsersWsResponse.parseFrom;
index 4339c5421de8573213252a38bfe9ad0981fb6f6f..47408c1d38ffb8b2dc0c80c87c05ee3c725cc470 100644 (file)
@@ -37,7 +37,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.ResourceTypesRule;
 import org.sonar.db.permission.GroupWithPermissionDto;
 import org.sonar.db.permission.OldPermissionQuery;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.exceptions.BadRequestException;
@@ -56,7 +56,7 @@ import static org.sonar.api.security.DefaultGroups.ANYONE;
 import static org.sonar.api.web.UserRole.ADMIN;
 import static org.sonar.api.web.UserRole.CODEVIEWER;
 import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
 import static org.sonar.db.user.GroupMembershipQuery.IN;
 import static org.sonar.db.user.GroupTesting.newGroupDto;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
index 32483b980fcc0b4a56ed8778065eda1a2bd03353..8d36f1a3e0d2d50b44bdd79a22aac905e4bc7c32 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ResourceTypesRule;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicDto;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicMapper;
 import org.sonar.server.component.ComponentFinder;
@@ -49,7 +49,7 @@ import org.sonar.server.ws.WsActionTester;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME;
index 5574cad4d15a1b5048340d770289196ec3e84c1c..a4d04af103cd9f983788da49540db28192b7b931 100644 (file)
@@ -35,7 +35,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ResourceTypesRule;
 import org.sonar.db.permission.OldPermissionQuery;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.UserWithPermissionDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.component.ComponentFinder;
@@ -53,7 +53,7 @@ import static com.google.common.collect.FluentIterable.from;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.api.web.UserRole.CODEVIEWER;
 import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
 import static org.sonar.db.user.GroupMembershipQuery.IN;
 import static org.sonar.db.user.UserTesting.newUserDto;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
index add9707d3648f629022773e8e41037a69dde50f3..5017a9b621dd1c10dc71275209b81970bf139c1e 100644 (file)
@@ -40,7 +40,7 @@ import org.sonar.db.component.ResourceTypesRule;
 import org.sonar.db.permission.GroupWithPermissionDto;
 import org.sonar.db.permission.OldPermissionQuery;
 import org.sonar.db.permission.PermissionRepository;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.UserWithPermissionDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.GroupRoleDto;
@@ -64,7 +64,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.sonar.db.component.ComponentTesting.newProjectDto;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
 import static org.sonar.db.user.GroupMembershipQuery.IN;
 import static org.sonar.db.user.GroupTesting.newGroupDto;
 import static org.sonar.db.user.UserTesting.newUserDto;
index 753c03c51915e76c459c317bd8b2df693ed3cd87..7a52c5b02755bc9656ff9955bfe98cc2893ee3cf 100644 (file)
@@ -25,7 +25,7 @@ import static org.mockito.Mockito.mock;
 import static org.sonar.db.component.ComponentTesting.newDeveloper;
 import static org.sonar.db.component.ComponentTesting.newProjectDto;
 import static org.sonar.db.component.ComponentTesting.newView;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
 import static org.sonar.db.user.GroupMembershipQuery.IN;
 import static org.sonar.db.user.GroupTesting.newGroupDto;
 import static org.sonar.db.user.UserTesting.newUserDto;
@@ -56,7 +56,7 @@ import org.sonar.db.component.ResourceTypesRule;
 import org.sonar.db.permission.GroupWithPermissionDto;
 import org.sonar.db.permission.OldPermissionQuery;
 import org.sonar.db.permission.PermissionRepository;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.UserWithPermissionDto;
 import org.sonar.db.user.GroupDbTester;
 import org.sonar.db.user.GroupDto;
index 6639835d9f733c36248dcd849f8f2aa40190cc9c..fb4a11ecc847207b43c10f1c24f90fcf2fc51a5a 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.UnauthorizedException;
@@ -41,7 +41,7 @@ import org.sonar.server.ws.WsActionTester;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_DESCRIPTION;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_NAME;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY_PATTERN;
index 2b36c654f1316b027a3da5caa9120d915cf93696..b608e12945d005597103a5ab5d645f73741c7fe8 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ResourceTypesRule;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.GroupTesting;
@@ -58,7 +58,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.mockito.internal.util.collections.Sets.newSet;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME;
 
index 9df6be6c9547f301acb40d1517579698d1279c89..f9b816417192f1b978b9aa920d638ab0a2003ce7 100644 (file)
@@ -36,7 +36,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.ResourceTypesRule;
 import org.sonar.db.permission.GroupWithPermissionDto;
 import org.sonar.db.permission.OldPermissionQuery;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.exceptions.BadRequestException;
@@ -53,7 +53,7 @@ import static com.google.common.collect.FluentIterable.from;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.api.security.DefaultGroups.ANYONE;
 import static org.sonar.api.web.UserRole.CODEVIEWER;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
 import static org.sonar.db.user.GroupMembershipQuery.IN;
 import static org.sonar.db.user.GroupTesting.newGroupDto;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
index 227ff2e2ea8c6c9931186450e57a4f8dfecb6b73..079297945f0cd6551b7211d8f92c6b970b620457 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ResourceTypesRule;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicDao;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicDto;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicMapper;
@@ -50,7 +50,7 @@ import org.sonar.server.ws.WsActionTester;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME;
index 764d4ad7bea1b357052ee7822c879b0890d96ac4..7bfb152b02567769d126a8247d573e36a6615b0d 100644 (file)
@@ -35,7 +35,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ResourceTypesRule;
 import org.sonar.db.permission.OldPermissionQuery;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.UserWithPermissionDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.component.ComponentFinder;
@@ -53,7 +53,7 @@ import static com.google.common.collect.FluentIterable.from;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.api.web.UserRole.CODEVIEWER;
 import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
 import static org.sonar.db.user.GroupMembershipQuery.IN;
 import static org.sonar.db.user.UserTesting.newUserDto;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
index 3a9610e4cab9153b3d27295f894352c9c9e871b6..a6e3e9eec3b7639a31b350e9dfe3c1ac6d780246 100644 (file)
@@ -33,7 +33,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ResourceTypesRule;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
@@ -47,7 +47,7 @@ import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
 import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
 import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02;
 import static org.sonar.core.util.Uuids.UUID_EXAMPLE_03;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
 import static org.sonar.db.user.GroupTesting.newGroupDto;
 import static org.sonar.db.user.UserTesting.newUserDto;
 import static org.sonar.server.permission.DefaultPermissionTemplates.defaultRootQualifierTemplateProperty;
index bcb6e08d27f8bdba7ca64ce3a9636b60ee5ae4e5..ec06471383f0357b2147d8aa78517d952f069be6 100644 (file)
@@ -26,7 +26,7 @@ import org.junit.rules.ExpectedException;
 import org.sonar.api.resources.Qualifiers;
 
 import static java.util.Collections.singletonList;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
 
 public class SearchTemplatesDataTest {
   @Rule
index 972c71dc18677a08179255b3174e9eb7b0e45bd5..a9c3918e28b07dd4d0c8afa1869f631e60e61c54 100644 (file)
@@ -34,8 +34,8 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
-import org.sonar.db.permission.PermissionTemplateDto;
-import org.sonar.db.permission.PermissionTemplateTesting;
+import org.sonar.db.permission.template.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateTesting;
 import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
index 48c39be3352ed71fdb976bcdf1354cafafb12986..1d5f5f9339884a4b4f59b5150f3fa88b4fd02241 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ResourceTypesRule;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.exceptions.BadRequestException;
@@ -49,7 +49,7 @@ import org.sonar.server.ws.WsActionTester;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_DESCRIPTION;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ID;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_NAME;
index 03573a2e0a2451ffb4612a4dc388409cc23a82fc..e50c9332baea8d45b0b19c39ce76239f20335540 100644 (file)
@@ -30,8 +30,8 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.loadedtemplate.LoadedTemplateDao;
 import org.sonar.db.loadedtemplate.LoadedTemplateDto;
-import org.sonar.db.permission.PermissionTemplateDao;
-import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateDao;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.user.GroupDao;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDao;
index 736aab507a4d16e1b8b518afd4503aab723a0088..a7e864eac058d3f61f0596e22d9f7f88ee6a9fc8 100644 (file)
@@ -30,7 +30,7 @@ import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.db.permission.PermissionTemplateDao;
+import org.sonar.db.permission.template.PermissionTemplateDao;
 import org.sonar.db.user.GroupDao;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.GroupRoleDto;
index effe78d17d0196eb0f2df5151933582fb7bea112..9eb8fcad164afba6693fe5dc20cb2d8c79d2a8c3 100644 (file)
@@ -49,7 +49,7 @@ import org.sonar.db.measure.custom.CustomMeasureDao;
 import org.sonar.db.metric.MetricDao;
 import org.sonar.db.notification.NotificationQueueDao;
 import org.sonar.db.permission.PermissionDao;
-import org.sonar.db.permission.PermissionTemplateDao;
+import org.sonar.db.permission.template.PermissionTemplateDao;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicDao;
 import org.sonar.db.property.PropertiesDao;
 import org.sonar.db.purge.PurgeDao;
index f14e36ed786989326e2d097dd207f70d2dcdfe52..e909f36c3d0dbf9f79bd6c98e1b30474d1c1858f 100644 (file)
@@ -49,7 +49,7 @@ import org.sonar.db.measure.custom.CustomMeasureDao;
 import org.sonar.db.metric.MetricDao;
 import org.sonar.db.notification.NotificationQueueDao;
 import org.sonar.db.permission.PermissionDao;
-import org.sonar.db.permission.PermissionTemplateDao;
+import org.sonar.db.permission.template.PermissionTemplateDao;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicDao;
 import org.sonar.db.property.PropertiesDao;
 import org.sonar.db.purge.PurgeDao;
index 99a53c3601d48f8956dc7bae4f5b51e1304f37ec..0a0b670ed225fea12af3b636448acf916de2c1db 100644 (file)
@@ -83,10 +83,10 @@ import org.sonar.db.metric.MetricMapper;
 import org.sonar.db.notification.NotificationQueueDto;
 import org.sonar.db.notification.NotificationQueueMapper;
 import org.sonar.db.permission.GroupWithPermissionDto;
-import org.sonar.db.permission.PermissionTemplateDto;
-import org.sonar.db.permission.PermissionTemplateGroupDto;
-import org.sonar.db.permission.PermissionTemplateMapper;
-import org.sonar.db.permission.PermissionTemplateUserDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateGroupDto;
+import org.sonar.db.permission.template.PermissionTemplateMapper;
+import org.sonar.db.permission.template.PermissionTemplateUserDto;
 import org.sonar.db.permission.UserWithPermissionDto;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicDto;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicMapper;
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/CountByTemplateAndPermissionDto.java b/sonar-db/src/main/java/org/sonar/db/permission/CountByTemplateAndPermissionDto.java
deleted file mode 100644 (file)
index 509715b..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.permission;
-
-public class CountByTemplateAndPermissionDto {
-  private long templateId;
-  private String permission;
-  private int count;
-
-  public long getTemplateId() {
-    return templateId;
-  }
-
-  public void setTemplateId(long templateId) {
-    this.templateId = templateId;
-  }
-
-  public String getPermission() {
-    return permission;
-  }
-
-  public void setPermission(String permission) {
-    this.permission = permission;
-  }
-
-  public int getCount() {
-    return count;
-  }
-
-  public void setCount(int count) {
-    this.count = count;
-  }
-}
index 9b16a3cd84a7a0b39a7c6dca4b962e6eb90114a1..7b13dfeb6618ccbc9567bd3d7acae2162d17831a 100644 (file)
@@ -32,7 +32,11 @@ import org.sonar.api.security.DefaultGroups;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.permission.template.PermissionTemplate;
 import org.sonar.db.permission.template.PermissionTemplateCharacteristicDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateGroupDto;
+import org.sonar.db.permission.template.PermissionTemplateUserDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.GroupRoleDto;
 import org.sonar.db.user.UserRoleDto;
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplate.java b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplate.java
deleted file mode 100644 (file)
index 79d9208..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-package org.sonar.db.permission;
-
-import java.util.List;
-import org.sonar.db.permission.template.PermissionTemplateCharacteristicDto;
-
-public class PermissionTemplate {
-  private final PermissionTemplateDto template;
-  private final List<PermissionTemplateUserDto> userPermissions;
-  private final List<PermissionTemplateGroupDto> groupPermissions;
-  private final List<PermissionTemplateCharacteristicDto> characteristics;
-
-  public PermissionTemplate(PermissionTemplateDto template,
-    List<PermissionTemplateUserDto> userPermissions,
-    List<PermissionTemplateGroupDto> groupPermissions,
-    List<PermissionTemplateCharacteristicDto> characteristics) {
-    this.template = template;
-    this.userPermissions = userPermissions;
-    this.groupPermissions = groupPermissions;
-    this.characteristics = characteristics;
-  }
-
-  public PermissionTemplateDto getTemplate() {
-    return template;
-  }
-
-  public List<PermissionTemplateUserDto> getUserPermissions() {
-    return userPermissions;
-  }
-
-  public List<PermissionTemplateGroupDto> getGroupPermissions() {
-    return groupPermissions;
-  }
-
-  public List<PermissionTemplateCharacteristicDto> getCharacteristics() {
-    return characteristics;
-  }
-}
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
deleted file mode 100644 (file)
index 71c2d3d..0000000
+++ /dev/null
@@ -1,425 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.permission;
-
-import com.google.common.annotations.VisibleForTesting;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import org.apache.ibatis.session.ResultHandler;
-import org.apache.ibatis.session.RowBounds;
-import org.apache.ibatis.session.SqlSession;
-import org.sonar.api.security.DefaultGroups;
-import org.sonar.api.utils.System2;
-import org.sonar.api.web.UserRole;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
-import org.sonar.db.permission.template.PermissionTemplateCharacteristicDto;
-import org.sonar.db.permission.template.PermissionTemplateCharacteristicMapper;
-
-import static com.google.common.collect.Maps.newHashMap;
-import static java.lang.String.format;
-import static org.sonar.db.DatabaseUtils.executeLargeInputsWithoutOutput;
-
-public class PermissionTemplateDao implements Dao {
-
-  public static final String QUERY_PARAMETER = "query";
-  public static final String TEMPLATE_ID_PARAMETER = "templateId";
-  private static final String ANYONE_GROUP_PARAMETER = "anyoneGroup";
-
-  private final MyBatis myBatis;
-  private final System2 system;
-
-  public PermissionTemplateDao(MyBatis myBatis, System2 system) {
-    this.myBatis = myBatis;
-    this.system = system;
-  }
-
-  /**
-   * @return a paginated list of users.
-   */
-  public List<UserWithPermissionDto> selectUsers(OldPermissionQuery query, Long templateId, int offset, int limit) {
-    DbSession session = myBatis.openSession(false);
-    try {
-      return selectUsers(session, query, templateId, offset, limit);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  /**
-   * @return a paginated list of users.
-   */
-  public List<UserWithPermissionDto> selectUsers(DbSession session, OldPermissionQuery query, Long templateId, int offset, int limit) {
-    Map<String, Object> params = newHashMap();
-    params.put(QUERY_PARAMETER, query);
-    params.put(TEMPLATE_ID_PARAMETER, templateId);
-    return mapper(session).selectUsers(params, new RowBounds(offset, limit));
-  }
-
-  public int countUsers(DbSession session, OldPermissionQuery query, Long templateId) {
-    Map<String, Object> params = newHashMap();
-    params.put(QUERY_PARAMETER, query);
-    params.put(TEMPLATE_ID_PARAMETER, templateId);
-    return mapper(session).countUsers(params);
-  }
-
-  @VisibleForTesting
-  List<UserWithPermissionDto> selectUsers(OldPermissionQuery query, Long templateId) {
-    return selectUsers(query, templateId, 0, Integer.MAX_VALUE);
-  }
-
-  /**
-   * 'Anyone' group is not returned when it has not the asked permission.
-   * Membership parameter from query is not taking into account in order to deal more easily with the 'Anyone' group.
-   * @return a non paginated list of groups.
-   */
-  public List<GroupWithPermissionDto> selectGroups(DbSession session, OldPermissionQuery query, Long templateId) {
-    return selectGroups(session, query, templateId, 0, Integer.MAX_VALUE);
-  }
-
-  public List<GroupWithPermissionDto> selectGroups(DbSession session, OldPermissionQuery query, Long templateId, int offset, int limit) {
-    Map<String, Object> params = groupsParameters(query, templateId);
-    return mapper(session).selectGroups(params, new RowBounds(offset, limit));
-  }
-
-  public List<GroupWithPermissionDto> selectGroups(OldPermissionQuery query, Long templateId) {
-    DbSession session = myBatis.openSession(false);
-    try {
-      return selectGroups(session, query, templateId);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public int countGroups(DbSession session, OldPermissionQuery query, long templateId) {
-    return countGroups(session, query, templateId, null);
-  }
-
-  private static int countGroups(DbSession session, OldPermissionQuery query, long templateId, @Nullable String groupName) {
-    Map<String, Object> parameters = groupsParameters(query, templateId);
-    if (groupName != null) {
-      parameters.put("groupName", groupName.toUpperCase(Locale.ENGLISH));
-    }
-    return mapper(session).countGroups(parameters);
-  }
-
-  public boolean hasGroup(DbSession session, OldPermissionQuery query, long templateId, String groupName) {
-    return countGroups(session, query, templateId, groupName) > 0;
-  }
-
-  private static Map<String, Object> groupsParameters(OldPermissionQuery query, Long templateId) {
-    Map<String, Object> params = newHashMap();
-    params.put(QUERY_PARAMETER, query);
-    params.put(TEMPLATE_ID_PARAMETER, templateId);
-    params.put("anyoneGroup", DefaultGroups.ANYONE);
-    params.put("projectAdminPermission", UserRole.ADMIN);
-    return params;
-  }
-
-  @CheckForNull
-  public PermissionTemplateDto selectByUuid(DbSession session, String templateUuid) {
-    return mapper(session).selectByUuid(templateUuid);
-  }
-
-  @CheckForNull
-  public PermissionTemplateDto selectByUuid(String templateUuid) {
-    DbSession session = myBatis.openSession(false);
-    try {
-      return selectByUuid(session, templateUuid);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  @CheckForNull
-  public PermissionTemplate selectByUuidWithUserAndGroupPermissions(DbSession session, String templateUuid) {
-    PermissionTemplateMapper mapper = mapper(session);
-
-    PermissionTemplateDto template = mapper.selectByUuid(templateUuid);
-    if (template == null) {
-      return null;
-    }
-
-    List<PermissionTemplateUserDto> userPermissions = mapper.selectUserPermissionsByTemplateId(template.getId());
-    List<PermissionTemplateGroupDto> groupPermissions = mapper.selectGroupPermissionsByTemplateId(template.getId());
-    PermissionTemplateCharacteristicMapper characteristicMapper = session.getMapper(PermissionTemplateCharacteristicMapper.class);
-    List<PermissionTemplateCharacteristicDto> characteristics = characteristicMapper.selectByTemplateId(template.getId());
-
-    return new PermissionTemplate(template, userPermissions, groupPermissions, characteristics);
-  }
-
-  @CheckForNull
-  public PermissionTemplate selectByUuidWithUserAndGroupPermissions(String templateUuid) {
-    DbSession session = myBatis.openSession(false);
-    try {
-      return selectByUuidWithUserAndGroupPermissions(session, templateUuid);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public List<PermissionTemplateDto> selectAll(DbSession session, String nameMatch) {
-    String uppercaseNameMatch = toUppercaseSqlQuery(nameMatch);
-    return mapper(session).selectAll(uppercaseNameMatch);
-  }
-
-  public List<PermissionTemplateDto> selectAll(DbSession session) {
-    return mapper(session).selectAll(null);
-  }
-
-  public List<PermissionTemplateDto> selectAll() {
-    DbSession session = myBatis.openSession(false);
-    try {
-      return selectAll(session);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public int countAll(DbSession dbSession, String nameQuery) {
-    String upperCasedNameQuery = toUppercaseSqlQuery(nameQuery);
-
-    return mapper(dbSession).countAll(upperCasedNameQuery);
-  }
-
-  private static String toUppercaseSqlQuery(String nameMatch) {
-    String wildcard = "%";
-    return format("%s%s%s", wildcard, nameMatch.toUpperCase(Locale.ENGLISH), wildcard);
-
-  }
-
-  public PermissionTemplateDto insert(DbSession session, PermissionTemplateDto permissionTemplate) {
-    mapper(session).insert(permissionTemplate);
-    session.commit();
-
-    return permissionTemplate;
-  }
-
-  /**
-   * Each row returns a #{@link CountByProjectAndPermissionDto}
-   */
-  public void usersCountByTemplateIdAndPermission(DbSession dbSession, List<Long> templateIds, ResultHandler resultHandler) {
-    Map<String, Object> parameters = new HashMap<>(1);
-
-    executeLargeInputsWithoutOutput(
-      templateIds,
-      partitionedTemplateIds -> {
-        parameters.put("templateIds", partitionedTemplateIds);
-        mapper(dbSession).usersCountByTemplateIdAndPermission(parameters, resultHandler);
-        return null;
-      });
-  }
-
-  /**
-   * Each row returns a #{@link CountByProjectAndPermissionDto}
-   */
-  public void groupsCountByTemplateIdAndPermission(DbSession dbSession, List<Long> templateIds, ResultHandler resultHandler) {
-    Map<String, Object> parameters = new HashMap<>(2);
-    parameters.put(ANYONE_GROUP_PARAMETER, DefaultGroups.ANYONE);
-
-    executeLargeInputsWithoutOutput(
-      templateIds,
-      partitionedTemplateIds -> {
-        parameters.put("templateIds", partitionedTemplateIds);
-        mapper(dbSession).groupsCountByTemplateIdAndPermission(parameters, resultHandler);
-        return null;
-      });
-  }
-
-  public void deleteById(DbSession session, long templateId) {
-    PermissionTemplateMapper mapper = mapper(session);
-    mapper.deleteUserPermissions(templateId);
-    mapper.deleteGroupPermissions(templateId);
-    session.getMapper(PermissionTemplateCharacteristicMapper.class).deleteByTemplateId(templateId);
-    mapper.delete(templateId);
-  }
-
-  /**
-   * @deprecated since 5.2 use {@link #update(DbSession, PermissionTemplateDto)}
-   */
-  @Deprecated
-  public void update(Long templateId, String templateName, @Nullable String description, @Nullable String projectPattern) {
-    PermissionTemplateDto permissionTemplate = new PermissionTemplateDto()
-      .setId(templateId)
-      .setName(templateName)
-      .setDescription(description)
-      .setKeyPattern(projectPattern)
-      .setUpdatedAt(now());
-
-    DbSession session = myBatis.openSession(false);
-    try {
-      update(session, permissionTemplate);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public PermissionTemplateDto update(DbSession session, PermissionTemplateDto permissionTemplate) {
-    mapper(session).update(permissionTemplate);
-    session.commit();
-
-    return permissionTemplate;
-  }
-
-  /**
-   * @deprecated since 5.2 {@link #insertUserPermission(DbSession, Long, Long, String)}
-   */
-  @Deprecated
-  public void insertUserPermission(Long templateId, Long userId, String permission) {
-    DbSession session = myBatis.openSession(false);
-    try {
-      insertUserPermission(session, templateId, userId, permission);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public void insertUserPermission(DbSession session, Long templateId, Long userId, String permission) {
-    PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto()
-      .setTemplateId(templateId)
-      .setUserId(userId)
-      .setPermission(permission)
-      .setCreatedAt(now())
-      .setUpdatedAt(now());
-
-    mapper(session).insertUserPermission(permissionTemplateUser);
-    session.commit();
-  }
-
-  public void insertUserPermission(DbSession session, PermissionTemplateUserDto permissionTemplateUserDto) {
-    mapper(session).insertUserPermission(permissionTemplateUserDto);
-  }
-
-  /**
-   * @deprecated since 5.2 {@link #deleteUserPermission(DbSession, Long, Long, String)}
-   */
-  @Deprecated
-  public void deleteUserPermission(Long templateId, Long userId, String permission) {
-    DbSession session = myBatis.openSession(false);
-    try {
-      deleteUserPermission(session, templateId, userId, permission);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public void deleteUserPermission(DbSession session, Long templateId, Long userId, String permission) {
-    PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto()
-      .setTemplateId(templateId)
-      .setPermission(permission)
-      .setUserId(userId);
-    mapper(session).deleteUserPermission(permissionTemplateUser);
-    session.commit();
-  }
-
-  /**
-   * @deprecated since 5.2 use {@link #insertGroupPermission(DbSession, Long, Long, String)}
-   */
-  @Deprecated
-  public void insertGroupPermission(Long templateId, @Nullable Long groupId, String permission) {
-    DbSession session = myBatis.openSession(false);
-    try {
-      insertGroupPermission(session, templateId, groupId, permission);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public void insertGroupPermission(DbSession session, Long templateId, @Nullable Long groupId, String permission) {
-    PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto()
-      .setTemplateId(templateId)
-      .setPermission(permission)
-      .setGroupId(groupId)
-      .setCreatedAt(now())
-      .setUpdatedAt(now());
-    mapper(session).insertGroupPermission(permissionTemplateGroup);
-    session.commit();
-  }
-
-  public void insertGroupPermission(DbSession session, PermissionTemplateGroupDto permissionTemplateGroup) {
-    mapper(session).insertGroupPermission(permissionTemplateGroup);
-  }
-
-  /**
-   * @deprecated since 5.2 use {@link #deleteGroupPermission(DbSession, Long, Long, String)}
-   */
-  @Deprecated
-  public void deleteGroupPermission(Long templateId, @Nullable Long groupId, String permission) {
-    DbSession session = myBatis.openSession(false);
-    try {
-      deleteGroupPermission(session, templateId, groupId, permission);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public void deleteGroupPermission(DbSession session, Long templateId, @Nullable Long groupId, String permission) {
-    PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto()
-      .setTemplateId(templateId)
-      .setPermission(permission)
-      .setGroupId(groupId);
-    mapper(session).deleteGroupPermission(permissionTemplateGroup);
-    session.commit();
-  }
-
-  /**
-   * Load permission template and load associated collections of users and groups permissions, and characteristics
-   */
-  PermissionTemplate selectPermissionTemplateWithPermissions(DbSession session, String templateUuid) {
-    PermissionTemplateDto template = selectByUuid(session, templateUuid);
-    if (template == null) {
-      throw new IllegalArgumentException("Could not retrieve permission template with uuid " + templateUuid);
-    }
-    PermissionTemplate templateWithDependencies = selectByUuidWithUserAndGroupPermissions(session, template.getUuid());
-    if (templateWithDependencies == null) {
-      throw new IllegalArgumentException("Could not retrieve permissions for template with uuid " + templateUuid);
-    }
-    return templateWithDependencies;
-  }
-
-  public PermissionTemplateDto selectByName(DbSession dbSession, String name) {
-    return mapper(dbSession).selectByName(name.toUpperCase(Locale.ENGLISH));
-  }
-
-  public List<String> selectPotentialPermissionsByUserIdAndTemplateId(DbSession dbSession, @Nullable Long currentUserId, long templateId) {
-    return mapper(dbSession).selectPotentialPermissionsByUserIdAndTemplateId(currentUserId, templateId);
-  }
-
-  /**
-   * Remove a group from all templates (used when removing a group)
-   */
-  public void deleteByGroup(SqlSession session, Long groupId) {
-    session.getMapper(PermissionTemplateMapper.class).deleteByGroupId(groupId);
-  }
-
-  private Date now() {
-    return new Date(system.now());
-  }
-
-  private static PermissionTemplateMapper mapper(SqlSession session) {
-    return session.getMapper(PermissionTemplateMapper.class);
-  }
-}
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
deleted file mode 100644 (file)
index 9ee2dea..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.permission;
-
-import java.util.Date;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-public class PermissionTemplateDto {
-
-  private Long id;
-  private String name;
-  private String uuid;
-  private String description;
-  private String keyPattern;
-  private Date createdAt;
-  private Date updatedAt;
-
-  public Long getId() {
-    return id;
-  }
-
-  public PermissionTemplateDto setId(Long id) {
-    this.id = id;
-    return this;
-  }
-
-  public String getName() {
-    return name;
-  }
-
-  public PermissionTemplateDto setName(String name) {
-    this.name = name;
-    return this;
-  }
-
-  /**
-   * @deprecated since 5.2 use {@link #getUuid()}
-   */
-  @Deprecated
-  public String getKee() {
-    return uuid;
-  }
-
-  /**
-   * @deprecated since 5.2 use {@link #setUuid(String)}
-   */
-  @Deprecated
-  public PermissionTemplateDto setKee(String 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.uuid = uuid;
-    return this;
-  }
-
-  @CheckForNull
-  public String getDescription() {
-    return description;
-  }
-
-  public PermissionTemplateDto setDescription(@Nullable String description) {
-    this.description = description;
-    return this;
-  }
-
-  @CheckForNull
-  public String getKeyPattern() {
-    return keyPattern;
-  }
-
-  public PermissionTemplateDto setKeyPattern(@Nullable String regexp) {
-    this.keyPattern = regexp;
-    return this;
-  }
-
-  public Date getCreatedAt() {
-    return createdAt;
-  }
-
-  public PermissionTemplateDto setCreatedAt(Date createdAt) {
-    this.createdAt = createdAt;
-    return this;
-  }
-
-  public Date getUpdatedAt() {
-    return updatedAt;
-  }
-
-  public PermissionTemplateDto setUpdatedAt(Date updatedAt) {
-    this.updatedAt = updatedAt;
-    return this;
-  }
-}
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateGroupDto.java b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateGroupDto.java
deleted file mode 100644 (file)
index 65a820b..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.permission;
-
-import java.util.Date;
-import javax.annotation.Nullable;
-
-public class PermissionTemplateGroupDto {
-  private Long id;
-  private Long templateId;
-  private Long groupId;
-  private String permission;
-  private String groupName;
-  private Date createdAt;
-  private Date updatedAt;
-
-  public Long getId() {
-    return id;
-  }
-
-  public PermissionTemplateGroupDto setId(Long id) {
-    this.id = id;
-    return this;
-  }
-
-  public Long getTemplateId() {
-    return templateId;
-  }
-
-  public PermissionTemplateGroupDto setTemplateId(Long templateId) {
-    this.templateId = templateId;
-    return this;
-  }
-
-  public Long getGroupId() {
-    return groupId;
-  }
-
-  public PermissionTemplateGroupDto setGroupId(@Nullable Long groupId) {
-    this.groupId = groupId;
-    return this;
-  }
-
-  public String getPermission() {
-    return permission;
-  }
-
-  public PermissionTemplateGroupDto setPermission(String permission) {
-    this.permission = permission;
-    return this;
-  }
-
-  public String getGroupName() {
-    return groupName;
-  }
-
-  public PermissionTemplateGroupDto setGroupName(String groupName) {
-    this.groupName = groupName;
-    return this;
-  }
-
-  public Date getCreatedAt() {
-    return createdAt;
-  }
-
-  public PermissionTemplateGroupDto setCreatedAt(Date createdAt) {
-    this.createdAt = createdAt;
-    return this;
-  }
-
-  public Date getUpdatedAt() {
-    return updatedAt;
-  }
-
-  public PermissionTemplateGroupDto setUpdatedAt(Date updatedAt) {
-    this.updatedAt = updatedAt;
-    return this;
-  }
-}
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateMapper.java b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateMapper.java
deleted file mode 100644 (file)
index 442b6a9..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.permission;
-
-import java.util.List;
-import java.util.Map;
-import javax.annotation.Nullable;
-import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.session.ResultHandler;
-import org.apache.ibatis.session.RowBounds;
-
-/**
- * @since 3.7
- */
-public interface PermissionTemplateMapper {
-
-  void insert(PermissionTemplateDto permissionTemplate);
-
-  void update(PermissionTemplateDto permissionTemplate);
-
-  void delete(long templateId);
-
-  void deleteUserPermissions(long templateId);
-
-  void deleteUserPermission(PermissionTemplateUserDto permissionTemplateUser);
-
-  void deleteGroupPermissions(long templateId);
-
-  void deleteGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup);
-
-  PermissionTemplateDto selectByUuid(String templateUuid);
-
-  List<PermissionTemplateUserDto> selectUserPermissionsByTemplateId(long templateId);
-
-  List<PermissionTemplateGroupDto> selectGroupPermissionsByTemplateId(long templateId);
-
-  void insertUserPermission(PermissionTemplateUserDto permissionTemplateUser);
-
-  void insertGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup);
-
-  void deleteByGroupId(long groupId);
-
-  List<GroupWithPermissionDto> selectGroups(Map<String, Object> params, RowBounds rowBounds);
-
-  List<UserWithPermissionDto> selectUsers(Map<String, Object> params, RowBounds rowBounds);
-
-  PermissionTemplateDto selectByName(String name);
-
-  int countUsers(Map<String, Object> params);
-
-  int countGroups(Map<String, Object> parameters);
-
-  List<PermissionTemplateDto> selectAll(@Param("nameMatch") String nameMatch);
-
-  int countAll(@Param("nameMatch") String nameMatch);
-
-  void usersCountByTemplateIdAndPermission(Map<String, Object> parameters, ResultHandler resultHandler);
-
-  void groupsCountByTemplateIdAndPermission(Map<String, Object> parameters, ResultHandler resultHandler);
-
-  List<String> selectPotentialPermissionsByUserIdAndTemplateId(@Param("userId") @Nullable Long currentUserId, @Param("templateId") long templateId);
-}
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateUserDto.java b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateUserDto.java
deleted file mode 100644 (file)
index 20ace57..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.permission;
-
-import java.util.Date;
-
-public class PermissionTemplateUserDto {
-  private Long id;
-  private Long templateId;
-  private Long userId;
-  private String permission;
-  private String userName;
-  private String userLogin;
-  private Date createdAt;
-  private Date updatedAt;
-
-  public Long getId() {
-    return id;
-  }
-
-  public PermissionTemplateUserDto setId(Long id) {
-    this.id = id;
-    return this;
-  }
-
-  public Long getTemplateId() {
-    return templateId;
-  }
-
-  public PermissionTemplateUserDto setTemplateId(Long templateId) {
-    this.templateId = templateId;
-    return this;
-  }
-
-  public Long getUserId() {
-    return userId;
-  }
-
-  public PermissionTemplateUserDto setUserId(Long userId) {
-    this.userId = userId;
-    return this;
-  }
-
-  public String getUserName() {
-    return userName;
-  }
-
-  public PermissionTemplateUserDto setUserName(String userName) {
-    this.userName = userName;
-    return this;
-  }
-
-  public String getUserLogin() {
-    return userLogin;
-  }
-
-  public PermissionTemplateUserDto setUserLogin(String userLogin) {
-    this.userLogin = userLogin;
-    return this;
-  }
-
-  public String getPermission() {
-    return permission;
-  }
-
-  public PermissionTemplateUserDto setPermission(String permission) {
-    this.permission = permission;
-    return this;
-  }
-
-  public Date getCreatedAt() {
-    return createdAt;
-  }
-
-  public PermissionTemplateUserDto setCreatedAt(Date createdAt) {
-    this.createdAt = createdAt;
-    return this;
-  }
-
-  public Date getUpdatedAt() {
-    return updatedAt;
-  }
-
-  public PermissionTemplateUserDto setUpdatedAt(Date updatedAt) {
-    this.updatedAt = updatedAt;
-    return this;
-  }
-}
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/template/CountByTemplateAndPermissionDto.java b/sonar-db/src/main/java/org/sonar/db/permission/template/CountByTemplateAndPermissionDto.java
new file mode 100644 (file)
index 0000000..e8e4496
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.permission.template;
+
+public class CountByTemplateAndPermissionDto {
+  private long templateId;
+  private String permission;
+  private int count;
+
+  public long getTemplateId() {
+    return templateId;
+  }
+
+  public void setTemplateId(long templateId) {
+    this.templateId = templateId;
+  }
+
+  public String getPermission() {
+    return permission;
+  }
+
+  public void setPermission(String permission) {
+    this.permission = permission;
+  }
+
+  public int getCount() {
+    return count;
+  }
+
+  public void setCount(int count) {
+    this.count = count;
+  }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplate.java b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplate.java
new file mode 100644 (file)
index 0000000..9f62d8a
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.db.permission.template;
+
+import java.util.List;
+import org.sonar.db.permission.template.PermissionTemplateCharacteristicDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateGroupDto;
+import org.sonar.db.permission.template.PermissionTemplateUserDto;
+
+public class PermissionTemplate {
+  private final PermissionTemplateDto template;
+  private final List<PermissionTemplateUserDto> userPermissions;
+  private final List<PermissionTemplateGroupDto> groupPermissions;
+  private final List<PermissionTemplateCharacteristicDto> characteristics;
+
+  public PermissionTemplate(PermissionTemplateDto template,
+    List<PermissionTemplateUserDto> userPermissions,
+    List<PermissionTemplateGroupDto> groupPermissions,
+    List<PermissionTemplateCharacteristicDto> characteristics) {
+    this.template = template;
+    this.userPermissions = userPermissions;
+    this.groupPermissions = groupPermissions;
+    this.characteristics = characteristics;
+  }
+
+  public PermissionTemplateDto getTemplate() {
+    return template;
+  }
+
+  public List<PermissionTemplateUserDto> getUserPermissions() {
+    return userPermissions;
+  }
+
+  public List<PermissionTemplateGroupDto> getGroupPermissions() {
+    return groupPermissions;
+  }
+
+  public List<PermissionTemplateCharacteristicDto> getCharacteristics() {
+    return characteristics;
+  }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java
new file mode 100644 (file)
index 0000000..27608d2
--- /dev/null
@@ -0,0 +1,427 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.permission.template;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.apache.ibatis.session.ResultHandler;
+import org.apache.ibatis.session.RowBounds;
+import org.apache.ibatis.session.SqlSession;
+import org.sonar.api.security.DefaultGroups;
+import org.sonar.api.utils.System2;
+import org.sonar.api.web.UserRole;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+import org.sonar.db.MyBatis;
+import org.sonar.db.permission.CountByProjectAndPermissionDto;
+import org.sonar.db.permission.GroupWithPermissionDto;
+import org.sonar.db.permission.OldPermissionQuery;
+import org.sonar.db.permission.UserWithPermissionDto;
+
+import static com.google.common.collect.Maps.newHashMap;
+import static java.lang.String.format;
+import static org.sonar.db.DatabaseUtils.executeLargeInputsWithoutOutput;
+
+public class PermissionTemplateDao implements Dao {
+
+  public static final String QUERY_PARAMETER = "query";
+  public static final String TEMPLATE_ID_PARAMETER = "templateId";
+  private static final String ANYONE_GROUP_PARAMETER = "anyoneGroup";
+
+  private final MyBatis myBatis;
+  private final System2 system;
+
+  public PermissionTemplateDao(MyBatis myBatis, System2 system) {
+    this.myBatis = myBatis;
+    this.system = system;
+  }
+
+  /**
+   * @return a paginated list of users.
+   */
+  public List<UserWithPermissionDto> selectUsers(OldPermissionQuery query, Long templateId, int offset, int limit) {
+    DbSession session = myBatis.openSession(false);
+    try {
+      return selectUsers(session, query, templateId, offset, limit);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  /**
+   * @return a paginated list of users.
+   */
+  public List<UserWithPermissionDto> selectUsers(DbSession session, OldPermissionQuery query, Long templateId, int offset, int limit) {
+    Map<String, Object> params = newHashMap();
+    params.put(QUERY_PARAMETER, query);
+    params.put(TEMPLATE_ID_PARAMETER, templateId);
+    return mapper(session).selectUsers(params, new RowBounds(offset, limit));
+  }
+
+  public int countUsers(DbSession session, OldPermissionQuery query, Long templateId) {
+    Map<String, Object> params = newHashMap();
+    params.put(QUERY_PARAMETER, query);
+    params.put(TEMPLATE_ID_PARAMETER, templateId);
+    return mapper(session).countUsers(params);
+  }
+
+  @VisibleForTesting
+  List<UserWithPermissionDto> selectUsers(OldPermissionQuery query, Long templateId) {
+    return selectUsers(query, templateId, 0, Integer.MAX_VALUE);
+  }
+
+  /**
+   * 'Anyone' group is not returned when it has not the asked permission.
+   * Membership parameter from query is not taking into account in order to deal more easily with the 'Anyone' group.
+   * @return a non paginated list of groups.
+   */
+  public List<GroupWithPermissionDto> selectGroups(DbSession session, OldPermissionQuery query, Long templateId) {
+    return selectGroups(session, query, templateId, 0, Integer.MAX_VALUE);
+  }
+
+  public List<GroupWithPermissionDto> selectGroups(DbSession session, OldPermissionQuery query, Long templateId, int offset, int limit) {
+    Map<String, Object> params = groupsParameters(query, templateId);
+    return mapper(session).selectGroups(params, new RowBounds(offset, limit));
+  }
+
+  public List<GroupWithPermissionDto> selectGroups(OldPermissionQuery query, Long templateId) {
+    DbSession session = myBatis.openSession(false);
+    try {
+      return selectGroups(session, query, templateId);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public int countGroups(DbSession session, OldPermissionQuery query, long templateId) {
+    return countGroups(session, query, templateId, null);
+  }
+
+  private static int countGroups(DbSession session, OldPermissionQuery query, long templateId, @Nullable String groupName) {
+    Map<String, Object> parameters = groupsParameters(query, templateId);
+    if (groupName != null) {
+      parameters.put("groupName", groupName.toUpperCase(Locale.ENGLISH));
+    }
+    return mapper(session).countGroups(parameters);
+  }
+
+  public boolean hasGroup(DbSession session, OldPermissionQuery query, long templateId, String groupName) {
+    return countGroups(session, query, templateId, groupName) > 0;
+  }
+
+  private static Map<String, Object> groupsParameters(OldPermissionQuery query, Long templateId) {
+    Map<String, Object> params = newHashMap();
+    params.put(QUERY_PARAMETER, query);
+    params.put(TEMPLATE_ID_PARAMETER, templateId);
+    params.put("anyoneGroup", DefaultGroups.ANYONE);
+    params.put("projectAdminPermission", UserRole.ADMIN);
+    return params;
+  }
+
+  @CheckForNull
+  public PermissionTemplateDto selectByUuid(DbSession session, String templateUuid) {
+    return mapper(session).selectByUuid(templateUuid);
+  }
+
+  @CheckForNull
+  public PermissionTemplateDto selectByUuid(String templateUuid) {
+    DbSession session = myBatis.openSession(false);
+    try {
+      return selectByUuid(session, templateUuid);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  @CheckForNull
+  public PermissionTemplate selectByUuidWithUserAndGroupPermissions(DbSession session, String templateUuid) {
+    PermissionTemplateMapper mapper = mapper(session);
+
+    PermissionTemplateDto template = mapper.selectByUuid(templateUuid);
+    if (template == null) {
+      return null;
+    }
+
+    List<PermissionTemplateUserDto> userPermissions = mapper.selectUserPermissionsByTemplateId(template.getId());
+    List<PermissionTemplateGroupDto> groupPermissions = mapper.selectGroupPermissionsByTemplateId(template.getId());
+    PermissionTemplateCharacteristicMapper characteristicMapper = session.getMapper(PermissionTemplateCharacteristicMapper.class);
+    List<PermissionTemplateCharacteristicDto> characteristics = characteristicMapper.selectByTemplateId(template.getId());
+
+    return new PermissionTemplate(template, userPermissions, groupPermissions, characteristics);
+  }
+
+  @CheckForNull
+  public PermissionTemplate selectByUuidWithUserAndGroupPermissions(String templateUuid) {
+    DbSession session = myBatis.openSession(false);
+    try {
+      return selectByUuidWithUserAndGroupPermissions(session, templateUuid);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public List<PermissionTemplateDto> selectAll(DbSession session, String nameMatch) {
+    String uppercaseNameMatch = toUppercaseSqlQuery(nameMatch);
+    return mapper(session).selectAll(uppercaseNameMatch);
+  }
+
+  public List<PermissionTemplateDto> selectAll(DbSession session) {
+    return mapper(session).selectAll(null);
+  }
+
+  public List<PermissionTemplateDto> selectAll() {
+    DbSession session = myBatis.openSession(false);
+    try {
+      return selectAll(session);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public int countAll(DbSession dbSession, String nameQuery) {
+    String upperCasedNameQuery = toUppercaseSqlQuery(nameQuery);
+
+    return mapper(dbSession).countAll(upperCasedNameQuery);
+  }
+
+  private static String toUppercaseSqlQuery(String nameMatch) {
+    String wildcard = "%";
+    return format("%s%s%s", wildcard, nameMatch.toUpperCase(Locale.ENGLISH), wildcard);
+
+  }
+
+  public PermissionTemplateDto insert(DbSession session, PermissionTemplateDto permissionTemplate) {
+    mapper(session).insert(permissionTemplate);
+    session.commit();
+
+    return permissionTemplate;
+  }
+
+  /**
+   * Each row returns a #{@link CountByProjectAndPermissionDto}
+   */
+  public void usersCountByTemplateIdAndPermission(DbSession dbSession, List<Long> templateIds, ResultHandler resultHandler) {
+    Map<String, Object> parameters = new HashMap<>(1);
+
+    executeLargeInputsWithoutOutput(
+      templateIds,
+      partitionedTemplateIds -> {
+        parameters.put("templateIds", partitionedTemplateIds);
+        mapper(dbSession).usersCountByTemplateIdAndPermission(parameters, resultHandler);
+        return null;
+      });
+  }
+
+  /**
+   * Each row returns a #{@link CountByProjectAndPermissionDto}
+   */
+  public void groupsCountByTemplateIdAndPermission(DbSession dbSession, List<Long> templateIds, ResultHandler resultHandler) {
+    Map<String, Object> parameters = new HashMap<>(2);
+    parameters.put(ANYONE_GROUP_PARAMETER, DefaultGroups.ANYONE);
+
+    executeLargeInputsWithoutOutput(
+      templateIds,
+      partitionedTemplateIds -> {
+        parameters.put("templateIds", partitionedTemplateIds);
+        mapper(dbSession).groupsCountByTemplateIdAndPermission(parameters, resultHandler);
+        return null;
+      });
+  }
+
+  public void deleteById(DbSession session, long templateId) {
+    PermissionTemplateMapper mapper = mapper(session);
+    mapper.deleteUserPermissions(templateId);
+    mapper.deleteGroupPermissions(templateId);
+    session.getMapper(PermissionTemplateCharacteristicMapper.class).deleteByTemplateId(templateId);
+    mapper.delete(templateId);
+  }
+
+  /**
+   * @deprecated since 5.2 use {@link #update(DbSession, PermissionTemplateDto)}
+   */
+  @Deprecated
+  public void update(Long templateId, String templateName, @Nullable String description, @Nullable String projectPattern) {
+    PermissionTemplateDto permissionTemplate = new PermissionTemplateDto()
+      .setId(templateId)
+      .setName(templateName)
+      .setDescription(description)
+      .setKeyPattern(projectPattern)
+      .setUpdatedAt(now());
+
+    DbSession session = myBatis.openSession(false);
+    try {
+      update(session, permissionTemplate);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public PermissionTemplateDto update(DbSession session, PermissionTemplateDto permissionTemplate) {
+    mapper(session).update(permissionTemplate);
+    session.commit();
+
+    return permissionTemplate;
+  }
+
+  /**
+   * @deprecated since 5.2 {@link #insertUserPermission(DbSession, Long, Long, String)}
+   */
+  @Deprecated
+  public void insertUserPermission(Long templateId, Long userId, String permission) {
+    DbSession session = myBatis.openSession(false);
+    try {
+      insertUserPermission(session, templateId, userId, permission);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public void insertUserPermission(DbSession session, Long templateId, Long userId, String permission) {
+    PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto()
+      .setTemplateId(templateId)
+      .setUserId(userId)
+      .setPermission(permission)
+      .setCreatedAt(now())
+      .setUpdatedAt(now());
+
+    mapper(session).insertUserPermission(permissionTemplateUser);
+    session.commit();
+  }
+
+  public void insertUserPermission(DbSession session, PermissionTemplateUserDto permissionTemplateUserDto) {
+    mapper(session).insertUserPermission(permissionTemplateUserDto);
+  }
+
+  /**
+   * @deprecated since 5.2 {@link #deleteUserPermission(DbSession, Long, Long, String)}
+   */
+  @Deprecated
+  public void deleteUserPermission(Long templateId, Long userId, String permission) {
+    DbSession session = myBatis.openSession(false);
+    try {
+      deleteUserPermission(session, templateId, userId, permission);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public void deleteUserPermission(DbSession session, Long templateId, Long userId, String permission) {
+    PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto()
+      .setTemplateId(templateId)
+      .setPermission(permission)
+      .setUserId(userId);
+    mapper(session).deleteUserPermission(permissionTemplateUser);
+    session.commit();
+  }
+
+  /**
+   * @deprecated since 5.2 use {@link #insertGroupPermission(DbSession, Long, Long, String)}
+   */
+  @Deprecated
+  public void insertGroupPermission(Long templateId, @Nullable Long groupId, String permission) {
+    DbSession session = myBatis.openSession(false);
+    try {
+      insertGroupPermission(session, templateId, groupId, permission);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public void insertGroupPermission(DbSession session, Long templateId, @Nullable Long groupId, String permission) {
+    PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto()
+      .setTemplateId(templateId)
+      .setPermission(permission)
+      .setGroupId(groupId)
+      .setCreatedAt(now())
+      .setUpdatedAt(now());
+    mapper(session).insertGroupPermission(permissionTemplateGroup);
+    session.commit();
+  }
+
+  public void insertGroupPermission(DbSession session, PermissionTemplateGroupDto permissionTemplateGroup) {
+    mapper(session).insertGroupPermission(permissionTemplateGroup);
+  }
+
+  /**
+   * @deprecated since 5.2 use {@link #deleteGroupPermission(DbSession, Long, Long, String)}
+   */
+  @Deprecated
+  public void deleteGroupPermission(Long templateId, @Nullable Long groupId, String permission) {
+    DbSession session = myBatis.openSession(false);
+    try {
+      deleteGroupPermission(session, templateId, groupId, permission);
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  public void deleteGroupPermission(DbSession session, Long templateId, @Nullable Long groupId, String permission) {
+    PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto()
+      .setTemplateId(templateId)
+      .setPermission(permission)
+      .setGroupId(groupId);
+    mapper(session).deleteGroupPermission(permissionTemplateGroup);
+    session.commit();
+  }
+
+  /**
+   * Load permission template and load associated collections of users and groups permissions, and characteristics
+   */
+  public PermissionTemplate selectPermissionTemplateWithPermissions(DbSession session, String templateUuid) {
+    PermissionTemplateDto template = selectByUuid(session, templateUuid);
+    if (template == null) {
+      throw new IllegalArgumentException("Could not retrieve permission template with uuid " + templateUuid);
+    }
+    PermissionTemplate templateWithDependencies = selectByUuidWithUserAndGroupPermissions(session, template.getUuid());
+    if (templateWithDependencies == null) {
+      throw new IllegalArgumentException("Could not retrieve permissions for template with uuid " + templateUuid);
+    }
+    return templateWithDependencies;
+  }
+
+  public PermissionTemplateDto selectByName(DbSession dbSession, String name) {
+    return mapper(dbSession).selectByName(name.toUpperCase(Locale.ENGLISH));
+  }
+
+  public List<String> selectPotentialPermissionsByUserIdAndTemplateId(DbSession dbSession, @Nullable Long currentUserId, long templateId) {
+    return mapper(dbSession).selectPotentialPermissionsByUserIdAndTemplateId(currentUserId, templateId);
+  }
+
+  /**
+   * Remove a group from all templates (used when removing a group)
+   */
+  public void deleteByGroup(SqlSession session, Long groupId) {
+    session.getMapper(PermissionTemplateMapper.class).deleteByGroupId(groupId);
+  }
+
+  private Date now() {
+    return new Date(system.now());
+  }
+
+  private static PermissionTemplateMapper mapper(SqlSession session) {
+    return session.getMapper(PermissionTemplateMapper.class);
+  }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateDto.java b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateDto.java
new file mode 100644 (file)
index 0000000..5d537cb
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.permission.template;
+
+import java.util.Date;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+public class PermissionTemplateDto {
+
+  private Long id;
+  private String name;
+  private String uuid;
+  private String description;
+  private String keyPattern;
+  private Date createdAt;
+  private Date updatedAt;
+
+  public Long getId() {
+    return id;
+  }
+
+  public PermissionTemplateDto setId(Long id) {
+    this.id = id;
+    return this;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public PermissionTemplateDto setName(String name) {
+    this.name = name;
+    return this;
+  }
+
+  /**
+   * @deprecated since 5.2 use {@link #getUuid()}
+   */
+  @Deprecated
+  public String getKee() {
+    return uuid;
+  }
+
+  /**
+   * @deprecated since 5.2 use {@link #setUuid(String)}
+   */
+  @Deprecated
+  public PermissionTemplateDto setKee(String 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.uuid = uuid;
+    return this;
+  }
+
+  @CheckForNull
+  public String getDescription() {
+    return description;
+  }
+
+  public PermissionTemplateDto setDescription(@Nullable String description) {
+    this.description = description;
+    return this;
+  }
+
+  @CheckForNull
+  public String getKeyPattern() {
+    return keyPattern;
+  }
+
+  public PermissionTemplateDto setKeyPattern(@Nullable String regexp) {
+    this.keyPattern = regexp;
+    return this;
+  }
+
+  public Date getCreatedAt() {
+    return createdAt;
+  }
+
+  public PermissionTemplateDto setCreatedAt(Date createdAt) {
+    this.createdAt = createdAt;
+    return this;
+  }
+
+  public Date getUpdatedAt() {
+    return updatedAt;
+  }
+
+  public PermissionTemplateDto setUpdatedAt(Date updatedAt) {
+    this.updatedAt = updatedAt;
+    return this;
+  }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateGroupDto.java
new file mode 100644 (file)
index 0000000..bd3f9a3
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.permission.template;
+
+import java.util.Date;
+import javax.annotation.Nullable;
+
+public class PermissionTemplateGroupDto {
+  private Long id;
+  private Long templateId;
+  private Long groupId;
+  private String permission;
+  private String groupName;
+  private Date createdAt;
+  private Date updatedAt;
+
+  public Long getId() {
+    return id;
+  }
+
+  public PermissionTemplateGroupDto setId(Long id) {
+    this.id = id;
+    return this;
+  }
+
+  public Long getTemplateId() {
+    return templateId;
+  }
+
+  public PermissionTemplateGroupDto setTemplateId(Long templateId) {
+    this.templateId = templateId;
+    return this;
+  }
+
+  public Long getGroupId() {
+    return groupId;
+  }
+
+  public PermissionTemplateGroupDto setGroupId(@Nullable Long groupId) {
+    this.groupId = groupId;
+    return this;
+  }
+
+  public String getPermission() {
+    return permission;
+  }
+
+  public PermissionTemplateGroupDto setPermission(String permission) {
+    this.permission = permission;
+    return this;
+  }
+
+  public String getGroupName() {
+    return groupName;
+  }
+
+  public PermissionTemplateGroupDto setGroupName(String groupName) {
+    this.groupName = groupName;
+    return this;
+  }
+
+  public Date getCreatedAt() {
+    return createdAt;
+  }
+
+  public PermissionTemplateGroupDto setCreatedAt(Date createdAt) {
+    this.createdAt = createdAt;
+    return this;
+  }
+
+  public Date getUpdatedAt() {
+    return updatedAt;
+  }
+
+  public PermissionTemplateGroupDto setUpdatedAt(Date updatedAt) {
+    this.updatedAt = updatedAt;
+    return this;
+  }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java
new file mode 100644 (file)
index 0000000..12515af
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.permission.template;
+
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.session.ResultHandler;
+import org.apache.ibatis.session.RowBounds;
+import org.sonar.db.permission.GroupWithPermissionDto;
+import org.sonar.db.permission.UserWithPermissionDto;
+
+/**
+ * @since 3.7
+ */
+public interface PermissionTemplateMapper {
+
+  void insert(PermissionTemplateDto permissionTemplate);
+
+  void update(PermissionTemplateDto permissionTemplate);
+
+  void delete(long templateId);
+
+  void deleteUserPermissions(long templateId);
+
+  void deleteUserPermission(PermissionTemplateUserDto permissionTemplateUser);
+
+  void deleteGroupPermissions(long templateId);
+
+  void deleteGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup);
+
+  PermissionTemplateDto selectByUuid(String templateUuid);
+
+  List<PermissionTemplateUserDto> selectUserPermissionsByTemplateId(long templateId);
+
+  List<PermissionTemplateGroupDto> selectGroupPermissionsByTemplateId(long templateId);
+
+  void insertUserPermission(PermissionTemplateUserDto permissionTemplateUser);
+
+  void insertGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup);
+
+  void deleteByGroupId(long groupId);
+
+  List<GroupWithPermissionDto> selectGroups(Map<String, Object> params, RowBounds rowBounds);
+
+  List<UserWithPermissionDto> selectUsers(Map<String, Object> params, RowBounds rowBounds);
+
+  PermissionTemplateDto selectByName(String name);
+
+  int countUsers(Map<String, Object> params);
+
+  int countGroups(Map<String, Object> parameters);
+
+  List<PermissionTemplateDto> selectAll(@Param("nameMatch") String nameMatch);
+
+  int countAll(@Param("nameMatch") String nameMatch);
+
+  void usersCountByTemplateIdAndPermission(Map<String, Object> parameters, ResultHandler resultHandler);
+
+  void groupsCountByTemplateIdAndPermission(Map<String, Object> parameters, ResultHandler resultHandler);
+
+  List<String> selectPotentialPermissionsByUserIdAndTemplateId(@Param("userId") @Nullable Long currentUserId, @Param("templateId") long templateId);
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateUserDto.java b/sonar-db/src/main/java/org/sonar/db/permission/template/PermissionTemplateUserDto.java
new file mode 100644 (file)
index 0000000..6fc1119
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.permission.template;
+
+import java.util.Date;
+
+public class PermissionTemplateUserDto {
+  private Long id;
+  private Long templateId;
+  private Long userId;
+  private String permission;
+  private String userName;
+  private String userLogin;
+  private Date createdAt;
+  private Date updatedAt;
+
+  public Long getId() {
+    return id;
+  }
+
+  public PermissionTemplateUserDto setId(Long id) {
+    this.id = id;
+    return this;
+  }
+
+  public Long getTemplateId() {
+    return templateId;
+  }
+
+  public PermissionTemplateUserDto setTemplateId(Long templateId) {
+    this.templateId = templateId;
+    return this;
+  }
+
+  public Long getUserId() {
+    return userId;
+  }
+
+  public PermissionTemplateUserDto setUserId(Long userId) {
+    this.userId = userId;
+    return this;
+  }
+
+  public String getUserName() {
+    return userName;
+  }
+
+  public PermissionTemplateUserDto setUserName(String userName) {
+    this.userName = userName;
+    return this;
+  }
+
+  public String getUserLogin() {
+    return userLogin;
+  }
+
+  public PermissionTemplateUserDto setUserLogin(String userLogin) {
+    this.userLogin = userLogin;
+    return this;
+  }
+
+  public String getPermission() {
+    return permission;
+  }
+
+  public PermissionTemplateUserDto setPermission(String permission) {
+    this.permission = permission;
+    return this;
+  }
+
+  public Date getCreatedAt() {
+    return createdAt;
+  }
+
+  public PermissionTemplateUserDto setCreatedAt(Date createdAt) {
+    this.createdAt = createdAt;
+    return this;
+  }
+
+  public Date getUpdatedAt() {
+    return updatedAt;
+  }
+
+  public PermissionTemplateUserDto setUpdatedAt(Date updatedAt) {
+    this.updatedAt = updatedAt;
+    return this;
+  }
+}
diff --git a/sonar-db/src/main/resources/org/sonar/db/permission/PermissionTemplateMapper.xml b/sonar-db/src/main/resources/org/sonar/db/permission/PermissionTemplateMapper.xml
deleted file mode 100644 (file)
index e6f609e..0000000
+++ /dev/null
@@ -1,324 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.db.permission.PermissionTemplateMapper">
-
-  <insert id="insert" parameterType="PermissionTemplate" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    INSERT INTO permission_templates (name, kee, description, key_pattern, created_at, updated_at)
-    VALUES (#{name}, #{kee}, #{description}, #{keyPattern}, #{createdAt}, #{updatedAt})
-  </insert>
-
-  <update id="update" parameterType="PermissionTemplate">
-    UPDATE permission_templates
-    SET name = #{name}, description = #{description}, key_pattern = #{keyPattern}, updated_at = #{updatedAt}
-    WHERE id = #{id}
-  </update>
-
-  <delete id="delete" parameterType="long">
-    DELETE FROM permission_templates
-    WHERE id = #{templateId}
-  </delete>
-
-  <delete id="deleteUserPermissions" parameterType="long">
-    DELETE FROM perm_templates_users
-    WHERE template_id = #{templateId}
-  </delete>
-
-  <delete id="deleteGroupPermissions" parameterType="long">
-    DELETE FROM perm_templates_groups
-    WHERE template_id = #{templateId}
-  </delete>
-
-  <insert id="insertUserPermission" parameterType="PermissionTemplateUser">
-    INSERT INTO perm_templates_users (template_id, user_id, permission_reference, created_at, updated_at)
-    VALUES (#{templateId}, #{userId}, #{permission}, #{createdAt}, #{updatedAt})
-  </insert>
-
-  <delete id="deleteUserPermission" parameterType="PermissionTemplateUser">
-    DELETE FROM perm_templates_users
-    WHERE template_id = #{templateId}
-    AND user_id = #{userId}
-    AND permission_reference = #{permission}
-  </delete>
-
-  <insert id="insertGroupPermission" parameterType="PermissionTemplateGroup">
-    INSERT INTO perm_templates_groups (template_id, group_id, permission_reference, created_at, updated_at)
-    VALUES (#{templateId}, #{groupId}, #{permission}, #{createdAt}, #{updatedAt})
-  </insert>
-
-  <delete id="deleteGroupPermission" parameterType="PermissionTemplateGroup">
-    DELETE FROM perm_templates_groups
-    WHERE template_id = #{templateId}
-    AND permission_reference = #{permission}
-    AND
-    <choose>
-      <when test="groupId != null">
-        group_id = #{groupId}
-      </when>
-      <otherwise>
-        group_id IS NULL
-      </otherwise>
-    </choose>
-  </delete>
-
-  <delete id="deleteByGroupId" parameterType="long">
-    DELETE FROM perm_templates_groups
-    WHERE group_id = #{groupId}
-  </delete>
-
-  <select id="selectUsers" parameterType="map" resultType="UserWithPermission">
-    SELECT u.login as login, u.name as name, u.email, ptu.permission_reference as permission
-    <include refid="usersSelection"/>
-    ORDER BY u.name
-  </select>
-
-  <select id="countUsers" parameterType="map" resultType="int">
-    SELECT count(u.login)
-    <include refid="usersSelection"/>
-  </select>
-
-  <sql id="usersSelection">
-    FROM users u
-    LEFT JOIN perm_templates_users ptu ON ptu.user_id=u.id
-    AND ptu.permission_reference=#{query.permission}
-    AND ptu.template_id=#{templateId}
-    <where>
-      u.active = ${_true}
-      <choose>
-        <when test="query.membership() == 'IN'">
-          AND ptu.permission_reference IS NOT NULL
-        </when>
-        <when test="query.membership() == 'OUT'">
-          AND ptu.permission_reference IS NULL
-        </when>
-      </choose>
-      <if test="query.search() != null">
-        AND (UPPER(u.name) LIKE #{query.searchSql} ESCAPE '/')
-      </if>
-    </where>
-  </sql>
-
-  <select id="selectGroups" parameterType="map" resultType="GroupWithPermission">
-    SELECT name, description, permission FROM
-    (SELECT g.name as name, g.description as description, ptg.permission_reference as permission
-    FROM groups g
-    LEFT JOIN perm_templates_groups ptg ON ptg.group_id=g.id
-    AND ptg.permission_reference=#{query.permission}
-    AND ptg.template_id=#{templateId}
-
-    <if test="!query.permission().equals(projectAdminPermission)">
-    UNION
-    -- Add Anyone group permission
-    SELECT
-      #{anyoneGroup} as name,
-      NULL as description,
-      (select ptg.permission_reference
-      FROM perm_templates_groups ptg
-      <where>
-        AND ptg.permission_reference=#{query.permission}
-        AND ptg.template_id=#{templateId}
-        AND ptg.group_id IS NULL
-      </where>) as permission
-    FROM groups g
-    </if>
-
-    ) groups
-    <where>
-      <if test="query.search() != null">
-        AND (UPPER(groups.name) LIKE #{query.searchSql} ESCAPE '/')
-      </if>
-      <choose>
-        <when test="query.membership() == 'IN'">
-          AND groups.permission IS NOT NULL
-        </when>
-        <when test="query.membership() == 'OUT'">
-          AND groups.permission IS NULL
-        </when>
-      </choose>
-    </where>
-    ORDER BY groups.name
-  </select>
-
-  <select id="countGroups" parameterType="map" resultType="int">
-    SELECT count(1) FROM
-    (SELECT g.name as name, g.description as description, ptg.permission_reference as permission
-    FROM groups g
-    LEFT JOIN perm_templates_groups ptg ON ptg.group_id=g.id
-    AND ptg.permission_reference=#{query.permission}
-    AND ptg.template_id=#{templateId}
-    UNION
-    -- Add Anyone group permission
-    SELECT
-    #{anyoneGroup} as name,
-    NULL as description,
-    (select ptg.permission_reference
-    FROM perm_templates_groups ptg
-    <where>
-      AND ptg.permission_reference=#{query.permission}
-      AND ptg.template_id=#{templateId}
-      AND ptg.group_id IS NULL
-    </where>) as permission
-    FROM groups g
-    ) groups
-    <where>
-      <if test="groupName!=null">
-        AND (UPPER(groups.name) LIKE #{groupName} ESCAPE '/')
-      </if>
-      <if test="query.search() != null">
-        AND (UPPER(groups.name) LIKE #{query.searchSql} ESCAPE '/')
-      </if>
-      <choose>
-        <when test="query.membership() == 'IN'">
-          AND groups.permission IS NOT NULL
-        </when>
-        <when test="query.membership() == 'OUT'">
-          AND groups.permission IS NULL
-        </when>
-      </choose>
-    </where>
-  </select>
-
-  <sql id="templateColumns">
-    id, name, kee, description, key_pattern AS keyPattern, created_at AS createdAt, updated_at AS updatedAt
-  </sql>
-
-  <select id="selectByUuid" parameterType="String" resultType="PermissionTemplate">
-    SELECT
-    <include refid="templateColumns"/>
-    FROM permission_templates
-    WHERE kee=#{uuid}
-  </select>
-
-  <select id="selectAll" parameterType="map" resultType="PermissionTemplate">
-    SELECT
-    <include refid="templateColumns"/>
-    FROM permission_templates
-    <where>
-      <if test="nameMatch!=null">
-        AND (UPPER(name) LIKE #{nameMatch} ESCAPE '/')
-      </if>
-    </where>
-    ORDER BY UPPER(name), name
-  </select>
-
-  <select id="countAll" parameterType="String" resultType="int">
-    SELECT count(1)
-    FROM permission_templates
-    <where>
-      <if test="nameMatch!=null">
-        AND (UPPER(name) LIKE #{nameMatch} ESCAPE '/')
-      </if>
-    </where>
-  </select>
-
-  <select id="selectByName" parameterType="String" resultType="PermissionTemplate">
-    SELECT
-    <include refid="templateColumns"/>
-    FROM permission_templates
-    WHERE UPPER(name)=#{templateName}
-  </select>
-
-  <select id="selectUserPermissionsByTemplateId" parameterType="Long" resultType="PermissionTemplateUser">
-    SELECT
-    ptu.id,
-    ptu.template_id as templateId,
-    ptu.permission_reference AS permission,
-    ptu.user_id AS userId,
-    u.name AS userName,
-    u.login AS userLogin,
-    ptu.created_at AS createdAt,
-    ptu.updated_at AS updatedAt
-    FROM perm_templates_users ptu
-    INNER JOIN users u ON u.id = ptu.user_id AND u.active = ${_true}
-    WHERE ptu.template_id = #{templateId}
-  </select>
-
-  <select id="selectGroupPermissionsByTemplateId" parameterType="Long" resultType="PermissionTemplateGroup">
-    SELECT
-    ptg.id,
-    ptg.template_id as templateId,
-    ptg.permission_reference AS permission,
-    ptg.group_id AS groupId,
-    g.name AS groupName,
-    ptg.created_at as createdAt,
-    ptg.updated_at as updatedAt
-    FROM perm_templates_groups ptg
-    LEFT OUTER JOIN groups g ON g.id=ptg.group_id
-    WHERE ptg.template_id=#{templateId}
-    AND (g.name IS NOT NULL OR ptg.group_id IS NULL)
-  </select>
-
-  <select id="selectPotentialPermissionsByUserIdAndTemplateId" parameterType="map" resultType="String">
-    <if test="userId!=null">
-      -- from template users
-      select ptu.permission_reference as permission_key
-      from perm_templates_users ptu
-      <where>
-        and ptu.user_id=#{userId}
-        and ptu.template_id=#{templateId}
-      </where>
-      UNION
-      -- from template groups except anyone group
-      select ptg.permission_reference as permission_key
-      from perm_templates_groups ptg
-      inner join groups_users gu on ptg.group_id = gu.group_id
-      <where>
-        and gu.user_id=#{userId}
-        and ptg.template_id=#{templateId}
-      </where>
-      UNION
-      -- from template characteristics
-      select ptc.permission_key as permission_key
-      from perm_tpl_characteristics ptc
-      <where>
-        and with_project_creator = ${_true}
-        and ptc.template_id = #{templateId}
-      </where>
-      UNION
-    </if>
-    -- from anyone group
-    select ptg.permission_reference as permission_key
-    from perm_templates_groups ptg
-    where ptg.template_id=#{templateId}
-    and ptg.group_id IS NULL
-  </select>
-
-  <select id="usersCountByTemplateIdAndPermission" parameterType="map"
-          resultType="org.sonar.db.permission.CountByTemplateAndPermissionDto">
-    SELECT ptu.template_id as templateId, ptu.permission_reference as permission, count(u.login) as count
-    FROM users u
-    INNER JOIN perm_templates_users ptu ON ptu.user_id=u.id
-    AND ptu.template_id in
-    <foreach collection="templateIds" open="(" close=")" item="id" separator=",">
-      #{id}
-    </foreach>
-    <where>
-      AND u.active = ${_true}
-    </where>
-    GROUP BY ptu.template_id, ptu.permission_reference
-  </select>
-
-  <select id="groupsCountByTemplateIdAndPermission" parameterType="map"
-          resultType="org.sonar.db.permission.CountByTemplateAndPermissionDto">
-    SELECT count(1) as count, permission, templateId
-    FROM
-    (SELECT g.name as name, ptg.permission_reference as permission, ptg.template_id as templateId
-    FROM groups g
-    INNER JOIN perm_templates_groups ptg ON ptg.group_id=g.id
-    UNION
-    -- Add Anyone group permission
-    SELECT #{anyoneGroup} as name, ptg.permission_reference as permission, ptg.template_id as templateId
-    FROM perm_templates_groups ptg
-    <where>
-      AND ptg.group_id IS NULL
-    </where>
-    ) groups
-    <where>
-      AND groups.templateId in
-      <foreach collection="templateIds" open="(" close=")" item="id" separator=",">
-        #{id}
-      </foreach>
-    </where>
-    GROUP BY groups.permission, groups.templateId
-  </select>
-</mapper>
diff --git a/sonar-db/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml b/sonar-db/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml
new file mode 100644 (file)
index 0000000..23e4904
--- /dev/null
@@ -0,0 +1,324 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.db.permission.template.PermissionTemplateMapper">
+
+  <insert id="insert" parameterType="PermissionTemplate" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+    INSERT INTO permission_templates (name, kee, description, key_pattern, created_at, updated_at)
+    VALUES (#{name}, #{kee}, #{description}, #{keyPattern}, #{createdAt}, #{updatedAt})
+  </insert>
+
+  <update id="update" parameterType="PermissionTemplate">
+    UPDATE permission_templates
+    SET name = #{name}, description = #{description}, key_pattern = #{keyPattern}, updated_at = #{updatedAt}
+    WHERE id = #{id}
+  </update>
+
+  <delete id="delete" parameterType="long">
+    DELETE FROM permission_templates
+    WHERE id = #{templateId}
+  </delete>
+
+  <delete id="deleteUserPermissions" parameterType="long">
+    DELETE FROM perm_templates_users
+    WHERE template_id = #{templateId}
+  </delete>
+
+  <delete id="deleteGroupPermissions" parameterType="long">
+    DELETE FROM perm_templates_groups
+    WHERE template_id = #{templateId}
+  </delete>
+
+  <insert id="insertUserPermission" parameterType="PermissionTemplateUser">
+    INSERT INTO perm_templates_users (template_id, user_id, permission_reference, created_at, updated_at)
+    VALUES (#{templateId}, #{userId}, #{permission}, #{createdAt}, #{updatedAt})
+  </insert>
+
+  <delete id="deleteUserPermission" parameterType="PermissionTemplateUser">
+    DELETE FROM perm_templates_users
+    WHERE template_id = #{templateId}
+    AND user_id = #{userId}
+    AND permission_reference = #{permission}
+  </delete>
+
+  <insert id="insertGroupPermission" parameterType="PermissionTemplateGroup">
+    INSERT INTO perm_templates_groups (template_id, group_id, permission_reference, created_at, updated_at)
+    VALUES (#{templateId}, #{groupId}, #{permission}, #{createdAt}, #{updatedAt})
+  </insert>
+
+  <delete id="deleteGroupPermission" parameterType="PermissionTemplateGroup">
+    DELETE FROM perm_templates_groups
+    WHERE template_id = #{templateId}
+    AND permission_reference = #{permission}
+    AND
+    <choose>
+      <when test="groupId != null">
+        group_id = #{groupId}
+      </when>
+      <otherwise>
+        group_id IS NULL
+      </otherwise>
+    </choose>
+  </delete>
+
+  <delete id="deleteByGroupId" parameterType="long">
+    DELETE FROM perm_templates_groups
+    WHERE group_id = #{groupId}
+  </delete>
+
+  <select id="selectUsers" parameterType="map" resultType="UserWithPermission">
+    SELECT u.login as login, u.name as name, u.email, ptu.permission_reference as permission
+    <include refid="usersSelection"/>
+    ORDER BY u.name
+  </select>
+
+  <select id="countUsers" parameterType="map" resultType="int">
+    SELECT count(u.login)
+    <include refid="usersSelection"/>
+  </select>
+
+  <sql id="usersSelection">
+    FROM users u
+    LEFT JOIN perm_templates_users ptu ON ptu.user_id=u.id
+    AND ptu.permission_reference=#{query.permission}
+    AND ptu.template_id=#{templateId}
+    <where>
+      u.active = ${_true}
+      <choose>
+        <when test="query.membership() == 'IN'">
+          AND ptu.permission_reference IS NOT NULL
+        </when>
+        <when test="query.membership() == 'OUT'">
+          AND ptu.permission_reference IS NULL
+        </when>
+      </choose>
+      <if test="query.search() != null">
+        AND (UPPER(u.name) LIKE #{query.searchSql} ESCAPE '/')
+      </if>
+    </where>
+  </sql>
+
+  <select id="selectGroups" parameterType="map" resultType="GroupWithPermission">
+    SELECT name, description, permission FROM
+    (SELECT g.name as name, g.description as description, ptg.permission_reference as permission
+    FROM groups g
+    LEFT JOIN perm_templates_groups ptg ON ptg.group_id=g.id
+    AND ptg.permission_reference=#{query.permission}
+    AND ptg.template_id=#{templateId}
+
+    <if test="!query.permission().equals(projectAdminPermission)">
+    UNION
+    -- Add Anyone group permission
+    SELECT
+      #{anyoneGroup} as name,
+      NULL as description,
+      (select ptg.permission_reference
+      FROM perm_templates_groups ptg
+      <where>
+        AND ptg.permission_reference=#{query.permission}
+        AND ptg.template_id=#{templateId}
+        AND ptg.group_id IS NULL
+      </where>) as permission
+    FROM groups g
+    </if>
+
+    ) groups
+    <where>
+      <if test="query.search() != null">
+        AND (UPPER(groups.name) LIKE #{query.searchSql} ESCAPE '/')
+      </if>
+      <choose>
+        <when test="query.membership() == 'IN'">
+          AND groups.permission IS NOT NULL
+        </when>
+        <when test="query.membership() == 'OUT'">
+          AND groups.permission IS NULL
+        </when>
+      </choose>
+    </where>
+    ORDER BY groups.name
+  </select>
+
+  <select id="countGroups" parameterType="map" resultType="int">
+    SELECT count(1) FROM
+    (SELECT g.name as name, g.description as description, ptg.permission_reference as permission
+    FROM groups g
+    LEFT JOIN perm_templates_groups ptg ON ptg.group_id=g.id
+    AND ptg.permission_reference=#{query.permission}
+    AND ptg.template_id=#{templateId}
+    UNION
+    -- Add Anyone group permission
+    SELECT
+    #{anyoneGroup} as name,
+    NULL as description,
+    (select ptg.permission_reference
+    FROM perm_templates_groups ptg
+    <where>
+      AND ptg.permission_reference=#{query.permission}
+      AND ptg.template_id=#{templateId}
+      AND ptg.group_id IS NULL
+    </where>) as permission
+    FROM groups g
+    ) groups
+    <where>
+      <if test="groupName!=null">
+        AND (UPPER(groups.name) LIKE #{groupName} ESCAPE '/')
+      </if>
+      <if test="query.search() != null">
+        AND (UPPER(groups.name) LIKE #{query.searchSql} ESCAPE '/')
+      </if>
+      <choose>
+        <when test="query.membership() == 'IN'">
+          AND groups.permission IS NOT NULL
+        </when>
+        <when test="query.membership() == 'OUT'">
+          AND groups.permission IS NULL
+        </when>
+      </choose>
+    </where>
+  </select>
+
+  <sql id="templateColumns">
+    id, name, kee, description, key_pattern AS keyPattern, created_at AS createdAt, updated_at AS updatedAt
+  </sql>
+
+  <select id="selectByUuid" parameterType="String" resultType="PermissionTemplate">
+    SELECT
+    <include refid="templateColumns"/>
+    FROM permission_templates
+    WHERE kee=#{uuid}
+  </select>
+
+  <select id="selectAll" parameterType="map" resultType="PermissionTemplate">
+    SELECT
+    <include refid="templateColumns"/>
+    FROM permission_templates
+    <where>
+      <if test="nameMatch!=null">
+        AND (UPPER(name) LIKE #{nameMatch} ESCAPE '/')
+      </if>
+    </where>
+    ORDER BY UPPER(name), name
+  </select>
+
+  <select id="countAll" parameterType="String" resultType="int">
+    SELECT count(1)
+    FROM permission_templates
+    <where>
+      <if test="nameMatch!=null">
+        AND (UPPER(name) LIKE #{nameMatch} ESCAPE '/')
+      </if>
+    </where>
+  </select>
+
+  <select id="selectByName" parameterType="String" resultType="PermissionTemplate">
+    SELECT
+    <include refid="templateColumns"/>
+    FROM permission_templates
+    WHERE UPPER(name)=#{templateName}
+  </select>
+
+  <select id="selectUserPermissionsByTemplateId" parameterType="Long" resultType="PermissionTemplateUser">
+    SELECT
+    ptu.id,
+    ptu.template_id as templateId,
+    ptu.permission_reference AS permission,
+    ptu.user_id AS userId,
+    u.name AS userName,
+    u.login AS userLogin,
+    ptu.created_at AS createdAt,
+    ptu.updated_at AS updatedAt
+    FROM perm_templates_users ptu
+    INNER JOIN users u ON u.id = ptu.user_id AND u.active = ${_true}
+    WHERE ptu.template_id = #{templateId}
+  </select>
+
+  <select id="selectGroupPermissionsByTemplateId" parameterType="Long" resultType="PermissionTemplateGroup">
+    SELECT
+    ptg.id,
+    ptg.template_id as templateId,
+    ptg.permission_reference AS permission,
+    ptg.group_id AS groupId,
+    g.name AS groupName,
+    ptg.created_at as createdAt,
+    ptg.updated_at as updatedAt
+    FROM perm_templates_groups ptg
+    LEFT OUTER JOIN groups g ON g.id=ptg.group_id
+    WHERE ptg.template_id=#{templateId}
+    AND (g.name IS NOT NULL OR ptg.group_id IS NULL)
+  </select>
+
+  <select id="selectPotentialPermissionsByUserIdAndTemplateId" parameterType="map" resultType="String">
+    <if test="userId!=null">
+      -- from template users
+      select ptu.permission_reference as permission_key
+      from perm_templates_users ptu
+      <where>
+        and ptu.user_id=#{userId}
+        and ptu.template_id=#{templateId}
+      </where>
+      UNION
+      -- from template groups except anyone group
+      select ptg.permission_reference as permission_key
+      from perm_templates_groups ptg
+      inner join groups_users gu on ptg.group_id = gu.group_id
+      <where>
+        and gu.user_id=#{userId}
+        and ptg.template_id=#{templateId}
+      </where>
+      UNION
+      -- from template characteristics
+      select ptc.permission_key as permission_key
+      from perm_tpl_characteristics ptc
+      <where>
+        and with_project_creator = ${_true}
+        and ptc.template_id = #{templateId}
+      </where>
+      UNION
+    </if>
+    -- from anyone group
+    select ptg.permission_reference as permission_key
+    from perm_templates_groups ptg
+    where ptg.template_id=#{templateId}
+    and ptg.group_id IS NULL
+  </select>
+
+  <select id="usersCountByTemplateIdAndPermission" parameterType="map"
+          resultType="org.sonar.db.permission.template.CountByTemplateAndPermissionDto">
+    SELECT ptu.template_id as templateId, ptu.permission_reference as permission, count(u.login) as count
+    FROM users u
+    INNER JOIN perm_templates_users ptu ON ptu.user_id=u.id
+    AND ptu.template_id in
+    <foreach collection="templateIds" open="(" close=")" item="id" separator=",">
+      #{id}
+    </foreach>
+    <where>
+      AND u.active = ${_true}
+    </where>
+    GROUP BY ptu.template_id, ptu.permission_reference
+  </select>
+
+  <select id="groupsCountByTemplateIdAndPermission" parameterType="map"
+          resultType="org.sonar.db.permission.template.CountByTemplateAndPermissionDto">
+    SELECT count(1) as count, permission, templateId
+    FROM
+    (SELECT g.name as name, ptg.permission_reference as permission, ptg.template_id as templateId
+    FROM groups g
+    INNER JOIN perm_templates_groups ptg ON ptg.group_id=g.id
+    UNION
+    -- Add Anyone group permission
+    SELECT #{anyoneGroup} as name, ptg.permission_reference as permission, ptg.template_id as templateId
+    FROM perm_templates_groups ptg
+    <where>
+      AND ptg.group_id IS NULL
+    </where>
+    ) groups
+    <where>
+      AND groups.templateId in
+      <foreach collection="templateIds" open="(" close=")" item="id" separator=",">
+        #{id}
+      </foreach>
+    </where>
+    GROUP BY groups.permission, groups.templateId
+  </select>
+</mapper>
diff --git a/sonar-db/src/test/java/org/sonar/db/permission/GroupWithPermissionTemplateDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/GroupWithPermissionTemplateDaoTest.java
deleted file mode 100644 (file)
index 25fd9d7..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.permission;
-
-import java.util.List;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.api.web.UserRole;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-
-public class GroupWithPermissionTemplateDaoTest {
-
-  private static final long TEMPLATE_ID = 50L;
-
-  @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
-  DbSession session = dbTester.getSession();
-
-  PermissionTemplateDao underTest = dbTester.getDbClient().permissionTemplateDao();
-
-  @Test
-  public void select_groups() {
-    dbTester.prepareDbUnit(getClass(), "groups_with_permissions.xml");
-
-    OldPermissionQuery query = OldPermissionQuery.builder().permission("user").build();
-    List<GroupWithPermissionDto> result = underTest.selectGroups(session, query, TEMPLATE_ID);
-    int count = underTest.countGroups(session, query, TEMPLATE_ID);
-
-    assertThat(result).hasSize(4);
-    assertThat(count).isEqualTo(4);
-
-    GroupWithPermissionDto anyone = result.get(0);
-    assertThat(anyone.getName()).isEqualTo("Anyone");
-    assertThat(anyone.getDescription()).isNull();
-    assertThat(anyone.getPermission()).isNotNull();
-
-    GroupWithPermissionDto group1 = result.get(1);
-    assertThat(group1.getName()).isEqualTo("sonar-administrators");
-    assertThat(group1.getDescription()).isEqualTo("System administrators");
-    assertThat(group1.getPermission()).isNotNull();
-
-    GroupWithPermissionDto group2 = result.get(2);
-    assertThat(group2.getName()).isEqualTo("sonar-reviewers");
-    assertThat(group2.getDescription()).isEqualTo("Reviewers");
-    assertThat(group2.getPermission()).isNull();
-
-    GroupWithPermissionDto group3 = result.get(3);
-    assertThat(group3.getName()).isEqualTo("sonar-users");
-    assertThat(group3.getDescription()).isEqualTo("Any new users created will automatically join this group");
-    assertThat(group3.getPermission()).isNotNull();
-  }
-
-  @Test
-  public void anyone_group_is_returned_when_it_has_no_permission() {
-    dbTester.prepareDbUnit(getClass(), "groups_with_permissions.xml");
-
-    // Anyone group is returned even if it doesn't have the permission
-    OldPermissionQuery query = OldPermissionQuery.builder().permission(UserRole.USER).build();
-    List<GroupWithPermissionDto> result = underTest.selectGroups(session, query, TEMPLATE_ID);
-    assertThat(result).hasSize(4);
-
-    GroupWithPermissionDto group1 = result.get(1);
-    assertThat(group1.getName()).isEqualTo("sonar-administrators");
-    assertThat(group1.getPermission()).isNotNull();
-
-    GroupWithPermissionDto group2 = result.get(2);
-    assertThat(group2.getName()).isEqualTo("sonar-reviewers");
-    assertThat(group2.getPermission()).isNull();
-
-    GroupWithPermissionDto group3 = result.get(3);
-    assertThat(group3.getName()).isEqualTo("sonar-users");
-    assertThat(group3.getPermission()).isNotNull();
-  }
-
-  @Test
-  public void search_by_groups_name() {
-    dbTester.prepareDbUnit(getClass(), "groups_with_permissions.xml");
-
-    List<GroupWithPermissionDto> result = underTest.selectGroups(session, OldPermissionQuery.builder().permission("user").search("aDMini").build(), TEMPLATE_ID);
-    assertThat(result).hasSize(1);
-    assertThat(result.get(0).getName()).isEqualTo("sonar-administrators");
-
-    result = underTest.selectGroups(session, OldPermissionQuery.builder().permission("user").search("sonar").build(), TEMPLATE_ID);
-    assertThat(result).hasSize(3);
-  }
-
-  @Test
-  public void search_groups_should_be_sorted_by_group_name() {
-    dbTester.prepareDbUnit(getClass(), "groups_with_permissions_should_be_sorted_by_group_name.xml");
-
-    List<GroupWithPermissionDto> result = underTest.selectGroups(session, OldPermissionQuery.builder().permission("user").build(), TEMPLATE_ID);
-    assertThat(result).hasSize(4);
-    assertThat(result.get(0).getName()).isEqualTo("Anyone");
-    assertThat(result.get(1).getName()).isEqualTo("sonar-administrators");
-    assertThat(result.get(2).getName()).isEqualTo("sonar-reviewers");
-    assertThat(result.get(3).getName()).isEqualTo("sonar-users");
-  }
-
-}
index 1a1b37cd1cadb9d6746b9cdf50d4313b7fdf4195..f6f1e415f3707a75eb7288f523bc49d700b51d67 100644 (file)
@@ -32,6 +32,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.permission.template.PermissionTemplateDbTester;
+import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.user.GroupDbTester;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.RoleDao;
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
deleted file mode 100644 (file)
index 82e9630..0000000
+++ /dev/null
@@ -1,398 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.permission;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import org.apache.ibatis.session.ResultContext;
-import org.apache.ibatis.session.ResultHandler;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.utils.System2;
-import org.sonar.api.web.UserRole;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.permission.template.PermissionTemplateCharacteristicDto;
-import org.sonar.db.permission.template.PermissionTemplateDbTester;
-import org.sonar.db.user.GroupDbTester;
-import org.sonar.db.user.GroupDto;
-import org.sonar.db.user.UserDbTester;
-import org.sonar.db.user.UserDto;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.tuple;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.sonar.api.web.UserRole.ADMIN;
-import static org.sonar.api.web.UserRole.CODEVIEWER;
-import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
-import static org.sonar.api.web.UserRole.USER;
-import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
-import static org.sonar.db.user.GroupTesting.newGroupDto;
-import static org.sonar.db.user.UserTesting.newUserDto;
-
-public class PermissionTemplateDaoTest {
-
-  System2 system = mock(System2.class);
-
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-  @Rule
-  public DbTester db = DbTester.create(system);
-  DbClient dbClient = db.getDbClient();
-  DbSession dbSession = db.getSession();
-  GroupDbTester groupDb = new GroupDbTester(db);
-  UserDbTester userDb = new UserDbTester(db);
-  PermissionTemplateDbTester templateDb = new PermissionTemplateDbTester(db);
-
-  PermissionTemplateDao underTest = new PermissionTemplateDao(db.myBatis(), system);
-
-  @Test
-  public void should_create_permission_template() throws ParseException {
-    db.prepareDbUnit(getClass(), "createPermissionTemplate.xml");
-
-    Date now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2013-01-02 01:04:05");
-    when(system.now()).thenReturn(now.getTime());
-
-    PermissionTemplateDto permissionTemplate = underTest.insert(db.getSession(), newPermissionTemplateDto()
-      .setName("my template")
-      .setDescription("my description")
-      .setKeyPattern("myregexp"));
-    assertThat(permissionTemplate).isNotNull();
-    assertThat(permissionTemplate.getId()).isEqualTo(1L);
-
-    db.assertDbUnitTable(getClass(), "createPermissionTemplate-result.xml", "permission_templates", "id", "name", "description");
-  }
-
-  @Test
-  public void should_select_permission_template() {
-    db.prepareDbUnit(getClass(), "selectPermissionTemplate.xml");
-
-    PermissionTemplate result = underTest.selectByUuidWithUserAndGroupPermissions("my_template_20130102_030405");
-
-    assertThat(result).isNotNull();
-    PermissionTemplateDto template = result.getTemplate();
-    assertThat(template.getName()).isEqualTo("my template");
-    assertThat(template.getUuid()).isEqualTo("my_template_20130102_030405");
-    assertThat(template.getDescription()).isEqualTo("my description");
-    List<PermissionTemplateUserDto> usersPermissions = result.getUserPermissions();
-    assertThat(usersPermissions).hasSize(3);
-    assertThat(usersPermissions).extracting("userId").containsOnly(1L, 2L, 1L);
-    assertThat(usersPermissions).extracting("userLogin").containsOnly("login1", "login2", "login2");
-    assertThat(usersPermissions).extracting("userName").containsOnly("user1", "user2", "user2");
-    assertThat(usersPermissions).extracting("permission").containsOnly("user_permission1", "user_permission1", "user_permission2");
-    List<PermissionTemplateGroupDto> groupsPermissions = result.getGroupPermissions();
-    assertThat(groupsPermissions).hasSize(3);
-    assertThat(groupsPermissions).extracting("groupId").containsOnly(1L, 2L, null);
-    assertThat(groupsPermissions).extracting("groupName").containsOnly("group1", "group2", null);
-    assertThat(groupsPermissions).extracting("permission").containsOnly("group_permission1", "group_permission1", "group_permission2");
-  }
-
-  @Test
-  public void should_select_permission_template_by_key() {
-    db.prepareDbUnit(getClass(), "selectPermissionTemplate.xml");
-
-    PermissionTemplateDto permissionTemplate = underTest.selectByUuid("my_template_20130102_030405");
-
-    assertThat(permissionTemplate).isNotNull();
-    assertThat(permissionTemplate.getId()).isEqualTo(1L);
-    assertThat(permissionTemplate.getName()).isEqualTo("my template");
-    assertThat(permissionTemplate.getUuid()).isEqualTo("my_template_20130102_030405");
-    assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
-  }
-
-  @Test
-  public void should_select_all_permission_templates() {
-    db.prepareDbUnit(getClass(), "selectAllPermissionTemplates.xml");
-    commit();
-
-    List<PermissionTemplateDto> permissionTemplates = underTest.selectAll();
-
-    assertThat(permissionTemplates).hasSize(3);
-    assertThat(permissionTemplates).extracting("id").containsOnly(1L, 2L, 3L);
-    assertThat(permissionTemplates).extracting("name").containsOnly("template1", "template2", "template3");
-    assertThat(permissionTemplates).extracting("kee").containsOnly("template1_20130102_030405", "template2_20130102_030405", "template3_20130102_030405");
-    assertThat(permissionTemplates).extracting("description").containsOnly("description1", "description2", "description3");
-  }
-
-  @Test
-  public void should_update_permission_template() {
-    db.prepareDbUnit(getClass(), "updatePermissionTemplate.xml");
-
-    underTest.update(1L, "new_name", "new_description", "new_regexp");
-
-    db.assertDbUnitTable(getClass(), "updatePermissionTemplate-result.xml", "permission_templates", "id", "name", "kee", "description");
-  }
-
-  @Test
-  public void should_delete_permission_template() {
-    db.prepareDbUnit(getClass(), "deletePermissionTemplate.xml");
-
-    underTest.deleteById(dbSession, 1L);
-    dbSession.commit();
-
-    checkTemplateTables("deletePermissionTemplate-result.xml");
-    db.assertDbUnitTable(getClass(), "deletePermissionTemplate-result.xml", "perm_tpl_characteristics");
-  }
-
-  @Test
-  public void should_add_user_permission_to_template() {
-    db.prepareDbUnit(getClass(), "addUserPermissionToTemplate.xml");
-
-    underTest.insertUserPermission(1L, 1L, "new_permission");
-
-    checkTemplateTables("addUserPermissionToTemplate-result.xml");
-  }
-
-  @Test
-  public void should_remove_user_permission_from_template() {
-    db.prepareDbUnit(getClass(), "removeUserPermissionFromTemplate.xml");
-
-    underTest.deleteUserPermission(1L, 2L, "permission_to_remove");
-
-    checkTemplateTables("removeUserPermissionFromTemplate-result.xml");
-  }
-
-  @Test
-  public void should_add_group_permission_to_template() {
-    db.prepareDbUnit(getClass(), "addGroupPermissionToTemplate.xml");
-
-    underTest.insertGroupPermission(1L, 1L, "new_permission");
-
-    checkTemplateTables("addGroupPermissionToTemplate-result.xml");
-  }
-
-  @Test
-  public void should_remove_group_permission_from_template() {
-    db.prepareDbUnit(getClass(), "removeGroupPermissionFromTemplate.xml");
-
-    underTest.deleteGroupPermission(1L, 2L, "permission_to_remove");
-
-    checkTemplateTables("removeGroupPermissionFromTemplate-result.xml");
-  }
-
-  @Test
-  public void remove_by_group() {
-    db.prepareDbUnit(getClass(), "remove_by_group.xml");
-
-    underTest.deleteByGroup(db.getSession(), 2L);
-    db.getSession().commit();
-
-    db.assertDbUnitTable(getClass(), "remove_by_group-result.xml", "permission_templates", "id", "name", "kee", "description");
-  }
-
-  @Test
-  public void should_add_group_permission_with_null_name() {
-    db.prepareDbUnit(getClass(), "addNullGroupPermissionToTemplate.xml");
-
-    underTest.insertGroupPermission(1L, null, "new_permission");
-
-    checkTemplateTables("addNullGroupPermissionToTemplate-result.xml");
-  }
-
-  @Test
-  public void should_remove_group_permission_with_null_name() {
-    db.prepareDbUnit(getClass(), "removeNullGroupPermissionFromTemplate.xml");
-
-    underTest.deleteGroupPermission(1L, null, "permission_to_remove");
-
-    checkTemplateTables("removeNullGroupPermissionFromTemplate-result.xml");
-  }
-
-  @Test
-  public void new_permission_template_with_empty_user_group_characteristics() {
-    PermissionTemplateDto template = underTest.insert(dbSession, newPermissionTemplateDto().setUuid("TEMPLATE_UUID"));
-
-    PermissionTemplate result = underTest.selectByUuidWithUserAndGroupPermissions(dbSession, "TEMPLATE_UUID");
-
-    assertThat(result.getTemplate())
-      .extracting(PermissionTemplateDto::getId, PermissionTemplateDto::getUuid, PermissionTemplateDto::getName, PermissionTemplateDto::getDescription)
-      .containsExactly(template.getId(), template.getUuid(), template.getName(), template.getDescription());
-
-    assertThat(result.getUserPermissions()).isEmpty();
-    assertThat(result.getGroupPermissions()).isEmpty();
-    assertThat(result.getCharacteristics()).isEmpty();
-  }
-
-  @Test
-  public void unknown_permission_template() {
-    PermissionTemplate result = underTest.selectByUuidWithUserAndGroupPermissions(dbSession, "UNKNOWN_TEMPLATE_UUID");
-
-    assertThat(result).isNull();
-  }
-
-  @Test
-  public void permission_template_with_user_group_and_characteristics() {
-    PermissionTemplateDto template = dbClient.permissionTemplateDao().insert(dbSession, newPermissionTemplateDto().setUuid("TEMPLATE_UUID"));
-    GroupDto group = groupDb.insertGroup(newGroupDto());
-    UserDto user = userDb.insertUser(newUserDto());
-    templateDb.addGroupToTemplate(template.getId(), group.getId(), UserRole.ADMIN);
-    templateDb.addUserToTemplate(template.getId(), user.getId(), UserRole.CODEVIEWER);
-    templateDb.addProjectCreatorToTemplate(template.getId(), UserRole.USER);
-
-    PermissionTemplate result = underTest.selectByUuidWithUserAndGroupPermissions(dbSession, "TEMPLATE_UUID");
-    assertThat(result.getTemplate())
-      .extracting(PermissionTemplateDto::getId, PermissionTemplateDto::getUuid, PermissionTemplateDto::getName, PermissionTemplateDto::getDescription)
-      .containsExactly(template.getId(), template.getUuid(), template.getName(), template.getDescription());
-    assertThat(result.getCharacteristics()).hasSize(1)
-      .extracting(PermissionTemplateCharacteristicDto::getPermission, PermissionTemplateCharacteristicDto::getWithProjectCreator)
-      .containsExactly(tuple(UserRole.USER, true));
-    assertThat(result.getGroupPermissions()).hasSize(1)
-      .extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission)
-      .containsExactly(tuple(group.getId(), group.getName(), UserRole.ADMIN));
-    assertThat(result.getUserPermissions()).hasSize(1)
-      .extracting(PermissionTemplateUserDto::getUserId, PermissionTemplateUserDto::getUserLogin, PermissionTemplateUserDto::getPermission)
-      .containsExactly(tuple(user.getId(), user.getLogin(), UserRole.CODEVIEWER));
-  }
-
-  @Test
-  public void should_fail_on_unmatched_template() {
-    expectedException.expect(IllegalArgumentException.class);
-
-    underTest.selectPermissionTemplateWithPermissions(db.getSession(), "unmatched");
-  }
-
-  @Test
-  public void group_count_by_template_and_permission() {
-    PermissionTemplateDto template1 = templateDb.insertTemplate();
-    PermissionTemplateDto template2 = templateDb.insertTemplate();
-    PermissionTemplateDto template3 = templateDb.insertTemplate();
-
-    GroupDto group1 = groupDb.insertGroup();
-    GroupDto group2 = groupDb.insertGroup();
-    GroupDto group3 = groupDb.insertGroup();
-
-    templateDb.addGroupToTemplate(42L, group1.getId(), ISSUE_ADMIN);
-    templateDb.addGroupToTemplate(template1.getId(), group1.getId(), CODEVIEWER);
-    templateDb.addGroupToTemplate(template1.getId(), group2.getId(), CODEVIEWER);
-    templateDb.addGroupToTemplate(template1.getId(), group3.getId(), CODEVIEWER);
-    templateDb.addGroupToTemplate(template1.getId(), null, CODEVIEWER);
-    templateDb.addGroupToTemplate(template1.getId(), group1.getId(), ADMIN);
-    templateDb.addGroupToTemplate(template2.getId(), group1.getId(), ADMIN);
-
-    final List<CountByTemplateAndPermissionDto> result = new ArrayList<>();
-    underTest.groupsCountByTemplateIdAndPermission(dbSession, Arrays.asList(template1.getId(), template2.getId(), template3.getId()), new ResultHandler() {
-      @Override
-      public void handleResult(ResultContext context) {
-        result.add((CountByTemplateAndPermissionDto) context.getResultObject());
-      }
-    });
-
-    assertThat(result).hasSize(3);
-    assertThat(result).extracting("permission").containsOnly(ADMIN, CODEVIEWER);
-    assertThat(result).extracting("templateId").containsOnly(template1.getId(), template2.getId());
-    assertThat(result).extracting("count").containsOnly(4, 1);
-  }
-
-  @Test
-  public void user_count_by_template_and_permission() {
-    PermissionTemplateDto template1 = templateDb.insertTemplate();
-    PermissionTemplateDto template2 = templateDb.insertTemplate();
-    PermissionTemplateDto template3 = templateDb.insertTemplate();
-
-    UserDto user1 = userDb.insertUser();
-    UserDto user2 = userDb.insertUser();
-    UserDto user3 = userDb.insertUser();
-
-    templateDb.addUserToTemplate(42L, user1.getId(), ISSUE_ADMIN);
-    templateDb.addUserToTemplate(template1.getId(), user1.getId(), ADMIN);
-    templateDb.addUserToTemplate(template1.getId(), user2.getId(), ADMIN);
-    templateDb.addUserToTemplate(template1.getId(), user3.getId(), ADMIN);
-    templateDb.addUserToTemplate(template1.getId(), user1.getId(), USER);
-    templateDb.addUserToTemplate(template2.getId(), user1.getId(), USER);
-
-    final List<CountByTemplateAndPermissionDto> result = new ArrayList<>();
-    underTest.usersCountByTemplateIdAndPermission(dbSession, Arrays.asList(template1.getId(), template2.getId(), template3.getId()),
-      context -> result.add((CountByTemplateAndPermissionDto) context.getResultObject()));
-    assertThat(result).hasSize(3);
-    assertThat(result).extracting("permission").containsOnly(ADMIN, USER);
-    assertThat(result).extracting("templateId").containsOnly(template1.getId(), template2.getId());
-    assertThat(result).extracting("count").containsOnly(3, 1);
-  }
-
-  @Test
-  public void select_by_name_query_and_pagination() {
-    templateDb.insertTemplate(newPermissionTemplateDto().setName("aaabbb"));
-    templateDb.insertTemplate(newPermissionTemplateDto().setName("aaaccc"));
-
-    List<PermissionTemplateDto> templates = underTest.selectAll(dbSession, "aaa");
-    int count = underTest.countAll(dbSession, "aaa");
-
-    assertThat(templates.get(0).getName()).isEqualTo("aaabbb");
-    assertThat(count).isEqualTo(2);
-  }
-
-  @Test
-  public void selectPotentialPermissions_with_unknown_template_and_no_user() {
-    List<String> result = underTest.selectPotentialPermissionsByUserIdAndTemplateId(dbSession, null, 42L);
-
-    assertThat(result).isEmpty();
-  }
-
-  @Test
-  public void selectPotentialPermissions_with_empty_template_and_new_user() {
-    UserDto user = userDb.insertUser();
-    PermissionTemplateDto template = templateDb.insertTemplate();
-
-    List<String> result = underTest.selectPotentialPermissionsByUserIdAndTemplateId(dbSession, user.getId(), template.getId());
-
-    assertThat(result).isEmpty();
-  }
-
-  @Test
-  public void selectPotentialPermission_with_template_users_groups_and_project_creator() {
-    UserDto user = userDb.insertUser();
-    GroupDto group = groupDb.insertGroup();
-    groupDb.addUserToGroup(user.getId(), group.getId());
-    PermissionTemplateDto template = templateDb.insertTemplate();
-    templateDb.addProjectCreatorToTemplate(template.getId(), SCAN_EXECUTION);
-    templateDb.addProjectCreatorToTemplate(template.getId(), UserRole.ADMIN);
-    templateDb.addUserToTemplate(template.getId(), user.getId(), UserRole.USER);
-    templateDb.addUserToTemplate(template.getId(), user.getId(), UserRole.ADMIN);
-    templateDb.addGroupToTemplate(template.getId(), group.getId(), UserRole.CODEVIEWER);
-    templateDb.addGroupToTemplate(template.getId(), group.getId(), UserRole.ADMIN);
-    templateDb.addGroupToTemplate(template.getId(), null, UserRole.ISSUE_ADMIN);
-
-    List<String> resultWithUser = underTest.selectPotentialPermissionsByUserIdAndTemplateId(dbSession, user.getId(), template.getId());
-    List<String> resultWithoutUser = underTest.selectPotentialPermissionsByUserIdAndTemplateId(dbSession, null, template.getId());
-
-    assertThat(resultWithUser).containsOnlyOnce(SCAN_EXECUTION, UserRole.ADMIN, UserRole.USER, UserRole.CODEVIEWER, UserRole.ISSUE_ADMIN);
-    // only permission from anyone group
-    assertThat(resultWithoutUser).containsOnly(UserRole.ISSUE_ADMIN);
-  }
-
-  private void commit() {
-    dbSession.commit();
-  }
-
-  private void checkTemplateTables(String fileName) {
-    db.assertDbUnitTable(getClass(), fileName, "permission_templates", "id", "name", "description");
-    db.assertDbUnitTable(getClass(), fileName, "perm_templates_users", "id", "template_id", "user_id", "permission_reference");
-    db.assertDbUnitTable(getClass(), fileName, "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
-  }
-
-}
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
deleted file mode 100644 (file)
index 06167ff..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.permission;
-
-import java.util.Date;
-import org.apache.commons.lang.math.RandomUtils;
-import org.sonar.core.permission.ProjectPermissions;
-import org.sonar.core.util.Uuids;
-import org.sonar.db.permission.template.PermissionTemplateCharacteristicDto;
-
-import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
-import static org.apache.commons.lang.RandomStringUtils.randomAscii;
-
-public class PermissionTemplateTesting {
-  public static PermissionTemplateDto newPermissionTemplateDto() {
-    return new PermissionTemplateDto()
-      .setName(randomAlphanumeric(60))
-      .setDescription(randomAscii(500))
-      .setUuid(Uuids.create())
-      .setCreatedAt(new Date())
-      .setUpdatedAt(new Date());
-  }
-
-  public static PermissionTemplateUserDto newPermissionTemplateUserDto() {
-    return new PermissionTemplateUserDto()
-      .setPermission(ProjectPermissions.ALL.get(RandomUtils.nextInt(ProjectPermissions.ALL.size())))
-      .setCreatedAt(new Date())
-      .setUpdatedAt(new Date());
-  }
-
-  public static PermissionTemplateGroupDto newPermissionTemplateGroupDto() {
-    return new PermissionTemplateGroupDto()
-      .setPermission(ProjectPermissions.ALL.get(RandomUtils.nextInt(ProjectPermissions.ALL.size())))
-      .setCreatedAt(new Date())
-      .setUpdatedAt(new Date());
-  }
-
-  public static PermissionTemplateCharacteristicDto newPermissionTemplateCharacteristicDto() {
-    return new PermissionTemplateCharacteristicDto()
-      .setPermission(ProjectPermissions.ALL.get(RandomUtils.nextInt(ProjectPermissions.ALL.size())))
-      .setWithProjectCreator(RandomUtils.nextBoolean())
-      .setCreatedAt(System.currentTimeMillis())
-      .setUpdatedAt(System.currentTimeMillis());
-  }
-
-}
diff --git a/sonar-db/src/test/java/org/sonar/db/permission/UserWithPermissionTemplateDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/UserWithPermissionTemplateDaoTest.java
deleted file mode 100644 (file)
index 1deb0bb..0000000
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.permission;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import java.util.List;
-import javax.annotation.Nullable;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-
-public class UserWithPermissionTemplateDaoTest {
-
-  private static final Long TEMPLATE_ID = 50L;
-
-  @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
-  PermissionTemplateDao dao = dbTester.getDbClient().permissionTemplateDao();
-
-  @Test
-  public void select_all_users() {
-    dbTester.prepareDbUnit(getClass(), "users_with_permissions.xml");
-
-    OldPermissionQuery query = OldPermissionQuery.builder().permission("user").build();
-    List<UserWithPermissionDto> result = dao.selectUsers(query, TEMPLATE_ID);
-    assertThat(result).hasSize(3);
-
-    UserWithPermissionDto user1 = result.get(0);
-    assertThat(user1.getLogin()).isEqualTo("user1");
-    assertThat(user1.getName()).isEqualTo("User1");
-    assertThat(user1.getPermission()).isNotNull();
-
-    UserWithPermissionDto user2 = result.get(1);
-    assertThat(user2.getLogin()).isEqualTo("user2");
-    assertThat(user2.getName()).isEqualTo("User2");
-    assertThat(user2.getPermission()).isNotNull();
-
-    UserWithPermissionDto user3 = result.get(2);
-    assertThat(user3.getLogin()).isEqualTo("user3");
-    assertThat(user3.getName()).isEqualTo("User3");
-    assertThat(user3.getPermission()).isNull();
-  }
-
-  @Test
-  public void return_nothing_on_unknown_template_key() {
-    dbTester.prepareDbUnit(getClass(), "users_with_permissions.xml");
-
-    OldPermissionQuery query = OldPermissionQuery.builder().permission("user").build();
-    List<UserWithPermissionDto> result = dao.selectUsers(query, 999L);
-    assertThat(result).hasSize(3);
-
-    UserWithPermissionDto user1 = result.get(0);
-    assertThat(user1.getPermission()).isNull();
-
-    UserWithPermissionDto user2 = result.get(1);
-    assertThat(user2.getPermission()).isNull();
-
-    UserWithPermissionDto user3 = result.get(2);
-    assertThat(user3.getPermission()).isNull();
-  }
-
-  @Test
-  public void select_only_user_with_permission() {
-    dbTester.prepareDbUnit(getClass(), "users_with_permissions.xml");
-
-    // user1 and user2 have permission user
-    assertThat(dao.selectUsers(OldPermissionQuery.builder().permission("user").membership(OldPermissionQuery.IN).build(), TEMPLATE_ID)).hasSize(2);
-  }
-
-  @Test
-  public void select_only_user_without_permission() {
-    dbTester.prepareDbUnit(getClass(), "users_with_permissions.xml");
-
-    // Only user3 has not the user permission
-    assertThat(dao.selectUsers(OldPermissionQuery.builder().permission("user").membership(OldPermissionQuery.OUT).build(), TEMPLATE_ID)).hasSize(1);
-  }
-
-  @Test
-  public void select_only_enable_users() {
-    dbTester.prepareDbUnit(getClass(), "select_only_enable_users.xml");
-
-    OldPermissionQuery query = OldPermissionQuery.builder().permission("user").build();
-    List<UserWithPermissionDto> result = dao.selectUsers(query, 999L);
-    assertThat(result).hasSize(3);
-
-    // Disabled user should not be returned
-    assertThat(Iterables.find(result, new Predicate<UserWithPermissionDto>() {
-      @Override
-      public boolean apply(@Nullable UserWithPermissionDto input) {
-        return input.getLogin().equals("disabledUser");
-      }
-    }, null)).isNull();
-  }
-
-  @Test
-  public void search_by_user_name() {
-    dbTester.prepareDbUnit(getClass(), "users_with_permissions.xml");
-
-    List<UserWithPermissionDto> result = dao.selectUsers(OldPermissionQuery.builder().permission("user").search("SEr1").build(), TEMPLATE_ID);
-    assertThat(result).hasSize(1);
-    assertThat(result.get(0).getName()).isEqualTo("User1");
-
-    result = dao.selectUsers(OldPermissionQuery.builder().permission("user").search("user").build(), TEMPLATE_ID);
-    assertThat(result).hasSize(3);
-  }
-
-  @Test
-  public void should_be_sorted_by_user_name() {
-    dbTester.prepareDbUnit(getClass(), "users_with_permissions_should_be_sorted_by_user_name.xml");
-
-    List<UserWithPermissionDto> result = dao.selectUsers(OldPermissionQuery.builder().permission("user").build(), TEMPLATE_ID);
-    assertThat(result).hasSize(3);
-    assertThat(result.get(0).getName()).isEqualTo("User1");
-    assertThat(result.get(1).getName()).isEqualTo("User2");
-    assertThat(result.get(2).getName()).isEqualTo("User3");
-  }
-
-  @Test
-  public void should_be_paginated() {
-    dbTester.prepareDbUnit(getClass(), "users_with_permissions.xml");
-
-    List<UserWithPermissionDto> result = dao.selectUsers(OldPermissionQuery.builder().permission("user").build(), TEMPLATE_ID, 0, 2);
-    assertThat(result).hasSize(2);
-    assertThat(result.get(0).getName()).isEqualTo("User1");
-    assertThat(result.get(1).getName()).isEqualTo("User2");
-
-    result = dao.selectUsers(OldPermissionQuery.builder().permission("user").build(), TEMPLATE_ID, 1, 2);
-    assertThat(result).hasSize(2);
-    assertThat(result.get(0).getName()).isEqualTo("User2");
-    assertThat(result.get(1).getName()).isEqualTo("User3");
-
-    result = dao.selectUsers(OldPermissionQuery.builder().permission("user").build(), TEMPLATE_ID, 2, 1);
-    assertThat(result).hasSize(1);
-    assertThat(result.get(0).getName()).isEqualTo("User3");
-  }
-
-}
diff --git a/sonar-db/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java
new file mode 100644 (file)
index 0000000..a924229
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.permission.template;
+
+import java.util.List;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.api.web.UserRole;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.permission.GroupWithPermissionDto;
+import org.sonar.db.permission.OldPermissionQuery;
+import org.sonar.db.permission.template.PermissionTemplateDao;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class GroupWithPermissionTemplateDaoTest {
+
+  private static final long TEMPLATE_ID = 50L;
+
+  @Rule
+  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  DbSession session = dbTester.getSession();
+
+  PermissionTemplateDao underTest = dbTester.getDbClient().permissionTemplateDao();
+
+  @Test
+  public void select_groups() {
+    dbTester.prepareDbUnit(getClass(), "groups_with_permissions.xml");
+
+    OldPermissionQuery query = OldPermissionQuery.builder().permission("user").build();
+    List<GroupWithPermissionDto> result = underTest.selectGroups(session, query, TEMPLATE_ID);
+    int count = underTest.countGroups(session, query, TEMPLATE_ID);
+
+    assertThat(result).hasSize(4);
+    assertThat(count).isEqualTo(4);
+
+    GroupWithPermissionDto anyone = result.get(0);
+    assertThat(anyone.getName()).isEqualTo("Anyone");
+    assertThat(anyone.getDescription()).isNull();
+    assertThat(anyone.getPermission()).isNotNull();
+
+    GroupWithPermissionDto group1 = result.get(1);
+    assertThat(group1.getName()).isEqualTo("sonar-administrators");
+    assertThat(group1.getDescription()).isEqualTo("System administrators");
+    assertThat(group1.getPermission()).isNotNull();
+
+    GroupWithPermissionDto group2 = result.get(2);
+    assertThat(group2.getName()).isEqualTo("sonar-reviewers");
+    assertThat(group2.getDescription()).isEqualTo("Reviewers");
+    assertThat(group2.getPermission()).isNull();
+
+    GroupWithPermissionDto group3 = result.get(3);
+    assertThat(group3.getName()).isEqualTo("sonar-users");
+    assertThat(group3.getDescription()).isEqualTo("Any new users created will automatically join this group");
+    assertThat(group3.getPermission()).isNotNull();
+  }
+
+  @Test
+  public void anyone_group_is_returned_when_it_has_no_permission() {
+    dbTester.prepareDbUnit(getClass(), "groups_with_permissions.xml");
+
+    // Anyone group is returned even if it doesn't have the permission
+    OldPermissionQuery query = OldPermissionQuery.builder().permission(UserRole.USER).build();
+    List<GroupWithPermissionDto> result = underTest.selectGroups(session, query, TEMPLATE_ID);
+    assertThat(result).hasSize(4);
+
+    GroupWithPermissionDto group1 = result.get(1);
+    assertThat(group1.getName()).isEqualTo("sonar-administrators");
+    assertThat(group1.getPermission()).isNotNull();
+
+    GroupWithPermissionDto group2 = result.get(2);
+    assertThat(group2.getName()).isEqualTo("sonar-reviewers");
+    assertThat(group2.getPermission()).isNull();
+
+    GroupWithPermissionDto group3 = result.get(3);
+    assertThat(group3.getName()).isEqualTo("sonar-users");
+    assertThat(group3.getPermission()).isNotNull();
+  }
+
+  @Test
+  public void search_by_groups_name() {
+    dbTester.prepareDbUnit(getClass(), "groups_with_permissions.xml");
+
+    List<GroupWithPermissionDto> result = underTest.selectGroups(session, OldPermissionQuery.builder().permission("user").search("aDMini").build(), TEMPLATE_ID);
+    assertThat(result).hasSize(1);
+    assertThat(result.get(0).getName()).isEqualTo("sonar-administrators");
+
+    result = underTest.selectGroups(session, OldPermissionQuery.builder().permission("user").search("sonar").build(), TEMPLATE_ID);
+    assertThat(result).hasSize(3);
+  }
+
+  @Test
+  public void search_groups_should_be_sorted_by_group_name() {
+    dbTester.prepareDbUnit(getClass(), "groups_with_permissions_should_be_sorted_by_group_name.xml");
+
+    List<GroupWithPermissionDto> result = underTest.selectGroups(session, OldPermissionQuery.builder().permission("user").build(), TEMPLATE_ID);
+    assertThat(result).hasSize(4);
+    assertThat(result.get(0).getName()).isEqualTo("Anyone");
+    assertThat(result.get(1).getName()).isEqualTo("sonar-administrators");
+    assertThat(result.get(2).getName()).isEqualTo("sonar-reviewers");
+    assertThat(result.get(3).getName()).isEqualTo("sonar-users");
+  }
+
+}
diff --git a/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDaoTest.java
new file mode 100644 (file)
index 0000000..e957c33
--- /dev/null
@@ -0,0 +1,396 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.permission.template;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import org.apache.ibatis.session.ResultContext;
+import org.apache.ibatis.session.ResultHandler;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.System2;
+import org.sonar.api.web.UserRole;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.user.GroupDbTester;
+import org.sonar.db.user.GroupDto;
+import org.sonar.db.user.UserDbTester;
+import org.sonar.db.user.UserDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.api.web.UserRole.ADMIN;
+import static org.sonar.api.web.UserRole.CODEVIEWER;
+import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
+import static org.sonar.api.web.UserRole.USER;
+import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.user.GroupTesting.newGroupDto;
+import static org.sonar.db.user.UserTesting.newUserDto;
+
+public class PermissionTemplateDaoTest {
+
+  System2 system = mock(System2.class);
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+  @Rule
+  public DbTester db = DbTester.create(system);
+  DbClient dbClient = db.getDbClient();
+  DbSession dbSession = db.getSession();
+  GroupDbTester groupDb = new GroupDbTester(db);
+  UserDbTester userDb = new UserDbTester(db);
+  PermissionTemplateDbTester templateDb = new PermissionTemplateDbTester(db);
+
+  PermissionTemplateDao underTest = new PermissionTemplateDao(db.myBatis(), system);
+
+  @Test
+  public void should_create_permission_template() throws ParseException {
+    db.prepareDbUnit(getClass(), "createPermissionTemplate.xml");
+
+    Date now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2013-01-02 01:04:05");
+    when(system.now()).thenReturn(now.getTime());
+
+    PermissionTemplateDto permissionTemplate = underTest.insert(db.getSession(), newPermissionTemplateDto()
+      .setName("my template")
+      .setDescription("my description")
+      .setKeyPattern("myregexp"));
+    assertThat(permissionTemplate).isNotNull();
+    assertThat(permissionTemplate.getId()).isEqualTo(1L);
+
+    db.assertDbUnitTable(getClass(), "createPermissionTemplate-result.xml", "permission_templates", "id", "name", "description");
+  }
+
+  @Test
+  public void should_select_permission_template() {
+    db.prepareDbUnit(getClass(), "selectPermissionTemplate.xml");
+
+    PermissionTemplate result = underTest.selectByUuidWithUserAndGroupPermissions("my_template_20130102_030405");
+
+    assertThat(result).isNotNull();
+    PermissionTemplateDto template = result.getTemplate();
+    assertThat(template.getName()).isEqualTo("my template");
+    assertThat(template.getUuid()).isEqualTo("my_template_20130102_030405");
+    assertThat(template.getDescription()).isEqualTo("my description");
+    List<PermissionTemplateUserDto> usersPermissions = result.getUserPermissions();
+    assertThat(usersPermissions).hasSize(3);
+    assertThat(usersPermissions).extracting("userId").containsOnly(1L, 2L, 1L);
+    assertThat(usersPermissions).extracting("userLogin").containsOnly("login1", "login2", "login2");
+    assertThat(usersPermissions).extracting("userName").containsOnly("user1", "user2", "user2");
+    assertThat(usersPermissions).extracting("permission").containsOnly("user_permission1", "user_permission1", "user_permission2");
+    List<PermissionTemplateGroupDto> groupsPermissions = result.getGroupPermissions();
+    assertThat(groupsPermissions).hasSize(3);
+    assertThat(groupsPermissions).extracting("groupId").containsOnly(1L, 2L, null);
+    assertThat(groupsPermissions).extracting("groupName").containsOnly("group1", "group2", null);
+    assertThat(groupsPermissions).extracting("permission").containsOnly("group_permission1", "group_permission1", "group_permission2");
+  }
+
+  @Test
+  public void should_select_permission_template_by_key() {
+    db.prepareDbUnit(getClass(), "selectPermissionTemplate.xml");
+
+    PermissionTemplateDto permissionTemplate = underTest.selectByUuid("my_template_20130102_030405");
+
+    assertThat(permissionTemplate).isNotNull();
+    assertThat(permissionTemplate.getId()).isEqualTo(1L);
+    assertThat(permissionTemplate.getName()).isEqualTo("my template");
+    assertThat(permissionTemplate.getUuid()).isEqualTo("my_template_20130102_030405");
+    assertThat(permissionTemplate.getDescription()).isEqualTo("my description");
+  }
+
+  @Test
+  public void should_select_all_permission_templates() {
+    db.prepareDbUnit(getClass(), "selectAllPermissionTemplates.xml");
+    commit();
+
+    List<PermissionTemplateDto> permissionTemplates = underTest.selectAll();
+
+    assertThat(permissionTemplates).hasSize(3);
+    assertThat(permissionTemplates).extracting("id").containsOnly(1L, 2L, 3L);
+    assertThat(permissionTemplates).extracting("name").containsOnly("template1", "template2", "template3");
+    assertThat(permissionTemplates).extracting("kee").containsOnly("template1_20130102_030405", "template2_20130102_030405", "template3_20130102_030405");
+    assertThat(permissionTemplates).extracting("description").containsOnly("description1", "description2", "description3");
+  }
+
+  @Test
+  public void should_update_permission_template() {
+    db.prepareDbUnit(getClass(), "updatePermissionTemplate.xml");
+
+    underTest.update(1L, "new_name", "new_description", "new_regexp");
+
+    db.assertDbUnitTable(getClass(), "updatePermissionTemplate-result.xml", "permission_templates", "id", "name", "kee", "description");
+  }
+
+  @Test
+  public void should_delete_permission_template() {
+    db.prepareDbUnit(getClass(), "deletePermissionTemplate.xml");
+
+    underTest.deleteById(dbSession, 1L);
+    dbSession.commit();
+
+    checkTemplateTables("deletePermissionTemplate-result.xml");
+    db.assertDbUnitTable(getClass(), "deletePermissionTemplate-result.xml", "perm_tpl_characteristics");
+  }
+
+  @Test
+  public void should_add_user_permission_to_template() {
+    db.prepareDbUnit(getClass(), "addUserPermissionToTemplate.xml");
+
+    underTest.insertUserPermission(1L, 1L, "new_permission");
+
+    checkTemplateTables("addUserPermissionToTemplate-result.xml");
+  }
+
+  @Test
+  public void should_remove_user_permission_from_template() {
+    db.prepareDbUnit(getClass(), "removeUserPermissionFromTemplate.xml");
+
+    underTest.deleteUserPermission(1L, 2L, "permission_to_remove");
+
+    checkTemplateTables("removeUserPermissionFromTemplate-result.xml");
+  }
+
+  @Test
+  public void should_add_group_permission_to_template() {
+    db.prepareDbUnit(getClass(), "addGroupPermissionToTemplate.xml");
+
+    underTest.insertGroupPermission(1L, 1L, "new_permission");
+
+    checkTemplateTables("addGroupPermissionToTemplate-result.xml");
+  }
+
+  @Test
+  public void should_remove_group_permission_from_template() {
+    db.prepareDbUnit(getClass(), "removeGroupPermissionFromTemplate.xml");
+
+    underTest.deleteGroupPermission(1L, 2L, "permission_to_remove");
+
+    checkTemplateTables("removeGroupPermissionFromTemplate-result.xml");
+  }
+
+  @Test
+  public void remove_by_group() {
+    db.prepareDbUnit(getClass(), "remove_by_group.xml");
+
+    underTest.deleteByGroup(db.getSession(), 2L);
+    db.getSession().commit();
+
+    db.assertDbUnitTable(getClass(), "remove_by_group-result.xml", "permission_templates", "id", "name", "kee", "description");
+  }
+
+  @Test
+  public void should_add_group_permission_with_null_name() {
+    db.prepareDbUnit(getClass(), "addNullGroupPermissionToTemplate.xml");
+
+    underTest.insertGroupPermission(1L, null, "new_permission");
+
+    checkTemplateTables("addNullGroupPermissionToTemplate-result.xml");
+  }
+
+  @Test
+  public void should_remove_group_permission_with_null_name() {
+    db.prepareDbUnit(getClass(), "removeNullGroupPermissionFromTemplate.xml");
+
+    underTest.deleteGroupPermission(1L, null, "permission_to_remove");
+
+    checkTemplateTables("removeNullGroupPermissionFromTemplate-result.xml");
+  }
+
+  @Test
+  public void new_permission_template_with_empty_user_group_characteristics() {
+    PermissionTemplateDto template = underTest.insert(dbSession, newPermissionTemplateDto().setUuid("TEMPLATE_UUID"));
+
+    PermissionTemplate result = underTest.selectByUuidWithUserAndGroupPermissions(dbSession, "TEMPLATE_UUID");
+
+    assertThat(result.getTemplate())
+      .extracting(PermissionTemplateDto::getId, PermissionTemplateDto::getUuid, PermissionTemplateDto::getName, PermissionTemplateDto::getDescription)
+      .containsExactly(template.getId(), template.getUuid(), template.getName(), template.getDescription());
+
+    assertThat(result.getUserPermissions()).isEmpty();
+    assertThat(result.getGroupPermissions()).isEmpty();
+    assertThat(result.getCharacteristics()).isEmpty();
+  }
+
+  @Test
+  public void unknown_permission_template() {
+    PermissionTemplate result = underTest.selectByUuidWithUserAndGroupPermissions(dbSession, "UNKNOWN_TEMPLATE_UUID");
+
+    assertThat(result).isNull();
+  }
+
+  @Test
+  public void permission_template_with_user_group_and_characteristics() {
+    PermissionTemplateDto template = dbClient.permissionTemplateDao().insert(dbSession, newPermissionTemplateDto().setUuid("TEMPLATE_UUID"));
+    GroupDto group = groupDb.insertGroup(newGroupDto());
+    UserDto user = userDb.insertUser(newUserDto());
+    templateDb.addGroupToTemplate(template.getId(), group.getId(), UserRole.ADMIN);
+    templateDb.addUserToTemplate(template.getId(), user.getId(), UserRole.CODEVIEWER);
+    templateDb.addProjectCreatorToTemplate(template.getId(), UserRole.USER);
+
+    PermissionTemplate result = underTest.selectByUuidWithUserAndGroupPermissions(dbSession, "TEMPLATE_UUID");
+    assertThat(result.getTemplate())
+      .extracting(PermissionTemplateDto::getId, PermissionTemplateDto::getUuid, PermissionTemplateDto::getName, PermissionTemplateDto::getDescription)
+      .containsExactly(template.getId(), template.getUuid(), template.getName(), template.getDescription());
+    assertThat(result.getCharacteristics()).hasSize(1)
+      .extracting(PermissionTemplateCharacteristicDto::getPermission, PermissionTemplateCharacteristicDto::getWithProjectCreator)
+      .containsExactly(tuple(UserRole.USER, true));
+    assertThat(result.getGroupPermissions()).hasSize(1)
+      .extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getGroupName, PermissionTemplateGroupDto::getPermission)
+      .containsExactly(tuple(group.getId(), group.getName(), UserRole.ADMIN));
+    assertThat(result.getUserPermissions()).hasSize(1)
+      .extracting(PermissionTemplateUserDto::getUserId, PermissionTemplateUserDto::getUserLogin, PermissionTemplateUserDto::getPermission)
+      .containsExactly(tuple(user.getId(), user.getLogin(), UserRole.CODEVIEWER));
+  }
+
+  @Test
+  public void should_fail_on_unmatched_template() {
+    expectedException.expect(IllegalArgumentException.class);
+
+    underTest.selectPermissionTemplateWithPermissions(db.getSession(), "unmatched");
+  }
+
+  @Test
+  public void group_count_by_template_and_permission() {
+    PermissionTemplateDto template1 = templateDb.insertTemplate();
+    PermissionTemplateDto template2 = templateDb.insertTemplate();
+    PermissionTemplateDto template3 = templateDb.insertTemplate();
+
+    GroupDto group1 = groupDb.insertGroup();
+    GroupDto group2 = groupDb.insertGroup();
+    GroupDto group3 = groupDb.insertGroup();
+
+    templateDb.addGroupToTemplate(42L, group1.getId(), ISSUE_ADMIN);
+    templateDb.addGroupToTemplate(template1.getId(), group1.getId(), CODEVIEWER);
+    templateDb.addGroupToTemplate(template1.getId(), group2.getId(), CODEVIEWER);
+    templateDb.addGroupToTemplate(template1.getId(), group3.getId(), CODEVIEWER);
+    templateDb.addGroupToTemplate(template1.getId(), null, CODEVIEWER);
+    templateDb.addGroupToTemplate(template1.getId(), group1.getId(), ADMIN);
+    templateDb.addGroupToTemplate(template2.getId(), group1.getId(), ADMIN);
+
+    final List<CountByTemplateAndPermissionDto> result = new ArrayList<>();
+    underTest.groupsCountByTemplateIdAndPermission(dbSession, Arrays.asList(template1.getId(), template2.getId(), template3.getId()), new ResultHandler() {
+      @Override
+      public void handleResult(ResultContext context) {
+        result.add((CountByTemplateAndPermissionDto) context.getResultObject());
+      }
+    });
+
+    assertThat(result).hasSize(3);
+    assertThat(result).extracting("permission").containsOnly(ADMIN, CODEVIEWER);
+    assertThat(result).extracting("templateId").containsOnly(template1.getId(), template2.getId());
+    assertThat(result).extracting("count").containsOnly(4, 1);
+  }
+
+  @Test
+  public void user_count_by_template_and_permission() {
+    PermissionTemplateDto template1 = templateDb.insertTemplate();
+    PermissionTemplateDto template2 = templateDb.insertTemplate();
+    PermissionTemplateDto template3 = templateDb.insertTemplate();
+
+    UserDto user1 = userDb.insertUser();
+    UserDto user2 = userDb.insertUser();
+    UserDto user3 = userDb.insertUser();
+
+    templateDb.addUserToTemplate(42L, user1.getId(), ISSUE_ADMIN);
+    templateDb.addUserToTemplate(template1.getId(), user1.getId(), ADMIN);
+    templateDb.addUserToTemplate(template1.getId(), user2.getId(), ADMIN);
+    templateDb.addUserToTemplate(template1.getId(), user3.getId(), ADMIN);
+    templateDb.addUserToTemplate(template1.getId(), user1.getId(), USER);
+    templateDb.addUserToTemplate(template2.getId(), user1.getId(), USER);
+
+    final List<CountByTemplateAndPermissionDto> result = new ArrayList<>();
+    underTest.usersCountByTemplateIdAndPermission(dbSession, Arrays.asList(template1.getId(), template2.getId(), template3.getId()),
+      context -> result.add((CountByTemplateAndPermissionDto) context.getResultObject()));
+    assertThat(result).hasSize(3);
+    assertThat(result).extracting("permission").containsOnly(ADMIN, USER);
+    assertThat(result).extracting("templateId").containsOnly(template1.getId(), template2.getId());
+    assertThat(result).extracting("count").containsOnly(3, 1);
+  }
+
+  @Test
+  public void select_by_name_query_and_pagination() {
+    templateDb.insertTemplate(newPermissionTemplateDto().setName("aaabbb"));
+    templateDb.insertTemplate(newPermissionTemplateDto().setName("aaaccc"));
+
+    List<PermissionTemplateDto> templates = underTest.selectAll(dbSession, "aaa");
+    int count = underTest.countAll(dbSession, "aaa");
+
+    assertThat(templates.get(0).getName()).isEqualTo("aaabbb");
+    assertThat(count).isEqualTo(2);
+  }
+
+  @Test
+  public void selectPotentialPermissions_with_unknown_template_and_no_user() {
+    List<String> result = underTest.selectPotentialPermissionsByUserIdAndTemplateId(dbSession, null, 42L);
+
+    assertThat(result).isEmpty();
+  }
+
+  @Test
+  public void selectPotentialPermissions_with_empty_template_and_new_user() {
+    UserDto user = userDb.insertUser();
+    PermissionTemplateDto template = templateDb.insertTemplate();
+
+    List<String> result = underTest.selectPotentialPermissionsByUserIdAndTemplateId(dbSession, user.getId(), template.getId());
+
+    assertThat(result).isEmpty();
+  }
+
+  @Test
+  public void selectPotentialPermission_with_template_users_groups_and_project_creator() {
+    UserDto user = userDb.insertUser();
+    GroupDto group = groupDb.insertGroup();
+    groupDb.addUserToGroup(user.getId(), group.getId());
+    PermissionTemplateDto template = templateDb.insertTemplate();
+    templateDb.addProjectCreatorToTemplate(template.getId(), SCAN_EXECUTION);
+    templateDb.addProjectCreatorToTemplate(template.getId(), UserRole.ADMIN);
+    templateDb.addUserToTemplate(template.getId(), user.getId(), UserRole.USER);
+    templateDb.addUserToTemplate(template.getId(), user.getId(), UserRole.ADMIN);
+    templateDb.addGroupToTemplate(template.getId(), group.getId(), UserRole.CODEVIEWER);
+    templateDb.addGroupToTemplate(template.getId(), group.getId(), UserRole.ADMIN);
+    templateDb.addGroupToTemplate(template.getId(), null, UserRole.ISSUE_ADMIN);
+
+    List<String> resultWithUser = underTest.selectPotentialPermissionsByUserIdAndTemplateId(dbSession, user.getId(), template.getId());
+    List<String> resultWithoutUser = underTest.selectPotentialPermissionsByUserIdAndTemplateId(dbSession, null, template.getId());
+
+    assertThat(resultWithUser).containsOnlyOnce(SCAN_EXECUTION, UserRole.ADMIN, UserRole.USER, UserRole.CODEVIEWER, UserRole.ISSUE_ADMIN);
+    // only permission from anyone group
+    assertThat(resultWithoutUser).containsOnly(UserRole.ISSUE_ADMIN);
+  }
+
+  private void commit() {
+    dbSession.commit();
+  }
+
+  private void checkTemplateTables(String fileName) {
+    db.assertDbUnitTable(getClass(), fileName, "permission_templates", "id", "name", "description");
+    db.assertDbUnitTable(getClass(), fileName, "perm_templates_users", "id", "template_id", "user_id", "permission_reference");
+    db.assertDbUnitTable(getClass(), fileName, "perm_templates_groups", "id", "template_id", "group_id", "permission_reference");
+  }
+
+}
index a1e4c380db2f5548505eae9ed2273254e9918a81..cfebcbed05601204219e27f0eb20adb6e1386a01 100644 (file)
@@ -24,10 +24,9 @@ import javax.annotation.Nullable;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.db.permission.PermissionTemplateDto;
 
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateCharacteristicDto;
-import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateCharacteristicDto;
+import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
 
 public class PermissionTemplateDbTester {
   private final DbTester db;
diff --git a/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateTesting.java b/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateTesting.java
new file mode 100644 (file)
index 0000000..713fe7d
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.permission.template;
+
+import java.util.Date;
+import org.apache.commons.lang.math.RandomUtils;
+import org.sonar.core.permission.ProjectPermissions;
+import org.sonar.core.util.Uuids;
+import org.sonar.db.permission.template.PermissionTemplateCharacteristicDto;
+import org.sonar.db.permission.template.PermissionTemplateDto;
+import org.sonar.db.permission.template.PermissionTemplateGroupDto;
+import org.sonar.db.permission.template.PermissionTemplateUserDto;
+
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
+import static org.apache.commons.lang.RandomStringUtils.randomAscii;
+
+public class PermissionTemplateTesting {
+  public static PermissionTemplateDto newPermissionTemplateDto() {
+    return new PermissionTemplateDto()
+      .setName(randomAlphanumeric(60))
+      .setDescription(randomAscii(500))
+      .setUuid(Uuids.create())
+      .setCreatedAt(new Date())
+      .setUpdatedAt(new Date());
+  }
+
+  public static PermissionTemplateUserDto newPermissionTemplateUserDto() {
+    return new PermissionTemplateUserDto()
+      .setPermission(ProjectPermissions.ALL.get(RandomUtils.nextInt(ProjectPermissions.ALL.size())))
+      .setCreatedAt(new Date())
+      .setUpdatedAt(new Date());
+  }
+
+  public static PermissionTemplateGroupDto newPermissionTemplateGroupDto() {
+    return new PermissionTemplateGroupDto()
+      .setPermission(ProjectPermissions.ALL.get(RandomUtils.nextInt(ProjectPermissions.ALL.size())))
+      .setCreatedAt(new Date())
+      .setUpdatedAt(new Date());
+  }
+
+  public static PermissionTemplateCharacteristicDto newPermissionTemplateCharacteristicDto() {
+    return new PermissionTemplateCharacteristicDto()
+      .setPermission(ProjectPermissions.ALL.get(RandomUtils.nextInt(ProjectPermissions.ALL.size())))
+      .setWithProjectCreator(RandomUtils.nextBoolean())
+      .setCreatedAt(System.currentTimeMillis())
+      .setUpdatedAt(System.currentTimeMillis());
+  }
+
+}
diff --git a/sonar-db/src/test/java/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest.java
new file mode 100644 (file)
index 0000000..6a32e78
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.permission.template;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+import org.sonar.db.permission.OldPermissionQuery;
+import org.sonar.db.permission.UserWithPermissionDto;
+import org.sonar.db.permission.template.PermissionTemplateDao;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class UserWithPermissionTemplateDaoTest {
+
+  private static final Long TEMPLATE_ID = 50L;
+
+  @Rule
+  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+
+  PermissionTemplateDao dao = dbTester.getDbClient().permissionTemplateDao();
+
+  @Test
+  public void select_all_users() {
+    dbTester.prepareDbUnit(getClass(), "users_with_permissions.xml");
+
+    OldPermissionQuery query = OldPermissionQuery.builder().permission("user").build();
+    List<UserWithPermissionDto> result = dao.selectUsers(query, TEMPLATE_ID);
+    assertThat(result).hasSize(3);
+
+    UserWithPermissionDto user1 = result.get(0);
+    assertThat(user1.getLogin()).isEqualTo("user1");
+    assertThat(user1.getName()).isEqualTo("User1");
+    assertThat(user1.getPermission()).isNotNull();
+
+    UserWithPermissionDto user2 = result.get(1);
+    assertThat(user2.getLogin()).isEqualTo("user2");
+    assertThat(user2.getName()).isEqualTo("User2");
+    assertThat(user2.getPermission()).isNotNull();
+
+    UserWithPermissionDto user3 = result.get(2);
+    assertThat(user3.getLogin()).isEqualTo("user3");
+    assertThat(user3.getName()).isEqualTo("User3");
+    assertThat(user3.getPermission()).isNull();
+  }
+
+  @Test
+  public void return_nothing_on_unknown_template_key() {
+    dbTester.prepareDbUnit(getClass(), "users_with_permissions.xml");
+
+    OldPermissionQuery query = OldPermissionQuery.builder().permission("user").build();
+    List<UserWithPermissionDto> result = dao.selectUsers(query, 999L);
+    assertThat(result).hasSize(3);
+
+    UserWithPermissionDto user1 = result.get(0);
+    assertThat(user1.getPermission()).isNull();
+
+    UserWithPermissionDto user2 = result.get(1);
+    assertThat(user2.getPermission()).isNull();
+
+    UserWithPermissionDto user3 = result.get(2);
+    assertThat(user3.getPermission()).isNull();
+  }
+
+  @Test
+  public void select_only_user_with_permission() {
+    dbTester.prepareDbUnit(getClass(), "users_with_permissions.xml");
+
+    // user1 and user2 have permission user
+    assertThat(dao.selectUsers(OldPermissionQuery.builder().permission("user").membership(OldPermissionQuery.IN).build(), TEMPLATE_ID)).hasSize(2);
+  }
+
+  @Test
+  public void select_only_user_without_permission() {
+    dbTester.prepareDbUnit(getClass(), "users_with_permissions.xml");
+
+    // Only user3 has not the user permission
+    assertThat(dao.selectUsers(OldPermissionQuery.builder().permission("user").membership(OldPermissionQuery.OUT).build(), TEMPLATE_ID)).hasSize(1);
+  }
+
+  @Test
+  public void select_only_enable_users() {
+    dbTester.prepareDbUnit(getClass(), "select_only_enable_users.xml");
+
+    OldPermissionQuery query = OldPermissionQuery.builder().permission("user").build();
+    List<UserWithPermissionDto> result = dao.selectUsers(query, 999L);
+    assertThat(result).hasSize(3);
+
+    // Disabled user should not be returned
+    assertThat(Iterables.find(result, new Predicate<UserWithPermissionDto>() {
+      @Override
+      public boolean apply(@Nullable UserWithPermissionDto input) {
+        return input.getLogin().equals("disabledUser");
+      }
+    }, null)).isNull();
+  }
+
+  @Test
+  public void search_by_user_name() {
+    dbTester.prepareDbUnit(getClass(), "users_with_permissions.xml");
+
+    List<UserWithPermissionDto> result = dao.selectUsers(OldPermissionQuery.builder().permission("user").search("SEr1").build(), TEMPLATE_ID);
+    assertThat(result).hasSize(1);
+    assertThat(result.get(0).getName()).isEqualTo("User1");
+
+    result = dao.selectUsers(OldPermissionQuery.builder().permission("user").search("user").build(), TEMPLATE_ID);
+    assertThat(result).hasSize(3);
+  }
+
+  @Test
+  public void should_be_sorted_by_user_name() {
+    dbTester.prepareDbUnit(getClass(), "users_with_permissions_should_be_sorted_by_user_name.xml");
+
+    List<UserWithPermissionDto> result = dao.selectUsers(OldPermissionQuery.builder().permission("user").build(), TEMPLATE_ID);
+    assertThat(result).hasSize(3);
+    assertThat(result.get(0).getName()).isEqualTo("User1");
+    assertThat(result.get(1).getName()).isEqualTo("User2");
+    assertThat(result.get(2).getName()).isEqualTo("User3");
+  }
+
+  @Test
+  public void should_be_paginated() {
+    dbTester.prepareDbUnit(getClass(), "users_with_permissions.xml");
+
+    List<UserWithPermissionDto> result = dao.selectUsers(OldPermissionQuery.builder().permission("user").build(), TEMPLATE_ID, 0, 2);
+    assertThat(result).hasSize(2);
+    assertThat(result.get(0).getName()).isEqualTo("User1");
+    assertThat(result.get(1).getName()).isEqualTo("User2");
+
+    result = dao.selectUsers(OldPermissionQuery.builder().permission("user").build(), TEMPLATE_ID, 1, 2);
+    assertThat(result).hasSize(2);
+    assertThat(result.get(0).getName()).isEqualTo("User2");
+    assertThat(result.get(1).getName()).isEqualTo("User3");
+
+    result = dao.selectUsers(OldPermissionQuery.builder().permission("user").build(), TEMPLATE_ID, 2, 1);
+    assertThat(result).hasSize(1);
+    assertThat(result.get(0).getName()).isEqualTo("User3");
+  }
+
+}
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/GroupWithPermissionTemplateDaoTest/groups_with_permissions.xml b/sonar-db/src/test/resources/org/sonar/db/permission/GroupWithPermissionTemplateDaoTest/groups_with_permissions.xml
deleted file mode 100644 (file)
index 8d6592c..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<dataset>
-
-  <groups id="200" name="sonar-administrators" description="System administrators"/>
-  <groups id="201" name="sonar-users" description="Any new users created will automatically join this group"/>
-  <groups id="202" name="sonar-reviewers" description="Reviewers"/>
-
-  <perm_templates_groups id="1" group_id="200" permission_reference="user" template_id="50"/>
-  <perm_templates_groups id="2" group_id="200" permission_reference="admin" template_id="50"/>
-  <perm_templates_groups id="3" group_id="200" permission_reference="codeviewer" template_id="50"/>
-
-  <perm_templates_groups id="4" group_id="201" permission_reference="user" template_id="50"/>
-
-  <!-- Permission 'user' for Anyone group -->
-  <perm_templates_groups id="5" group_id="[null]" permission_reference="user" template_id="50"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/GroupWithPermissionTemplateDaoTest/groups_with_permissions_should_be_sorted_by_group_name.xml b/sonar-db/src/test/resources/org/sonar/db/permission/GroupWithPermissionTemplateDaoTest/groups_with_permissions_should_be_sorted_by_group_name.xml
deleted file mode 100644 (file)
index baf745a..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<dataset>
-
-  <groups id="200" name="sonar-reviewers"/>
-  <groups id="201" name="sonar-users"/>
-  <groups id="202" name="sonar-administrators"/>
-
-  <perm_templates_groups id="1" group_id="200" permission_reference="user" template_id="50"/>
-  <perm_templates_groups id="2" group_id="200" permission_reference="admin" template_id="50"/>
-  <perm_templates_groups id="3" group_id="200" permission_reference="codeviewer" template_id="50"/>
-
-  <perm_templates_groups id="4" group_id="201" permission_reference="user" template_id="50"/>
-
-  <!-- Permission 'user' for Anyone group -->
-  <perm_templates_groups id="5" group_id="[null]" permission_reference="user" template_id="50"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addGroupPermissionToTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addGroupPermissionToTemplate-result.xml
deleted file mode 100644 (file)
index c802167..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="new_permission"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addGroupPermissionToTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addGroupPermissionToTemplate.xml
deleted file mode 100644 (file)
index 6645e85..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addNullGroupPermissionToTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addNullGroupPermissionToTemplate-result.xml
deleted file mode 100644 (file)
index 7d42701..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups id="1" template_id="1" group_id="[null]" permission_reference="new_permission"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addNullGroupPermissionToTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addNullGroupPermissionToTemplate.xml
deleted file mode 100644 (file)
index 6645e85..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addUserPermissionToTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addUserPermissionToTemplate-result.xml
deleted file mode 100644 (file)
index 40bf5d4..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
-  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="new_permission"/>
-  <perm_templates_groups/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addUserPermissionToTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/addUserPermissionToTemplate.xml
deleted file mode 100644 (file)
index 6645e85..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/createNonAsciiPermissionTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/createNonAsciiPermissionTemplate-result.xml
deleted file mode 100644 (file)
index 8596137..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="Môü Gnô Gnèçàß" kee="mou_gno_gneca_20130102_010405" description="my description"
-                        key_pattern="[null]"/>
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/createNonAsciiPermissionTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/createNonAsciiPermissionTemplate.xml
deleted file mode 100644 (file)
index 5ed00ba..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<dataset></dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/createPermissionTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/createPermissionTemplate-result.xml
deleted file mode 100644 (file)
index 4f889d5..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_010405" description="my description"
-                        key_pattern="myregexp"/>
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/createPermissionTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/createPermissionTemplate.xml
deleted file mode 100644 (file)
index 5ed00ba..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<dataset></dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/deletePermissionTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/deletePermissionTemplate-result.xml
deleted file mode 100644 (file)
index 29e39f9..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<dataset>
-  <permission_templates id="2" name="other template" kee="my_template_20130102_030405" description="other description"
-                        created_at="[null]" updated_at="[null]"/>
-
-  <perm_templates_users id="4" template_id="2" user_id="2" permission_reference="user_permission2"/>
-
-  <perm_templates_groups id="4" template_id="2" group_id="[null]" permission_reference="group_permission2"/>
-
-  <perm_tpl_characteristics id="2" template_id="2" permission_key="user" with_project_creator="[true]" created_at="1000000" updated_at="1000000"/>
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/deletePermissionTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/deletePermissionTemplate.xml
deleted file mode 100644 (file)
index ad3dea1..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"
-                        created_at="[null]" updated_at="[null]"/>
-  <permission_templates id="2" name="other template" kee="my_template_20130102_030405" description="other description"
-                        created_at="[null]" updated_at="[null]"/>
-
-  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="user_permission1"/>
-  <perm_templates_users id="2" template_id="1" user_id="2" permission_reference="user_permission1"/>
-  <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="user_permission2"/>
-  <perm_templates_users id="4" template_id="2" user_id="2" permission_reference="user_permission2"/>
-
-  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="group_permission1"/>
-  <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="group_permission1"/>
-  <perm_templates_groups id="3" template_id="1" group_id="[null]" permission_reference="group_permission2"/>
-  <perm_templates_groups id="4" template_id="2" group_id="[null]" permission_reference="group_permission2"/>
-
-  <perm_tpl_characteristics id="1" template_id="1" permission_key="user" with_project_creator="[true]" created_at="1000000" updated_at="1000000"/>
-  <perm_tpl_characteristics id="2" template_id="2" permission_key="user" with_project_creator="[true]" created_at="1000000" updated_at="1000000"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeGroupPermissionFromTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeGroupPermissionFromTemplate-result.xml
deleted file mode 100644 (file)
index 140738d..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
-  <perm_templates_groups id="3" template_id="1" group_id="2" permission_reference="remaining_permission_same_group"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeGroupPermissionFromTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeGroupPermissionFromTemplate.xml
deleted file mode 100644 (file)
index 3258dcc..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
-  <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="permission_to_remove"/>
-  <perm_templates_groups id="3" template_id="1" group_id="2" permission_reference="remaining_permission_same_group"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeNullGroupPermissionFromTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeNullGroupPermissionFromTemplate-result.xml
deleted file mode 100644 (file)
index c37bf10..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
-  <perm_templates_groups id="3" template_id="1" group_id="[null]"
-                         permission_reference="remaining_permission_same_group"/>
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeNullGroupPermissionFromTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeNullGroupPermissionFromTemplate.xml
deleted file mode 100644 (file)
index 9e28fa9..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
-  <perm_templates_groups id="2" template_id="1" group_id="[null]" permission_reference="permission_to_remove"/>
-  <perm_templates_groups id="3" template_id="1" group_id="[null]"
-                         permission_reference="remaining_permission_same_group"/>
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeUserPermissionFromTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeUserPermissionFromTemplate-result.xml
deleted file mode 100644 (file)
index 8998378..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
-
-  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="remaining_permission_other_user"/>
-  <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="remaining_permission_same_user"/>
-
-  <perm_templates_groups/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeUserPermissionFromTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/removeUserPermissionFromTemplate.xml
deleted file mode 100644 (file)
index 779bd77..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
-
-  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="remaining_permission_other_user"/>
-  <perm_templates_users id="2" template_id="1" user_id="2" permission_reference="permission_to_remove"/>
-  <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="remaining_permission_same_user"/>
-
-  <perm_templates_groups/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/remove_by_group-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/remove_by_group-result.xml
deleted file mode 100644 (file)
index 94ab2fd..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/remove_by_group.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/remove_by_group.xml
deleted file mode 100644 (file)
index 2ff5815..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
-  <perm_templates_users/>
-  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
-  <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="permission_to_remove"/>
-  <perm_templates_groups id="3" template_id="1" group_id="2" permission_reference="permission_to_remove2"/>
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/selectAllPermissionTemplates.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/selectAllPermissionTemplates.xml
deleted file mode 100644 (file)
index e2e9391..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="template1" kee="template1_20130102_030405" description="description1"
-                        created_at="[null]" updated_at="[null]"/>
-  <permission_templates id="2" name="template2" kee="template2_20130102_030405" description="description2"
-                        created_at="[null]" updated_at="[null]"/>
-  <permission_templates id="3" name="template3" kee="template3_20130102_030405" description="description3"
-                        created_at="[null]" updated_at="[null]"/>
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/selectEmptyPermissionTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/selectEmptyPermissionTemplate.xml
deleted file mode 100644 (file)
index ab25dd4..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"
-                        created_at="[null]" updated_at="[null]"/>
-
-  <users id="1" login="user1" name="user1"/>
-  <users id="2" login="user2" name="user2"/>
-
-  <groups id="1" name="group1"/>
-  <groups id="2" name="group2"/>
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/selectPermissionTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/selectPermissionTemplate.xml
deleted file mode 100644 (file)
index 2c82c31..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"
-                        created_at="[null]" updated_at="[null]"/>
-
-  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="user_permission1"/>
-  <perm_templates_users id="2" template_id="1" user_id="2" permission_reference="user_permission1"/>
-  <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="user_permission2"/>
-
-  <users id="1" login="login1" name="user1"/>
-  <users id="2" login="login2" name="user2"/>
-
-  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="group_permission1"/>
-  <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="group_permission1"/>
-  <!-- Anyone group -->
-  <perm_templates_groups id="3" template_id="1" group_id="[null]" permission_reference="group_permission2"/>
-  <!-- Unmatched group -->
-  <perm_templates_groups id="4" template_id="1" group_id="999999" permission_reference="group_permission2"/>
-
-  <groups id="1" name="group1"/>
-  <groups id="2" name="group2"/>
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/updatePermissionTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/updatePermissionTemplate-result.xml
deleted file mode 100644 (file)
index 2449862..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="new_name" kee="template1_20130102_030405" description="new_description"
-                        key_pattern="new_regexp" created_at="[null]" updated_at="[null]"/>
-  <permission_templates id="2" name="template2" kee="template2_20130102_030405" description="description2"
-                        key_pattern="barregexp" created_at="[null]" updated_at="[null]"/>
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/updatePermissionTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/PermissionTemplateDaoTest/updatePermissionTemplate.xml
deleted file mode 100644 (file)
index c14e8b6..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<dataset>
-  <permission_templates id="1" name="template1" kee="template1_20130102_030405" description="description1"
-                        key_pattern="fooregexp" created_at="[null]" updated_at="[null]"/>
-  <permission_templates id="2" name="template2" kee="template2_20130102_030405" description="description2"
-                        key_pattern="barregexp" created_at="[null]" updated_at="[null]"/>
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/UserWithPermissionTemplateDaoTest/select_only_enable_users.xml b/sonar-db/src/test/resources/org/sonar/db/permission/UserWithPermissionTemplateDaoTest/select_only_enable_users.xml
deleted file mode 100644 (file)
index 1483391..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<dataset>
-
-  <users id="200" login="user1" name="User1" active="[true]"/>
-  <users id="201" login="user2" name="User2" active="[true]"/>
-  <users id="202" login="user3" name="User3" active="[true]"/>
-  <users id="999" login="disabledUser" name="disabledUser" active="[false]"/>
-
-  <perm_templates_users id="1" user_id="200" permission_reference="user" template_id="50"/>
-  <perm_templates_users id="2" user_id="200" permission_reference="admin" template_id="50"/>
-  <perm_templates_users id="3" user_id="200" permission_reference="codeviewer" template_id="50"/>
-
-  <perm_templates_users id="4" user_id="201" permission_reference="user" template_id="50"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/UserWithPermissionTemplateDaoTest/users_with_permissions.xml b/sonar-db/src/test/resources/org/sonar/db/permission/UserWithPermissionTemplateDaoTest/users_with_permissions.xml
deleted file mode 100644 (file)
index e886636..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<dataset>
-
-  <users id="200" login="user1" name="User1" active="[true]"/>
-  <users id="201" login="user2" name="User2" active="[true]"/>
-  <users id="202" login="user3" name="User3" active="[true]"/>
-
-  <perm_templates_users id="1" user_id="200" permission_reference="user" template_id="50"/>
-  <perm_templates_users id="2" user_id="200" permission_reference="admin" template_id="50"/>
-  <perm_templates_users id="3" user_id="200" permission_reference="codeviewer" template_id="50"/>
-
-  <perm_templates_users id="4" user_id="201" permission_reference="user" template_id="50"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml b/sonar-db/src/test/resources/org/sonar/db/permission/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml
deleted file mode 100644 (file)
index fd8b981..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<dataset>
-
-  <users id="200" login="user3" name="User3" active="[true]"/>
-  <users id="201" login="user1" name="User1" active="[true]"/>
-  <users id="202" login="user2" name="User2" active="[true]"/>
-
-  <perm_templates_users id="1" user_id="200" permission_reference="user" template_id="50"/>
-  <perm_templates_users id="2" user_id="200" permission_reference="admin" template_id="50"/>
-  <perm_templates_users id="3" user_id="200" permission_reference="codeviewer" template_id="50"/>
-
-  <perm_templates_users id="4" user_id="201" permission_reference="user" template_id="50"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest/groups_with_permissions.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest/groups_with_permissions.xml
new file mode 100644 (file)
index 0000000..8d6592c
--- /dev/null
@@ -0,0 +1,16 @@
+<dataset>
+
+  <groups id="200" name="sonar-administrators" description="System administrators"/>
+  <groups id="201" name="sonar-users" description="Any new users created will automatically join this group"/>
+  <groups id="202" name="sonar-reviewers" description="Reviewers"/>
+
+  <perm_templates_groups id="1" group_id="200" permission_reference="user" template_id="50"/>
+  <perm_templates_groups id="2" group_id="200" permission_reference="admin" template_id="50"/>
+  <perm_templates_groups id="3" group_id="200" permission_reference="codeviewer" template_id="50"/>
+
+  <perm_templates_groups id="4" group_id="201" permission_reference="user" template_id="50"/>
+
+  <!-- Permission 'user' for Anyone group -->
+  <perm_templates_groups id="5" group_id="[null]" permission_reference="user" template_id="50"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest/groups_with_permissions_should_be_sorted_by_group_name.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest/groups_with_permissions_should_be_sorted_by_group_name.xml
new file mode 100644 (file)
index 0000000..baf745a
--- /dev/null
@@ -0,0 +1,16 @@
+<dataset>
+
+  <groups id="200" name="sonar-reviewers"/>
+  <groups id="201" name="sonar-users"/>
+  <groups id="202" name="sonar-administrators"/>
+
+  <perm_templates_groups id="1" group_id="200" permission_reference="user" template_id="50"/>
+  <perm_templates_groups id="2" group_id="200" permission_reference="admin" template_id="50"/>
+  <perm_templates_groups id="3" group_id="200" permission_reference="codeviewer" template_id="50"/>
+
+  <perm_templates_groups id="4" group_id="201" permission_reference="user" template_id="50"/>
+
+  <!-- Permission 'user' for Anyone group -->
+  <perm_templates_groups id="5" group_id="[null]" permission_reference="user" template_id="50"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addGroupPermissionToTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addGroupPermissionToTemplate-result.xml
new file mode 100644 (file)
index 0000000..c802167
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="new_permission"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addGroupPermissionToTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addGroupPermissionToTemplate.xml
new file mode 100644 (file)
index 0000000..6645e85
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addNullGroupPermissionToTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addNullGroupPermissionToTemplate-result.xml
new file mode 100644 (file)
index 0000000..7d42701
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups id="1" template_id="1" group_id="[null]" permission_reference="new_permission"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addNullGroupPermissionToTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addNullGroupPermissionToTemplate.xml
new file mode 100644 (file)
index 0000000..6645e85
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addUserPermissionToTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addUserPermissionToTemplate-result.xml
new file mode 100644 (file)
index 0000000..40bf5d4
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="new_permission"/>
+  <perm_templates_groups/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addUserPermissionToTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/addUserPermissionToTemplate.xml
new file mode 100644 (file)
index 0000000..6645e85
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/createNonAsciiPermissionTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/createNonAsciiPermissionTemplate-result.xml
new file mode 100644 (file)
index 0000000..8596137
--- /dev/null
@@ -0,0 +1,4 @@
+<dataset>
+  <permission_templates id="1" name="Môü Gnô Gnèçàß" kee="mou_gno_gneca_20130102_010405" description="my description"
+                        key_pattern="[null]"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/createNonAsciiPermissionTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/createNonAsciiPermissionTemplate.xml
new file mode 100644 (file)
index 0000000..5ed00ba
--- /dev/null
@@ -0,0 +1 @@
+<dataset></dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/createPermissionTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/createPermissionTemplate-result.xml
new file mode 100644 (file)
index 0000000..4f889d5
--- /dev/null
@@ -0,0 +1,4 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_010405" description="my description"
+                        key_pattern="myregexp"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/createPermissionTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/createPermissionTemplate.xml
new file mode 100644 (file)
index 0000000..5ed00ba
--- /dev/null
@@ -0,0 +1 @@
+<dataset></dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/deletePermissionTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/deletePermissionTemplate-result.xml
new file mode 100644 (file)
index 0000000..29e39f9
--- /dev/null
@@ -0,0 +1,10 @@
+<dataset>
+  <permission_templates id="2" name="other template" kee="my_template_20130102_030405" description="other description"
+                        created_at="[null]" updated_at="[null]"/>
+
+  <perm_templates_users id="4" template_id="2" user_id="2" permission_reference="user_permission2"/>
+
+  <perm_templates_groups id="4" template_id="2" group_id="[null]" permission_reference="group_permission2"/>
+
+  <perm_tpl_characteristics id="2" template_id="2" permission_key="user" with_project_creator="[true]" created_at="1000000" updated_at="1000000"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/deletePermissionTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/deletePermissionTemplate.xml
new file mode 100644 (file)
index 0000000..ad3dea1
--- /dev/null
@@ -0,0 +1,20 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"
+                        created_at="[null]" updated_at="[null]"/>
+  <permission_templates id="2" name="other template" kee="my_template_20130102_030405" description="other description"
+                        created_at="[null]" updated_at="[null]"/>
+
+  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="user_permission1"/>
+  <perm_templates_users id="2" template_id="1" user_id="2" permission_reference="user_permission1"/>
+  <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="user_permission2"/>
+  <perm_templates_users id="4" template_id="2" user_id="2" permission_reference="user_permission2"/>
+
+  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="group_permission1"/>
+  <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="group_permission1"/>
+  <perm_templates_groups id="3" template_id="1" group_id="[null]" permission_reference="group_permission2"/>
+  <perm_templates_groups id="4" template_id="2" group_id="[null]" permission_reference="group_permission2"/>
+
+  <perm_tpl_characteristics id="1" template_id="1" permission_key="user" with_project_creator="[true]" created_at="1000000" updated_at="1000000"/>
+  <perm_tpl_characteristics id="2" template_id="2" permission_key="user" with_project_creator="[true]" created_at="1000000" updated_at="1000000"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeGroupPermissionFromTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeGroupPermissionFromTemplate-result.xml
new file mode 100644 (file)
index 0000000..140738d
--- /dev/null
@@ -0,0 +1,6 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
+  <perm_templates_groups id="3" template_id="1" group_id="2" permission_reference="remaining_permission_same_group"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeGroupPermissionFromTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeGroupPermissionFromTemplate.xml
new file mode 100644 (file)
index 0000000..3258dcc
--- /dev/null
@@ -0,0 +1,7 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
+  <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="permission_to_remove"/>
+  <perm_templates_groups id="3" template_id="1" group_id="2" permission_reference="remaining_permission_same_group"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeNullGroupPermissionFromTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeNullGroupPermissionFromTemplate-result.xml
new file mode 100644 (file)
index 0000000..c37bf10
--- /dev/null
@@ -0,0 +1,7 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
+  <perm_templates_groups id="3" template_id="1" group_id="[null]"
+                         permission_reference="remaining_permission_same_group"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeNullGroupPermissionFromTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeNullGroupPermissionFromTemplate.xml
new file mode 100644 (file)
index 0000000..9e28fa9
--- /dev/null
@@ -0,0 +1,8 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
+  <perm_templates_groups id="2" template_id="1" group_id="[null]" permission_reference="permission_to_remove"/>
+  <perm_templates_groups id="3" template_id="1" group_id="[null]"
+                         permission_reference="remaining_permission_same_group"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeUserPermissionFromTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeUserPermissionFromTemplate-result.xml
new file mode 100644 (file)
index 0000000..8998378
--- /dev/null
@@ -0,0 +1,8 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+
+  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="remaining_permission_other_user"/>
+  <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="remaining_permission_same_user"/>
+
+  <perm_templates_groups/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeUserPermissionFromTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/removeUserPermissionFromTemplate.xml
new file mode 100644 (file)
index 0000000..779bd77
--- /dev/null
@@ -0,0 +1,9 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+
+  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="remaining_permission_other_user"/>
+  <perm_templates_users id="2" template_id="1" user_id="2" permission_reference="permission_to_remove"/>
+  <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="remaining_permission_same_user"/>
+
+  <perm_templates_groups/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/remove_by_group-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/remove_by_group-result.xml
new file mode 100644 (file)
index 0000000..94ab2fd
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/remove_by_group.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/remove_by_group.xml
new file mode 100644 (file)
index 0000000..2ff5815
--- /dev/null
@@ -0,0 +1,7 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <perm_templates_users/>
+  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="remaining_permission_other_group"/>
+  <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="permission_to_remove"/>
+  <perm_templates_groups id="3" template_id="1" group_id="2" permission_reference="permission_to_remove2"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/selectAllPermissionTemplates.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/selectAllPermissionTemplates.xml
new file mode 100644 (file)
index 0000000..e2e9391
--- /dev/null
@@ -0,0 +1,8 @@
+<dataset>
+  <permission_templates id="1" name="template1" kee="template1_20130102_030405" description="description1"
+                        created_at="[null]" updated_at="[null]"/>
+  <permission_templates id="2" name="template2" kee="template2_20130102_030405" description="description2"
+                        created_at="[null]" updated_at="[null]"/>
+  <permission_templates id="3" name="template3" kee="template3_20130102_030405" description="description3"
+                        created_at="[null]" updated_at="[null]"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/selectEmptyPermissionTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/selectEmptyPermissionTemplate.xml
new file mode 100644 (file)
index 0000000..ab25dd4
--- /dev/null
@@ -0,0 +1,10 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"
+                        created_at="[null]" updated_at="[null]"/>
+
+  <users id="1" login="user1" name="user1"/>
+  <users id="2" login="user2" name="user2"/>
+
+  <groups id="1" name="group1"/>
+  <groups id="2" name="group2"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/selectPermissionTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/selectPermissionTemplate.xml
new file mode 100644 (file)
index 0000000..2c82c31
--- /dev/null
@@ -0,0 +1,21 @@
+<dataset>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"
+                        created_at="[null]" updated_at="[null]"/>
+
+  <perm_templates_users id="1" template_id="1" user_id="1" permission_reference="user_permission1"/>
+  <perm_templates_users id="2" template_id="1" user_id="2" permission_reference="user_permission1"/>
+  <perm_templates_users id="3" template_id="1" user_id="2" permission_reference="user_permission2"/>
+
+  <users id="1" login="login1" name="user1"/>
+  <users id="2" login="login2" name="user2"/>
+
+  <perm_templates_groups id="1" template_id="1" group_id="1" permission_reference="group_permission1"/>
+  <perm_templates_groups id="2" template_id="1" group_id="2" permission_reference="group_permission1"/>
+  <!-- Anyone group -->
+  <perm_templates_groups id="3" template_id="1" group_id="[null]" permission_reference="group_permission2"/>
+  <!-- Unmatched group -->
+  <perm_templates_groups id="4" template_id="1" group_id="999999" permission_reference="group_permission2"/>
+
+  <groups id="1" name="group1"/>
+  <groups id="2" name="group2"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/updatePermissionTemplate-result.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/updatePermissionTemplate-result.xml
new file mode 100644 (file)
index 0000000..2449862
--- /dev/null
@@ -0,0 +1,6 @@
+<dataset>
+  <permission_templates id="1" name="new_name" kee="template1_20130102_030405" description="new_description"
+                        key_pattern="new_regexp" created_at="[null]" updated_at="[null]"/>
+  <permission_templates id="2" name="template2" kee="template2_20130102_030405" description="description2"
+                        key_pattern="barregexp" created_at="[null]" updated_at="[null]"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/updatePermissionTemplate.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/PermissionTemplateDaoTest/updatePermissionTemplate.xml
new file mode 100644 (file)
index 0000000..c14e8b6
--- /dev/null
@@ -0,0 +1,6 @@
+<dataset>
+  <permission_templates id="1" name="template1" kee="template1_20130102_030405" description="description1"
+                        key_pattern="fooregexp" created_at="[null]" updated_at="[null]"/>
+  <permission_templates id="2" name="template2" kee="template2_20130102_030405" description="description2"
+                        key_pattern="barregexp" created_at="[null]" updated_at="[null]"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/select_only_enable_users.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/select_only_enable_users.xml
new file mode 100644 (file)
index 0000000..1483391
--- /dev/null
@@ -0,0 +1,14 @@
+<dataset>
+
+  <users id="200" login="user1" name="User1" active="[true]"/>
+  <users id="201" login="user2" name="User2" active="[true]"/>
+  <users id="202" login="user3" name="User3" active="[true]"/>
+  <users id="999" login="disabledUser" name="disabledUser" active="[false]"/>
+
+  <perm_templates_users id="1" user_id="200" permission_reference="user" template_id="50"/>
+  <perm_templates_users id="2" user_id="200" permission_reference="admin" template_id="50"/>
+  <perm_templates_users id="3" user_id="200" permission_reference="codeviewer" template_id="50"/>
+
+  <perm_templates_users id="4" user_id="201" permission_reference="user" template_id="50"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions.xml
new file mode 100644 (file)
index 0000000..e886636
--- /dev/null
@@ -0,0 +1,13 @@
+<dataset>
+
+  <users id="200" login="user1" name="User1" active="[true]"/>
+  <users id="201" login="user2" name="User2" active="[true]"/>
+  <users id="202" login="user3" name="User3" active="[true]"/>
+
+  <perm_templates_users id="1" user_id="200" permission_reference="user" template_id="50"/>
+  <perm_templates_users id="2" user_id="200" permission_reference="admin" template_id="50"/>
+  <perm_templates_users id="3" user_id="200" permission_reference="codeviewer" template_id="50"/>
+
+  <perm_templates_users id="4" user_id="201" permission_reference="user" template_id="50"/>
+
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml b/sonar-db/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml
new file mode 100644 (file)
index 0000000..fd8b981
--- /dev/null
@@ -0,0 +1,13 @@
+<dataset>
+
+  <users id="200" login="user3" name="User3" active="[true]"/>
+  <users id="201" login="user1" name="User1" active="[true]"/>
+  <users id="202" login="user2" name="User2" active="[true]"/>
+
+  <perm_templates_users id="1" user_id="200" permission_reference="user" template_id="50"/>
+  <perm_templates_users id="2" user_id="200" permission_reference="admin" template_id="50"/>
+  <perm_templates_users id="3" user_id="200" permission_reference="codeviewer" template_id="50"/>
+
+  <perm_templates_users id="4" user_id="201" permission_reference="user" template_id="50"/>
+
+</dataset>