简体   繁体   中英

How to take an action on a deleted Asset in Adobe Experience Manager?

I have a system external to Adobe Experience Manager that I need to make a quick call to whenever an Asset is deleted in AEM. Not being an expert in AEM, my options feel very limited.

I've attempted to create a workflow with a step that can make the appropriate call, and have hooked up a Launcher to listen for a Remove event on any "dam:Asset" type nodes from a certain path in AEM. That means I've got a Java class I've pushed into AEM that extends WorkflowProcess, and is called as part of that workflow.

However, this workflow is not being triggered when I go delete an Asset. If, however, I change the Launcher to listen for a Remove event on "Any Node Type", the workflow is called as I would have expected, however it appears that the asset has already been deleted by the time it hits my process, so the node path provided to my process is already null and void and I'm unable to do anything with it. In any case, I can't leave the Launcher set to fire on "Any Node Type"...

What am I missing? Is there a better way to capture a delete event on an asset? All I need is to be able to gather some information from the deleted node and its children to make this external call. I just need a handle on the Node when a user deletes an Asset...

There are basically 3 ways to do this :

1) Using workflows - The way you are doing it right now. Create a workflow and use a launcher to trigger the workflow. This method has its disadvantages. if there are going to be lot of concurrent events then you should avoid using workflows since each workflow is an independent thread. if there are lot of workflows then you could end up with lot of waiting threads.

2) Using Sling Eventing - This is an eventing mechanism provided by sling. This is a publish-subscribe model Here you subscribe to different topics and you are notified when any event for that topic occurs. There are different topics like "RESOURCE_ADDED", "RESOURCE_REMOVED" etc.

Here is a sample code on how to create a listener which is notified when a resource is removed.

public class AssetRemoved implements EventHandler {

    private Logger logger = LoggerFactory.getLogger(AssetRemoved.class);

    @Override
    public void handleEvent(Event event) {

        logger.info("********Node removed");

        String[] propertyNames = event.getPropertyNames();



    }
}

3) using Lower level JCR API's - This is an eventing mechanism provided by JCR implementations. This is the lowest level of eventing right at the persistence level. As a good pratice, it is always recommended to use higher level API's like sling or the one's provided by Adobe as a general rule.

In JCR eventing mechanism, you create an observation listener which is notified

http://www.day.com/specs/jsr170/javadocs/jcr-1.0/javax/jcr/observation/EventListener.html

There are 6 types of events which can occur :

Node added Node moved Node removed Property added Property removed Property changed

Your Event listener is notified for all the events and you have to filter based on which type you want to listen(unlike Sling eventing).

You can create an Event listener like the below sample code :

Public class SampleEventListener implements EventListener{

    pubic void onEvent(EventIterator events){

        //filter the type of event type & do your stuff here:

    }
}

For your use case I would suggest to use the Sling Eventing(option 2). Until and unless really necessary or you need a really granular access, always stick to higher level API's like sling.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM