diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-06-03 11:16:23 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-06-03 11:16:23 +0200 |
commit | 507e8b9a0c214ca86722af265cb3fa81c3d0c09f (patch) | |
tree | 1e8e09d3197c8eda121a414ab57a4b9ba4118c40 /sonar-server/src/main/java/org | |
parent | 6ce3ec7f1b3f0b3c1baf823037873bdd672af4e5 (diff) | |
download | sonarqube-507e8b9a0c214ca86722af265cb3fa81c3d0c09f.tar.gz sonarqube-507e8b9a0c214ca86722af265cb3fa81c3d0c09f.zip |
SONAR-4315 Add Issue Action WS and add Action links to Issue detail
Diffstat (limited to 'sonar-server/src/main/java/org')
5 files changed, 32 insertions, 138 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/issue/ActionService.java b/sonar-server/src/main/java/org/sonar/server/issue/ActionService.java index 41b9a79a12e..301d0d2bf15 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/ActionService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/ActionService.java @@ -40,9 +40,9 @@ import org.sonar.server.user.UserSession; import javax.annotation.CheckForNull; import javax.annotation.Nullable; +import java.util.Collections; import java.util.Date; import java.util.List; -import java.util.Map; import static com.google.common.collect.Lists.newArrayList; @@ -52,7 +52,6 @@ public class ActionService implements ServerComponent { private final IssueStorage issueStorage; private final IssueUpdater updater; private final List<Action> actions; -// private final DefaultActions actions; public ActionService(DefaultIssueFinder finder, IssueStorage issueStorage, IssueUpdater updater, List<Action> actions) { this.finder = finder; @@ -61,10 +60,11 @@ public class ActionService implements ServerComponent { this.actions = actions; } - public List<Action> listAvailableActions(String issueKey) { - IssueQueryResult queryResult = loadIssue(issueKey); - final DefaultIssue issue = (DefaultIssue) queryResult.first(); + public ActionService(DefaultIssueFinder finder, IssueStorage issueStorage, IssueUpdater updater) { + this(finder, issueStorage, updater, Collections.<Action>emptyList()); + } + public List<Action> listAvailableActions(final Issue issue) { return newArrayList(Iterables.filter(actions, new Predicate<Action>() { @Override public boolean apply(Action action) { @@ -73,32 +73,31 @@ public class ActionService implements ServerComponent { })); } - @CheckForNull - public Action getAction(final String actionKey) { - return Iterables.find(actions, new Predicate<Action>() { - @Override - public boolean apply(Action action) { - return action.key().equals(actionKey); - } - }, null); + public List<Action> listAvailableActions(String issueKey) { + IssueQueryResult queryResult = loadIssue(issueKey); + final DefaultIssue issue = (DefaultIssue) queryResult.first(); + if (issue == null) { + throw new IllegalArgumentException("Issue is not found : " + issueKey); + } + + return listAvailableActions(issue); } - public Issue execute(String issueKey, String actionKey, UserSession userSession, Map<String, String> parameters) { public Issue execute(String issueKey, String actionKey, UserSession userSession) { Preconditions.checkArgument(!Strings.isNullOrEmpty(actionKey), "Missing action"); IssueQueryResult queryResult = loadIssue(issueKey); DefaultIssue issue = (DefaultIssue) queryResult.first(); if (issue == null) { - throw new IllegalStateException("Issue is not found : " + issueKey); + throw new IllegalArgumentException("Issue is not found : " + issueKey); } Action action = getAction(actionKey); if (action == null) { - throw new IllegalStateException("Action is not found : " + actionKey); + throw new IllegalArgumentException("Action is not found : " + actionKey); } if (!action.supports(issue)) { - throw new IllegalStateException("A condition is not respected."); + throw new IllegalStateException("A condition is not respected"); } IssueChangeContext changeContext = IssueChangeContext.createUser(new Date(), userSession.login()); @@ -115,6 +114,16 @@ public class ActionService implements ServerComponent { return finder.find(query); } + @CheckForNull + private Action getAction(final String actionKey) { + return Iterables.find(actions, new Predicate<Action>() { + @Override + public boolean apply(Action action) { + return action.key().equals(actionKey); + } + }, null); + } + static class FunctionContext implements Function.Context { private final DefaultIssue issue; @@ -133,11 +142,6 @@ public class ActionService implements ServerComponent { } @Override - public Map<String, String> parameters() { - return parameters; - } - - @Override public Function.Context setAttribute(String key, @Nullable String value) { updater.setAttribute(issue, key, value, changeContext); return this; diff --git a/sonar-server/src/main/java/org/sonar/server/issue/DefaultActions.java b/sonar-server/src/main/java/org/sonar/server/issue/DefaultActions.java deleted file mode 100644 index 7e80303bb7a..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/issue/DefaultActions.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; -import org.sonar.api.issue.action.Action; -import org.sonar.api.issue.action.Actions; - -import javax.annotation.CheckForNull; - -import java.util.Set; - -/** - * @since 3.6 - */ -public final class DefaultActions implements Actions { - - private Set<Action> actions = Sets.newLinkedHashSet(); - - public DefaultActions addAction(Action action) { - actions.add(action); - return this; - } - - public Set<Action> getActions() { - return actions; - } - - @CheckForNull - public Action getAction(final String actionKey) { - return Iterables.find(actions, new Predicate<Action>() { - @Override - public boolean apply(Action action) { - return action.key().equals(actionKey); - } - }, null); - } - -} diff --git a/sonar-server/src/main/java/org/sonar/server/issue/ExtendWorkflow.java b/sonar-server/src/main/java/org/sonar/server/issue/ExtendWorkflow.java deleted file mode 100644 index 2cdc076b4d6..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/issue/ExtendWorkflow.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.ServerExtension; -import org.sonar.api.issue.Issue; -import org.sonar.api.issue.action.Action; -import org.sonar.api.issue.action.Actions; -import org.sonar.api.issue.condition.HasResolution; -import org.sonar.api.workflow.function.CommentFunction; - -public final class ExtendWorkflow implements ServerExtension { - - private final Actions actions; - - public ExtendWorkflow(Actions actions) { - this.actions = actions; - } - - public void start() { - actions.addAction(Action.builder("fake") - .conditions(new HasResolution(Issue.RESOLUTION_FIXED)) - .functions(new CommentFunction()) - .build() - ); - } -} - diff --git a/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java b/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java index 4944d000b08..adb53c4b0c6 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java @@ -45,6 +45,7 @@ import org.sonar.server.user.UserSession; import org.sonar.server.util.RubyUtils; import javax.annotation.Nullable; + import java.util.Collection; import java.util.Date; import java.util.List; @@ -318,4 +319,8 @@ public class InternalRubyIssueService implements ServerComponent { public List<Action> listActions(String issueKey){ return actionService.listAvailableActions(issueKey); } + + public List<Action> listActions(Issue issue) { + return actionService.listAvailableActions(issue); + } }
\ 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 57972aa6eb0..f17401cce00 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 @@ -22,9 +22,6 @@ package org.sonar.server.platform; import org.apache.commons.configuration.BaseConfiguration; import org.slf4j.LoggerFactory; import org.sonar.api.config.EmailSettings; -import org.sonar.api.issue.Issue; -import org.sonar.api.issue.action.Action; -import org.sonar.api.issue.condition.HasResolution; import org.sonar.api.platform.ComponentContainer; import org.sonar.api.platform.Server; import org.sonar.api.profiles.AnnotationProfileParser; @@ -37,7 +34,6 @@ import org.sonar.api.rules.XMLRuleParser; import org.sonar.api.utils.HttpDownloader; import org.sonar.api.utils.TimeProfiler; import org.sonar.api.utils.UriReader; -import org.sonar.api.workflow.function.CommentFunction; import org.sonar.core.component.SnapshotPerspectives; import org.sonar.core.config.Logback; import org.sonar.core.i18n.GwtI18n; @@ -211,7 +207,7 @@ public final class Platform { */ private void startServiceComponents() { servicesContainer = coreContainer.createChild(); - servicesContainer.addSingleton(DefaultActions.class); + servicesContainer.addSingleton(HttpDownloader.class); servicesContainer.addSingleton(UriReader.class); servicesContainer.addSingleton(UpdateCenterClient.class); @@ -275,13 +271,6 @@ public final class Platform { servicesContainer.addSingleton(IssueNotifications.class); servicesContainer.addSingleton(ActionService.class); - // TODO only for test - servicesContainer.addSingleton(Action.builder("fake") - .conditions(new HasResolution(Issue.RESOLUTION_FIXED)) - .functions(new CommentFunction()) - .build() - ); - // rules servicesContainer.addSingleton(RubyRuleService.class); |