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;
24 import org.sonar.api.notifications.Notification;
25 import org.sonar.api.notifications.NotificationChannel;
26 import org.sonar.server.notification.NotificationDispatcher;
27 import org.sonar.server.notification.NotificationDispatcherMetadata;
28 import org.sonar.server.notification.NotificationManager;
30 import static org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject.ALL_MUST_HAVE_ROLE_USER;
33 * This dispatcher means: "notify me when new issues are introduced during project analysis"
35 public class MyNewIssuesNotificationDispatcher extends NotificationDispatcher {
37 public static final String KEY = "SQ-MyNewIssues";
38 private final NotificationManager manager;
40 public MyNewIssuesNotificationDispatcher(NotificationManager manager) {
41 super(MyNewIssuesNotification.MY_NEW_ISSUES_NOTIF_TYPE);
42 this.manager = manager;
45 public static NotificationDispatcherMetadata newMetadata() {
46 return NotificationDispatcherMetadata.create(KEY)
47 .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(true))
48 .setProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION, String.valueOf(true));
52 public String getKey() {
57 public void dispatch(Notification notification, Context context) {
58 String projectUuid = notification.getFieldValue("projectUuid");
59 String assignee = notification.getFieldValue("assignee");
60 Multimap<String, NotificationChannel> subscribedRecipients = manager.findSubscribedRecipientsForDispatcher(
61 this, projectUuid, ALL_MUST_HAVE_ROLE_USER);
63 Collection<NotificationChannel> channels = subscribedRecipients.get(assignee);
64 for (NotificationChannel channel : channels) {
65 context.addUser(assignee, channel);