Created
May 19, 2016 20:12
-
-
Save badvision/fed0475ec2df92f179cece595c30997f to your computer and use it in GitHub Desktop.
Regenerate thumbnails using synthetic workflow
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="com.adobe.acs.commons.workflow.synthetic.*, | |
com.adobe.acs.commons.fam.*, | |
com.adobe.acs.commons.functions.*, | |
org.apache.sling.api.resource.*, | |
java.util.*, | |
javax.jcr.*, | |
com.day.cq.search.*, | |
com.day.cq.dam.commons.util.DamUtil, | |
com.day.cq.wcm.api.*, | |
com.day.cq.dam.api.*"%><% | |
BiFunction<ResourceResolver, String, Boolean> oldRenditions = | |
new BiFunction<ResourceResolver, String, Boolean>() { | |
@Override | |
public Boolean apply(ResourceResolver r, String path) { | |
Resource res = r.getResource(path); | |
Asset asset = DamUtil.resolveToAsset(res); | |
if (asset == null) { | |
return false; | |
} | |
Rendition original = asset.getRendition("original"); | |
if (original == null) { | |
return false; | |
} | |
long originalTime = original.getResourceMetadata().getCreationTime(); | |
int counter = 0; | |
for (Rendition rendition : asset.getRenditions()) { | |
counter++; | |
long time = rendition.getResourceMetadata().getCreationTime(); | |
if (time < originalTime) { | |
return true; | |
} | |
} | |
return counter <= 1; | |
} | |
}; | |
SyntheticWorkflowRunner swr = sling.getService(SyntheticWorkflowRunner.class); | |
ActionManagerFactory amf = sling.getService(ActionManagerFactory.class); | |
DeferredActions actions = sling.getService(DeferredActions.class); | |
SyntheticWorkflowModel model = swr.getSyntheticWorkflowModel( | |
resourceResolver, "/etc/workflow/models/my-thumbnail-workflow-model", true | |
); | |
ActionManager manager = amf.createTaskManager("Fiddle", resourceResolver, 10); | |
int numberOfAssets = manager.withQueryResults( | |
"SELECT * FROM [dam:Asset] as a WHERE ISDESCENDANTNODE(a,'/content/dam')", | |
"JCR-SQL2", | |
actions.startSyntheticWorkflows(model), | |
oldRenditions | |
); | |
manager.addCleanupTask(); | |
%> | |
Finished adding <%=numberOfAssets%> items. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment