diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-06-18 14:35:51 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-06-18 14:36:41 +0200 |
commit | fad234f996df211ae5d12f8dc3af0893b0ca9ffe (patch) | |
tree | d7d8bb5fedf43fb16874587709679f7337f7af8e | |
parent | 8a9bf0e1541175c1505237a49636efa0bcd88f6a (diff) | |
download | sonarqube-fad234f996df211ae5d12f8dc3af0893b0ca9ffe.tar.gz sonarqube-fad234f996df211ae5d12f8dc3af0893b0ca9ffe.zip |
Add extra fields "reporterName" to /api/issues/search
3 files changed, 34 insertions, 10 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueSearchAction.java b/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueSearchAction.java index fa4d10a024b..8ee8705b275 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueSearchAction.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueSearchAction.java @@ -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); } } } diff --git a/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueSearchActionTest.java b/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueSearchActionTest.java index 0b2776a4b08..a1b56acdfd1 100644 --- a/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueSearchActionTest.java +++ b/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueSearchActionTest.java @@ -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"); } diff --git a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueSearchActionTest/issues_with_extra_fields.json b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueSearchActionTest/issues_with_extra_fields.json index 2954b381c70..3d610a334bb 100644 --- a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueSearchActionTest/issues_with_extra_fields.json +++ b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueSearchActionTest/issues_with_extra_fields.json @@ -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": [ @@ -31,6 +33,11 @@ "rules": [], "users": [ { + "login": "henry", + "name": "Henry", + "active": false + }, + { "login": "john", "name": "John", "active": false |