Hi everyone,
we use an EventHandler to listen for Events from type PageEvent and we want to use a specific filter. The problem is that all information are saved inside an array (called: modifications). Here is a code example:
@Component(immediate = true) @Service(value = EventHandler.class) @Properties({ @Property(name = EventConstants.EVENT_TOPIC, value = PageEvent.EVENT_TOPIC), @Property(name = EventConstants.EVENT_FILTER, value = "(modifications=*)") })
Is there an opportunity to filter specific attributes from "modifications", like "path" or "type"? We already tried LDAP filters like: "modifications.path=...", "modifications/path=...", etc.
Are there any suggestions?
Solved! Go to Solution.
Views
Replies
Total Likes
If your requirement is to handle the page event only if it is triggered at specific path in your repo, if that is the case below should help.
To get the path details where page event occurs, you can make use of method - PageModification.getEventProperties() this returns the event properties map which contains following details:
Sample from log:
16.04.2015 17:14:28.573 *INFO* [Thread-2301] com.sample.impl.PageEventHandlerImpl EVENT******** Page Modifications Event Properties are {userId=admin, path=/content/geometrixx/en/testpage/test3, type=PageCreated, modifiedDate=Thu Apr 16 17:14:28 IST 2015}
Hope it helps.
- Runal
Views
Replies
Total Likes
Here is a community article that talks about Sling Event Handling and Filters:
Using Event filters for handling JCR events through an event handler
Hope this helps.
Views
Replies
Total Likes
Hello and thanks for your response. This is a good article about Sling Event Handling with a good use of a filter, but we have a problem with filtering events from type PageEvent.EVENT_TOPIC.
I will try to explain it: SlingConstants.TOPIC_RESOURCE_ADDED/CHANGED/REMOVED has different attributes for filtering, like "path", "userid", etc. All these attributes are standalone and therefor usefull for a filter. But the event PageEvent.EVENT_TOPIC only has one attribute called "modifications" which is an array of attributes like "path", "userid", etc.
In our case we want a filter for the "path" but don't get the path from the array through LDAP Syntax.
So does anybody know if this is even possible?
Views
Replies
Total Likes
If your requirement is to handle the page event only if it is triggered at specific path in your repo, if that is the case below should help.
To get the path details where page event occurs, you can make use of method - PageModification.getEventProperties() this returns the event properties map which contains following details:
Sample from log:
16.04.2015 17:14:28.573 *INFO* [Thread-2301] com.sample.impl.PageEventHandlerImpl EVENT******** Page Modifications Event Properties are {userId=admin, path=/content/geometrixx/en/testpage/test3, type=PageCreated, modifiedDate=Thu Apr 16 17:14:28 IST 2015}
Hope it helps.
- Runal
Views
Replies
Total Likes
Hello Runal,
thanks for your help. We know the way to get the path using PageModification.getEventProperties() but with this we only determine to handle the event after the event has received.
We wanted to filter for a specific event so that our EventListener doesn't listen to every PageModification he got. Now we decided to use a simple if-then-statement to handle only the events with the specific path. It's not correctly solved but this workaround does its job.
Views
Replies
Total Likes