diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-06-26 10:21:25 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-06-26 10:21:35 +0200 |
commit | 9d4402db8268d0f062f839445a201dcc257de685 (patch) | |
tree | 93c0c84ff3b3e5bad21a33a78dbb8cf835a84753 | |
parent | 98209bc02909cf01540ffc2590f38dd5d7b3ad54 (diff) | |
download | sonarqube-9d4402db8268d0f062f839445a201dcc257de685.tar.gz sonarqube-9d4402db8268d0f062f839445a201dcc257de685.zip |
SONAR-3714 Add transition action
4 files changed, 128 insertions, 4 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/issue/TransitionAction.java b/sonar-server/src/main/java/org/sonar/server/issue/TransitionAction.java new file mode 100644 index 00000000000..e954440132a --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/issue/TransitionAction.java @@ -0,0 +1,57 @@ +/* + * 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.server.issue; + +import org.sonar.api.ServerComponent; +import org.sonar.api.issue.Issue; +import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.core.issue.workflow.IssueWorkflow; +import org.sonar.server.user.UserSession; + +import java.util.List; +import java.util.Map; + +public class TransitionAction extends Action implements ServerComponent { + + public static final String PLAN_ACTION_KEY = "transition"; + + private final IssueWorkflow workflow; + + public TransitionAction(IssueWorkflow workflow) { + super(PLAN_ACTION_KEY); + this.workflow = workflow; + } + + @Override + public boolean verify(Map<String, Object> properties, List<Issue> issues, UserSession userSession) { + return true; + } + + @Override + public boolean execute(Map<String, Object> properties, Context context) { + return workflow.doTransition((DefaultIssue) context.issue(), transition(properties), context.issueChangeContext()); + } + + private String transition(Map<String, Object> properties) { + return (String) properties.get("transition"); + } + +}
\ No newline at end of file diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java index 9bdc3e50d99..3d8aa0fe71d 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java @@ -282,6 +282,7 @@ public final class Platform { servicesContainer.addSingleton(PlanAction.class); servicesContainer.addSingleton(SetSeverityAction.class); servicesContainer.addSingleton(CommentAction.class); + servicesContainer.addSingleton(TransitionAction.class); // rules servicesContainer.addSingleton(RubyRuleService.class); 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 b3b568af4b3..ffdf06a3693 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 @@ -72,14 +72,11 @@ <a href='#' onclick="return issueForm('assign', this)" class="link-action"><%= message('assigned_to') -%></a> <%= h @issue_results.user(issue.assignee).name -%> <% else %> <a href='#' onclick="return issueForm('assign', this)" class="link-action"><%= message('issue.assign.formlink') -%></a> - <% if issue.assignee!=current_user.login %> + <% if issue.assignee != current_user.login %> [<a href="#" onclick="return assignIssueToMe(this)" class="link-action"><%= message('issue.assign.to_me') -%></a>] <% end %> <% end %> </span> - <% end %> - - <% unless issue.resolution %> <img src="<%= ApplicationController.root_context -%>/images/sep12.png"/> <span class="spacer-right"> diff --git a/sonar-server/src/test/java/org/sonar/server/issue/TransitionActionTest.java b/sonar-server/src/test/java/org/sonar/server/issue/TransitionActionTest.java new file mode 100644 index 00000000000..ffda6ea9470 --- /dev/null +++ b/sonar-server/src/test/java/org/sonar/server/issue/TransitionActionTest.java @@ -0,0 +1,69 @@ +/* + * 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.server.issue; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.issue.Issue; +import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.api.issue.internal.IssueChangeContext; +import org.sonar.core.issue.workflow.IssueWorkflow; + +import java.util.Map; + +import static com.google.common.collect.Maps.newHashMap; +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.*; + +public class TransitionActionTest { + + private TransitionAction action; + + private IssueWorkflow workflow = mock(IssueWorkflow.class); + + @Before + public void before() { + action = new TransitionAction(workflow); + } + + @Test + public void should_execute() { + String transition = "reopen"; + Map<String, Object> properties = newHashMap(); + properties.put("transition", transition); + DefaultIssue issue = mock(DefaultIssue.class); + + Action.Context context = mock(Action.Context.class); + when(context.issue()).thenReturn(issue); + + action.execute(properties, context); + verify(workflow).doTransition(eq(issue), eq(transition), any(IssueChangeContext.class)); + } + + @Test + public void should_support_all_issues() { + assertThat(action.supports(new DefaultIssue().setResolution(null))).isTrue(); + assertThat(action.supports(new DefaultIssue().setResolution(Issue.RESOLUTION_FIXED))).isTrue(); + } + +} |