Expand my Community achievements bar.

SOLVED

On Deletion, how to get the resource details before it gets deleted?

Avatar

Level 2

Hi,

On deletion of a resource, I need get a property from the resource BEFORE the resource becoming null.

I tried this through Event Listener. In the event listener, the resource is null.

I tried to achieve this through on delete -> launcher -> workflow.   Here also the resource is null. But in this workflow, I have only one processor which tries to get the resource details.

Here can I get the resource details before it gets deleted from the workflow? Actual deletion is done in OOTB code, how can move that code to my workflow?

Here How to take an action on a deleted Asset in Adobe Experience Manager? , Jörg said we can control when the actual deletion is called. But how?

thanks

Srini

1 Accepted Solution

Avatar

Correct answer by
Level 10

Write a custom workflow step. Then using the AEM Workflow APIs, you can get the path of the node that is deleted. You can use this API logic that writes out the path of the node that will be deleted.

public void execute(WorkItem item, WorkflowSession wfsession, MetaDataMap args) throws WorkflowException {

          

try

{

WorkflowData data = item.getWorkflowData();

String path = null;

String type = data.getPayloadType();

   if (data.getPayload() != null) {

       String payloadData = (String) data.getPayload();

       path = payloadData;

      

   }

log.info("*** THE path of the node to DELETED IS "+path);

}

  

    catch (Exception e)

    {

    log.info(" MASSIVE ERROR "+e.getMessage())  ;

    }

}

Then the next step in the workflow deletes the page. This is how you get information about JCR content - typically a page that is deleted.

Workflow model --

cusStep.png

Hope this helps....

View solution in original post

11 Replies

Avatar

Level 5

You can implement Preprocessor to fetch the data from resource before it's deletion. Remember Preprocessor works only on activated page as mentioned here.

Avatar

Level 4

You can create a Custom Event Listener Class when a node is removed it.

Basically, you have to add your action and response  when certain event occurs, in your case, it could be something like this ( javax.jcr.observation.Event.NODE_REMOVED)

Let me know if you need complete example, how to implemented

Best Regards

Diego

Avatar

Level 2

Hi,

Here my case is, the content which I am deleting is unpublished content. So in this case, Preprocessor won't get triggered. Any other option I have?

Avatar

Level 10

To solve this requirement, you need to do what Joerg suggests. You need to build a custom workflow step and in that custom step, read the Java node props using a Java API. This step would be invoked before the payload was deleted - which would be a later step.

I will add this use case to our HELPX articles list.

TIP - An event handler will not work as the Event Handler will be fired after the node is  deleted.

Avatar

Level 2

Scott,

Thanks for your reply. Please let me know once the HELPX article is available. I already built a custom workflow with only one workflow step which triggers on node delete. But the resource is getting deleted by the time it comes to the workflow. Should I add one more step for deletion?

thanks

Srini

Avatar

Level 10

I will look into this at code lvl tomorrow.

Avatar

Level 10

I am going to show you how to perform this use case via a custom Workflow Step so we can read the information from the deleted node prior to deleting it. I will post back soon.

Avatar

Correct answer by
Level 10

Write a custom workflow step. Then using the AEM Workflow APIs, you can get the path of the node that is deleted. You can use this API logic that writes out the path of the node that will be deleted.

public void execute(WorkItem item, WorkflowSession wfsession, MetaDataMap args) throws WorkflowException {

          

try

{

WorkflowData data = item.getWorkflowData();

String path = null;

String type = data.getPayloadType();

   if (data.getPayload() != null) {

       String payloadData = (String) data.getPayload();

       path = payloadData;

      

   }

log.info("*** THE path of the node to DELETED IS "+path);

}

  

    catch (Exception e)

    {

    log.info(" MASSIVE ERROR "+e.getMessage())  ;

    }

}

Then the next step in the workflow deletes the page. This is how you get information about JCR content - typically a page that is deleted.

Workflow model --

cusStep.png

Hope this helps....

Avatar

Level 2

Hi, How can we trigger this workflow while a Node/Page is deleted. If I add a launcher for Removed for cq:Page, the workflow is triggered post the page is deleted.

Is there any way to trigger this workflow right before the page/node is deleted?

Avatar

Level 1

how this is a correct answer?

As said by author, workflow is fired AFTER deletion, you cannot get properties of that deleted node.

For that you would need some sling post processor to dump the property to a place from which workflow can read it after deletion of the node

Avatar

Level 10

This log file has this message -- /content/summit-toys/pt] com.aem.community.core.CustomDataStep *** THE TITLE OF THE DELETED ITEM IS /content/summit-toys/pt

This code works!