Sling Event Listener | Community
Skip to main content
Murali89
Level 2
June 18, 2018

Sling Event Listener

  • June 18, 2018
  • 3 replies
  • 3914 views

Is there way to listen to the Tag Move events? I could find there is one for Page move when we have event topic value as below

EventConstants.EVENT_TOPIC + "=com/day/cq/wcm/core/page"

But i want to do something when tags are moved around namespaces.

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

3 replies

arunpatidar
Community Advisor
Community Advisor
June 18, 2018

Hi,

like page move , there is no special event for Tag move. When we move Tags it will create events like CHANGED and ADDED wrt to destination and source of tag.

e.g. if I move /etc/tags/we-retail/activity/biking tag to we-retail root(/etc/tags/we-retail/), following events are captured.

Thanks

Arun

Arun Patidar
Techaspect_Solu
Level 7
June 18, 2018

Hi,

There is no specific EVENT for the 'tags', instead of EVENT_TOPIC we can use EVENT_FILTER. The following code snippet can be used for the event to be triggered  when tag is moved from one namespace to other.

@Component(

  immediate = true,

  service = EventHandler.class,

  property = {

    EventConstants.EVENT_FILTER + "=(path=/etc/tags/*)",

    EventConstants.EVENT_TOPIC + "=" + SlingConstants.TOPIC_RESOURCE_ADDED,

    EventConstants.EVENT_TOPIC + "=" + SlingConstants.TOPIC_RESOURCE_CHANGED,

    EventConstants.EVENT_TOPIC + "=" + SlingConstants.TOPIC_RESOURCE_REMOVED

  }

)

public class EventHandlerDemo implements EventHandler {

@Override

public void handleEvent(Event event) {

  String topic = event.getTopic();

  Object path = event.getProperty(SlingConstants.PROPERTY_PATH);

  logger.info("Path of the asset and topic of the event:" + topic + ":::path:" + path);

}

}

Hope this helps.

Regards,

TechAspect Solutions

smacdonald2008
Level 10
June 18, 2018

Great responses!