Skip to content

Commit

Permalink
Merge pull request #1921 from bosch-io/bugfix/policy-nouncments-pubsub
Browse files Browse the repository at this point in the history
PolicyAnnouncementTopicExtractor pub/sub namespaced topics support
  • Loading branch information
alstanchev committed Apr 1, 2024
2 parents f7b4b22 + 8e83bf8 commit 6ee7ce0
Showing 1 changed file with 13 additions and 2 deletions.
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 6ee7ce0

Please sign in to comment.