use of com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor in project acs-aem-commons by Adobe-Consulting-Services.
the class BrokenLinksReport method buildReport.
public void buildReport(ActionManager manager) {
TreeFilteringResourceVisitor visitor = new TreeFilteringResourceVisitor();
visitor.setBreadthFirstMode();
visitor.setTraversalFilter(null);
visitor.setResourceVisitor((resource, depth) -> {
manager.deferredWithResolver(rr -> {
Map<String, List<String>> brokenRefs = collectBrokenReferences(resource, regex, excludeList, deepCheckList);
for (Map.Entry<String, List<String>> ref : brokenRefs.entrySet()) {
String propertyPath = ref.getKey();
List<String> refs = ref.getValue();
reportData.put(propertyPath, new EnumMap<>(Report.class));
reportData.get(propertyPath).put(Report.reference, refs.stream().collect(Collectors.joining(",")));
}
});
});
manager.deferredWithResolver(rr -> visitor.accept(rr.getResource(sourcePath)));
}
use of com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor 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();
});
}
use of com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor 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();
}
use of com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor in project acs-aem-commons by Adobe-Consulting-Services.
the class FolderRelocator method buildTargetFolders.
private void buildTargetFolders(ActionManager step2) {
TreeFilteringResourceVisitor folderVisitor = new TreeFilteringResourceVisitor();
folderVisitor.setBreadthFirstMode();
folderVisitor.setResourceVisitor((res, level) -> {
String path = res.getPath();
step2.deferredWithResolver(Actions.retry(5, 100, rr -> buildDestinationFolder(rr, path)));
});
sourceToDestination.keySet().forEach(sourcePath -> beginStep(step2, sourcePath, folderVisitor));
}
use of com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor in project acs-aem-commons by Adobe-Consulting-Services.
the class ProcessCleanup method performCleanupActivity.
@SuppressWarnings("squid:S00112")
private void performCleanupActivity(ActionManager manager) throws Exception {
Calendar c = Calendar.getInstance();
c.clear(Calendar.HOUR_OF_DAY);
c.clear(Calendar.MINUTE);
c.clear(Calendar.SECOND);
// minus 1 day
c.add(Calendar.DATE, -miniumumAge);
manager.withResolver(rr -> {
TreeFilteringResourceVisitor visitor = new TreeFilteringResourceVisitor();
visitor.setLeafVisitor((res, level) -> {
if (isCreatedDateBefore(res, c)) {
String path = res.getPath();
manager.deferredWithResolver(rr2 -> {
rr2.delete(rr2.getResource(path));
});
}
});
visitor.accept(rr.getResource(ProcessInstanceImpl.BASE_PATH));
});
}
Aggregations