-
-
Notifications
You must be signed in to change notification settings - Fork 459
Add support for RegEx expressions in event WebSocket topic filter #5116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for RegEx expressions in event WebSocket topic filter #5116
Conversation
|
When updating the docs after this has been merged, don’t forget to correct the docs, that the * wildcard does match multiple topic segments. |
|
@florian-h05 Could you please rebase this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR extends the event WebSocket topic filter to support regular expressions in addition to the existing wildcard (*) pattern matching. The implementation introduces a TopicFilterMapper class that determines whether a topic filter is a simple pattern (using word characters, slashes, and optional asterisks) or a regular expression. Simple patterns are converted to regex with wildcard expansion and anchoring, while regex patterns are used directly. The change refactors the filter processing logic from EventWebSocket into the new mapper class, improves error handling by passing PatternSyntaxException through the chain, and adds comprehensive test coverage for the new regex functionality.
Key Changes
- Introduced
TopicFilterMapperclass to handle conversion of topic expressions to regex patterns, supporting both simple wildcard syntax and full regex - Extended
TopicEventFilterconstructor to declarePatternSyntaxExceptionfor better error transparency - Added comprehensive test cases covering regex patterns in both include and exclude topic filters
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
TopicFilterMapper.java |
New class that maps topic filter expressions to TopicEventFilter, handling both simple wildcard patterns and regex patterns |
TopicEventFilter.java |
Updated constructor to declare PatternSyntaxException and corrected JavaDoc |
EventWebSocket.java |
Refactored topic filter logic to use TopicFilterMapper instead of inline processing |
EventProcessingException.java |
Added constructor accepting both message and cause for better exception chaining |
EventWebSocketTest.java |
Enhanced tests to cover regex patterns in both include and exclude filters |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bundles/org.openhab.core/src/main/java/org/openhab/core/events/TopicEventFilter.java
Outdated
Show resolved
Hide resolved
...b.core.io.websocket/src/main/java/org/openhab/core/io/websocket/event/TopicFilterMapper.java
Outdated
Show resolved
Hide resolved
...b.core.io.websocket/src/main/java/org/openhab/core/io/websocket/event/TopicFilterMapper.java
Outdated
Show resolved
Hide resolved
Closes openhab#4600. Signed-off-by: Florian Hotze <[email protected]>
Signed-off-by: Florian Hotze <[email protected]>
c5bdb4b to
5bc42d2
Compare
Signed-off-by: Florian Hotze <[email protected]>
|
@kaikreuzer Done |
Closes #4600.
This extends the topic filter for the event WebSocket to support RegEx in addition to the existing
*wildcard expressions.This works by:
*wildcard