From: Eric Giffon Date: Fri, 3 Mar 2023 10:54:13 +0000 (+0100) Subject: SONAR-18214 Add documentation url to api/navigation/global X-Git-Tag: 10.0.0.68432~172 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=54ff9dc3689b20f76bb3d241a510ceaceb7955be;p=sonarqube.git SONAR-18214 Add documentation url to api/navigation/global --- diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java index c0a32151fdd..a4fd924769e 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java @@ -33,6 +33,7 @@ import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService.NewController; import org.sonar.api.utils.text.JsonWriter; import org.sonar.api.web.page.Page; +import org.sonar.core.documentation.DocumentationLinkGenerator; import org.sonar.core.platform.PlatformEditionProvider; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -76,11 +77,12 @@ public class GlobalAction implements NavigationWsAction, Startable { private final WebAnalyticsLoader webAnalyticsLoader; private final IssueIndexSyncProgressChecker issueIndexSyncChecker; private final DefaultAdminCredentialsVerifier defaultAdminCredentialsVerifier; + private final DocumentationLinkGenerator documentationLinkGenerator; public GlobalAction(PageRepository pageRepository, Configuration config, ResourceTypes resourceTypes, Server server, - NodeInformation nodeInformation, DbClient dbClient, UserSession userSession, PlatformEditionProvider editionProvider, - WebAnalyticsLoader webAnalyticsLoader, IssueIndexSyncProgressChecker issueIndexSyncChecker, - DefaultAdminCredentialsVerifier defaultAdminCredentialsVerifier) { + NodeInformation nodeInformation, DbClient dbClient, UserSession userSession, PlatformEditionProvider editionProvider, + WebAnalyticsLoader webAnalyticsLoader, IssueIndexSyncProgressChecker issueIndexSyncChecker, + DefaultAdminCredentialsVerifier defaultAdminCredentialsVerifier, DocumentationLinkGenerator documentationLinkGenerator) { this.pageRepository = pageRepository; this.config = config; this.resourceTypes = resourceTypes; @@ -93,6 +95,7 @@ public class GlobalAction implements NavigationWsAction, Startable { this.systemSettingValuesByKey = new HashMap<>(); this.issueIndexSyncChecker = issueIndexSyncChecker; this.defaultAdminCredentialsVerifier = defaultAdminCredentialsVerifier; + this.documentationLinkGenerator = documentationLinkGenerator; } @Override @@ -131,6 +134,7 @@ public class GlobalAction implements NavigationWsAction, Startable { writeNeedIssueSync(json); json.prop("standalone", nodeInformation.isStandalone()); writeWebAnalytics(json); + writeDocumentationUrl(json); json.endObject(); } } @@ -194,4 +198,8 @@ public class GlobalAction implements NavigationWsAction, Startable { private void writeWebAnalytics(JsonWriter json) { webAnalyticsLoader.getUrlPathToJs().ifPresent(p -> json.prop("webAnalyticsJsPath", p)); } + + private void writeDocumentationUrl(JsonWriter json) { + json.prop("documentationUrl", documentationLinkGenerator.getDocumentationLink(null)); + } } diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json index a1619ee69fd..d4fe2343741 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json @@ -27,5 +27,6 @@ "productionDatabase": true, "canAdmin": false, "standalone": true, - "edition": "community" + "edition": "community", + "documentationUrl": "http://docs.example.com/10.0" } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java index c59d03af371..58926e4b783 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java @@ -29,6 +29,7 @@ import org.sonar.api.resources.ResourceTypeTree; import org.sonar.api.resources.ResourceTypes; import org.sonar.api.web.page.Page; import org.sonar.api.web.page.PageDefinition; +import org.sonar.core.documentation.DocumentationLinkGenerator; import org.sonar.core.extension.CoreExtensionRepository; import org.sonar.core.platform.EditionProvider; import org.sonar.core.platform.PlatformEditionProvider; @@ -68,6 +69,7 @@ public class GlobalActionTest { private final PlatformEditionProvider editionProvider = mock(PlatformEditionProvider.class); private final WebAnalyticsLoader webAnalyticsLoader = mock(WebAnalyticsLoader.class); private final DefaultAdminCredentialsVerifier defaultAdminCredentialsVerifier = mock(DefaultAdminCredentialsVerifier.class); + private final DocumentationLinkGenerator documentationLinkGenerator = mock(DocumentationLinkGenerator.class); private WsActionTester ws; @@ -282,6 +284,7 @@ public class GlobalActionTest { when(dbClient.getDatabase().getDialect()).thenReturn(new PostgreSql()); when(nodeInformation.isStandalone()).thenReturn(true); when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.COMMUNITY)); + when(documentationLinkGenerator.getDocumentationLink(null)).thenReturn("http://docs.example.com/10.0"); String result = call(); assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString()); @@ -324,6 +327,16 @@ public class GlobalActionTest { assertJson(json).isSimilarTo("{\"webAnalyticsJsPath\":\"" + path + "\"}"); } + @Test + public void call_shouldReturnDocumentationUrl() { + init(); + String url = "https://docs.sonarqube.org/10.0"; + when(documentationLinkGenerator.getDocumentationLink(null)).thenReturn(url); + + String json = call(); + assertJson(json).isSimilarTo("{\"documentationUrl\":\"" + url + "\"}"); + } + private void init() { init(new org.sonar.api.web.page.Page[] {}, new ResourceTypeTree[] {}); } @@ -344,7 +357,7 @@ public class GlobalActionTest { pageRepository.start(); GlobalAction wsAction = new GlobalAction(pageRepository, settings.asConfig(), new ResourceTypes(resourceTypeTrees), server, nodeInformation, dbClient, userSession, editionProvider, webAnalyticsLoader, - indexSyncProgressChecker, defaultAdminCredentialsVerifier); + indexSyncProgressChecker, defaultAdminCredentialsVerifier, documentationLinkGenerator); ws = new WsActionTester(wsAction); wsAction.start(); }