aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2013-10-31 12:17:12 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2013-10-31 12:17:22 +0100
commitd5de65e30715c1da5f3b55d264d8014e2a582092 (patch)
tree504c3f43f7ebf046f22ebe7db88a49eddf49f2a4 /sonar-ws-client
parente37853f1daf4ec9e744d92381ca274f4b85dc815 (diff)
downloadsonarqube-d5de65e30715c1da5f3b55d264d8014e2a582092.tar.gz
sonarqube-d5de65e30715c1da5f3b55d264d8014e2a582092.zip
SONAR-4836 Create Web Service to get changelog on an Issue
Diffstat (limited to 'sonar-ws-client')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueChange.java38
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueChangeDiff.java33
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueClient.java7
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueChange.java63
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueChangeDiff.java54
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueClient.java7
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/IssueJsonParser.java15
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java32
-rw-r--r--sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog.json33
9 files changed, 281 insertions, 1 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueChange.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueChange.java
new file mode 100644
index 00000000000..d7fb2f8afc8
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueChange.java
@@ -0,0 +1,38 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.wsclient.issue;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @since 4.1
+ */
+public interface IssueChange {
+
+ String user();
+
+ Date createdAt();
+
+ Date updatedAt();
+
+ List<IssueChangeDiff> diffs();
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueChangeDiff.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueChangeDiff.java
new file mode 100644
index 00000000000..e8859ae7a6a
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueChangeDiff.java
@@ -0,0 +1,33 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.wsclient.issue;
+
+/**
+ * @since 4.1
+ */
+public interface IssueChangeDiff {
+
+ String key();
+
+ String newValue();
+
+ String oldValue();
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueClient.java
index b5f26595474..d7ea45952c9 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueClient.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueClient.java
@@ -72,4 +72,11 @@ public interface IssueClient {
*/
BulkChange bulkChange(BulkChangeQuery query);
+ /**
+ * @since 4.1
+ *
+ * @return the list of changes of an issue
+ */
+ List<IssueChange> changes(String issueKey);
+
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueChange.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueChange.java
new file mode 100644
index 00000000000..382cb5d6835
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueChange.java
@@ -0,0 +1,63 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.wsclient.issue.internal;
+
+import org.sonar.wsclient.issue.IssueChange;
+import org.sonar.wsclient.issue.IssueChangeDiff;
+import org.sonar.wsclient.unmarshallers.JsonUtils;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @since 4.1
+ */
+public class DefaultIssueChange implements IssueChange {
+
+ private final Map json;
+
+ DefaultIssueChange(Map json) {
+ this.json = json;
+ }
+
+ public String user() {
+ return JsonUtils.getString(json, "user");
+ }
+
+ public Date createdAt() {
+ return JsonUtils.getDateTime(json, "createdAt");
+ }
+
+ public Date updatedAt() {
+ return JsonUtils.getDateTime(json, "updatedAt");
+ }
+
+ public List<IssueChangeDiff> diffs() {
+ List<IssueChangeDiff> diffs = new ArrayList<IssueChangeDiff>();
+ List<Map> jsonDiffs = (List<Map>) json.get("diffs");
+ for (Map jsonDiff : jsonDiffs) {
+ diffs.add(new DefaultIssueChangeDiff(jsonDiff));
+ }
+ return diffs;
+ }
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueChangeDiff.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueChangeDiff.java
new file mode 100644
index 00000000000..0454267e920
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueChangeDiff.java
@@ -0,0 +1,54 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.wsclient.issue.internal;
+
+import org.sonar.wsclient.issue.IssueChangeDiff;
+import org.sonar.wsclient.unmarshallers.JsonUtils;
+
+import javax.annotation.CheckForNull;
+
+import java.util.Map;
+
+/**
+ * @since 4.1
+ */
+public class DefaultIssueChangeDiff implements IssueChangeDiff {
+
+ private final Map json;
+
+ DefaultIssueChangeDiff(Map json) {
+ this.json = json;
+ }
+
+ public String key() {
+ return JsonUtils.getString(json, "key");
+ }
+
+ @CheckForNull
+ public String newValue() {
+ return JsonUtils.getString(json, "newValue");
+ }
+
+ @CheckForNull
+ public String oldValue() {
+ return JsonUtils.getString(json, "oldValue");
+ }
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueClient.java
index 6e8c60c8c14..95b4cf798fa 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueClient.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueClient.java
@@ -118,6 +118,13 @@ public class DefaultIssueClient implements IssueClient {
return parser.parseBulkChange(json);
}
+ @Override
+ public List<IssueChange> changes(String issueKey) {
+ Map<String, Object> queryParams = EncodingUtils.toMap("issue", issueKey);
+ String json = requestFactory.post("/api/issues/changelog", queryParams);
+ return parser.parseChangelog(json);
+ }
+
private Issue jsonToIssue(String json) {
Map jsonRoot = (Map) JSONValue.parse(json);
return new DefaultIssue((Map) jsonRoot.get("issue"));
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/IssueJsonParser.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/IssueJsonParser.java
index 9640d2520fc..43cadc7cc7d 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/IssueJsonParser.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/IssueJsonParser.java
@@ -24,6 +24,7 @@ import org.json.simple.JSONValue;
import org.sonar.wsclient.base.Paging;
import org.sonar.wsclient.component.Component;
import org.sonar.wsclient.issue.BulkChange;
+import org.sonar.wsclient.issue.IssueChange;
import org.sonar.wsclient.issue.Issues;
import org.sonar.wsclient.rule.Rule;
import org.sonar.wsclient.unmarshallers.JsonUtils;
@@ -120,6 +121,18 @@ public class IssueJsonParser {
return transitions;
}
+ List<IssueChange> parseChangelog(String json) {
+ List<IssueChange> changes = new ArrayList<IssueChange>();
+ Map jRoot = (Map) JSONValue.parse(json);
+ List<Map> jChanges = (List<Map>) jRoot.get("changelog");
+ if (jChanges != null) {
+ for (Map jChange : jChanges) {
+ changes.add(new DefaultIssueChange(jChange));
+ }
+ }
+ return changes;
+ }
+
List<String> parseActions(String json) {
List<String> actions = new ArrayList<String>();
Map jRoot = (Map) JSONValue.parse(json);
@@ -144,6 +157,6 @@ public class IssueJsonParser {
result.setIssuesNotChanged(issuesJson);
}
- return result;
+ return result;
}
}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java
index 42e517cd069..d7c5e22a07b 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java
@@ -208,6 +208,38 @@ public class IssueJsonParserTest {
assertThat(issue.technicalDebt().minutes()).isEqualTo(10);
}
+
+ @Test
+ public void should_parse_changelog() throws Exception {
+ String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog.json"));
+ List<IssueChange> changes = new IssueJsonParser().parseChangelog(json);
+
+ assertThat(changes).hasSize(2);
+ IssueChange change1 = changes.get(0);
+ assertThat(change1.user()).isEqualTo("julien");
+ assertThat(change1.createdAt().getTime()).isEqualTo(1383202235000l);
+ assertThat(change1.updatedAt().getTime()).isEqualTo(1383202235000l);
+ assertThat(change1.diffs()).hasSize(1);
+ IssueChangeDiff diffChange1 = change1.diffs().get(0);
+ assertThat(diffChange1.key()).isEqualTo("actionPlan");
+ assertThat(diffChange1.newValue()).isEqualTo("1.0");
+ assertThat(diffChange1.oldValue()).isNull();
+
+ IssueChange change2 = changes.get(1);
+ assertThat(change2.user()).isEqualTo("simon");
+ assertThat(change2.createdAt().getTime()).isEqualTo(1383202239000l);
+ assertThat(change2.updatedAt().getTime()).isEqualTo(1383202239000l);
+ assertThat(change2.diffs()).hasSize(2);
+ IssueChangeDiff diff1Change2 = change2.diffs().get(0);
+ assertThat(diff1Change2.key()).isEqualTo("severity");
+ assertThat(diff1Change2.newValue()).isEqualTo("INFO");
+ assertThat(diff1Change2.oldValue()).isEqualTo("BLOCKER");
+ IssueChangeDiff diff2Change2 = change2.diffs().get(1);
+ assertThat(diff2Change2.key()).isEqualTo("status");
+ assertThat(diff2Change2.newValue()).isEqualTo("REOPEN");
+ assertThat(diff2Change2.oldValue()).isEqualTo("RESOLVED");
+ }
+
@Test
public void should_parse_bulk_change() throws Exception {
String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/internal/IssueJsonParserTest/bulk-change.json"));
diff --git a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog.json b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog.json
new file mode 100644
index 00000000000..ba3f0cee1ff
--- /dev/null
+++ b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog.json
@@ -0,0 +1,33 @@
+{
+ "changelog": [
+ {
+ "user": "julien",
+ "createdAt": "2013-10-31T07:50:35+0100",
+ "updatedAt": "2013-10-31T07:50:35+0100",
+ "diffs": [
+ {
+ "key": "actionPlan",
+ "newValue": "1.0"
+ }
+ ]
+ },
+ {
+ "user": "simon",
+ "createdAt": "2013-10-31T07:50:39+0100",
+ "updatedAt": "2013-10-31T07:50:39+0100",
+ "diffs": [
+ {
+ "key": "severity",
+ "newValue": "INFO",
+ "oldValue": "BLOCKER"
+ },
+ {
+ "key": "status",
+ "newValue": "REOPEN",
+ "oldValue": "RESOLVED"
+ }
+ ]
+ }
+ ]
+}
+