use of com.adobe.acs.commons.workflow.synthetic.SyntheticWorkflowModel 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