Search in sources :

Example 6 with WorkflowException

use of com.day.cq.workflow.WorkflowException in project acs-aem-commons by Adobe-Consulting-Services.

the class FFMpegAudioEncodeProcess method execute.

@SuppressWarnings({ "PMD.CollapsibleIfStatements", "squid:S1066" })
@Override
public final void execute(WorkItem workItem, WorkflowSession wfSession, MetaDataMap metaData) throws WorkflowException {
    final WorkflowHelper.AssetResourceResolverPair pair = workflowHelper.getAssetFromPayload(workItem, wfSession);
    if (pair == null) {
        String wfPayload = workItem.getWorkflowData().getPayload().toString();
        String message = "execute: cannot process audio, asset [{" + wfPayload + "}] in payload doesn't exist for workflow [{" + workItem.getId() + "}].";
        throw new WorkflowException(message);
    }
    final String assetMimeType = pair.asset.getMimeType();
    if ((assetMimeType == null || !assetMimeType.startsWith("audio/"))) {
        if (!pair.asset.getName().endsWith(".wav") || !pair.asset.getName().endsWith(".mp3") || !pair.asset.getName().endsWith(".ogg")) {
            log.info("execute: asset [{}] is not of a audio mime type, asset ignored.", pair.asset.getPath());
            return;
        }
    }
    try {
        helper.process(pair.asset, pair.resourceResolver, metaData, this);
    } catch (AudioException e) {
        throw new WorkflowException("Unable to transcode audio", e);
    } finally {
        pair.resourceResolver.close();
    }
}
Also used : WorkflowHelper(com.adobe.acs.commons.util.WorkflowHelper) WorkflowException(com.day.cq.workflow.WorkflowException)

Example 7 with WorkflowException

use of com.day.cq.workflow.WorkflowException in project acs-aem-commons by Adobe-Consulting-Services.

the class SetReplicationStatusProcess method execute.

@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metadataMap) throws WorkflowException {
    ResourceResolver resourceResolver = null;
    try {
        resourceResolver = workflowHelper.getResourceResolver(workflowSession);
        final String replicatedResourcePath = getReplicatedResourcePath(workItem, resourceResolver);
        Map<String, String> params = extractWorkflowParams(metadataMap);
        String replAction;
        if (!params.containsKey(ARG_REPL_ACTION)) {
            log.warn("Please add a replicationAction to your process arguments (ACTIVATED, DEACTIVATED or CLEAR).  Will now exit without processing.");
            return;
        } else {
            replAction = params.get(ARG_REPL_ACTION);
        }
        Calendar replicatedAt;
        if (!params.containsKey(ARG_REPL_DATE)) {
            log.info("No replicationDate argument specified, will default to current time.");
            replicatedAt = Calendar.getInstance();
        } else {
            replicatedAt = getReplicationDate(params);
        }
        String replicatedBy;
        if (!params.containsKey(ARG_REPL_BY)) {
            log.info("No replicatedBy argument specified, will default to 'migration'.");
            replicatedBy = "migration";
        } else {
            replicatedBy = params.get(ARG_REPL_BY);
        }
        replStatusMgr.setReplicationStatus(resourceResolver, replicatedBy, replicatedAt, ReplicationStatusManager.Status.valueOf(replAction), replicatedResourcePath);
    } catch (Exception e) {
        log.error("An exception occurred while setting replication status.", e);
    }
}
Also used : Calendar(java.util.Calendar) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) WorkflowException(com.day.cq.workflow.WorkflowException) ParseException(java.text.ParseException)

Example 8 with WorkflowException

use of com.day.cq.workflow.WorkflowException in project acs-aem-commons by Adobe-Consulting-Services.

the class AEMWorkflowRunnerImpl method forceTerminate.

