use of org.sonar.api.notifications.NotificationChannel in project sonarqube by SonarSource.
the class ChangesOnMyIssueNotificationDispatcherTest method should_dispatch_to_assignee.
@Test
public void should_dispatch_to_assignee() {
Multimap<String, NotificationChannel> recipients = HashMultimap.create();
recipients.put("simon", emailChannel);
recipients.put("freddy", twitterChannel);
recipients.put("godin", twitterChannel);
when(notifications.findNotificationSubscribers(dispatcher, "struts")).thenReturn(recipients);
Notification notification = new IssueChangeNotification().setFieldValue("projectKey", "struts").setFieldValue("changeAuthor", "olivier").setFieldValue("assignee", "freddy");
dispatcher.performDispatch(notification, context);
verify(context).addUser("freddy", twitterChannel);
verify(context, never()).addUser("godin", twitterChannel);
verifyNoMoreInteractions(context);
}
use of org.sonar.api.notifications.NotificationChannel in project sonarqube by SonarSource.
the class RemoveActionTest method setUp.
@Before
public void setUp() {
NotificationDispatcherMetadata metadata1 = NotificationDispatcherMetadata.create(NOTIF_MY_NEW_ISSUES).setProperty(GLOBAL_NOTIFICATION, "true").setProperty(PER_PROJECT_NOTIFICATION, "true");
NotificationDispatcherMetadata metadata2 = NotificationDispatcherMetadata.create(NOTIF_NEW_ISSUES).setProperty(GLOBAL_NOTIFICATION, "true");
NotificationDispatcherMetadata metadata3 = NotificationDispatcherMetadata.create(NOTIF_NEW_QUALITY_GATE_STATUS).setProperty(GLOBAL_NOTIFICATION, "true").setProperty(PER_PROJECT_NOTIFICATION, "true");
notificationCenter = new NotificationCenter(new NotificationDispatcherMetadata[] { metadata1, metadata2, metadata3 }, new NotificationChannel[] { emailChannel, twitterChannel, defaultChannel });
notificationUpdater = new NotificationUpdater(userSession, dbClient);
underTest = new RemoveAction(notificationCenter, notificationUpdater, dbClient, new ComponentFinder(dbClient), userSession);
ws = new WsActionTester(underTest);
}
use of org.sonar.api.notifications.NotificationChannel in project sonarqube by SonarSource.
the class NewIssuesNotificationDispatcher method dispatch.
@Override
public void dispatch(Notification notification, Context context) {
String projectKey = notification.getFieldValue("projectKey");
Multimap<String, NotificationChannel> subscribedRecipients = manager.findNotificationSubscribers(this, projectKey);
for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) {
String userLogin = channelsByRecipients.getKey();
for (NotificationChannel channel : channelsByRecipients.getValue()) {
context.addUser(userLogin, channel);
}
}
}
use of org.sonar.api.notifications.NotificationChannel in project sonarqube by SonarSource.
the class NotificationChannelTest method defaultMethods.
@Test
public void defaultMethods() {
NotificationChannel channel = new FakeNotificationChannel();
assertThat(channel.getKey()).isEqualTo("FakeNotificationChannel");
assertThat(channel.toString()).isEqualTo("FakeNotificationChannel");
}
use of org.sonar.api.notifications.NotificationChannel in project sonarqube by SonarSource.
the class DefaultNotificationManager method findSubscribedRecipientsForDispatcher.
/**
* {@inheritDoc}
*/
@Override
public Multimap<String, NotificationChannel> findSubscribedRecipientsForDispatcher(NotificationDispatcher dispatcher, String projectKey, SubscriberPermissionsOnProject subscriberPermissionsOnProject) {
verifyProjectKey(projectKey);
String dispatcherKey = dispatcher.getKey();
Set<SubscriberAndChannel> subscriberAndChannels = Arrays.stream(notificationChannels).flatMap(notificationChannel -> toSubscriberAndChannels(dispatcherKey, projectKey, notificationChannel)).collect(Collectors.toSet());
if (subscriberAndChannels.isEmpty()) {
return ImmutableMultimap.of();
}
ImmutableSetMultimap.Builder<String, NotificationChannel> builder = ImmutableSetMultimap.builder();
try (DbSession dbSession = dbClient.openSession(false)) {
Set<String> authorizedLogins = keepAuthorizedLogins(dbSession, projectKey, subscriberAndChannels, subscriberPermissionsOnProject);
subscriberAndChannels.stream().filter(subscriberAndChannel -> authorizedLogins.contains(subscriberAndChannel.getSubscriber().getLogin())).forEach(subscriberAndChannel -> builder.put(subscriberAndChannel.getSubscriber().getLogin(), subscriberAndChannel.getChannel()));
}
return builder.build();
}
Aggregations