Skip to content

Commit

Permalink
PolicyAnnouncementTopicExtractor pub/sub namespaced topics support
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandar Stanchev <aleksandar.stanchev@bosch.com>
  • Loading branch information
alstanchev committed Mar 29, 2024
1 parent f7b4b22 commit 8e83bf8
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.ditto.internal.utils.pubsub.extractors.PubSubTopicExtractor;
import org.eclipse.ditto.policies.model.SubjectId;
Expand All @@ -28,11 +31,19 @@ final class PolicyAnnouncementTopicExtractor implements PubSubTopicExtractor<Pol
@Override
public Collection<String> getTopics(final PolicyAnnouncement<?> message) {
if (message instanceof SubjectDeletionAnnouncement announcement) {
return announcement.getSubjectIds()
final Set<String> topicsWithoutNamespace = announcement.getSubjectIds()
.stream()
.map(SubjectId::toString)
.toList();
.collect(Collectors.toSet());
return Stream.concat(combineNamespaceWithAuthSubjects(announcement.getEntityId().getNamespace(), topicsWithoutNamespace),
topicsWithoutNamespace.stream())
.collect(Collectors.toList());
}
return List.of();
}

private static Stream<String> combineNamespaceWithAuthSubjects(final String namespace,
final Set<String> authorizationSubjectIds) {
return authorizationSubjectIds.stream().map(subject -> namespace + "#" + subject);
}
}

0 comments on commit 8e83bf8

Please sign in to comment.