/** * Returns true if at least one user is subscribed to at least one notification with given types. * Subscription can be global or on the specific project. */ public boolean hasProjectSubscribersForTypes(String projectUuid, Set<String> notificationTypes) { Collection<String> dispatcherKeys = new ArrayList<>(); for (NotificationDispatcher dispatcher : dispatchers) { if (notificationTypes.contains(dispatcher.getType())) { dispatcherKeys.add(dispatcher.getKey()); } } return dbClient.propertiesDao().hasProjectNotificationSubscribersForDispatchers(projectUuid, dispatcherKeys); }
@Test public void hasProjectSubscribersForType() { setUpMocks(); PropertiesDao dao = mock(PropertiesDao.class); when(dbClient.propertiesDao()).thenReturn(dao); // no subscribers when(dao.hasProjectNotificationSubscribersForDispatchers("PROJECT_UUID", Arrays.asList("CommentOnIssueAssignedToMe", "CommentOnIssueCreatedByMe"))).thenReturn(false); assertThat(service.hasProjectSubscribersForTypes("PROJECT_UUID", Sets.newHashSet("issue-changes"))).isFalse(); // has subscribers on one dispatcher (among the two) when(dao.hasProjectNotificationSubscribersForDispatchers("PROJECT_UUID", Arrays.asList("CommentOnIssueAssignedToMe", "CommentOnIssueCreatedByMe"))).thenReturn(true); assertThat(service.hasProjectSubscribersForTypes("PROJECT_UUID", Sets.newHashSet("issue-changes"))).isTrue(); }
@Test public void hasNotificationSubscribers() { int userId1 = db.users().insertUser(u -> u.setLogin("user1")).getId(); int userId2 = db.users().insertUser(u -> u.setLogin("user2")).getId(); Long projectId = insertPrivateProject("PROJECT_A").getId(); // global subscription insertProperty("notification.DispatcherWithGlobalSubscribers.Email", "true", null, userId2); // project subscription insertProperty("notification.DispatcherWithProjectSubscribers.Email", "true", projectId, userId1); insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", 56L, userId1); insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", projectId, userId1); // global subscription insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", null, userId2); // Nobody is subscribed assertThat(underTest.hasProjectNotificationSubscribersForDispatchers("PROJECT_A", singletonList("NotSexyDispatcher"))) .isFalse(); // Global subscribers assertThat(underTest.hasProjectNotificationSubscribersForDispatchers("PROJECT_A", singletonList("DispatcherWithGlobalSubscribers"))) .isTrue(); // Project subscribers assertThat(underTest.hasProjectNotificationSubscribersForDispatchers("PROJECT_A", singletonList("DispatcherWithProjectSubscribers"))) .isTrue(); assertThat(underTest.hasProjectNotificationSubscribersForDispatchers("PROJECT_B", singletonList("DispatcherWithProjectSubscribers"))) .isFalse(); // Global + Project subscribers assertThat(underTest.hasProjectNotificationSubscribersForDispatchers("PROJECT_A", singletonList("DispatcherWithGlobalAndProjectSubscribers"))) .isTrue(); assertThat(underTest.hasProjectNotificationSubscribersForDispatchers("PROJECT_B", singletonList("DispatcherWithGlobalAndProjectSubscribers"))) .isTrue(); }
/** * Returns true if at least one user is subscribed to at least one notifications with given types. * Subscription can be globally or on the specific project. */ public boolean hasProjectSubscribersForTypes(String projectUuid, Set<String> notificationTypes) { Collection<String> dispatcherKeys = new ArrayList<>(); for (NotificationDispatcher dispatcher : dispatchers) { if (notificationTypes.contains(dispatcher.getType())) { dispatcherKeys.add(dispatcher.getKey()); } } return dbClient.propertiesDao().hasProjectNotificationSubscribersForDispatchers(projectUuid, dispatcherKeys); }