AEM: replicate to a specific publisher

I've added the possibility to replicate to a single publisher under the already existing /etc/replication/treeactivation.html. The user can select an agent or keep the default (replicate to all publishers).

treeactivation

There is not that much code to show, I'll just summarize the most important parts.

/libs/cq/replication/components/treeactivation/treeactivation.jsp:

...
Map<String, Agent> agents = agentMgr.getAgents();
List<String> agentIdsList = new ArrayList<>();
for(Map.Entry<String, Agent> entry: agents.entrySet()){
	Agent agent = entry.getValue();
	if(agent.isEnabled()){
		agentIdsList.add(entry.getValue().getId());
	}
}
...
...
<tr>
	<td><label for="agent">Agent:</label></td>
	<td>
		<select id="agent" name="agent">
			<option selected="all">All</option>
		</select>
	</td>
</tr>
...
...
var select = document.getElementById("agent");
<% for (int i=0; i< agentIdsList.size(); i++) { %>
	var option = document.createElement("option");
	var id = "<%= xssAPI.encodeForJSString(agentIdsList.get(i)) %>";
	option.text = id;
	option.value = id;
	select.add(option);
<% } %>
...

/libs/cq/replication/components/treeactivation/POST.jsp:

...
ReplicationOptions opts = null;
if (!agentId.equalsIgnoreCase("all")) {
	opts = new ReplicationOptions();
	opts.setFilter(new AgentFilter() {
		public boolean isIncluded(final Agent agent) {
			return agentId.equals(agent.getId());
		}
	});
}
...
...
replicator.replicate(session, ReplicationActionType.ACTIVATE, array, opts);
...

You can find the full code here:

If you do have any questions, do not hesitate to contact me or leave a comment below.