aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-01-31 11:46:01 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-01-31 11:46:12 +0100
commitaf595f0fda1855b09033a0ed98c955db0c5432c6 (patch)
tree613bcde36bc0a66ca63d3d66d1fd761c45c2f4f1 /sonar-server
parentb1fd664797646cb4d31ff36ed32f146456923ebf (diff)
downloadsonarqube-af595f0fda1855b09033a0ed98c955db0c5432c6.tar.gz
sonarqube-af595f0fda1855b09033a0ed98c955db0c5432c6.zip
Add characteristic and sub characteristic to Issue Show WS
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowWsHandler.java18
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/issues/search.html.erb3
-rw-r--r--sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java31
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_characteristics.json26
4 files changed, 73 insertions, 5 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 fa631bc7881..d59f27910f5 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
@@ -29,10 +29,12 @@ import org.sonar.api.issue.internal.WorkDayDuration;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
+import org.sonar.api.technicaldebt.server.Characteristic;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.api.web.UserRole;
import org.sonar.core.issue.workflow.Transition;
+import org.sonar.core.technicaldebt.DefaultTechnicalDebtManager;
import org.sonar.markdown.Markdown;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.issue.ActionService;
@@ -58,15 +60,17 @@ public class IssueShowWsHandler implements RequestHandler {
private final IssueChangelogService issueChangelogService;
private final ActionService actionService;
private final TechnicalDebtFormatter technicalDebtFormatter;
+ private final DefaultTechnicalDebtManager technicalDebtManager;
private final I18n i18n;
public IssueShowWsHandler(IssueFinder issueFinder, IssueService issueService, IssueChangelogService issueChangelogService, ActionService actionService,
- TechnicalDebtFormatter technicalDebtFormatter, I18n i18n) {
+ TechnicalDebtFormatter technicalDebtFormatter, DefaultTechnicalDebtManager technicalDebtManager, I18n i18n) {
this.issueFinder = issueFinder;
this.issueService = issueService;
this.issueChangelogService = issueChangelogService;
this.actionService = actionService;
this.technicalDebtFormatter = technicalDebtFormatter;
+ this.technicalDebtManager = technicalDebtManager;
this.i18n = i18n;
}
@@ -127,6 +131,18 @@ public class IssueShowWsHandler implements RequestHandler {
addUserWithLabel(result, issue.assignee(), "assignee", json);
addUserWithLabel(result, issue.reporter(), "reporter", json);
+ addCharacteristics(result, issue, json);
+ }
+
+ private void addCharacteristics(IssueQueryResult result, DefaultIssue issue, JsonWriter json) {
+ Characteristic requirement = technicalDebtManager.findRequirementByRule(result.rule(issue));
+ // Requirement can be null if it has been disabled
+ if (requirement != null) {
+ Characteristic characteristic = technicalDebtManager.findCharacteristicById(requirement.rootId());
+ json.prop("characteristic", characteristic != null ? characteristic.name() : null);
+ Characteristic subCharacteristic = technicalDebtManager.findCharacteristicById(requirement.parentId());
+ json.prop("subCharacteristic", subCharacteristic != null ? subCharacteristic.name() : null);
+ }
}
private void writeTransitions(Issue issue, JsonWriter json) {
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/issues/search.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/issues/search.html.erb
index 33dca1e189a..10ca6b2f58e 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/issues/search.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/issues/search.html.erb
@@ -100,7 +100,8 @@
unassigned: '<%= escape_javascript message('unassigned') -%>',
assignedToMe: '<%= escape_javascript message('assigned_to_me') -%>',
filtersList: '<%= escape_javascript message('issue_filter.filter_list') -%>',
- commentConfirmDelete: '<%= escape_javascript message('issue.comment.delete_confirm_message') -%>',
+ commentConfirmDelete: '<%= escape_javascript message('issue.comment.delete_confirm_message') -%>',
+ requirementRemoved: '<%= escape_javascript message('issue.technical_debt_deleted') -%>',
select2: {
noMatches: '<%= escape_javascript message('select2.noMatches') -%>',
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 d610d85ad04..6be87b7c7a6 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
@@ -39,12 +39,15 @@ import org.sonar.api.issue.internal.WorkDayDuration;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
import org.sonar.api.server.ws.WsTester;
+import org.sonar.api.technicaldebt.server.Characteristic;
+import org.sonar.api.technicaldebt.server.internal.DefaultCharacteristic;
import org.sonar.api.user.User;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.web.UserRole;
import org.sonar.core.issue.DefaultActionPlan;
import org.sonar.core.issue.DefaultIssueQueryResult;
import org.sonar.core.issue.workflow.Transition;
+import org.sonar.core.technicaldebt.DefaultTechnicalDebtManager;
import org.sonar.core.user.DefaultUser;
import org.sonar.server.issue.ActionService;
import org.sonar.server.issue.IssueChangelog;
@@ -84,6 +87,9 @@ public class IssueShowWsHandlerTest {
TechnicalDebtFormatter technicalDebtFormatter;
@Mock
+ DefaultTechnicalDebtManager technicalDebtManager;
+
+ @Mock
I18n i18n;
List<Issue> issues;
@@ -107,7 +113,7 @@ public class IssueShowWsHandlerTest {
when(i18n.message(any(Locale.class), eq("created"), eq((String) null))).thenReturn("Created");
- tester = new WsTester(new IssuesWs(new IssueShowWsHandler(issueFinder, issueService, issueChangelogService, actionService, technicalDebtFormatter, i18n)));
+ tester = new WsTester(new IssuesWs(new IssueShowWsHandler(issueFinder, issueService, issueChangelogService, actionService, technicalDebtFormatter, technicalDebtManager, i18n)));
}
@Test
@@ -216,6 +222,25 @@ public class IssueShowWsHandlerTest {
}
@Test
+ public void show_issue_with_characteristics() throws Exception {
+ WorkDayDuration technicalDebt = WorkDayDuration.of(1, 2, 0);
+ Issue issue = createStandardIssue()
+ .setTechnicalDebt(technicalDebt);
+ issues.add(issue);
+
+ Characteristic requirement = new DefaultCharacteristic().setId(5).setParentId(2).setRootId(1);
+ Characteristic characteristic = new DefaultCharacteristic().setId(1).setName("Maintainability");
+ Characteristic subCharacteristic = new DefaultCharacteristic().setId(2).setName("Readability");
+ when(technicalDebtManager.findRequirementByRule(result.rule(issue))).thenReturn(requirement);
+ when(technicalDebtManager.findCharacteristicById(1)).thenReturn(characteristic);
+ when(technicalDebtManager.findCharacteristicById(2)).thenReturn(subCharacteristic);
+
+ MockUserSession.set();
+ WsTester.TestRequest request = tester.newRequest("show").setParam("key", issue.key());
+ request.execute().assertJson(getClass(), "show_issue_with_characteristics.json");
+ }
+
+ @Test
public void show_issue_with_dates() throws Exception {
Date creationDate = DateUtils.parseDateTime("2014-01-22T19:10:03+0100");
Date updateDate = DateUtils.parseDateTime("2014-01-23T19:10:03+0100");
@@ -378,7 +403,7 @@ public class IssueShowWsHandlerTest {
}
private DefaultIssue createStandardIssue() {
- DefaultIssue issue = createIssue();
+ DefaultIssue issue = createIssue();
addComponentAndProject();
return issue;
}
@@ -392,7 +417,7 @@ public class IssueShowWsHandlerTest {
.setCreationDate(issue_creation_date);
}
- private void addComponentAndProject(){
+ private void addComponentAndProject() {
Component component = mock(Component.class);
when(component.key()).thenReturn("org.sonar.server.issue.IssueClient");
when(component.longName()).thenReturn("SonarQube :: Issue Client");
diff --git a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_characteristics.json b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_characteristics.json
new file mode 100644
index 00000000000..373ad27273c
--- /dev/null
+++ b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_characteristics.json
@@ -0,0 +1,26 @@
+{
+ "issue": {
+ "key": "ABCD",
+ "component": "org.sonar.server.issue.IssueClient",
+ "componentLongName": "SonarQube :: Issue Client",
+ "componentQualifier": "FIL",
+ "project": "org.sonar.Sonar",
+ "projectLongName": "SonarQube",
+ "rule": "squid:AvoidCycle",
+ "ruleName": "Avoid cycle",
+ "characteristic": "Maintainability",
+ "subCharacteristic": "Readability",
+ "creationDate": "2014-01-22T19:10:03+0100",
+ "fCreationDate": "Jan 22, 2014 10:03 AM",
+ "transitions": [],
+ "actions": [],
+ "comments": [],
+ "changelog": [
+ {
+ "creationDate": "2014-01-22T19:10:03+0100",
+ "fCreationDate": "Jan 22, 2014 10:03 AM",
+ "diffs": ["Created"]
+ }
+ ]
+ }
+}