@SuppressWarnings("squid:S00112")
@Override
public void forceTerminate(Workspace workspace, Payload payload) throws Exception {
    final WorkflowSession workflowSession = workflowService.getWorkflowSession(payload.getResourceResolver().adaptTo(Session.class));
    Workflow workflow = null;
    fail(workspace, payload);
    try {
        workflow = payload.getWorkflow();
        if (workflow != null) {
            if (workflow.isActive()) {
                workflowSession.terminateWorkflow(workflow);
                log.info("Force Terminated workflow [ {} ]", workflow.getId());
                payload.setStatus(Status.FORCE_TERMINATED);
                if (workspace.getConfig().isPurgeWorkflow()) {
                    purge(payload);
                }
            } else {
                log.warn("Trying to force terminate an inactive workflow [ {} ]", workflow.getId());
            }
        } else {
            payload.setStatus(Status.FORCE_TERMINATED);
        }
    } catch (WorkflowException e) {
        throw new Exception(e);
    }
}
Also used : WorkflowSession(com.day.cq.workflow.WorkflowSession) WorkflowException(com.day.cq.workflow.WorkflowException) Workflow(com.day.cq.workflow.exec.Workflow) WorkflowException(com.day.cq.workflow.WorkflowException) RepositoryException(javax.jcr.RepositoryException) PersistenceException(org.apache.sling.api.resource.PersistenceException) WorkflowSession(com.day.cq.workflow.WorkflowSession) Session(javax.jcr.Session)

Example 9 with WorkflowException

use of com.day.cq.workflow.WorkflowException in project acs-aem-commons by Adobe-Consulting-Services.

the class Payload method getWorkflow.

public Workflow getWorkflow() throws WorkflowException {
    final WorkflowSession workflowSession = workflowService.getWorkflowSession(resource.getResourceResolver().adaptTo(Session.class));
    String tmp = getWorkflowInstanceId();
    try {
        if (resource.getResourceResolver().getResource(tmp) != null) {
            return workflowSession.getWorkflow(tmp);
        }
    } catch (Exception e) {
        log.error(String.format("Could not get workflow with id [ %s ] for payload [ %s ~> %s ]", tmp, getPath(), getPayloadPath()), e);
    }
    return null;
}
Also used : WorkflowSession(com.day.cq.workflow.WorkflowSession) WorkflowException(com.day.cq.workflow.WorkflowException) JSONException(org.apache.sling.commons.json.JSONException) PersistenceException(org.apache.sling.api.resource.PersistenceException) Session(javax.jcr.Session) WorkflowSession(com.day.cq.workflow.WorkflowSession)

Example 10 with WorkflowException

use of com.day.cq.workflow.WorkflowException 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

WorkflowException (com.day.cq.workflow.WorkflowException)10 WorkflowSession (com.day.cq.workflow.WorkflowSession)5 Session (javax.jcr.Session)5 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)4 RepositoryException (javax.jcr.RepositoryException)3 Resource (org.apache.sling.api.resource.Resource)3 ContentVisitor (com.adobe.acs.commons.util.visitors.ContentVisitor)2 ResourceRunnable (com.adobe.acs.commons.util.visitors.ResourceRunnable)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 PersistenceException (org.apache.sling.api.resource.PersistenceException)2 WorkflowHelper (com.adobe.acs.commons.util.WorkflowHelper)1 SyntheticWorkflowModel (com.adobe.acs.commons.workflow.synthetic.SyntheticWorkflowModel)1 SyntheticWorkflowRunner (com.adobe.acs.commons.workflow.synthetic.SyntheticWorkflowRunner)1 SyntheticWorkflowStep (com.adobe.acs.commons.workflow.synthetic.SyntheticWorkflowStep)1 SyntheticWorkflow (com.adobe.acs.commons.workflow.synthetic.impl.cq.SyntheticWorkflow)1 SyntheticWorkflowSession (com.adobe.acs.commons.workflow.synthetic.impl.cq.SyntheticWorkflowSession)1 SyntheticCompleteWorkflowException (com.adobe.acs.commons.workflow.synthetic.impl.cq.exceptions.SyntheticCompleteWorkflowException)1 SyntheticRestartWorkflowException (com.adobe.acs.commons.workflow.synthetic.impl.cq.exceptions.SyntheticRestartWorkflowException)1 SyntheticTerminateWorkflowException (com.adobe.acs.commons.workflow.synthetic.impl.cq.exceptions.SyntheticTerminateWorkflowException)1 Asset (com.day.cq.dam.api.Asset)1