CQ 5.6.1 - PageEvent, Filter for modifications | Community
Skip to main content
Level 2
October 16, 2015
Solved

CQ 5.6.1 - PageEvent, Filter for modifications

  • October 16, 2015
  • 4 replies
  • 1838 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Runal_Trivedi

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:

  • userid of user that caused the event
  • path where event occured
  • type of event
  • modifiedDate

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

4 replies

smacdonald2008
Level 10
October 16, 2015

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. 

Level 2
October 16, 2015

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?

Runal_Trivedi
Runal_TrivediAccepted solution
Level 6
October 16, 2015

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:

  • userid of user that caused the event
  • path where event occured
  • type of event
  • modifiedDate

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

Level 2
October 16, 2015

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.