use case is When any assets got updated , send mail to admin using event handler .Please help/advise if you have worked upon such requirement.
Thanks in advance.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @KNan,
In general you can use DAM EVENT_TOPIC which is dedicated to handle asset related operations, it defines multiple types related to different activities (asset metadata modification, asset move etc), you can find full list under:
In terms of usage in code you can have something like this:
package com.mysite.core.models; import com.day.cq.dam.api.DamEvent; import org.osgi.service.component.annotations.Component; import org.osgi.service.event.Event; import org.osgi.service.event.EventConstants; import org.osgi.service.event.EventHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Component( immediate = true, service = EventHandler.class, property = EventConstants.EVENT_TOPIC + "=" + DamEvent.EVENT_TOPIC) public class DAMEventHandler implements EventHandler { private static final Logger LOG = LoggerFactory.getLogger(DAMEventHandler.class); @Override public void handleEvent(Event event) { DamEvent damEvent = DamEvent.fromEvent(event); if (shouldBeProcessed(damEvent)) { // place for your code } } private boolean shouldBeProcessed(DamEvent damEvent) { // list of Asset related events return DamEvent.Type.METADATA_UPDATED.equals(damEvent.getType() || DamEvent.Type.ASSET_MOVED.equals(damEvent.getType(); } }
You can easily extend list of events that should trigger email to be send.
Regarding sending email itself - please do not do this directly from event handler - this activity should be delegated to Sling Job and maybe queued. In general any code that is not related to event information processing should be executed outside, in other case your event could be blacklisted.
hi @KNan , for the above requirement, you can write ResourceChangeListener. Sample code can be found here.
aem63app-repo/SampleResourceChangeListener2.java at master · arunpatidar02/aem63app-repo · GitHub
Hope this helps
Thanks,
Nikita
Hi @KNan,
In general you can use DAM EVENT_TOPIC which is dedicated to handle asset related operations, it defines multiple types related to different activities (asset metadata modification, asset move etc), you can find full list under:
In terms of usage in code you can have something like this:
package com.mysite.core.models; import com.day.cq.dam.api.DamEvent; import org.osgi.service.component.annotations.Component; import org.osgi.service.event.Event; import org.osgi.service.event.EventConstants; import org.osgi.service.event.EventHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Component( immediate = true, service = EventHandler.class, property = EventConstants.EVENT_TOPIC + "=" + DamEvent.EVENT_TOPIC) public class DAMEventHandler implements EventHandler { private static final Logger LOG = LoggerFactory.getLogger(DAMEventHandler.class); @Override public void handleEvent(Event event) { DamEvent damEvent = DamEvent.fromEvent(event); if (shouldBeProcessed(damEvent)) { // place for your code } } private boolean shouldBeProcessed(DamEvent damEvent) { // list of Asset related events return DamEvent.Type.METADATA_UPDATED.equals(damEvent.getType() || DamEvent.Type.ASSET_MOVED.equals(damEvent.getType(); } }
You can easily extend list of events that should trigger email to be send.
Regarding sending email itself - please do not do this directly from event handler - this activity should be delegated to Sling Job and maybe queued. In general any code that is not related to event information processing should be executed outside, in other case your event could be blacklisted.
Views
Replies
Total Likes
Views
Likes
Replies