Search in sources :

Example 1 with SyntheticWorkflowModel

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);
    }
}
Also used : ContentVisitor(com.adobe.acs.commons.util.visitors.ContentVisitor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SyntheticWorkflowRunner(com.adobe.acs.commons.workflow.synthetic.SyntheticWorkflowRunner) WorkflowException(com.day.cq.workflow.WorkflowException) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) WorkflowException(com.day.cq.workflow.WorkflowException) SyntheticWorkflowModel(com.adobe.acs.commons.workflow.synthetic.SyntheticWorkflowModel) ResourceRunnable(com.adobe.acs.commons.util.visitors.ResourceRunnable)

Aggregations

ContentVisitor (com.adobe.acs.commons.util.visitors.ContentVisitor)1 ResourceRunnable (com.adobe.acs.commons.util.visitors.ResourceRunnable)1 SyntheticWorkflowModel (com.adobe.acs.commons.workflow.synthetic.SyntheticWorkflowModel)1 SyntheticWorkflowRunner (com.adobe.acs.commons.workflow.synthetic.SyntheticWorkflowRunner)1 WorkflowException (com.day.cq.workflow.WorkflowException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Resource (org.apache.sling.api.resource.Resource)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1