From 740b4c7713b384788591997f4fccdc1eb5b2f987 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 6 May 2013 14:57:57 +0200 Subject: [PATCH] SONAR-3755 Display action plan on issue detail page --- .../resources/org/sonar/l10n/core.properties | 4 ++++ .../sonar/server/issue/ServerIssueFinder.java | 1 + .../app/controllers/api/issues_controller.rb | 14 +++++++++++++- .../WEB-INF/app/controllers/issue_controller.rb | 4 ++-- .../WEB-INF/app/views/issue/_issue.html.erb | 17 ++++++++++++----- .../WEB-INF/app/views/resource/_issue.html.erb | 1 - .../server/issue/ServerIssueFinderTest.java | 7 +++---- 7 files changed, 35 insertions(+), 13 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index 1707520ffef..4973e370057 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -528,6 +528,10 @@ reviews.filtered_by.to=To date #------------------------------------------------------------------------------ issues.issue_number=Issue #{0} +issues.no_action_plan=None +issues.planned_for_x=Planned for {0} +issues.planned_for_label=Planned for +issues.an_action_plan_must_be_created_first=An action plan should be first created to plan the remediation effort of this violation. issues.hide_this_message=Hide this message issues.user_does_not_exist=\ : user does not exist. \\nPlease select a valid user or leave the field blank. issues.new_severity_label=New severity: diff --git a/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueFinder.java b/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueFinder.java index 864d6e43036..51e82d1cd0e 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueFinder.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueFinder.java @@ -99,6 +99,7 @@ public class ServerIssueFinder implements IssueFinder { ruleIds.add(dto.getRuleId()); componentIds.add(dto.getResourceId()); + actionPlanKeys.add(dto.getActionPlanKey()); } } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb index 5c6690ec503..aeb725b5dad 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb @@ -33,7 +33,8 @@ class Api::IssuesController < Api::ApiController :securityExclusions => results.securityExclusions, :paging => paging_to_json(results.paging), :issues => results.issues.map { |issue| issue_to_json(issue) }, - :rules => results.rules.map { |rule| rule_to_json(rule) } + :rules => results.rules.map { |rule| rule_to_json(rule) }, + :actionPlans => results.actionPlans.map { |action_plan| action_plan_to_json(action_plan) } } ) end @@ -183,6 +184,7 @@ class Api::IssuesController < Api::ApiController :rule => issue.ruleKey.toString(), :status => issue.status } + json[:actionPlan] = issue.actionPlanKey if issue.actionPlanKey json[:resolution] = issue.resolution if issue.resolution json[:severity] = issue.severity if issue.severity json[:desc] = issue.description if issue.description @@ -216,6 +218,16 @@ class Api::IssuesController < Api::ApiController json end + def action_plan_to_json(action_plan) + json = {:key => action_plan.key(), :name => action_plan.name(), :status => action_plan.status()} + json[:desc] = action_plan.description() if action_plan.description() && !action_plan.description().blank? + json[:userLogin] = action_plan.userLogin() if action_plan.userLogin() + json[:deadLine] = format_java_datetime(action_plan.deadLine()) if action_plan.deadLine() + json[:creationDate] = format_java_datetime(action_plan.creationDate()) if action_plan.creationDate() + json[:updateDate] = format_java_datetime(action_plan.updateDate()) if action_plan.updateDate() + json + end + def paging_to_json(paging) { :pageIndex => paging.pageIndex, diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb index d9e31eb255f..c5ed9cf1ec7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb @@ -177,8 +177,8 @@ class IssueController < ApplicationController protected def init_issue(issue_key) - issue_result = find_issue(issue_key) - @issue = issue_result.issues[0] + @issue_result = find_issue(issue_key) + @issue = @issue_result.issues[0] end def init_resource diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb index 6a0c2fb39c1..e2237ca947e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb @@ -82,12 +82,19 @@ <%= l(Api::Utils.to_date(@issue.updateDate())) if @issue.updateDate() -%> - - <% # TODO action plan %> - - + <% if @issue.actionPlanKey() %> + <% action_plan = @issue_result.actionPlan(@issue) %> + + + <%= message('issues.planned_for_label') -%>: + + + <%= h(action_plan.name()) -%> + + + <% end %> <% if @issue.rule_key %> - <% rule_name = Internal.rules.ruleL10nName(@issue.rule_key) %> + <% rule_name = Internal.rules.ruleL10nName(@issue_result.rule(@issue)) %> <%= message('rule') -%>: diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_issue.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_issue.html.erb index d17782ac261..372fcd57625 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_issue.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_issue.html.erb @@ -37,7 +37,6 @@ <% end %> <% # TODO display assignee name instead of login - #if violation.review && violation.review.assignee_id if issue.assignee %> <%= image_tag 'sep12.png' -%> diff --git a/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueFinderTest.java b/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueFinderTest.java index 114d377f1af..0b1429c4aeb 100644 --- a/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueFinderTest.java +++ b/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueFinderTest.java @@ -197,13 +197,12 @@ public class ServerIssueFinderTest { when(issueDao.selectIssueIdsAndComponentsId(eq(query), any(SqlSession.class))).thenReturn(dtoList); when(issueDao.selectByIds(anyCollection(), any(SqlSession.class))).thenReturn(dtoList); - IssueFinder.Results results = finder.find(query, null, UserRole.USER); assertThat(results.issues()).hasSize(2); - Issue issue = results.issues().iterator().next(); assertThat(results.issues()).hasSize(2); - assertThat(results.component(issue)).isEqualTo(component); assertThat(results.components()).hasSize(1); + Issue issue = results.issues().iterator().next(); + assertThat(results.component(issue)).isEqualTo(component); } @Test @@ -225,11 +224,11 @@ public class ServerIssueFinderTest { List dtoList = newArrayList(issue1, issue2); when(issueDao.selectIssueIdsAndComponentsId(eq(query), any(SqlSession.class))).thenReturn(dtoList); when(issueDao.selectByIds(anyCollection(), any(SqlSession.class))).thenReturn(dtoList); - when(actionPlanFinder.findByKeys(anyCollection())).thenReturn(newArrayList(actionPlan1, actionPlan2)); IssueFinder.Results results = finder.find(query, null, UserRole.USER); assertThat(results.issues()).hasSize(2); + assertThat(results.actionPlans()).hasSize(2); Issue issue = results.issues().iterator().next(); assertThat(results.actionPlan(issue)).isNotNull(); } -- 2.39.5