Search in sources :

Example 6 with TreeFilteringResourceVisitor

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)));
}
Also used : TreeFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor) GenericReport(com.adobe.acs.commons.mcp.model.GenericReport) List(java.util.List) Map(java.util.Map) EnumMap(java.util.EnumMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 7 with TreeFilteringResourceVisitor

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();
    });
}
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 8 with TreeFilteringResourceVisitor

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();
}
Also used : TreeFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor) ActionBatch(com.adobe.acs.commons.fam.actions.ActionBatch)

Example 9 with TreeFilteringResourceVisitor

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));
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ProcessDefinition(com.adobe.acs.commons.mcp.ProcessDefinition) HashMap(java.util.HashMap) SimpleFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.SimpleFilteringResourceVisitor) StringUtils(org.apache.commons.lang3.StringUtils) Failure(com.adobe.acs.commons.fam.Failure) Level(java.util.logging.Level) RepositoryException(javax.jcr.RepositoryException) Map(java.util.Map) ActionBatch(com.adobe.acs.commons.fam.actions.ActionBatch) FormField(com.adobe.acs.commons.mcp.form.FormField) PersistenceException(org.apache.sling.api.resource.PersistenceException) Actions(com.adobe.acs.commons.fam.actions.Actions) PathfieldComponent(com.adobe.acs.commons.mcp.form.PathfieldComponent) Session(javax.jcr.Session) Resource(org.apache.sling.api.resource.Resource) RadioComponent(com.adobe.acs.commons.mcp.form.RadioComponent) ActionManager(com.adobe.acs.commons.fam.ActionManager) Logger(java.util.logging.Logger) Serializable(java.io.Serializable) Objects(java.util.Objects) LoginException(org.apache.sling.api.resource.LoginException) List(java.util.List) TreeFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor) Optional(java.util.Optional) AccessControlManager(javax.jcr.security.AccessControlManager) Pattern(java.util.regex.Pattern) Privilege(javax.jcr.security.Privilege) ProcessInstance(com.adobe.acs.commons.mcp.ProcessInstance) TreeFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor)

Example 10 with TreeFilteringResourceVisitor

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));
    });
}
Also used : TreeFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor) Calendar(java.util.Calendar)

Aggregations

TreeFilteringResourceVisitor (com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor)11 Resource (org.apache.sling.api.resource.Resource)6 ProcessInstance (com.adobe.acs.commons.mcp.ProcessInstance)5 List (java.util.List)5 Map (java.util.Map)5 LoginException (org.apache.sling.api.resource.LoginException)5 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)5 ActionManager (com.adobe.acs.commons.fam.ActionManager)4 Actions (com.adobe.acs.commons.fam.actions.Actions)4 ProcessDefinition (com.adobe.acs.commons.mcp.ProcessDefinition)4 FormField (com.adobe.acs.commons.mcp.form.FormField)4 PathfieldComponent (com.adobe.acs.commons.mcp.form.PathfieldComponent)4 RadioComponent (com.adobe.acs.commons.mcp.form.RadioComponent)4 SimpleFilteringResourceVisitor (com.adobe.acs.commons.util.visitors.SimpleFilteringResourceVisitor)4 HashMap (java.util.HashMap)4 Level (java.util.logging.Level)4 Logger (java.util.logging.Logger)4 Pattern (java.util.regex.Pattern)4 RepositoryException (javax.jcr.RepositoryException)4 Session (javax.jcr.Session)4