Search in sources :

Example 16 with NotificationChannel

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);
}
Also used : NotificationChannel(org.sonar.api.notifications.NotificationChannel) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 17 with NotificationChannel

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);
}
Also used : NotificationChannel(org.sonar.api.notifications.NotificationChannel) ComponentFinder(org.sonar.server.component.ComponentFinder) NotificationCenter(org.sonar.server.notification.NotificationCenter) NotificationDispatcherMetadata(org.sonar.server.notification.NotificationDispatcherMetadata) NotificationUpdater(org.sonar.server.notification.NotificationUpdater) WsActionTester(org.sonar.server.ws.WsActionTester) Before(org.junit.Before)

Example 18 with NotificationChannel

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);
        }
    }
}
Also used : NotificationChannel(org.sonar.api.notifications.NotificationChannel) Collection(java.util.Collection) Map(java.util.Map)

Example 19 with NotificationChannel

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");
}
Also used : NotificationChannel(org.sonar.api.notifications.NotificationChannel) Test(org.junit.Test)

Example 20 with NotificationChannel

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();
}
Also used : Arrays(java.util.Arrays) SonarException(org.sonar.api.utils.SonarException) Multimap(com.google.common.collect.Multimap) DbSession(org.sonar.db.DbSession) Collections.singletonList(java.util.Collections.singletonList) InvalidClassException(java.io.InvalidClassException) Loggers(org.sonar.api.utils.log.Loggers) Objects.requireNonNull(java.util.Objects.requireNonNull) NotificationChannel(org.sonar.api.notifications.NotificationChannel) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Nullable(javax.annotation.Nullable) Logger(org.sonar.api.utils.log.Logger) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) Subscriber(org.sonar.db.property.Subscriber) Collections.emptySet(java.util.Collections.emptySet) Notification(org.sonar.api.notifications.Notification) Set(java.util.Set) NotificationQueueDto(org.sonar.db.notification.NotificationQueueDto) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) DbClient(org.sonar.db.DbClient) List(java.util.List) Stream(java.util.stream.Stream) EmailSubscriberDto(org.sonar.db.EmailSubscriberDto) VisibleForTesting(com.google.common.annotations.VisibleForTesting) EmailNotificationChannel(org.sonar.server.notification.email.EmailNotificationChannel) Collections(java.util.Collections) NotificationChannel(org.sonar.api.notifications.NotificationChannel) EmailNotificationChannel(org.sonar.server.notification.email.EmailNotificationChannel) DbSession(org.sonar.db.DbSession) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap)

Aggregations

NotificationChannel (org.sonar.api.notifications.NotificationChannel)21 Test (org.junit.Test)12 Notification (org.sonar.api.notifications.Notification)8 Collection (java.util.Collection)6 Subscriber (org.sonar.db.property.Subscriber)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Before (org.junit.Before)3 NotificationDispatcherMetadata (org.sonar.server.notification.NotificationDispatcherMetadata)3 SubscriberPermissionsOnProject (org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject)3 Map (java.util.Map)2 ComponentFinder (org.sonar.server.component.ComponentFinder)2 NotificationCenter (org.sonar.server.notification.NotificationCenter)2 NotificationUpdater (org.sonar.server.notification.NotificationUpdater)2 WsActionTester (org.sonar.server.ws.WsActionTester)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 Multimap (com.google.common.collect.Multimap)1 IOException (java.io.IOException)1 InvalidClassException (java.io.InvalidClassException)1