From 7652deb6f19e3bc4ed062a34f3a04b47cd89fbfe Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 30 May 2013 11:13:00 +0200 Subject: Fix some quality flaws --- .../org/sonar/core/issue/IssueNotifications.java | 42 ++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'sonar-core') diff --git a/sonar-core/src/main/java/org/sonar/core/issue/IssueNotifications.java b/sonar-core/src/main/java/org/sonar/core/issue/IssueNotifications.java index b57f001b3da..0fc2debfc09 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/IssueNotifications.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/IssueNotifications.java @@ -30,6 +30,7 @@ import org.sonar.api.rules.Rule; import org.sonar.api.utils.DateUtils; import org.sonar.core.i18n.RuleI18nManager; +import javax.annotation.CheckForNull; import javax.annotation.Nullable; import java.util.Locale; import java.util.Map; @@ -58,31 +59,36 @@ public class IssueNotifications implements BatchComponent, ServerComponent { return notification; } + @CheckForNull public Notification sendChanges(DefaultIssue issue, IssueChangeContext context, IssueQueryResult queryResult) { return sendChanges(issue, context, queryResult.rule(issue), queryResult.project(issue), queryResult.component(issue)); } + @CheckForNull public Notification sendChanges(DefaultIssue issue, IssueChangeContext context, Rule rule, Component project, @Nullable Component component) { - Notification notification = newNotification(project, "issue-changes"); - notification.setFieldValue("key", issue.key()); - notification.setFieldValue("changeAuthor", context.login()); - notification.setFieldValue("reporter", issue.reporter()); - notification.setFieldValue("assignee", issue.assignee()); - notification.setFieldValue("message", issue.message()); - notification.setFieldValue("ruleName", ruleName(rule)); - notification.setFieldValue("componentKey", issue.componentKey()); - if (component != null) { - notification.setFieldValue("componentName", component.name()); - } + if (issue.diffs() != null) { + Notification notification = newNotification(project, "issue-changes"); + notification.setFieldValue("key", issue.key()); + notification.setFieldValue("changeAuthor", context.login()); + notification.setFieldValue("reporter", issue.reporter()); + notification.setFieldValue("assignee", issue.assignee()); + notification.setFieldValue("message", issue.message()); + notification.setFieldValue("ruleName", ruleName(rule)); + notification.setFieldValue("componentKey", issue.componentKey()); + if (component != null) { + notification.setFieldValue("componentName", component.name()); + } - for (Map.Entry entry : issue.diffs().diffs().entrySet()) { - String type = entry.getKey(); - FieldDiffs.Diff diff = entry.getValue(); - notification.setFieldValue("old." + type, diff.oldValue() != null ? diff.oldValue().toString() : null); - notification.setFieldValue("new." + type, diff.newValue() != null ? diff.newValue().toString() : null); + for (Map.Entry entry : issue.diffs().diffs().entrySet()) { + String type = entry.getKey(); + FieldDiffs.Diff diff = entry.getValue(); + notification.setFieldValue("old." + type, diff.oldValue() != null ? diff.oldValue().toString() : null); + notification.setFieldValue("new." + type, diff.newValue() != null ? diff.newValue().toString() : null); + } + notificationsManager.scheduleForSending(notification); + return notification; } - notificationsManager.scheduleForSending(notification); - return notification; + return null; } private String ruleName(@Nullable Rule rule) { -- cgit v1.2.3