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.ce.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 public class ReportAnalysisFailureNotificationDispatcher extends NotificationDispatcher {
33 public static final String KEY = "CeReportTaskFailure";
35 private final NotificationManager manager;
37 public ReportAnalysisFailureNotificationDispatcher(NotificationManager manager) {
38 super(ReportAnalysisFailureNotification.TYPE);
39 this.manager = manager;
42 public static NotificationDispatcherMetadata newMetadata() {
43 return NotificationDispatcherMetadata.create(KEY)
44 .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(true))
45 .setProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION, String.valueOf(true));
49 public String getKey() {
54 public void dispatch(Notification notification, Context context) {
55 String projectUuid = notification.getFieldValue("project.uuid");
56 Multimap<String, NotificationChannel> subscribedRecipients = manager.findSubscribedRecipientsForDispatcher(
57 this, projectUuid, NotificationManager.SubscriberPermissionsOnProject.ALL_MUST_HAVE_ROLE_USER);
59 for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) {
60 String userLogin = channelsByRecipients.getKey();
61 for (NotificationChannel channel : channelsByRecipients.getValue()) {
62 context.addUser(userLogin, channel);