]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5912 refactor SendIssueNotificationPostJob
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 6 Jan 2015 16:53:20 +0000 (17:53 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 6 Jan 2015 17:04:45 +0000 (18:04 +0100)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/SendIssueNotificationsPostJob.java

index 3fe3c0cdfa23c7bed11f2021208e999ddc5d4fdb..6dd705e21bd1e4f8f0658bfa9ed516a63c97c650 100644 (file)
@@ -58,22 +58,41 @@ public class SendIssueNotificationsPostJob implements PostJob {
   private void sendNotifications(Project project) {
     IssuesBySeverity newIssues = new IssuesBySeverity();
     IssueChangeContext context = IssueChangeContext.createScan(project.getAnalysisDate());
-    Map<DefaultIssue, Rule> shouldSentNotification = new LinkedHashMap<DefaultIssue, Rule>();
+    Map<DefaultIssue, Rule> changedIssuesRuleMap = new LinkedHashMap<>();
     for (DefaultIssue issue : issueCache.all()) {
-      if (issue.isNew() && issue.resolution() == null) {
+      if (isNew(issue)) {
         newIssues.add(issue);
+      } else if (hasChangedAndNeedNotification(issue)) {
+        addIssueToMap(issue, changedIssuesRuleMap);
       }
-      if (!issue.isNew() && issue.isChanged() && issue.mustSendNotifications()) {
-        Rule rule = ruleFinder.findByKey(issue.ruleKey());
-        // TODO warning - rules with status REMOVED are currently ignored, but should not
-        if (rule != null) {
-          shouldSentNotification.put(issue, rule);
-        }
-      }
     }
-    if (!shouldSentNotification.isEmpty()) {
-      notifications.sendChanges(shouldSentNotification, context, project, null, null);
+    sendChangedIssues(project, context, changedIssuesRuleMap);
+    sendNewIssues(project, newIssues);
+  }
+
+  private void addIssueToMap(DefaultIssue issue, Map<DefaultIssue, Rule> changedIssuesRuleMap) {
+    Rule rule = ruleFinder.findByKey(issue.ruleKey());
+    // TODO warning - rules with status REMOVED are currently ignored, but should not
+    if (rule != null) {
+      changedIssuesRuleMap.put(issue, rule);
+    }
+  }
+
+  private boolean isNew(DefaultIssue issue) {
+    return issue.isNew() && issue.resolution() == null;
+  }
+
+  private boolean hasChangedAndNeedNotification(DefaultIssue issue) {
+    return !issue.isNew() && issue.isChanged() && issue.mustSendNotifications();
+  }
+
+  private void sendChangedIssues(Project project, IssueChangeContext context, Map<DefaultIssue, Rule> changedIssuesRuleMap) {
+    if (!changedIssuesRuleMap.isEmpty()) {
+      notifications.sendChanges(changedIssuesRuleMap, context, project, null, null);
     }
+  }
+
+  private void sendNewIssues(Project project, IssuesBySeverity newIssues) {
     if (!newIssues.isEmpty()) {
       notifications.sendNewIssues(project, newIssues);
     }