]> source.dussan.org Git - sonarqube.git/commitdiff
Add extra fields "reporterName" to /api/issues/search
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 18 Jun 2014 12:35:51 +0000 (14:35 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 18 Jun 2014 12:36:41 +0000 (14:36 +0200)
sonar-server/src/main/java/org/sonar/server/issue/ws/IssueSearchAction.java
sonar-server/src/test/java/org/sonar/server/issue/ws/IssueSearchActionTest.java
sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueSearchActionTest/issues_with_extra_fields.json

index fa4d10a024ba5978b5e7960239bf474087adb348..8ee8705b2759ffb29bb0717f17b58451991a6de0 100644 (file)
@@ -60,6 +60,12 @@ import static com.google.common.collect.Lists.newArrayList;
 
 public class IssueSearchAction implements RequestHandler {
 
+  private static final String ACTIONS_EXTRA_FIELD = "actions";
+  private static final String TRANSITIONS_EXTRA_FIELD = "transitions";
+  private static final String ASSIGNEE_NAME_EXTRA_FIELD = "assigneeName";
+  private static final String REPORTER_NAME_EXTRA_FIELD = "reporterName";
+  private static final String ACTION_PLAN_NAME_EXTRA_FIELD = "actionPlanName";
+
   private static final String EXTRA_FIELDS_PARAM = "extra_fields";
 
   private final IssueFinder issueFinder;
@@ -135,7 +141,7 @@ public class IssueSearchAction implements RequestHandler {
       .setExampleValue("java,js");
     action.createParam(EXTRA_FIELDS_PARAM)
       .setDescription("Add some extra fields on each issue. Available since 4.4")
-      .setPossibleValues("actions", "transitions", "assigneeName", "actionPlanName");
+      .setPossibleValues(ACTIONS_EXTRA_FIELD, TRANSITIONS_EXTRA_FIELD, ASSIGNEE_NAME_EXTRA_FIELD, REPORTER_NAME_EXTRA_FIELD, ACTION_PLAN_NAME_EXTRA_FIELD);
     action.createParam(IssueFilterParameters.CREATED_AT)
       .setDescription("To retrieve issues created at a given date. Format: date or datetime ISO formats")
       .setExampleValue("2013-05-01 (or 2013-05-01T13:00:00+0100)");
@@ -275,21 +281,30 @@ public class IssueSearchAction implements RequestHandler {
 
   private void writeIssueExtraFields(IssueQueryResult result, Issue issue, @Nullable List<String> extraFields, JsonWriter json) {
     if (extraFields != null && UserSession.get().isLoggedIn()) {
-      if (extraFields.contains("actions")) {
+      if (extraFields.contains(ACTIONS_EXTRA_FIELD)) {
         actionsWriter.writeActions(issue, json);
       }
-      if (extraFields.contains("transitions")) {
+
+      if (extraFields.contains(TRANSITIONS_EXTRA_FIELD)) {
         actionsWriter.writeTransitions(issue, json);
       }
+
       String assignee = issue.assignee();
-      if (extraFields.contains("assigneeName") && assignee != null) {
+      if (extraFields.contains(ASSIGNEE_NAME_EXTRA_FIELD) && assignee != null) {
         User user = result.user(assignee);
-        json.prop("assigneeName", user != null ? user.name() : null);
+        json.prop(ASSIGNEE_NAME_EXTRA_FIELD, user != null ? user.name() : null);
       }
+
+      String reporter = issue.reporter();
+      if (extraFields.contains(REPORTER_NAME_EXTRA_FIELD) && reporter != null) {
+        User user = result.user(reporter);
+        json.prop(REPORTER_NAME_EXTRA_FIELD, user != null ? user.name() : null);
+      }
+
       String actionPlanKey = issue.actionPlanKey();
-      if (extraFields.contains("actionPlanName") && actionPlanKey != null) {
+      if (extraFields.contains(ACTION_PLAN_NAME_EXTRA_FIELD) && actionPlanKey != null) {
         ActionPlan actionPlan = result.actionPlan(issue);
-        json.prop("actionPlanName", actionPlan != null ? actionPlan.name() : null);
+        json.prop(ACTION_PLAN_NAME_EXTRA_FIELD, actionPlan != null ? actionPlan.name() : null);
       }
     }
   }
index 0b2776a4b0847f38af4747392468537974ce68c3..a1b56acdfd1b9b8b2f8e33e845d7355534f385de 100644 (file)
@@ -237,7 +237,8 @@ public class IssueSearchActionTest {
   public void issues_with_extra_fields() throws Exception {
     Issue issue = createIssue()
       .setActionPlanKey("AP-ABCD")
-      .setAssignee("john");
+      .setAssignee("john")
+      .setReporter("henry");
     issues.add(issue);
 
     MockUserSession.set().setLogin("john");
@@ -246,10 +247,11 @@ public class IssueSearchActionTest {
     result.addActionPlans(newArrayList((ActionPlan) new DefaultActionPlan().setKey("AP-ABCD").setName("1.0")));
 
     result.addUsers(Lists.<User>newArrayList(
-      new DefaultUser().setName("John").setLogin("john")
+      new DefaultUser().setName("John").setLogin("john"),
+      new DefaultUser().setName("Henry").setLogin("henry")
     ));
 
-    WsTester.TestRequest request = tester.newGetRequest("api/issues", "search").setParam("extra_fields", "actions,transitions,assigneeName,actionPlanName");
+    WsTester.TestRequest request = tester.newGetRequest("api/issues", "search").setParam("extra_fields", "actions,transitions,assigneeName,reporterName,actionPlanName");
     request.execute().assertJson(getClass(), "issues_with_extra_fields.json");
   }
 
index 2954b381c70590d495695cc9056a3338aeaa58c9..3d610a334bb607d9f5c22b0bbe6206eb2ee58b51 100644 (file)
@@ -16,6 +16,8 @@
       "creationDate": "2014-01-22T19:10:03+0100",
       "assignee": "john",
       "assigneeName": "John",
+      "reporter": "henry",
+      "reporterName": "Henry",
       "actionPlan": "AP-ABCD",
       "actionPlanName": "1.0",
       "actions": [
   "projects": [],
   "rules": [],
   "users": [
+    {
+      "login": "henry",
+      "name": "Henry",
+      "active": false
+    },
     {
       "login": "john",
       "name": "John",