Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Sling Event Listener

Avatar

Level 3

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.

3 Replies

Avatar

Community Advisor

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.

Screen Shot 2018-06-18 at 2.26.31 PM.png

Thanks

Arun



Arun Patidar

Avatar

Level 7

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