diff options
author | BenoƮt Gianinetti <benoit.gianinetti@sonarsource.com> | 2019-06-28 09:46:59 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-07-05 20:21:13 +0200 |
commit | c2ee935557c8cc2dd34c48761cc8eafbe75b50dc (patch) | |
tree | 60ac938a107a8aa0fface6df167b49461a51fcbd /server/sonar-server | |
parent | 31d3e86b6a6e0589017c6597e4b0f9ffc3939019 (diff) | |
download | sonarqube-c2ee935557c8cc2dd34c48761cc8eafbe75b50dc.tar.gz sonarqube-c2ee935557c8cc2dd34c48761cc8eafbe75b50dc.zip |
SC-764 Return alm organization type in /api/organizations/search
Diffstat (limited to 'server/sonar-server')
-rw-r--r-- | server/sonar-server/src/main/java/org/sonar/server/organization/ws/SearchAction.java | 24 | ||||
-rw-r--r-- | server/sonar-server/src/test/java/org/sonar/server/organization/ws/SearchActionTest.java | 1 |
2 files changed, 19 insertions, 6 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/SearchAction.java index d19e3ae109b..96df687d0ea 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/SearchAction.java @@ -32,6 +32,7 @@ import org.sonar.api.server.ws.WebService.Param; import org.sonar.core.util.stream.MoreCollectors; 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.organization.OrganizationDto; import org.sonar.db.organization.OrganizationQuery; @@ -110,9 +111,11 @@ public class SearchAction implements OrganizationsWsAction { Set<String> provisionOrganizationUuids = searchOrganizationWithProvisionPermission(dbSession); Map<String, OrganizationAlmBindingDto> organizationAlmBindingByOrgUuid = dbClient.organizationAlmBindingDao().selectByOrganizations(dbSession, organizations) .stream().collect(MoreCollectors.uniqueIndex(OrganizationAlmBindingDto::getOrganizationUuid)); + Map<String, AlmAppInstallDto> almAppInstallDtoByUuid = dbClient.almAppInstallDao().selectByOrganizations(dbSession, organizations) + .stream().collect(MoreCollectors.uniqueIndex(AlmAppInstallDto::getUuid)); Organizations.SearchWsResponse wsResponse = buildOrganizations(organizations, adminOrganizationUuids, provisionOrganizationUuids, organizationAlmBindingByOrgUuid, - onlyMembershipOrganizations, paging); + almAppInstallDtoByUuid, onlyMembershipOrganizations, paging); writeProtobuf(wsResponse, request, response); } } @@ -137,7 +140,8 @@ public class SearchAction implements OrganizationsWsAction { } private Organizations.SearchWsResponse buildOrganizations(List<OrganizationDto> organizations, Set<String> adminOrganizationUuids, Set<String> provisionOrganizationUuids, - Map<String, OrganizationAlmBindingDto> organizationAlmBindingByOrgUuid, boolean onlyMembershipOrganizations, Paging paging) { + Map<String, OrganizationAlmBindingDto> organizationAlmBindingByOrgUuid, Map<String, AlmAppInstallDto> almAppInstallDtoByUuid, boolean onlyMembershipOrganizations, + Paging paging) { Organizations.SearchWsResponse.Builder response = Organizations.SearchWsResponse.newBuilder(); response.setPaging(paging); Organization.Builder wsOrganization = Organization.newBuilder(); @@ -150,13 +154,17 @@ public class SearchAction implements OrganizationsWsAction { .setAdmin(isAdmin) .setProvision(canProvision) .setDelete(isAdmin)); - response.addOrganizations(toOrganization(wsOrganization, o, organizationAlmBindingByOrgUuid.get(o.getUuid()), onlyMembershipOrganizations)); + OrganizationAlmBindingDto organizationAlmBinding = organizationAlmBindingByOrgUuid.get(o.getUuid()); + AlmAppInstallDto almAppinstall = organizationAlmBinding == null + ? null + : almAppInstallDtoByUuid.get(organizationAlmBinding.getAlmAppInstallUuid()); + response.addOrganizations(toOrganization(wsOrganization, o, organizationAlmBinding, almAppinstall, onlyMembershipOrganizations)); }); return response.build(); } private static Organization.Builder toOrganization(Organization.Builder builder, OrganizationDto organization, @Nullable OrganizationAlmBindingDto organizationAlmBinding, - boolean onlyMembershipOrganizations) { + @Nullable AlmAppInstallDto almAppInstallDto, boolean onlyMembershipOrganizations) { builder .setName(organization.getName()) .setKey(organization.getKey()); @@ -164,9 +172,13 @@ public class SearchAction implements OrganizationsWsAction { ofNullable(organization.getUrl()).ifPresent(builder::setUrl); ofNullable(organization.getAvatarUrl()).ifPresent(builder::setAvatar); if (onlyMembershipOrganizations && organizationAlmBinding != null) { - builder.setAlm(Organization.Alm.newBuilder() + Organization.Alm.Builder almBuilder = Organization.Alm.newBuilder() .setKey(organizationAlmBinding.getAlm().getId()) - .setUrl(organizationAlmBinding.getUrl())); + .setUrl(organizationAlmBinding.getUrl()); + if (almAppInstallDto != null) { + almBuilder.setPersonal(almAppInstallDto.isOwnerUser()); + } + builder.setAlm(almBuilder.build()); } if (onlyMembershipOrganizations) { builder.setSubscription(Organizations.Subscription.valueOf(organization.getSubscription().name())); diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/SearchActionTest.java index b190cb30202..7f141946b7a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/SearchActionTest.java @@ -272,6 +272,7 @@ public class SearchActionTest { Map<String, Organization> orgByKey = result.getOrganizationsList().stream().collect(toMap(Organization::getKey, identity())); assertThat(orgByKey.get(organization.getKey()).getAlm().getKey()).isEqualTo(organizationAlmBinding.getAlm().getId()); assertThat(orgByKey.get(organization.getKey()).getAlm().getUrl()).isEqualTo(organizationAlmBinding.getUrl()); + assertThat(orgByKey.get(organization.getKey()).getAlm().getPersonal()).isEqualTo(almAppInstall.isOwnerUser()); assertThat(orgByKey.get(organizationNotBoundToAlm.getKey()).hasAlm()).isEqualTo(false); } |