Search in sources :

Example 1 with ActionBatch

use of com.adobe.acs.commons.fam.actions.ActionBatch in project acs-aem-commons by Adobe-Consulting-Services.

the class DeepPrune method purgeJobs.

private void purgeJobs(ActionManager manager) {
    ActionBatch batch = new ActionBatch(manager, batchSize);
    batch.setRetryCount(retryCount);
    batch.setRetryWait(retryWait);
    TreeFilteringResourceVisitor visitor = new TreeFilteringResourceVisitor();
    visitor.setDepthFirstMode();
    visitor.setTraversalFilter(res -> visitor.isFolder(res) && !shouldIgnore(res));
    AtomicInteger lastLevel = new AtomicInteger(0);
    visitor.setResourceVisitor((res, level) -> {
        if (level >= minPurgeDepth && !shouldIgnore(res) && folderRule.matcher.apply(res.getName())) {
            if (lastLevel.getAndSet(level) != level) {
                batch.commitBatch();
            }
            String path = res.getPath();
            batch.add(rr -> deleteResource(rr, path));
        }
    });
    visitor.setLeafVisitor((res, level) -> {
        if (!shouldIgnore(res)) {
            if (lastLevel.getAndSet(level) != level) {
                batch.commitBatch();
            }
            String path = res.getPath();
            batch.add(rr -> deleteResource(rr, path));
        }
    });
    manager.deferredWithResolver(rr -> {
        Resource res = rr.getResource(startingFolder);
        if (res != null) {
            visitor.accept(res);
        }
        batch.commitBatch();
    });
}
Also used : TreeFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Resource(org.apache.sling.api.resource.Resource) ActionBatch(com.adobe.acs.commons.fam.actions.ActionBatch)

Example 2 with ActionBatch

use of com.adobe.acs.commons.fam.actions.ActionBatch in project acs-aem-commons by Adobe-Consulting-Services.

the class FolderRelocator method moveNodes.

private void moveNodes(ActionManager step3) {
    ActionBatch batch = new ActionBatch(step3, batchSize);
    batch.setRetryCount(10);
    TreeFilteringResourceVisitor folderVisitor = new TreeFilteringResourceVisitor();
    folderVisitor.setBreadthFirstMode();
    folderVisitor.setLeafVisitor((res, level) -> {
        String path = res.getPath();
        if (!path.endsWith("jcr:content")) {
            batch.add(rr -> moveItem(rr, path));
        }
    });
    sourceToDestination.keySet().forEach(sourcePath -> beginStep(step3, sourcePath, folderVisitor));
    batch.commitBatch();
}
Also used : TreeFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor) ActionBatch(com.adobe.acs.commons.fam.actions.ActionBatch)

Aggregations

ActionBatch (com.adobe.acs.commons.fam.actions.ActionBatch)2 TreeFilteringResourceVisitor (com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Resource (org.apache.sling.api.resource.Resource)1