3 * Copyright (C) 2009-2017 SonarSource SA
4 * mailto:info 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.collect.Multimap;
23 import java.util.Collection;
25 import org.sonar.api.notifications.Notification;
26 import org.sonar.api.notifications.NotificationChannel;
27 import org.sonar.server.notification.NotificationDispatcher;
28 import org.sonar.server.notification.NotificationDispatcherMetadata;
29 import org.sonar.server.notification.NotificationManager;
32 * This dispatcher means: "notify me when new issues are introduced during project analysis"
34 public class NewIssuesNotificationDispatcher extends NotificationDispatcher {
36 public static final String KEY = "NewIssues";
37 private final NotificationManager manager;
39 public NewIssuesNotificationDispatcher(NotificationManager manager) {
40 super(NewIssuesNotification.TYPE);
41 this.manager = manager;
45 public String getKey() {
49 public static NotificationDispatcherMetadata newMetadata() {
50 return NotificationDispatcherMetadata.create(KEY)
51 .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(true))
52 .setProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION, String.valueOf(true));
56 public void dispatch(Notification notification, Context context) {
57 String projectKey = notification.getFieldValue("projectKey");
58 Multimap<String, NotificationChannel> subscribedRecipients = manager.findNotificationSubscribers(this, projectKey);
60 for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) {
61 String userLogin = channelsByRecipients.getKey();
62 for (NotificationChannel channel : channelsByRecipients.getValue()) {
63 context.addUser(userLogin, channel);