Last active
May 19, 2016 20:04
-
-
Save badvision/2ee06ba46d1da8a5bc202cab52faa9c7 to your computer and use it in GitHub Desktop.
Publish non-original renditions to another instance, using multiple publish queues in round-robin fashion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@include file="/libs/foundation/global.jsp"%> | |
<%@page session="false" contentType="text/html; charset=utf-8" pageEncoding="UTF-8" | |
import="java.util.*, | |
com.adobe.acs.commons.fam.*, | |
com.adobe.acs.commons.functions.*, | |
com.adobe.granite.asset.api.*, | |
com.day.cq.replication.*, | |
org.apache.sling.api.resource.*, | |
javax.jcr.*"%><% | |
ActionManagerFactory amf = sling.getService(ActionManagerFactory.class); | |
DeferredActions actions = sling.getService(DeferredActions.class); | |
ReplicationOptions p1 = new ReplicationOptions(); | |
p1.setFilter(new AgentIdFilter("prodPublish1")); | |
p1.setSynchronous(true); | |
ReplicationOptions p2 = new ReplicationOptions(); | |
p2.setFilter(new AgentIdFilter("prodPublish2")); | |
p2.setSynchronous(true); | |
ReplicationOptions p3 = new ReplicationOptions(); | |
p3.setFilter(new AgentIdFilter("prodPublish3")); | |
p3.setSynchronous(true); | |
ReplicationOptions p4 = new ReplicationOptions(); | |
p4.setFilter(new AgentIdFilter("prodPublish4")); | |
p4.setSynchronous(true); | |
ActionManager manager = amf.createTaskManager("Activation", resourceResolver, 10); | |
final BiConsumer<ResourceResolver, String> action = actions.activateAllWithRoundRobin(p1, p2, p3, p4); | |
BiConsumer<ResourceResolver, String> withAllRenditions = new BiConsumer<ResourceResolver, String>() { | |
@Override | |
public void accept(ResourceResolver r, String path) throws Exception { | |
AssetManager assetManager = r.adaptTo(AssetManager.class); | |
Asset asset = assetManager.getAsset(path); | |
for (Iterator<? extends Rendition> renditions = asset.listRenditions(); renditions.hasNext();) { | |
Rendition rendition = renditions.next(); | |
if (!rendition.getPath().contains("original")) { | |
action.accept(r, rendition.getPath()); | |
} | |
} | |
} | |
}; | |
int numberOfAssets = manager.withQueryResults( | |
"SELECT * FROM [dam:Asset] as a WHERE ISDESCENDANTNODE(a,'/content/dam/my-folder')", | |
"JCR-SQL2", | |
withAllRenditions, | |
actions.filterOutSubassets() | |
); | |
manager.addCleanupTask(); | |
%> | |
Finished adding <%=numberOfAssets%> items to the activation queue. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment