0
votes

In AEM CQ , I am using asset manager api to write content(images uploaded from) in dam. This triggers out of the box Dam Update Asset workflow. I require to read renditions and asset properties that would be written available once the workflow is completed. My question is how to wait until the workflow is completed for reading the asset properties instead of thread.sleep.

I tried with a recursive function call to iterate while the asset property is present. This gave null pointer exception. But when I put a thread.sleep of 50 ms inside the iteration it works for me.

Another approach I tried to get the workflow object inside the service to read workflow status but found that it takes few milliseconds for the ootb workflow to start after the content is written. Here also had to give thread.sleep.

One more attempt to use a event handler to listen workflow events. We are able to enter the event type as workflow completed. How to notify the service or jsp that the workflow is completed and we can read the asset properties and renditions?

It would be great if someone can share their suggestions feedback on the approach. Thank you.

1

1 Answers

1
votes

You have the wrong approach to solve this problem. In my eyes you have exactly 2 reasonable solutions on this.

Create workflow process/step and extend the Dam Update Asset Workflow with your custom step.

OR

Create JCR observation listener and listen for Event.PROPERTY_ADDED for example or use the higher sling APIs and create event handler with the appropriate topic and than execute your business logic as soon the property you look for is added or changed.

Why not to use Thread.sleep() or other similar solution:

  • you don't know when the workflow is executed exactly. it may be delayed if many asssets are uploaded or just get stuck
  • you cannot assure that your thread will be able to execute it's logic. the instance may be stopped for example
  • creating a new tread for every resource uploaded may be expensive task. you also waste resources when you create an infinite loop and put those threads to sleep, than wake them and check again and again ... and so on until eventually the thread is able to do it's job