Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

How to get all the changes in Workflow custom process?

Avatar

Level 4

Scenario:

Authors adding a new image or modifying an existing image in a page and create workflow for publishing the page. I use a Custom Workflow process step to publish the content and also construct & migrate the package to another AEM instance via curl. The problem I'm facing is, in the custom workflow process class, I get only the page (which the Author is trying to publish) in the payload and not the image added/modified. 

Is there a way to get the image as well so that I can add the same in filter and migrate the package. Please help.

Thanks,

Rakesh

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

You can write aem query to find all images in aem pages or think an easy option is to use AssetSearchReferenceAPI, this will return a list of all the assets associated with a page, 

Here you have a full code sample of how to use it: https://github.com/Adobe-Marketing-Cloud/aem-samples/blob/master/tutorial-referenced-assets/bundle/s... . 

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

You can write aem query to find all images in aem pages or think an easy option is to use AssetSearchReferenceAPI, this will return a list of all the assets associated with a page, 

Here you have a full code sample of how to use it: https://github.com/Adobe-Marketing-Cloud/aem-samples/blob/master/tutorial-referenced-assets/bundle/s... . 

Avatar

Community Advisor

@rakesh_h2 instead of this custom workflow process, did you guys evaluated replication agent (AEM On-Prem or AMS) or Sling Distribution (AEM Cloud)? It will internally take care of References publish as well. Also Adobe has many scripts and Now a Cloud manager option to sync content abd images across AEM environments. Please reevaluate your usecase.

Avatar

Community Advisor

Hello @rakesh_h2 

 

As @DPrakashRaj  mentioned, we can use the AssetReferenceSearch API to be the list of Assets used in a Page.

 

Once you get the list of Assets, publish only the ones that need to be:

- Never published assets

- Unpublished assets

- Modified after publish.

 

If we publish more than what is needed it can cause performance issues, because of following reasons:

- assets take more resources

- Unnecessary cache flush

 

 String Pagepath = "/content/geometrixx/en"; //This would be your page path

        Resource r = resourceResolver.getResource(Pagepath + "/" + JcrConstants.JCR_CONTENT);

        Node n = r.adaptTo(Node.class);

        AssetReferenceSearch ref = new AssetReferenceSearch(n, DamConstants.MOUNTPOINT_ASSETS, resourceResolver);

        Map<String, Asset> allref = new HashMap<String, Asset>();

        allref.putAll(ref.search());

        for (Map.Entry<String, Asset> entry : allref.entrySet()) {

            Asset asset = entry.getValue();

            final ReplicationStatus replStatus = asset.adaptTo(ReplicationStatus.class);

            if (replStatus != null) {

                //will give you activation status ...
                if (replStatus.isActivated()) {
                    //do not publish
                }
            }
        }

Aanchal Sikka