]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8134 remove ComponentFinder from PermissionService
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 20 Oct 2016 17:04:00 +0000 (19:04 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 21 Oct 2016 13:58:39 +0000 (15:58 +0200)
server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.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

index e060991ed80c95c6ba7d41fbb30f282c764bb6e8..7778a8acd58e1f023ba2e478f20efccafb9a6fd9 100644 (file)
@@ -33,12 +33,12 @@ import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ResourceDto;
 import org.sonar.db.permission.PermissionRepository;
 import org.sonar.db.permission.template.PermissionTemplateDto;
-import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.permission.index.PermissionIndexer;
 import org.sonar.server.user.UserSession;
 
 import static java.util.Arrays.asList;
 import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentKey;
+import static org.sonar.server.ws.WsUtils.checkFoundWithOptional;
 
 @ServerSide
 public class PermissionService {
@@ -47,15 +47,12 @@ public class PermissionService {
   private final PermissionRepository permissionRepository;
   private final PermissionIndexer permissionIndexer;
   private final UserSession userSession;
-  private final ComponentFinder componentFinder;
 
-  public PermissionService(DbClient dbClient, PermissionRepository permissionRepository, PermissionIndexer permissionIndexer, UserSession userSession,
-                           ComponentFinder componentFinder) {
+  public PermissionService(DbClient dbClient, PermissionRepository permissionRepository, PermissionIndexer permissionIndexer, UserSession userSession) {
     this.dbClient = dbClient;
     this.permissionRepository = permissionRepository;
     this.permissionIndexer = permissionIndexer;
     this.userSession = userSession;
-    this.componentFinder = componentFinder;
   }
 
   public void applyDefaultPermissionTemplate(String componentKey) {
@@ -73,7 +70,7 @@ public class PermissionService {
    */
   @Deprecated
   public void applyDefaultPermissionTemplate(DbSession session, String componentKey) {
-    ComponentDto component = componentFinder.getByKey(session, componentKey);
+    ComponentDto component = checkFoundWithOptional(dbClient.componentDao().selectByKey(session, componentKey), "Component key '%s' not found", componentKey);
     ResourceDto provisioned = dbClient.resourceDao().selectProvisionedProject(session, componentKey);
     if (provisioned == null) {
       checkProjectAdminUserByComponentKey(userSession, componentKey);
index a9d8adf9e6003137acd731bb579cef41c3505ca3..20cb9cf0cd225a7f2aff3fdeb411a25ab13cf9cf 100644 (file)
@@ -78,8 +78,7 @@ public class ApplyTemplateActionTest extends BasePermissionWsTest<ApplyTemplateA
   @Override
   protected ApplyTemplateAction buildWsAction() {
     PermissionRepository repository = new PermissionRepository(db.getDbClient(), new MapSettings());
-    ComponentFinder componentFinder = new ComponentFinder(db.getDbClient());
-    PermissionService permissionService = new PermissionService(db.getDbClient(), repository, permissionIndexer, userSession, componentFinder);
+    PermissionService permissionService = new PermissionService(db.getDbClient(), repository, permissionIndexer, userSession);
     return new ApplyTemplateAction(db.getDbClient(), userSession, permissionService, newPermissionWsSupport());
   }
 
index 58e3809573ff5b78e0481048046687718e7a8534..5d201f5e1339e1d15a81d2fed904f62c1312c9d8 100644 (file)
@@ -32,7 +32,6 @@ import org.sonar.db.permission.PermissionRepository;
 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;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.i18n.I18nRule;
@@ -62,8 +61,7 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT
   @Override
   protected BulkApplyTemplateAction buildWsAction() {
     PermissionRepository repository = new PermissionRepository(db.getDbClient(), new MapSettings());
-    ComponentFinder componentFinder = new ComponentFinder(db.getDbClient());
-    PermissionService permissionService = new PermissionService(db.getDbClient(), repository, issuePermissionIndexer, userSession, componentFinder);
+    PermissionService permissionService = new PermissionService(db.getDbClient(), repository, issuePermissionIndexer, userSession);
     return new BulkApplyTemplateAction(db.getDbClient(), userSession, permissionService, newPermissionWsSupport(), new I18nRule(), newRootResourceTypes());
   }