use of com.adobe.acs.commons.util.visitors.ContentVisitor in project acs-aem-commons by Adobe-Consulting-Services.
the class ReplicateWithOptionsWorkflowProcess method execute.
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
ResourceResolver resourceResolver = null;
final long start = System.currentTimeMillis();
try {
resourceResolver = workflowHelper.getResourceResolver(workflowSession);
final String originalPayload = (String) workItem.getWorkflowData().getPayload();
final List<String> payloads = workflowPackageManager.getPaths(resourceResolver, originalPayload);
final ProcessArgs processArgs = new ProcessArgs(metaDataMap);
final AtomicInteger count = new AtomicInteger(0);
// Anonymous inner class to facilitate counting of processed payloads
final ResourceRunnable replicatorRunnable = new ResourceRunnable() {
@Override
public void run(final Resource resource) throws Exception {
if (processArgs.isThrottle()) {
throttledTaskRunner.waitForLowCpuAndLowMemory();
}
replicator.replicate(resource.getResourceResolver().adaptTo(Session.class), processArgs.getReplicationActionType(), resource.getPath(), processArgs.getReplicationOptions(resource));
count.incrementAndGet();
}
};
final ContentVisitor visitor = new ContentVisitor(replicatorRunnable);
for (final String payload : payloads) {
final Resource resource = resourceResolver.getResource(payload);
if (processArgs.isTraverseTree()) {
// Traverse the tree
visitor.accept(resource);
} else {
// Only execute on the provided payload
replicatorRunnable.run(resource);
}
}
log.info("Replicate with Options processed [ {} ] total payloads in {} ms", count.get(), System.currentTimeMillis() - start);
} catch (Exception e) {
throw new WorkflowException(e);
}
}
use of com.adobe.acs.commons.util.visitors.ContentVisitor in project acs-aem-commons by Adobe-Consulting-Services.
the class SyntheticWrapperWorkflowProcess method execute.
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
ResourceResolver resourceResolver = null;
final SyntheticWorkflowRunner syntheticWorkflowRunner = syntheticWorkflowRunnerAccessor.getSyntheticWorkflowRunner();
final String payload = (String) workItem.getWorkflowData().getPayload();
final ProcessArgs processArgs = new ProcessArgs(metaDataMap);
try {
resourceResolver = workflowHelper.getResourceResolver(workflowSession);
final SyntheticWorkflowModel syntheticWorkflowModel = syntheticWorkflowRunner.getSyntheticWorkflowModel(resourceResolver, processArgs.getWorkflowModelId(), true);
final AtomicInteger count = new AtomicInteger(0);
// Anonymous inner class to facilitate counting of processed payloads
final ResourceRunnable syntheticRunnable = new ResourceRunnable() {
@Override
public void run(final Resource resource) throws java.lang.Exception {
if (processArgs.isThrottle()) {
throttledTaskRunner.waitForLowCpuAndLowMemory();
}
syntheticWorkflowRunner.execute(resource.getResourceResolver(), resource.getPath(), syntheticWorkflowModel, false, false);
// Commit as needed
if (processArgs.getSaveInterval() > 0 && count.incrementAndGet() % processArgs.getSaveInterval() == 0 && resource.getResourceResolver().hasChanges()) {
resource.getResourceResolver().commit();
}
}
};
final ContentVisitor visitor = new ContentVisitor(syntheticRunnable);
final Resource resource = resourceResolver.getResource(payload);
if (processArgs.isTraverseTree()) {
visitor.accept(resource);
} else {
syntheticRunnable.run(resource);
}
if (processArgs.getSaveInterval() > 0 && resourceResolver.hasChanges()) {
// Commit any stranglers
resourceResolver.commit();
}
log.info("Synthetic Workflow Wrapper processed [ {} ] total payloads", count.get());
} catch (Exception e) {
throw new WorkflowException(e);
}
}
Aggregations