aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-09-05 18:17:37 +0200
committerStas Vilchik <stas.vilchik@sonarsource.com>2017-09-11 11:28:29 +0200
commitb6a2847855ffd7d2c499639473336b65a73e2c51 (patch)
tree0f67cbf8f6aae34fada99d363105ca3cdfa64d53
parent2f84511c91478521a45a606cd13a703ff4de08f4 (diff)
downloadsonarqube-b6a2847855ffd7d2c499639473336b65a73e2c51.tar.gz
sonarqube-b6a2847855ffd7d2c499639473336b65a73e2c51.zip
SONAR-9181 ProjectWsSupport has dependency on DefaultOrganizationProvider
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/project/ws/CreateAction.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java14
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/project/ws/ProvisionedAction.java9
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/project/ws/SearchAction.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/project/ws/CreateActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java3
9 files changed, 25 insertions, 33 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/project/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/project/ws/CreateAction.java
index 76e31ce5077..90f4ffd2e8c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/project/ws/CreateAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/project/ws/CreateAction.java
@@ -28,13 +28,11 @@ import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.component.ComponentUpdater;
-import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.project.Visibility;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.WsProjects.CreateWsResponse;
import org.sonarqube.ws.client.project.CreateRequest;
-import static java.util.Optional.ofNullable;
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.db.permission.OrganizationPermission.PROVISION_PROJECTS;
import static org.sonar.server.component.NewComponent.newComponentBuilder;
@@ -55,15 +53,12 @@ public class CreateAction implements ProjectsWsAction {
private final DbClient dbClient;
private final UserSession userSession;
private final ComponentUpdater componentUpdater;
- private final DefaultOrganizationProvider defaultOrganizationProvider;
- public CreateAction(ProjectsWsSupport support, DbClient dbClient, UserSession userSession, ComponentUpdater componentUpdater,
- DefaultOrganizationProvider defaultOrganizationProvider) {
+ public CreateAction(ProjectsWsSupport support, DbClient dbClient, UserSession userSession, ComponentUpdater componentUpdater) {
this.support = support;
this.dbClient = dbClient;
this.userSession = userSession;
this.componentUpdater = componentUpdater;
- this.defaultOrganizationProvider = defaultOrganizationProvider;
}
@Override
@@ -114,8 +109,7 @@ public class CreateAction implements ProjectsWsAction {
private CreateWsResponse doHandle(CreateRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
- OrganizationDto organization = support.getOrganization(dbSession, ofNullable(request.getOrganization())
- .orElseGet(defaultOrganizationProvider.get()::getKey));
+ OrganizationDto organization = support.getOrganization(dbSession, request.getOrganization());
userSession.checkPermission(PROVISION_PROJECTS, organization);
String visibility = request.getVisibility();
Boolean changeToPrivate = visibility == null ? dbClient.organizationDao().getNewProjectPrivate(dbSession, organization) : "private".equals(visibility);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java b/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java
index 3a044b3d43e..5a3debb07b6 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProjectsWsSupport.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.project.ws;
+import javax.annotation.Nullable;
import org.sonar.api.server.ServerSide;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
@@ -26,6 +27,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.organization.BillingValidations;
import org.sonar.server.organization.BillingValidationsProxy;
+import org.sonar.server.organization.DefaultOrganizationProvider;
import static org.sonar.server.ws.WsUtils.checkFoundWithOptional;
@@ -34,11 +36,12 @@ public class ProjectsWsSupport {
public static final String PARAM_ORGANIZATION = "organization";
private final DbClient dbClient;
-
+ private final DefaultOrganizationProvider organizationProvider;
private final BillingValidationsProxy billingValidations;
- public ProjectsWsSupport(DbClient dbClient, BillingValidationsProxy billingValidations) {
+ public ProjectsWsSupport(DbClient dbClient, DefaultOrganizationProvider organizationProvider, BillingValidationsProxy billingValidations) {
this.dbClient = dbClient;
+ this.organizationProvider = organizationProvider;
this.billingValidations = billingValidations;
}
@@ -50,10 +53,11 @@ public class ProjectsWsSupport {
.setSince("6.3");
}
- OrganizationDto getOrganization(DbSession dbSession, String organizationKey) {
+ OrganizationDto getOrganization(DbSession dbSession, @Nullable String organizationKeyParam) {
+ String organizationKey = organizationKeyParam == null ? organizationProvider.get().getKey() : organizationKeyParam;
return checkFoundWithOptional(
- dbClient.organizationDao().selectByKey(dbSession, organizationKey),
- "No organization for key '%s'", organizationKey);
+ dbClient.organizationDao().selectByKey(dbSession, organizationKey),
+ "No organization for key '%s'", organizationKey);
}
void checkCanUpdateProjectsVisibility(OrganizationDto organization, boolean newProjectsPrivate) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProvisionedAction.java b/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProvisionedAction.java
index f4fafb04bc1..a19e83f044f 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProvisionedAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/project/ws/ProvisionedAction.java
@@ -37,7 +37,6 @@ import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentQuery;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.Common.Paging;
import org.sonarqube.ws.WsComponents.ProvisionedWsResponse;
@@ -57,19 +56,16 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf;
public class ProvisionedAction implements ProjectsWsAction {
- private static final Set<String> QUALIFIERS_FILTER = newHashSet(Qualifiers.PROJECT);
private static final Set<String> POSSIBLE_FIELDS = newHashSet("uuid", "key", "name", "creationDate", "visibility");
private final ProjectsWsSupport support;
private final DbClient dbClient;
private final UserSession userSession;
- private final DefaultOrganizationProvider defaultOrganizationProvider;
- public ProvisionedAction(ProjectsWsSupport support, DbClient dbClient, UserSession userSession, DefaultOrganizationProvider defaultOrganizationProvider) {
+ public ProvisionedAction(ProjectsWsSupport support, DbClient dbClient, UserSession userSession) {
this.support = support;
this.dbClient = dbClient;
this.userSession = userSession;
- this.defaultOrganizationProvider = defaultOrganizationProvider;
}
@Override
@@ -105,8 +101,7 @@ public class ProvisionedAction implements ProjectsWsAction {
String query = request.param(Param.TEXT_QUERY);
try (DbSession dbSession = dbClient.openSession(false)) {
- OrganizationDto organization = support.getOrganization(dbSession,
- request.getParam(PARAM_ORGANIZATION).or(defaultOrganizationProvider.get()::getKey));
+ OrganizationDto organization = support.getOrganization(dbSession, request.param(PARAM_ORGANIZATION));
userSession.checkPermission(PROVISION_PROJECTS, organization);
ComponentQuery dbQuery = buildDbQuery(query);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/project/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/project/ws/SearchAction.java
index ecbf987db9e..7cfd3cb87ee 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/project/ws/SearchAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/project/ws/SearchAction.java
@@ -37,14 +37,12 @@ import org.sonar.db.component.ComponentQuery;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
-import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.project.Visibility;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.WsProjects.SearchWsResponse;
import org.sonarqube.ws.client.project.SearchWsRequest;
import static com.google.common.base.Preconditions.checkArgument;
-import static java.util.Optional.ofNullable;
import static org.sonar.api.resources.Qualifiers.APP;
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.api.resources.Qualifiers.VIEW;
@@ -74,13 +72,11 @@ public class SearchAction implements ProjectsWsAction {
private final DbClient dbClient;
private final UserSession userSession;
- private final DefaultOrganizationProvider defaultOrganizationProvider;
private final ProjectsWsSupport support;
- public SearchAction(DbClient dbClient, UserSession userSession, DefaultOrganizationProvider defaultOrganizationProvider, ProjectsWsSupport support) {
+ public SearchAction(DbClient dbClient, UserSession userSession, ProjectsWsSupport support) {
this.dbClient = dbClient;
this.userSession = userSession;
- this.defaultOrganizationProvider = defaultOrganizationProvider;
this.support = support;
}
@@ -167,7 +163,7 @@ public class SearchAction implements ProjectsWsAction {
private SearchWsResponse doHandle(SearchWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
- OrganizationDto organization = support.getOrganization(dbSession, ofNullable(request.getOrganization()).orElseGet(defaultOrganizationProvider.get()::getKey));
+ OrganizationDto organization = support.getOrganization(dbSession, request.getOrganization());
userSession.checkPermission(OrganizationPermission.ADMINISTER, organization);
ComponentQuery query = buildDbQuery(request);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java
index 0ca7c7f2886..5982f45f5b0 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java
@@ -34,6 +34,7 @@ import org.sonar.server.component.ComponentCleanerService;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.organization.BillingValidationsProxy;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
@@ -61,7 +62,8 @@ public class BulkDeleteActionTest {
private ComponentCleanerService componentCleanerService = mock(ComponentCleanerService.class);
private WsTester ws;
private DbClient dbClient = db.getDbClient();
- private BulkDeleteAction underTest = new BulkDeleteAction(componentCleanerService, dbClient, userSession, new ProjectsWsSupport(dbClient, mock(BillingValidationsProxy.class)));
+ private ProjectsWsSupport support = new ProjectsWsSupport(dbClient, TestDefaultOrganizationProvider.from(db), mock(BillingValidationsProxy.class));
+ private BulkDeleteAction underTest = new BulkDeleteAction(componentCleanerService, dbClient, userSession, support);
private OrganizationDto org1;
private OrganizationDto org2;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/CreateActionTest.java
index c9d7e3013e4..d8e17c542f8 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/CreateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/CreateActionTest.java
@@ -85,11 +85,11 @@ public class CreateActionTest {
private TestProjectIndexers projectIndexers = new TestProjectIndexers();
private WsActionTester ws = new WsActionTester(
new CreateAction(
- new ProjectsWsSupport(db.getDbClient(), billingValidations),
+ new ProjectsWsSupport(db.getDbClient(), defaultOrganizationProvider, billingValidations),
db.getDbClient(), userSession,
new ComponentUpdater(db.getDbClient(), i18n, system2, mock(PermissionTemplateService.class), new FavoriteUpdater(db.getDbClient()),
- projectIndexers),
- defaultOrganizationProvider));
+ projectIndexers)
+ ));
@Test
public void create_project() throws Exception {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java
index 218e0912cd8..269a85ba068 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java
@@ -66,7 +66,7 @@ public class ProvisionedActionTest {
private DbClient dbClient = db.getDbClient();
private WsActionTester ws = new WsActionTester(
- new ProvisionedAction(new ProjectsWsSupport(dbClient, mock(BillingValidationsProxy.class)), dbClient, userSessionRule, defaultOrganizationProvider));
+ new ProvisionedAction(new ProjectsWsSupport(dbClient, defaultOrganizationProvider, mock(BillingValidationsProxy.class)), dbClient, userSessionRule));
@Test
public void definition() {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchActionTest.java
index 40cf88ca7c1..799bd1ef68a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchActionTest.java
@@ -94,7 +94,7 @@ public class SearchActionTest {
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
private WsActionTester ws = new WsActionTester(
- new SearchAction(db.getDbClient(), userSession, defaultOrganizationProvider, new ProjectsWsSupport(db.getDbClient(), mock(BillingValidationsProxy.class))));
+ new SearchAction(db.getDbClient(), userSession, new ProjectsWsSupport(db.getDbClient(), defaultOrganizationProvider, mock(BillingValidationsProxy.class))));
@Test
public void search_by_key_query_with_partial_match_case_insensitive() throws IOException {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java
index 3621957098b..da79a2b05e1 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java
@@ -53,6 +53,7 @@ import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.organization.BillingValidations;
import org.sonar.server.organization.BillingValidationsProxy;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.permission.index.FooIndexDefinition;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
@@ -94,7 +95,7 @@ public class UpdateVisibilityActionTest {
private TestProjectIndexers projectIndexers = new TestProjectIndexers();
private BillingValidationsProxy billingValidations = mock(BillingValidationsProxy.class);
- private ProjectsWsSupport wsSupport = new ProjectsWsSupport(dbClient, billingValidations);
+ private ProjectsWsSupport wsSupport = new ProjectsWsSupport(dbClient, TestDefaultOrganizationProvider.from(dbTester), billingValidations);
private UpdateVisibilityAction underTest = new UpdateVisibilityAction(dbClient, TestComponentFinder.from(dbTester), userSessionRule, projectIndexers, wsSupport);
private WsActionTester actionTester = new WsActionTester(underTest);