Search code examples
adobeaemtarget

Exporting AEM experience fragments to Adobe Target automatically every time a related Content Fragment is updated


I have this unique requirement where each time a particular Content Fragment is updated in AEM, all the Experience Fragments referencing that particular Content Fragment need to be automatically exported to Adobe Target.

Thinking about using SQL2 query to retrieve XFs referencing a particular CF and then incorporating this into a workflow process. Also, wondering if I can leverage aem OOTB workflow process called "Export to Target" in this. Not really sure of how to call this "Export to Target" process on each Experience Fragment that we need to export to Target or is this possible at all?

Wondering if anyone has ever come across this requirement and succeeded. Highly appreciate any tips or suggestions in this regard. Many Thanks in advance.


Solution

  • Whenever a Content Fragment is created or updated an OSGi event is triggered. All events are logged under http://localhost:4502/system/console/events. You could write a EventListener or EventHandler, get the path of the event, get the Resource and adapt it to com.adobe.cq.dam.cfm.ContentFragment. The topic for these events is "com/day/cq/dam" or in this constant.

    From the adapted Class or Resource you can get informations about the model and if it's the model you want to process.

    To find all references I would also create an oak index and use SQL2 query to find all references.

    The query would be something like this:

    select [jcr:path], [jcr:score], * from [nt:base] as a where contains(*, '"/content/dam/myReferencedModel"') 
    

    If you have all referencing XF's you can kick off any workflow via WorkflowService:

        @Reference
        private WorkflowService workflowService;
    
            WorkflowSession wfSession = workflowService.getWorkflowSession(session);
            WorkflowModel wfModel = wfSession.getModel("/var/workflow/models/mymodel");
            WorkflowData wfData = wfSession.newWorkflowData("JCR_PATH", "/payload");
            wfSession.startWorkflow(wfModel, wfData);