]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18214 Add documentation url to api/navigation/global
authorEric Giffon <eric.giffon@sonarsource.com>
Fri, 3 Mar 2023 10:54:13 +0000 (11:54 +0100)
committersonartech <sonartech@sonarsource.com>
Mon, 6 Mar 2023 20:03:37 +0000 (20:03 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java

index c0a32151fdd01b4d405e14cca8c3b00fee56bc4a..a4fd924769eaab4da12fcf40acf2ccc44ab3e274 100644 (file)
@@ -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));
+  }
 }
index a1619ee69fd3b9b7a966625869aeced2c5afea1e..d4fe234374145d27c279ea3756245ea02601e93b 100644 (file)
@@ -27,5 +27,6 @@
   "productionDatabase": true,
   "canAdmin": false,
   "standalone": true,
-  "edition": "community"
+  "edition": "community",
+  "documentationUrl": "http://docs.example.com/10.0"
 }
index c59d03af371d6790921f4ba7d7e8a32b82c731d7..58926e4b783e80055cc7d7b0ffc65b9f503bf2c6 100644 (file)
@@ -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();
   }