Bulk Publish
Tags: aem, devjournal, adobe, cms
Published: 2021-06-09 13:08:00


Greetings, AEM geeks! This Bulk Publish a Replicator Application may be useful if you're an AEM content author who wants to publish a large number of pages with a single button click rather than publishing each page individually.

## **Purpose**

This functionality allows you to publish a large number of pages, as well as the assets included inside those pages, with a single button click.

### Existing feature and its limitation

AEM's *[Activation Tree](https://experienceleague.adobe.com/docs/experience-manager-64/classic-ui/authoring/classic-page-author-publish-pages.html?lang=en#howtoactivateacompletesectiontreeofyourwebsite)* feature allows for bulk activation/deactivation of pages that are *only modified, only activated, or Ignore Deactivated* under a specific tree.

Even though it has a lot of features, it's hard to publish certain pages but not others under a tree. 

So, following the instructions below, you may use the bulk publish functionality to solve this problem.

### Demo

{% youtube jVrBUoF8XwM%}

### Steps to use Bulk Publish Component

- Drag and drop Bulk Publish Component in a page
- Author dialog of the component by specifying the paths of the pages needed to be published

Enter the Page Paths to Publish in the format - /content/trainingproject/en

![1_Author](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1lofoh8ku3i11al82pnj.png)

:bulb: *Note: There is no need to include the.html extension to the path, such as→/content/trainingproject/en.html*

- To publish the list of pages available and the assets contained within them, click the Publish button.

    ![Publish Done](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8zb52l9yn75zj6z83s8b.png)

- Yayyy!!! :open_hands: We can find the pages have now been published in their respective paths successfully 😋

![3_check](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3btckzzzxhz46cf78jnh.png)

:point_right: *Now let's take a look at the code that makes all of this magic  💫  happen.*

### Back End Code

##### Replication API

AEM contains a [*Replication API*](https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/diff-previous/changes/com.day.cq.replication.Replicator.html) that allows you to replicate content using code. We can take advantage of this and replicate the Pages.

{% gist https://gist.github.com/rpriyaraji/04247e30a0520d0ab97b68d8b6091bc6 %}

##### Activating Page Assets

To search for all Dam Assets, [*AssetReferenceSearch*](https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/javadoc/com/day/cq/dam/commons/util/AssetReferenceSearch.html) API is used. It searches in pages for referenced assets.

[*DamConstants.MOUNTPOINT_ASSETS*](https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/javadoc/com/day/cq/dam/api/DamConstants.html)- Defines common used dam constants and the repository path (mount point) under which asset metadata is stored.

{% gist https://gist.github.com/rpriyaraji/5c583833cbcd583e2aeb1ccf3fc8da6f %}

### Front End Code

Now we need to make an Ajax call from the UI to process the BulkPublishServlet on the backend when a button is clicked.

##### AJAX Call

{% gist https://gist.github.com/rpriyaraji/5b983e1049a605b009d3162006c72a8a %}

:bulb: *On hover, you can find the entire code of both [*Frontend component*](https://github.com/rpriyaraji/AEM-Learning/tree/main/ui.apps/src/main/content/jcr_root/apps/trainingproject/components/content/bulkPublish) and [*Backend Core*](https://github.com/rpriyaraji/AEM-Learning/blob/main/core/src/main/java/com/adobe/training/core/core/BulkPublishServlet.java).*

## The Benefits

- Excludes the complications associated with activation trees.
- Hassle free publishing of pages
- Eliminates the need to publish each page from the AEM Sites console separately.
- Enhances the User Experience

That's just simple 😃 how it is; Thanks for your time people :coffee:, keep exploring and enjoy coding 😇

I'm always happy to hear your valuable feedback if so, leave a comment 📝 or feel free to connect :thought_balloon: with me via [*LinkedIn*](https://www.linkedin.com/in/rajalakshmi-23/) or [*Twitter*](https://twitter.com/Rajalak36424741).

Also, fork or raise open issues if any.