diff options
author | BenoƮt Gianinetti <benoit.gianinetti@sonarsource.com> | 2019-06-27 15:05:45 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-07-05 20:21:13 +0200 |
commit | 31d3e86b6a6e0589017c6597e4b0f9ffc3939019 (patch) | |
tree | 1df18f02065bbc34ca9c9a2b7b23789184815c21 /server/sonar-server | |
parent | 3d4b6b483f8bfccf322f53f61e995ef72f3ca7e4 (diff) | |
download | sonarqube-31d3e86b6a6e0589017c6597e4b0f9ffc3939019.tar.gz sonarqube-31d3e86b6a6e0589017c6597e4b0f9ffc3939019.zip |
SC-764 Return alm ogranization type in /api/navigation/organization
Diffstat (limited to 'server/sonar-server')
-rw-r--r-- | server/sonar-server/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java | 48 | ||||
-rw-r--r-- | server/sonar-server/src/test/java/org/sonar/server/ui/ws/OrganizationActionTest.java | 3 |
2 files changed, 37 insertions, 14 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java index e2d3b0a9080..19d4b8a9a19 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java @@ -19,8 +19,10 @@ */ package org.sonar.server.ui.ws; +import com.google.common.base.Preconditions; import java.util.List; import java.util.Optional; +import javax.annotation.Nullable; import org.sonar.api.resources.Qualifiers; import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.Request; @@ -30,6 +32,7 @@ import org.sonar.api.utils.text.JsonWriter; import org.sonar.api.web.page.Page; import org.sonar.db.DbClient; import org.sonar.db.DbSession; +import org.sonar.db.alm.AlmAppInstallDto; import org.sonar.db.alm.OrganizationAlmBindingDto; import org.sonar.db.component.ComponentQuery; import org.sonar.db.organization.OrganizationDto; @@ -100,16 +103,26 @@ public class OrganizationAction implements NavigationWsAction { } } boolean newProjectPrivate = dbClient.organizationDao().getNewProjectPrivate(dbSession, organization); + Optional<OrganizationAlmBindingDto> optOrganizationAlmBinding = dbClient.organizationAlmBindingDao().selectByOrganization(dbSession, organization); JsonWriter json = response.newJsonWriter(); json.beginObject(); - writeOrganization(json, organization, dbClient.organizationAlmBindingDao().selectByOrganization(dbSession, organization), newProjectPrivate); + if (optOrganizationAlmBinding.isPresent()) { + OrganizationAlmBindingDto organizationAlmBinding = optOrganizationAlmBinding.get(); + Optional<AlmAppInstallDto> almAppInstall = dbClient.almAppInstallDao().selectByUuid(dbSession, organizationAlmBinding.getAlmAppInstallUuid()); + Preconditions.checkState(almAppInstall.isPresent(), "Failed to get ALM information for organization '{}': '{}' application is not installed.", + organization.getName(), organizationAlmBinding.getAlm().getId()); + writeOrganization(json, organization, newProjectPrivate, organizationAlmBinding, almAppInstall.get()); + } else { + writeOrganization(json, organization, newProjectPrivate, null, null); + } json.endObject() .close(); } } - private void writeOrganization(JsonWriter json, OrganizationDto organization, Optional<OrganizationAlmBindingDto> organizationAlmBinding, boolean newProjectPrivate) { + private void writeOrganization(JsonWriter json, OrganizationDto organization, boolean newProjectPrivate, @Nullable OrganizationAlmBindingDto organizationAlmBinding, + @Nullable AlmAppInstallDto almAppInstall) { json.name("organization") .beginObject() .prop("isDefault", organization.getKey().equals(defaultOrganizationProvider.get().getKey())) @@ -118,7 +131,26 @@ public class OrganizationAction implements NavigationWsAction { .prop("canUpdateProjectsVisibilityToPrivate", userSession.hasPermission(ADMINISTER, organization) && billingValidations.canUpdateProjectVisibilityToPrivate(new BillingValidations.Organization(organization.getKey(), organization.getUuid(), organization.getName()))); - writeAlm(json, organizationAlmBinding); + + if (organizationAlmBinding != null && almAppInstall != null) { + writeAlm(json, organizationAlmBinding, almAppInstall); + } + + writeOrganizationPages(json, organization); + } + + private static void writeAlm(JsonWriter json, OrganizationAlmBindingDto organizationAlmBinding, AlmAppInstallDto almAppInstall) { + json + .name("alm") + .beginObject() + .prop("key", organizationAlmBinding.getAlm().getId()) + .prop("url", organizationAlmBinding.getUrl()) + .prop("membersSync", organizationAlmBinding.isMembersSyncEnable()) + .prop("personal", almAppInstall.isOwnerUser()) + .endObject(); + } + + private void writeOrganizationPages(JsonWriter json, OrganizationDto organization) { json.name("pages"); writePages(json, pageRepository.getOrganizationPages(false)); if (userSession.hasPermission(ADMINISTER, organization)) { @@ -137,14 +169,4 @@ public class OrganizationAction implements NavigationWsAction { json.endArray(); } - private static void writeAlm(JsonWriter json, Optional<OrganizationAlmBindingDto> organizationAlmBindingOpt) { - organizationAlmBindingOpt.ifPresent( - organizationAlmBinding -> json - .name("alm") - .beginObject() - .prop("key", organizationAlmBinding.getAlm().getId()) - .prop("url", organizationAlmBinding.getUrl()) - .prop("membersSync", organizationAlmBinding.isMembersSyncEnable()) - .endObject()); - } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/OrganizationActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/OrganizationActionTest.java index 29fa073a563..7d2e3f9905a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/OrganizationActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/OrganizationActionTest.java @@ -194,7 +194,8 @@ public class OrganizationActionTest { " \"alm\": {" + " \"key\": \"" + organizationAlmBinding.getAlm().getId() + "\"," + " \"url\": \"" + organizationAlmBinding.getUrl() + "\"," + - " \"membersSync\": " + organizationAlmBinding.isMembersSyncEnable() + + " \"membersSync\": " + organizationAlmBinding.isMembersSyncEnable() + "," + + " \"personal\": " + almAppInstall.isOwnerUser() + " }" + " }" + "}"); |