3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.issue.notification;
22 import com.google.common.base.Objects;
23 import com.google.common.collect.Multimap;
24 import java.util.Collection;
26 import org.sonar.api.issue.Issue;
27 import org.sonar.api.notifications.Notification;
28 import org.sonar.api.notifications.NotificationChannel;
29 import org.sonar.server.notification.NotificationDispatcher;
30 import org.sonar.server.notification.NotificationDispatcherMetadata;
31 import org.sonar.server.notification.NotificationManager;
34 * This dispatcher means: "notify me when an issue is resolved as false positive or won't fix".
36 public class DoNotFixNotificationDispatcher extends NotificationDispatcher {
38 public static final String KEY = "NewFalsePositiveIssue";
40 private final NotificationManager notifications;
42 public DoNotFixNotificationDispatcher(NotificationManager notifications) {
43 super(IssueChangeNotification.TYPE);
44 this.notifications = notifications;
48 public String getKey() {
52 public static NotificationDispatcherMetadata newMetadata() {
53 return NotificationDispatcherMetadata.create(KEY)
54 .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(true))
55 .setProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION, String.valueOf(true));
59 public void dispatch(Notification notification, Context context) {
60 String newResolution = notification.getFieldValue("new.resolution");
61 if (Objects.equal(newResolution, Issue.RESOLUTION_FALSE_POSITIVE) || Objects.equal(newResolution, Issue.RESOLUTION_WONT_FIX)) {
62 String author = notification.getFieldValue("changeAuthor");
63 String projectKey = notification.getFieldValue("projectKey");
64 Multimap<String, NotificationChannel> subscribedRecipients = notifications.findNotificationSubscribers(this, projectKey);
65 notify(author, context, subscribedRecipients);
69 private void notify(String author, Context context, Multimap<String, NotificationChannel> subscribedRecipients) {
70 for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) {
71 String login = channelsByRecipients.getKey();
72 // Do not notify the person that resolved the issue
73 if (!Objects.equal(author, login)) {
74 for (NotificationChannel channel : channelsByRecipients.getValue()) {
75 context.addUser(login, channel);