diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-06-26 09:12:21 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-06-26 09:12:21 +0200 |
commit | c0880d1f396241e7dd0226ff6cd66f84fc73c33a (patch) | |
tree | eb4713cd4091c6d259c2a4f642ca1d5d57457b2a | |
parent | 518e18bf793fa576e09bce11f62e62f45e0c2f71 (diff) | |
download | sonarqube-c0880d1f396241e7dd0226ff6cd66f84fc73c33a.tar.gz sonarqube-c0880d1f396241e7dd0226ff6cd66f84fc73c33a.zip |
Fix quality flaws
5 files changed, 18 insertions, 15 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java b/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java index 501683771d6..2f870d85e0a 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java @@ -31,27 +31,27 @@ import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.issue.internal.IssueChangeContext; import org.sonar.api.web.UserRole; import org.sonar.core.issue.IssueNotifications; -import org.sonar.core.issue.IssueUpdater; import org.sonar.core.issue.db.IssueStorage; import org.sonar.server.user.UserSession; import javax.annotation.CheckForNull; + import java.util.Date; import java.util.List; +import static com.google.common.collect.Lists.newArrayList; + public class IssueBulkChangeService { private static final Logger LOG = LoggerFactory.getLogger(IssueBulkChangeService.class); private final DefaultIssueFinder issueFinder; - private final IssueUpdater issueUpdater; private final IssueStorage issueStorage; private final IssueNotifications issueNotifications; private final List<Action> actions; - public IssueBulkChangeService(DefaultIssueFinder issueFinder, IssueUpdater issueUpdater, IssueStorage issueStorage, IssueNotifications issueNotifications, List<Action> actions) { + public IssueBulkChangeService(DefaultIssueFinder issueFinder, IssueStorage issueStorage, IssueNotifications issueNotifications, List<Action> actions) { this.issueFinder = issueFinder; - this.issueUpdater = issueUpdater; this.issueStorage = issueStorage; this.issueNotifications = issueNotifications; this.actions = actions; @@ -64,21 +64,22 @@ public class IssueBulkChangeService { IssueBulkChangeResult result = new IssueBulkChangeResult(); IssueQueryResult issueQueryResult = issueFinder.find(IssueQuery.builder().issueKeys(issueBulkChangeQuery.issues()).requiredRole(UserRole.USER).build()); List<Issue> issues = issueQueryResult.issues(); + List<Action> actions = newArrayList(); for (String actionName : issueBulkChangeQuery.actions()) { Action action = getAction(actionName); if (action == null) { throw new IllegalArgumentException("The action : '"+ actionName + "' is unknown"); } action.verify(issueBulkChangeQuery.properties(actionName), issues, userSession); + actions.add(action); } IssueChangeContext issueChangeContext = IssueChangeContext.createUser(new Date(), userSession.login()); for (Issue issue : issues) { - for (String actionName : issueBulkChangeQuery.actions()) { + for (Action action : actions) { try { - Action action = getAction(actionName); ActionContext actionContext = new ActionContext(issue, issueChangeContext); - if (action.supports(issue) && action.execute(issueBulkChangeQuery.properties(actionName), actionContext)) { + if (action.supports(issue) && action.execute(issueBulkChangeQuery.properties(action.key()), actionContext)) { issueStorage.save((DefaultIssue) issue); issueNotifications.sendChanges((DefaultIssue) issue, issueChangeContext, issueQueryResult); result.addIssueChanged(issue); @@ -87,7 +88,7 @@ public class IssueBulkChangeService { } } catch (Exception e) { result.addIssueNotChanged(issue); - LOG.info("An error occur when trying to apply the action : "+ actionName + " on issue : "+ issue.key() + ". This issue has been ignored.", e); + LOG.info("An error occur when trying to apply the action : "+ action.key() + " on issue : "+ issue.key() + ". This issue has been ignored.", e); } } } diff --git a/sonar-server/src/main/java/org/sonar/server/issue/IssueFilterService.java b/sonar-server/src/main/java/org/sonar/server/issue/IssueFilterService.java index eddbe7c0245..97769cb927e 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/IssueFilterService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/IssueFilterService.java @@ -95,7 +95,7 @@ public class IssueFilterService implements ServerComponent { String user = getNotNullLogin(userSession); IssueFilterDto issueFilterDto = findIssueFilterDto(issueFilter.id(), user); verifyCurrentUserCanModifyFilter(issueFilterDto.toIssueFilter(), user); - if(issueFilterDto.getUserLogin() != issueFilter.user()) { + if(!issueFilterDto.getUserLogin().equals(issueFilter.user())) { verifyCurrentUserCanChangeFilterOwnership(user); } validateFilter(issueFilter, user); diff --git a/sonar-server/src/main/java/org/sonar/server/issue/PlanAction.java b/sonar-server/src/main/java/org/sonar/server/issue/PlanAction.java index 59fe7f240dd..a64b8df9814 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/PlanAction.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/PlanAction.java @@ -75,7 +75,8 @@ public class PlanAction extends Action implements ServerComponent { String projectKey = actionPlan.projectKey(); for (Issue issue : issues) { DefaultIssue defaultIssue = (DefaultIssue) issue; - if (!defaultIssue.projectKey().equals(projectKey)) { + String issueProjectKey = defaultIssue.projectKey(); + if (issueProjectKey == null || !issueProjectKey.equals(projectKey)) { throw new IllegalArgumentException("Issues are not all related to the action plan project: " + projectKey); } } diff --git a/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceTest.java b/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceTest.java index 64fba1ec89f..4626dc38a2b 100644 --- a/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceTest.java +++ b/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceTest.java @@ -57,7 +57,6 @@ public class IssueBulkChangeServiceTest { private IssueBulkChangeService service; private Action action = mock(Action.class); - private List<Action> actions; @Before public void before() { @@ -70,10 +69,10 @@ public class IssueBulkChangeServiceTest { when(action.key()).thenReturn("assign"); - actions = newArrayList(); + List<Action> actions = newArrayList(); actions.add(action); - service = new IssueBulkChangeService(finder, issueUpdater, issueStorage, issueNotifications, actions); + service = new IssueBulkChangeService(finder, issueStorage, issueNotifications, actions); } @Test diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/BulkChangeQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/BulkChangeQueryTest.java index cd756e7001e..b764942da60 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/BulkChangeQueryTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/BulkChangeQueryTest.java @@ -39,12 +39,14 @@ public class BulkChangeQueryTest { .issues("ABCD", "EFGH") .actions("assign") .actionParameter("assign", "assignee", "geoffrey") + .comment("My bulk comment") ; - assertThat(query.urlParams()).hasSize(3).includes( + assertThat(query.urlParams()).hasSize(4).includes( entry("issues", "ABCD,EFGH"), entry("actions", "assign"), - entry("assign.assignee", "geoffrey") + entry("assign.assignee", "geoffrey"), + entry("comment", "My bulk comment") ); } |