diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-05-30 13:27:22 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-05-30 13:27:22 +0200 |
commit | a49b0c598c69d3b4b095f5b583368db4b6708282 (patch) | |
tree | 0839df2b1e7ddb411bb93dedf001fbb50a771c5c /sonar-ws-client | |
parent | 6c5dbb1cd3d9cc8775bd057bcac106a32a326332 (diff) | |
download | sonarqube-a49b0c598c69d3b4b095f5b583368db4b6708282.tar.gz sonarqube-a49b0c598c69d3b4b095f5b583368db4b6708282.zip |
SONAR-3755 Add actionPlans in Issues Client WS
Diffstat (limited to 'sonar-ws-client')
6 files changed, 120 insertions, 0 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issue.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issue.java index ff9bad62e2c..7e8ca71744e 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issue.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issue.java @@ -99,6 +99,11 @@ public class Issue { return JsonUtils.getString(json, "assignee"); } + @CheckForNull + public String actionPlan() { + return JsonUtils.getString(json, "actionPlan"); + } + public Date creationDate() { return JsonUtils.getDateTime(json, "creationDate"); } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueJsonParser.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueJsonParser.java index fc1b1fb6ccc..635a624758b 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueJsonParser.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueJsonParser.java @@ -47,6 +47,7 @@ class IssueJsonParser { parseUsers(result, jsonRoot); parseComponents(result, jsonRoot); parseProjects(result, jsonRoot); + parseActionPlans(result, jsonRoot); parsePaging(result, jsonRoot); return result; } @@ -93,6 +94,15 @@ class IssueJsonParser { } } + private void parseActionPlans(Issues result, Map jsonRoot) { + List<Map> jsonRules = (List) jsonRoot.get("actionPlans"); + if (jsonRules != null) { + for (Map jsonRule : jsonRules) { + result.add(new ActionPlan(jsonRule)); + } + } + } + List<String> parseTransitions(String json) { List<String> transitions = new ArrayList<String>(); Map jRoot = (Map) JSONValue.parse(json); diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issues.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issues.java index 9dcd5926c94..ff761f26cdf 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issues.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issues.java @@ -37,6 +37,7 @@ public class Issues { private final Map<String, User> usersByKey = new HashMap<String, User>(); private final Map<String, Component> componentsByKey = new HashMap<String, Component>(); private final Map<String, Component> projectsByKey = new HashMap<String, Component>(); + private final Map<String, ActionPlan> actionPlansByKey = new HashMap<String, ActionPlan>(); private Paging paging; private Boolean maxResultsReached; @@ -83,6 +84,15 @@ public class Issues { return projectsByKey.get(issue.projectKey()); } + public Collection<ActionPlan> actionPlans() { + return actionPlansByKey.values(); + } + + @CheckForNull + public ActionPlan actionPlans(Issue issue) { + return actionPlansByKey.get(issue.actionPlan()); + } + public Paging paging() { return paging; } @@ -106,6 +116,11 @@ public class Issues { return this; } + Issues add(ActionPlan actionPlan) { + actionPlansByKey.put(actionPlan.key(), actionPlan); + return this; + } + Issues addComponent(Component c) { componentsByKey.put(c.key(), c); return this; diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueJsonParserTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueJsonParserTest.java index 82c71f7446d..a33d6093190 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueJsonParserTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueJsonParserTest.java @@ -49,6 +49,7 @@ public class IssueJsonParserTest { assertThat(first.message()).isEqualTo("the message"); assertThat(first.effortToFix()).isEqualTo(4.2); assertThat(first.reporter()).isEqualTo("perceval"); + assertThat(first.actionPlan()).isEqualTo("9450b10c-e725-48b8-bf01-acdec751c491"); assertThat(first.creationDate()).isNotNull(); assertThat(first.updateDate()).isNotNull(); assertThat(first.closeDate()).isNotNull(); @@ -170,4 +171,21 @@ public class IssueJsonParserTest { assertThat(component.name()).isEqualTo("Struts"); assertThat(component.longName()).isEqualTo("org.struts"); } + + @Test + public void should_parse_action_plans() throws Exception { + String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/issue-with-action-plans.json")); + Issues issues = new IssueJsonParser().parseIssues(json); + + assertThat(issues.actionPlans()).hasSize(1); + + ActionPlan actionPlan = issues.actionPlans(issues.list().get(0)); + assertThat(actionPlan.key()).isEqualTo("9450b10c-e725-48b8-bf01-acdec751c491"); + assertThat(actionPlan.name()).isEqualTo("3.6"); + assertThat(actionPlan.status()).isEqualTo("OPEN"); + assertThat(actionPlan.project()).isEqualTo("struts"); + assertThat(actionPlan.deadLine().getTime()).isEqualTo(1369951200000l); + assertThat(actionPlan.createdAt().getTime()).isEqualTo(1369828520000l); + assertThat(actionPlan.updatedAt().getTime()).isEqualTo(1369828520000l); + } } diff --git a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-action-plans.json b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-action-plans.json new file mode 100644 index 00000000000..46718d5b39f --- /dev/null +++ b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-action-plans.json @@ -0,0 +1,71 @@ +{ + "issues": [ + { + "key": "ABCDE", + "component": "struts:Action.java", + "project": "struts", + "rule": "squid:CycleBetweenPackages", + "severity": "CRITICAL", + "status": "OPEN", + "actionPlan": "9450b10c-e725-48b8-bf01-acdec751c491", + "comments": [ + { + "key": "COMMENT-1", + "login": "morgan", + "htmlText": "the first comment", + "createdAt": "2013-05-18T13:45:34+0200" + }, + { + "key": "COMMENT-2", + "login": "arthur", + "htmlText": "the second comment", + "createdAt": "2013-06-19T00:02:03+0100" + } + ] + } + ], + "rules": [ + { + + "key": "squid:CycleBetweenPackages", + "name": "Avoid cycle between java packages", + "desc": "<p>\nWhen several packages are involved in a cycle (package A > package B > package C > package A where \">\" means \"depends upon\"),\nthat means that those packages are highly coupled and that there is no way to reuse/extract one of those packages without importing all the other packages.\nSuch cycle could quickly increase the effort required to maintain an application and to embrace business change.\nSonar not only detect cycles between packages but also determines what is the minimum effort to break those cycles.\nThis rule log a violation on each source file having an outgoing dependency to be but in order to break a cycle.\n</p>\n" + + } + ], + "components": [ + { + "key": "struts:Action.java", + "name": "Action", + "qualifier": "CLA", + "longName": "org.struts.Action" + } + ], + "projects": [ + { + "key": "struts", + "name": "Struts", + "qualifier": "TRK", + "longName": "org.struts" + } + ], + "actionPlans": [ + { + "key": "9450b10c-e725-48b8-bf01-acdec751c491", + "name": "3.6", + "status": "OPEN", + "project": "struts", + "userLogin": "arthur", + "deadLine": "2013-05-31T00:00:00+0200", + "createdAt": "2013-05-29T13:55:20+0200", + "updatedAt": "2013-05-29T13:55:20+0200" + } + ], + "paging": { + "pageIndex": 1, + "pageSize": 100, + "total": 2, + "pages": 1 + }, + "maxResultsReached": false +}
\ No newline at end of file diff --git a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/search.json b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/search.json index 55ff5e79e53..40e1a7ab144 100644 --- a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/search.json +++ b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/search.json @@ -14,6 +14,7 @@ "message": "the message", "title": "the title", "reporter": "perceval", + "actionPlan": "9450b10c-e725-48b8-bf01-acdec751c491", "creationDate": "2013-05-18T12:45:34+0200", "updateDate": "2013-05-18T13:45:34+0200", "closeDate": "2013-05-18T14:45:34+0200", |