AEM: Replicate to a specific publisher

2018-04-03

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).

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

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

1
2
3
4
5
6
7
8
9
10
...
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());
	}
}
...
1
2
3
4
5
6
7
8
9
10
...
<tr>
	<td><label for="agent">Agent:</label></td>
	<td>
		<select id="agent" name="agent">
			<option selected="all">All</option>
		</select>
	</td>
</tr>
...
1
2
3
4
5
6
7
8
9
10
...
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:

1
2
3
4
5
6
7
8
9
10
11
...
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());
		}
	});
}
...
1
2
3
...
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.

Created by Jeroen Druwé