private Set<String> keepAuthorizedLogins(DbSession dbSession, String projectKey, Set<SubscriberAndChannel> subscriberAndChannels, @Nullable Boolean global, String permission) { Set<String> logins = subscriberAndChannels.stream() .filter(s -> global == null || s.getSubscriber().isGlobal() == global) .map(s -> s.getSubscriber().getLogin()) .collect(Collectors.toSet()); if (logins.isEmpty()) { return Collections.emptySet(); } return dbClient.authorizationDao().keepAuthorizedLoginsOnProject(dbSession, logins, projectKey, permission); }
/** * {@inheritDoc} */ @Override public Multimap<String, NotificationChannel> findSubscribedRecipientsForDispatcher(NotificationDispatcher dispatcher, String projectKey, SubscriberPermissionsOnProject subscriberPermissionsOnProject) { requireNonNull(projectKey, "projectKey is mandatory"); 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(); }
private Set<String> keepAuthorizedLogins(DbSession dbSession, String projectKey, Set<SubscriberAndChannel> subscriberAndChannels, @Nullable Boolean global, String permission) { Set<String> logins = subscriberAndChannels.stream() .filter(s -> global == null || s.getSubscriber().isGlobal() == global) .map(s -> s.getSubscriber().getLogin()) .collect(Collectors.toSet()); if (logins.isEmpty()) { return Collections.emptySet(); } return dbClient.authorizationDao().keepAuthorizedLoginsOnProject(dbSession, logins, projectKey, permission); }
/** * {@inheritDoc} */ @Override public Multimap<String, NotificationChannel> findSubscribedRecipientsForDispatcher(NotificationDispatcher dispatcher, String projectKey, SubscriberPermissionsOnProject subscriberPermissionsOnProject) { requireNonNull(projectKey, "projectKey is mandatory"); 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(); }