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;
31 import static org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject.ALL_MUST_HAVE_ROLE_USER;
34 * This dispatcher means: "notify me when new issues are introduced during project analysis"
36 public class NewIssuesNotificationDispatcher extends NotificationDispatcher {
38 public static final String KEY = "NewIssues";
39 private final NotificationManager manager;
41 public NewIssuesNotificationDispatcher(NotificationManager manager) {
42 super(NewIssuesNotification.TYPE);
43 this.manager = manager;
47 public String getKey() {
51 public static NotificationDispatcherMetadata newMetadata() {
52 return NotificationDispatcherMetadata.create(KEY)
53 .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(true))
54 .setProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION, String.valueOf(true));
58 public void dispatch(Notification notification, Context context) {
59 String projectUuid = notification.getFieldValue("projectUuid");
60 Multimap<String, NotificationChannel> subscribedRecipients = manager.findSubscribedRecipientsForDispatcher(
61 this, projectUuid, ALL_MUST_HAVE_ROLE_USER);
63 for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) {
64 String userLogin = channelsByRecipients.getKey();
65 for (NotificationChannel channel : channelsByRecipients.getValue()) {
66 context.addUser(userLogin, channel);