Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Event listener with a Workflow Launcher

TheBigRed
Level 4
Level 4

Hello,

I have workflow launcher active on a directory.

Also have a custom event listener set on the same directory. The event listener moves files to a different folder.

Problem is the workflow is interfering with the event listener as the event listener can't move the files since it's in a workflow.

How to work around this?

1 Reply
smacdonald2008
Level 10
Level 10

Are you referring Java logic that implements javax.jcr.observation.EventListener?

TheBigRed
Level 4
Level 4

smacdonald2008 wrote...

Are you referring Java logic that implements javax.jcr.observation.EventListener?

 


Yes I am.

TheBigRed
Level 4
Level 4
This is the error I'm receiving, I'm guessing my event listener is moving the file before DAM XMP Writeback is finished? com.day.cq.workflow.WorkflowException: execute: cannot set last modified, asset [{/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1785745288_prism.xml/jcr:content/metadata}] in payload doesn't exist for workflow [{VolatileWorkItem_node1_etc_workflow_instances_server0_2016-08-03_1_dam-xmp-writeback_660}]. at com.day.cq.dam.core.process.AssetSetLastModifiedProcess.execute(AssetSetLastModifiedProcess.java:202) at com.day.cq.workflow.compatibility.CQWorkflowProcessRunner.execute(CQWorkflowProcessRunner.java:93) at com.adobe.granite.workflow.core.job.HandlerBase.executeProcess(HandlerBase.java:189) at com.adobe.granite.workflow.core.job.JobHandler.process(JobHandler.java:244) at org.apache.sling.event.impl.jobs.JobConsumerManager$JobConsumerWrapper.process(JobConsumerManager.java:500) at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.startJob(JobQueueImpl.java:291) at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.access$100(JobQueueImpl.java:58) at org.apache.sling.event.impl.jobs.queues.JobQueueImpl$1.run(JobQueueImpl.java:227) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)
smacdonald2008
Level 10
Level 10

You are correct - the issue seems to be the Event Handler and Workflow tries to access the same content. I would re-think your design. Its not good practice to have an Event Hanlder and WF try and modify the same content.  

TheBigRed
Level 4
Level 4

What would you suggest? Use the payload api to see if the asset is in a workflow...wait then execute the functions in the event listener?

Problem is it's an OOTB workflow (DAM Update Asset) which interferes with our design. We actually want that workflow to run on those assets as well.

Gdubz-57m2mu
Level 5
Level 5

Have you given any thought to writing a WorkflowProcess step and including it at the end of the DAM Update Asset workflow? Maybe create a copy of the DAM Update Asset workflow first and the modify the Launchers to use your custom DAM Update Asset workflow instead of the OOTB one.

TheBigRed
Level 4
Level 4

I've added my code to the end of DAM XMP Writeback. However getting this error:

05.08.2016 10:28:39.498 *WARN* [JobHandler: /etc/workflow/instances/server0/2016-08-04/luxid-processing_632:/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1359150071_prism.xml/jcr:content/renditions/original] org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate Attempted to perform refresh while thread JobHandler: /etc/workflow/instances/server0/2016-08-04/luxid-processing_634:/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1370879008_prism.xml/jcr:content/renditions/original was concurrently writing to this session. Blocked until the other thread finished using this session. Please review your code to avoid concurrent use of a session.
05.08.2016 10:28:39.531 *WARN* [JobHandler: /etc/workflow/instances/server0/2016-08-04/luxid-processing_632:/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1359150071_prism.xml/jcr:content/renditions/original] org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate Attempted to perform Setting property [/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1359150071_prism.xml/jcr:content/metadata/dc:language] while thread JobHandler: /etc/workflow/instances/server0/2016-08-04/luxid-processing_634:/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1370879008_prism.xml/jcr:content/renditions/original was concurrently writing to this session. Blocked until the other thread finished using this session. Please review your code to avoid concurrent use of a session.
05.08.2016 10:28:39.844 *INFO* [JobHandler: /etc/workflow/instances/server0/2016-08-04/luxidfilemover_636:/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1353637368_prism.xml/jcr:content/metadata] com.day.cq.dam.core.process.XMPWritebackProcess payload path :/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1353637368_prism.xml/jcr:content/metadata
05.08.2016 10:28:39.856 *INFO* [JobHandler: /etc/workflow/instances/server0/2016-08-04/luxidfilemover_636:/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1353637368_prism.xml/jcr:content/metadata] com.rogers.aem.LuxidFileMover -1
05.08.2016 10:28:40.031 *INFO* [JobHandler: /etc/workflow/instances/server0/2016-08-04/luxidfilemover_637:/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1370879008_prism.xml/jcr:content/metadata] com.day.cq.dam.core.process.XMPWritebackProcess payload path :/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1370879008_prism.xml/jcr:content/metadata
05.08.2016 10:28:40.034 *INFO* [JobHandler: /etc/workflow/instances/server0/2016-08-04/luxidfilemover_637:/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1370879008_prism.xml/jcr:content/metadata] com.rogers.aem.LuxidFileMover -1
05.08.2016 10:28:40.244 *INFO* [JobHandler: /etc/workflow/instances/server0/2016-08-04/luxidfilemover_638:/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1359150071_prism.xml/jcr:content/metadata] com.day.cq.dam.core.process.XMPWritebackProcess payload path :/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1359150071_prism.xml/jcr:content/metadata
05.08.2016 10:28:40.246 *INFO* [JobHandler: /etc/workflow/instances/server0/2016-08-04/luxidfilemover_638:/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1359150071_prism.xml/jcr:content/metadata] com.rogers.aem.LuxidFileMover -1
05.08.2016 10:28:40.475 *INFO* [JobHandler: /etc/workflow/instances/server0/2016-08-04/luxidfilemover_639:/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1376988250_prism.xml/jcr:content/metadata] com.day.cq.dam.core.process.XMPWritebackProcess payload path :/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1376988250_prism.xml/jcr:content/metadata
05.08.2016 10:28:40.480 *INFO* [JobHandler: /etc/workflow/instances/server0/2016-08-04/luxidfilemover_639:/content/dam/rogers/rpl_brandpublications/prism/CHE_20160701_1376988250_prism.xml/jcr:content/metadata] com.rogers.aem.LuxidFileMover -1

 
TheBigRed
Level 4
Level 4

I've added a custom workflow step to the end of DAM XMP Writeback to move files once XMP Writeback is done.

ebin_Aby
Level 3
Level 3

hey smacdonald2008 , is there anyway i can trigger a workflow on a click of button. I want to create a tools page and onclick of button i want to start workflow . Would perfer javascript or Java

Jörg_Hoh
Employee
Employee

What is your requirement, that you want to move things around while potentially at the same time a workflow is started for it?

Kind regards,

Jörg

ebin_Aby
Level 3
Level 3

We wanted to create a tools page to delete a node eg ecom data node , where we will have a button to request deletion and once it is approved by workflow process the node is deleted and replicated to publish server .

Jörg_Hoh
Employee
Employee

Hi,

I think I understand your usecase, but at which point comes this EventHandler into the play?

kind regards,
Jörg

ebin_Aby
Level 3
Level 3

In my senerio onclick of button start workflow and send the some parameters .

Jörg_Hoh
Employee
Employee

Ok, understood.

I think you are confused by the term EventListener.

In the AEM (backend) world the term EventListener describes a functionality, which listens for OSGI events and performs certain activities when they happen. OSGI events are sent for many things in the system; for example when a page has been created, an event with the topic "com/day/cq/wcm/core/page" is being sent.

This Event handling has nothing to do with any kind of reaction to UI/frontend actions.

Does this help?

Jörg