]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@gmail.com>
Wed, 26 Jun 2013 07:12:21 +0000 (09:12 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Wed, 26 Jun 2013 07:12:21 +0000 (09:12 +0200)
sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java
sonar-server/src/main/java/org/sonar/server/issue/IssueFilterService.java
sonar-server/src/main/java/org/sonar/server/issue/PlanAction.java
sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/issue/BulkChangeQueryTest.java

index 501683771d677a700246f563b84272044ae9f9d0..2f870d85e0a7b32e3f8032f651da541c70c98dce 100644 (file)
@@ -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);
         }
       }
     }
index eddbe7c0245d4a5ea0508879d15ab750bf34a16a..97769cb927e18b8469717bbe4a699058dc19df25 100644 (file)
@@ -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);
index 59fe7f240ddf6978065e06bb4806eb199666a1e5..a64b8df98142cee5b24e299250d1574235de0670 100644 (file)
@@ -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);
       }
     }
index 64fba1ec89f1dae2cb081efb5c46cfe4f777d94e..4626dc38a2b43f4544414791763e922c36cb9ce2 100644 (file)
@@ -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
index cd756e7001e43de44ed48fe28c2e9adcee39df96..b764942da601c8a033ee44ee41f2325d6ca305d1 100644 (file)
@@ -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")
     );
   }