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.api.web.UserRole;
28 import org.sonar.server.notification.NotificationDispatcher;
29 import org.sonar.server.notification.NotificationDispatcherMetadata;
30 import org.sonar.server.notification.NotificationManager;
31 import org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject;
33 public class ReportAnalysisFailureNotificationDispatcher extends NotificationDispatcher {
35 public static final String KEY = "CeReportTaskFailure";
36 private static final SubscriberPermissionsOnProject REQUIRED_SUBSCRIBER_PERMISSIONS = new SubscriberPermissionsOnProject(UserRole.ADMIN, UserRole.USER);
38 private final NotificationManager manager;
40 public ReportAnalysisFailureNotificationDispatcher(NotificationManager manager) {
41 super(ReportAnalysisFailureNotification.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("project.uuid");
59 Multimap<String, NotificationChannel> subscribedRecipients = manager.findSubscribedRecipientsForDispatcher(
60 this, projectUuid, REQUIRED_SUBSCRIBER_PERMISSIONS);
62 for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) {
63 String userLogin = channelsByRecipients.getKey();
64 for (NotificationChannel channel : channelsByRecipients.getValue()) {
65 context.addUser(userLogin, channel);