Expand my Community achievements bar.

Event listener with a Workflow Launcher

Avatar

Level 5

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?

17 Replies

Avatar

Level 10

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

Avatar

Level 5

smacdonald2008 wrote...

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

 


Yes I am.

Avatar

Level 5
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)

Avatar

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.  

Avatar

Level 5

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.

Avatar

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.

Avatar

Level 5

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

 

Avatar

Level 5

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

Avatar

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

Avatar

Employee Advisor

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

Avatar

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 .

Avatar

Employee Advisor

Hi,

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

kind regards,
Jörg

Avatar

Level 3

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

Avatar

Employee Advisor

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