]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5785 Add languages to the issues WS response
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 31 Oct 2014 09:46:26 +0000 (10:46 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 31 Oct 2014 10:46:09 +0000 (11:46 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/IssuesWsTest.java

index 4c5b73ce6c1c8ec8720f20c5ae06c191b5bf3451..4853acc9bed3779bf17217810534b4e63834f41c 100644 (file)
@@ -29,6 +29,8 @@ import org.sonar.api.issue.ActionPlan;
 import org.sonar.api.issue.Issue;
 import org.sonar.api.issue.IssueComment;
 import org.sonar.api.issue.internal.DefaultIssueComment;
+import org.sonar.api.resources.Language;
+import org.sonar.api.resources.Languages;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.Severity;
 import org.sonar.api.server.ws.Request;
@@ -90,9 +92,10 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
   private final UserFinder userFinder;
   private final I18n i18n;
   private final Durations durations;
+  private final Languages languages;
 
   public SearchAction(DbClient dbClient, IssueChangeDao issueChangeDao, IssueService service, IssueActionsWriter actionsWriter, IssueQueryService issueQueryService,
-    RuleService ruleService, ActionPlanService actionPlanService, UserFinder userFinder, I18n i18n, Durations durations) {
+    RuleService ruleService, ActionPlanService actionPlanService, UserFinder userFinder, I18n i18n, Durations durations, Languages languages) {
     super(SEARCH_ACTION);
     this.dbClient = dbClient;
     this.issueChangeDao = issueChangeDao;
@@ -104,6 +107,7 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
     this.userFinder = userFinder;
     this.i18n = i18n;
     this.durations = durations;
+    this.languages = languages;
   }
 
   @Override
@@ -315,6 +319,7 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
     writeRules(json, !request.mandatoryParamAsBoolean(IssueFilterParameters.HIDE_RULES) ? ruleService.getByKeys(ruleKeys) : Collections.<Rule>emptyList());
     writeUsers(json, usersByLogin);
     writeActionPlans(json, actionPlanByKeys.values());
+    writeLanguages(json);
 
     // TODO remove legacy paging. Handled by the SearchRequestHandler
     writeLegacyPaging(context, json, result);
@@ -522,6 +527,17 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
     json.endArray();
   }
 
+  private void writeLanguages(JsonWriter json) {
+    json.name("languages").beginArray();
+    for (Language language: languages.all()) {
+      json.beginObject()
+        .prop("key", language.getKey())
+        .prop("name", language.getName())
+        .endObject();
+    }
+    json.endArray();
+  }
+
   private void writeActionPlans(JsonWriter json, Collection<ActionPlan> plans) {
     if (!plans.isEmpty()) {
       json.name("actionPlans").beginArray();
index a83eb86e62a12bbeb2ac2c9b30209ed36e83563e..b27b078c31797df8d2f834776ac784e5a5dffe7c 100644 (file)
@@ -31,6 +31,7 @@ import org.sonar.api.issue.Issue;
 import org.sonar.api.issue.internal.DefaultIssue;
 import org.sonar.api.issue.internal.DefaultIssueComment;
 import org.sonar.api.issue.internal.FieldDiffs;
+import org.sonar.api.resources.Languages;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.server.debt.internal.DefaultDebtCharacteristic;
 import org.sonar.api.user.User;
@@ -143,7 +144,7 @@ public class IssueShowActionTest {
         new IssueActionsWriter(issueService, actionService), actionPlanService, userFinder, debtModel, ruleService, i18n, durations),
       new SearchAction(mock(DbClient.class), mock(IssueChangeDao.class), mock(IssueService.class), mock(IssueActionsWriter.class), mock(IssueQueryService.class),
         mock(RuleService.class),
-        mock(ActionPlanService.class), mock(UserFinder.class), mock(I18n.class), mock(Durations.class))));
+        mock(ActionPlanService.class), mock(UserFinder.class), mock(I18n.class), mock(Durations.class), mock(Languages.class))));
   }
 
   @Test
index ccb9ab999239cd07bb1e27f5952776e7466caf27..ca827954550f34a67dffb26bd5283f206dcd4d57 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.issue.ws;
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.i18n.I18n;
+import org.sonar.api.resources.Languages;
 import org.sonar.api.server.ws.RailsHandler;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.user.UserFinder;
@@ -59,7 +60,7 @@ public class IssuesWsTest {
       debtModelService, mock(RuleService.class), i18n, durations);
     SearchAction searchAction = new SearchAction(mock(DbClient.class), mock(IssueChangeDao.class), mock(IssueService.class), mock(IssueActionsWriter.class),
       mock(IssueQueryService.class), mock(RuleService.class),
-      mock(ActionPlanService.class), mock(UserFinder.class), mock(I18n.class), mock(Durations.class));
+      mock(ActionPlanService.class), mock(UserFinder.class), mock(I18n.class), mock(Durations.class), mock(Languages.class));
     tester = new WsTester(new IssuesWs(showAction, searchAction));
   }