如何在Adobe Experience Manager中对已删除的资产采取措施? [英] How to take an action on a deleted Asset in Adobe Experience Manager?

查看:139
本文介绍了如何在Adobe Experience Manager中对已删除的资产采取措施?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Adobe Experience Manager外部的系统,每当在AEM中删除资产时,我都需要快速致电该系统。不是AEM专家,我的选择感到非常有限。

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.

我试图创建一个工作流,并且该步骤可以进行适当的调用,并且已经实现了连接启动器,以侦听AEM中某个路径上任何 dam:Asset类型节点上的Remove事件。这意味着我已经将Java类推入AEM,该类扩展了WorkflowProcess,并被称为该工作流的一部分。

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.

但是,当我删除资产时,不会触发此工作流程。但是,如果我将启动程序更改为侦听任何节点类型上的Remove事件,则将按我期望的那样调用工作流程,但是看来资产在它到达我的进程时已经被删除,因此提供给我的流程的节点路径已经无效,并且我无法对其进行任何操作。无论如何,我都无法将启动器设置为在任何节点类型上启动...

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"...

我丢失了什么?有没有更好的方法来捕获资产上的删除事件?我需要做的就是能够从已删除的节点及其子节点收集一些信息以进行此外部调用。当用户删除资产时,我只需要在Node上使用一个句柄即可。

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...

推荐答案

基本上有3种方法可以做到这一点:

There are basically 3 ways to do this :

1)使用工作流程-您现在的工作方式。创建工作流程并使用启动器触发工作流程。这种方法有其缺点。如果会有很多并发事件,那么您应该避免使用工作流,因为每个工作流都是一个独立的线程。如果工作流程很多,那么您可能会遇到很多等待线程。

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)使用吊索事件-这是吊索提供的事件机制。这是一个发布-订阅模型。在这里,您可以订阅不同的主题,并且在该主题发生任何事件时都会收到通知。有很多不同的主题,例如 RESOURCE_ADDED, RESOURCE_REMOVED等。

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)使用较低级别的JCR API -这是JCR实现提供的事件机制。这是持久性级别上最低的事件级别。作为一个好习惯,通常建议使用较高级别的API(例如吊索)或Adobe提供的API作为一般规则。

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.

在JCR事件机制中,您创建了一个观察者侦听器,该侦听器被通知

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

可以发生6种类型的事件:

There are 6 types of events which can occur :

节点已添加
节点已移动
节点已删除
属性已添加
属性已删除
属性已更改

Node added Node moved Node removed Prop­erty added Prop­erty removed Prop­erty changed

您的事件侦听器会收到所有事件的通知,您必须根据要侦听的类型进行过滤(不同于Sling事件)。

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:

    }
}

为您的用例,我建议使用Sling Eventing(选项2)。除非(除非确实有必要)或者您需要非常细致的访问,否则始终坚持使用诸如吊索之类的更高级别的API。

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.

这篇关于如何在Adobe Experience Manager中对已删除的资产采取措施?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