aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-01-23 09:48:55 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-01-23 09:48:55 +0100
commitb9798b1f7f3a6014a84aac497f2db04d326d035d (patch)
tree2cf735e805b1400d6bbe3d6838cc9e6536c5a74c
parente4f3fc79c89f0cfcd732bc751f56b7d92365eadd (diff)
downloadsonarqube-b9798b1f7f3a6014a84aac497f2db04d326d035d.tar.gz
sonarqube-b9798b1f7f3a6014a84aac497f2db04d326d035d.zip
IssueShowWS : Add changelog (without formatted label) and fix issue with NPE on author
-rw-r--r--sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowWsHandler.java42
-rw-r--r--sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java37
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue.json3
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_action_plan.json3
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_actions.json3
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_actions_defined_by_plugins.json3
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_changelog.json41
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_comments.json3
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_dates.json3
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_technical_debt.json3
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_transitions.json3
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_users.json3
12 files changed, 131 insertions, 16 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowWsHandler.java b/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowWsHandler.java
index 5e3bd854c0d..4de83cc922d 100644
--- a/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowWsHandler.java
+++ b/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowWsHandler.java
@@ -22,6 +22,7 @@ package org.sonar.server.issue.ws;
import org.sonar.api.issue.*;
import org.sonar.api.issue.action.Action;
import org.sonar.api.issue.internal.DefaultIssue;
+import org.sonar.api.issue.internal.FieldDiffs;
import org.sonar.api.issue.internal.WorkDayDuration;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
@@ -31,6 +32,8 @@ import org.sonar.api.utils.text.JsonWriter;
import org.sonar.core.issue.workflow.Transition;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.issue.ActionService;
+import org.sonar.server.issue.IssueChangelog;
+import org.sonar.server.issue.IssueChangelogService;
import org.sonar.server.issue.IssueService;
import org.sonar.server.technicaldebt.InternalRubyTechnicalDebtService;
import org.sonar.server.text.RubyTextService;
@@ -39,6 +42,7 @@ import org.sonar.server.user.UserSession;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
+import java.util.Map;
import static com.google.common.collect.Lists.newArrayList;
@@ -46,14 +50,16 @@ public class IssueShowWsHandler implements RequestHandler {
private final IssueFinder issueFinder;
private final IssueService issueService;
+ private final IssueChangelogService issueChangelogService;
private final ActionService actionService;
private final InternalRubyTechnicalDebtService technicalDebtService;
private final RubyTextService textService;
- public IssueShowWsHandler(IssueFinder issueFinder, IssueService issueService, ActionService actionService,
+ public IssueShowWsHandler(IssueFinder issueFinder, IssueService issueService, IssueChangelogService issueChangelogService, ActionService actionService,
InternalRubyTechnicalDebtService technicalDebtService, RubyTextService textService) {
this.issueFinder = issueFinder;
this.issueService = issueService;
+ this.issueChangelogService = issueChangelogService;
this.actionService = actionService;
this.technicalDebtService = technicalDebtService;
this.textService = textService;
@@ -75,7 +81,7 @@ public class IssueShowWsHandler implements RequestHandler {
writeTransitions(issue, json);
writeActions(issue, json);
writeComments(queryResult, issue, json);
- //TODO write changelog
+ writeChangelog(issue, json);
json.endObject().endObject().close();
}
@@ -97,6 +103,7 @@ public class IssueShowWsHandler implements RequestHandler {
.prop("resolution", issue.resolution())
.prop("status", issue.status())
.prop("severity", issue.severity())
+ .prop("author", issue.authorLogin())
.prop("actionPlan", actionPlanKey)
.prop("actionPlanName", actionPlanKey != null ? result.actionPlan(issue).name() : null)
.prop("technicalDebt", technicalDebt != null ? technicalDebtService.format(technicalDebt) : null)
@@ -107,7 +114,6 @@ public class IssueShowWsHandler implements RequestHandler {
addUserWithLabel(result, issue.assignee(), "assignee", json);
addUserWithLabel(result, issue.reporter(), "reporter", json);
- addUserWithLabel(result, issue.authorLogin(), "author", json);
}
private void writeTransitions(Issue issue, JsonWriter json) {
@@ -155,7 +161,7 @@ public class IssueShowWsHandler implements RequestHandler {
.prop("userLogin", userLogin)
.prop("userName", userLogin != null ? queryResult.user(userLogin).name() : null)
.prop("html", textService.markdownToHtml(comment.markdownText()))
- // add markdownText ?
+ // add markdownText ?
.prop("creationDate", DateUtils.formatDateTime(comment.createdAt()))
// TODO add formatted date
.endObject();
@@ -163,6 +169,34 @@ public class IssueShowWsHandler implements RequestHandler {
json.endArray();
}
+ private void writeChangelog(Issue issue, JsonWriter json) {
+ json.name("changelog").beginArray();
+ IssueChangelog changelog = issueChangelogService.changelog(issue);
+ for (FieldDiffs diffs : changelog.changes()) {
+ String userLogin = diffs.userLogin();
+ json
+ .beginObject()
+ .prop("userLogin", userLogin)
+ .prop("userName", userLogin != null ? changelog.user(diffs).name() : null)
+ .prop("creationDate", DateUtils.formatDateTime(diffs.creationDate()));
+ // TODO add formatted date
+
+ json.name("diffs").beginArray();
+ for (Map.Entry<String, FieldDiffs.Diff> entry : diffs.diffs().entrySet()) {
+ FieldDiffs.Diff diff = entry.getValue();
+ json
+ .beginObject()
+ .prop("key", entry.getKey())
+ .prop("newValue", (String) diff.newValue())
+ .prop("oldValue", (String) diff.oldValue())
+ .endObject();
+ }
+ json.endArray();
+ json.endObject();
+ }
+ json.endArray();
+ }
+
private void addUserWithLabel(IssueQueryResult result, String value, String field, JsonWriter json) {
if (value != null) {
json
diff --git a/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java
index a802f65d499..d058ecb9a07 100644
--- a/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java
@@ -33,6 +33,7 @@ import org.sonar.api.issue.IssueQuery;
import org.sonar.api.issue.action.Action;
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.issue.internal.WorkDayDuration;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
@@ -44,6 +45,8 @@ import org.sonar.core.issue.DefaultIssueQueryResult;
import org.sonar.core.issue.workflow.Transition;
import org.sonar.core.user.DefaultUser;
import org.sonar.server.issue.ActionService;
+import org.sonar.server.issue.IssueChangelog;
+import org.sonar.server.issue.IssueChangelogService;
import org.sonar.server.issue.IssueService;
import org.sonar.server.technicaldebt.InternalRubyTechnicalDebtService;
import org.sonar.server.text.RubyTextService;
@@ -70,6 +73,9 @@ public class IssueShowWsHandlerTest {
IssueService issueService;
@Mock
+ IssueChangelogService issueChangelogService;
+
+ @Mock
ActionService actionService;
@Mock
@@ -93,7 +99,9 @@ public class IssueShowWsHandlerTest {
result.addRules(newArrayList(Rule.create("squid", "AvoidCycle").setName("Avoid cycle")));
when(issueFinder.find(any(IssueQuery.class))).thenReturn(result);
- tester = new WsTester(new IssuesWs(new IssueShowWsHandler(issueFinder, issueService, actionService, technicalDebtService, textService)));
+ when(issueChangelogService.changelog(any(Issue.class))).thenReturn(mock(IssueChangelog.class));
+
+ tester = new WsTester(new IssuesWs(new IssueShowWsHandler(issueFinder, issueService, issueChangelogService, actionService, technicalDebtService, textService)));
}
@Test
@@ -121,8 +129,7 @@ public class IssueShowWsHandlerTest {
@Test
public void show_issue_with_action_plan() throws Exception {
Issue issue = createStandardIssue()
- .setActionPlanKey("AP-ABCD")
- .setCreationDate(DateUtils.parseDateTime("2014-01-22T19:10:03+0100"));
+ .setActionPlanKey("AP-ABCD");
issues.add(issue);
result.addActionPlans(newArrayList((ActionPlan) new DefaultActionPlan().setKey("AP-ABCD").setName("Version 4.2")));
@@ -238,6 +245,30 @@ public class IssueShowWsHandlerTest {
tester.execute("show", request).assertJson(getClass(), "show_issue_with_actions_defined_by_plugins.json");
}
+ @Test
+ public void show_issue_with_changelog() throws Exception {
+ Issue issue = createStandardIssue();
+ issues.add(issue);
+
+ List<User> users = Lists.<User>newArrayList(
+ new DefaultUser().setLogin("john").setName("John")
+ );
+
+ FieldDiffs userChange = new FieldDiffs()
+ .setUserLogin("john")
+ .setDiff("actionPlan", null, "1.0")
+ .setCreationDate(DateUtils.parseDateTime("2014-01-22T19:10:03+0100"));
+ FieldDiffs scanChange = new FieldDiffs()
+ .setDiff("severity", "INFO", "BLOCKER")
+ .setDiff("status", "REOPEN", "RESOLVED")
+ .setCreationDate(DateUtils.parseDateTime("2014-01-23T19:10:03+0100"));
+ when(issueChangelogService.changelog(issue)).thenReturn(new IssueChangelog(newArrayList(userChange, scanChange), users));
+
+ MockUserSession.set();
+ SimpleRequest request = new SimpleRequest().setParam("key", issue.key());
+ tester.execute("show", request).assertJson(getClass(), "show_issue_with_changelog.json");
+ }
+
private DefaultIssue createStandardIssue(){
return new DefaultIssue()
.setKey("ABCD")
diff --git a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue.json b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue.json
index c7cfc369de3..83dfdb018fe 100644
--- a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue.json
+++ b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue.json
@@ -13,6 +13,7 @@
"creationDate": "2014-01-22T19:10:03+0100",
"transitions": [],
"actions": [],
- "comments": []
+ "comments": [],
+ "changelog": []
}
}
diff --git a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_action_plan.json b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_action_plan.json
index 57c425a26cd..618350122be 100644
--- a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_action_plan.json
+++ b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_action_plan.json
@@ -10,6 +10,7 @@
"creationDate": "2014-01-22T19:10:03+0100",
"transitions": [],
"actions": [],
- "comments": []
+ "comments": [],
+ "changelog": []
}
}
diff --git a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_actions.json b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_actions.json
index a30a0500faf..689c9cf12b7 100644
--- a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_actions.json
+++ b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_actions.json
@@ -11,6 +11,7 @@
"actions": [
"comment", "assign", "plan"
],
- "comments": []
+ "comments": [],
+ "changelog": []
}
}
diff --git a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_actions_defined_by_plugins.json b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_actions_defined_by_plugins.json
index 5d5d578bb49..7017792593b 100644
--- a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_actions_defined_by_plugins.json
+++ b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_actions_defined_by_plugins.json
@@ -11,6 +11,7 @@
"actions": [
"comment", "assign", "plan", "link-to-jira"
],
- "comments": []
+ "comments": [],
+ "changelog": []
}
}
diff --git a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_changelog.json b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_changelog.json
new file mode 100644
index 00000000000..a493b6b9393
--- /dev/null
+++ b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_changelog.json
@@ -0,0 +1,41 @@
+{
+ "issue": {
+ "key": "ABCD",
+ "component": "org.sonar.server.issue.IssueClient",
+ "project": "org.sonar.Sonar",
+ "rule": "squid:AvoidCycle",
+ "ruleName": "Avoid cycle",
+ "creationDate": "2014-01-22T19:10:03+0100",
+ "transitions": [],
+ "actions": [],
+ "comments": [],
+ "changelog": [
+ {
+ "userLogin": "john",
+ "userName": "John",
+ "creationDate": "2014-01-22T19:10:03+0100",
+ "diffs": [
+ {
+ "key": "actionPlan",
+ "newValue": "1.0"
+ }
+ ]
+ },
+ {
+ "creationDate": "2014-01-23T19:10:03+0100",
+ "diffs": [
+ {
+ "key": "severity",
+ "newValue": "BLOCKER",
+ "oldValue": "INFO"
+ },
+ {
+ "key": "status",
+ "newValue": "RESOLVED",
+ "oldValue": "REOPEN"
+ }
+ ]
+ }
+ ]
+ }
+}
diff --git a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_comments.json b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_comments.json
index fbbe26f0e31..a4a5389477e 100644
--- a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_comments.json
+++ b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_comments.json
@@ -16,6 +16,7 @@
"html": "<b>My comment</b>",
"creationDate": "2014-01-23T19:10:03+0100"
}
- ]
+ ],
+ "changelog": []
}
}
diff --git a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_dates.json b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_dates.json
index b337255aa76..2acfa022389 100644
--- a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_dates.json
+++ b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_dates.json
@@ -10,6 +10,7 @@
"closeDate": "2014-01-24T19:10:03+0100",
"transitions": [],
"actions": [],
- "comments": []
+ "comments": [],
+ "changelog": []
}
}
diff --git a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_technical_debt.json b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_technical_debt.json
index 81c72221c8b..373549564af 100644
--- a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_technical_debt.json
+++ b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_technical_debt.json
@@ -9,6 +9,7 @@
"creationDate": "2014-01-22T19:10:03+0100",
"transitions": [],
"actions": [],
- "comments": []
+ "comments": [],
+ "changelog": []
}
}
diff --git a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_transitions.json b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_transitions.json
index 8556b4764ca..df575c0fa9f 100644
--- a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_transitions.json
+++ b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_transitions.json
@@ -10,6 +10,7 @@
"creationDate": "2014-01-22T19:10:03+0100",
"transitions": ["reopen"],
"actions": ["comment"],
- "comments": []
+ "comments": [],
+ "changelog": []
}
}
diff --git a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_users.json b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_users.json
index 0b21b8bf485..74c8c1ab508 100644
--- a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_users.json
+++ b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_users.json
@@ -14,6 +14,7 @@
"creationDate": "2014-01-22T19:10:03+0100",
"transitions": [],
"actions": [],
- "comments": []
+ "comments": [],
+ "changelog": []
}
}