Search in sources :

Example 1 with Workflow

use of com.day.cq.workflow.exec.Workflow 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 2 with Workflow

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

the class AEMWorkflowRunnerImpl method purge.

private void purge(Payload payload) throws PersistenceException, WorkflowException {
    Workflow workflow = payload.getWorkflow();
    if (workflow != null) {
        ResourceResolver resourceResolver = payload.getResourceResolver();
        final Resource resource = resourceResolver.getResource(workflow.getId());
        if (resource != null) {
            try {
                String path = resource.getPath();
                resource.adaptTo(Node.class).remove();
                log.info("Purging working instance [ {} ]", path);
            } catch (RepositoryException e) {
                throw new PersistenceException("Unable to purge workflow instance node.", e);
            }
        } else {
            log.warn("Could not find workflow instance at [ {} ] to purge.", workflow.getId());
        }
    }
}
Also used : Node(javax.jcr.Node) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) PersistenceException(org.apache.sling.api.resource.PersistenceException) Workflow(com.day.cq.workflow.exec.Workflow) RepositoryException(javax.jcr.RepositoryException)

Aggregations

Workflow (com.day.cq.workflow.exec.Workflow)2 RepositoryException (javax.jcr.RepositoryException)2 PersistenceException (org.apache.sling.api.resource.PersistenceException)2 WorkflowException (com.day.cq.workflow.WorkflowException)1 WorkflowSession (com.day.cq.workflow.WorkflowSession)1 Node (javax.jcr.Node)1 Session (javax.jcr.Session)1 Resource (org.apache.sling.api.resource.Resource)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1