use of com.adobe.acs.commons.workflow.synthetic.impl.cq.exceptions.SyntheticTerminateWorkflowException in project acs-aem-commons by Adobe-Consulting-Services.
the class SyntheticWorkflowRunnerImpl method run.
@SuppressWarnings({ "squid:S3776", "squid:S1163", "squid:S1143" })
private void run(final ResourceResolver resourceResolver, final String payloadPath, final List<SyntheticWorkflowStep> workflowSteps, final boolean autoSaveAfterEachWorkflowProcess, final boolean autoSaveAtEnd) throws WorkflowException {
final Session session = resourceResolver.adaptTo(Session.class);
// Create the WorkflowData obj; This will persist through all WF Process Steps
// This must be remained defined once to it can be shared by reference across CQ and Granite SyntheticWorkflow isntances
final SyntheticWorkflowData workflowData = new SyntheticWorkflowData("JCR_PATH", payloadPath);
// Create the Workflow obj; This will persist through all WF Process Steps
// The Workflow MetadataMap will leverage the WorkflowData's MetadataMap as these two maps should be in sync
final SyntheticWorkflow cqWorkflow = new SyntheticWorkflow("Synthetic Workflow ( " + payloadPath + " )", workflowData);
final com.adobe.acs.commons.workflow.synthetic.impl.granite.SyntheticWorkflow graniteWorkflow = new com.adobe.acs.commons.workflow.synthetic.impl.granite.SyntheticWorkflow("Synthetic Workflow ( " + payloadPath + " )", workflowData);
boolean terminated = false;
for (final SyntheticWorkflowStep workflowStep : workflowSteps) {
SyntheticWorkflowProcess workflowProcess;
if (WorkflowProcessIdType.PROCESS_LABEL.equals(workflowStep.getIdType())) {
workflowProcess = this.workflowProcessesByLabel.get(workflowStep.getId());
} else {
workflowProcess = this.workflowProcessesByProcessName.get(workflowStep.getId());
}
if (workflowProcess != null) {
final long start = System.currentTimeMillis();
try {
final SyntheticMetaDataMap workflowProcessMetaDataMap = new SyntheticMetaDataMap(workflowStep.getMetadataMap());
if (SyntheticWorkflowProcess.Type.GRANITE.equals(workflowProcess.getWorkflowType())) {
runGraniteWorkflowProcess(session, graniteWorkflow, workflowProcessMetaDataMap, workflowProcess);
} else if (SyntheticWorkflowProcess.Type.CQ.equals(workflowProcess.getWorkflowType())) {
runCqWorkflowProcess(session, cqWorkflow, workflowProcessMetaDataMap, workflowProcess);
} else {
log.warn("Workflow process step is of an unknown type [ {} ]. Skipping.", workflowProcess.getWorkflowType());
}
} catch (SyntheticTerminateWorkflowException ex) {
// Terminate entire Workflow execution for this payload
terminated = true;
log.info("Synthetic CQ workflow execution stopped via terminate for [ {} ]", payloadPath);
break;
} catch (com.adobe.acs.commons.workflow.synthetic.impl.granite.exceptions.SyntheticTerminateWorkflowException ex) {
// Terminate entire Workflow execution for this payload
terminated = true;
log.info("Synthetic Granite workflow execution stopped via terminate for [ {} ]", payloadPath);
break;
} catch (SyntheticRestartWorkflowException ex) {
// Handle CQ Restart Workflow; catch/throw for clarity in whats happening
throw ex;
} catch (com.adobe.acs.commons.workflow.synthetic.impl.granite.exceptions.SyntheticRestartWorkflowException ex) {
// Handle Granite Restart Exceptions by transforming them into CQ Worlflow Restart Exceptions which the rest of this API leverages
throw new SyntheticRestartWorkflowException(ex.getMessage());
} catch (WorkflowException ex) {
// Handle CQ Workflow Exception; catch/throw for clarity in whats happening
throw ex;
} catch (com.adobe.granite.workflow.WorkflowException ex) {
// Handle Granite Workflow Exceptions by transforming them into CQ Workflow Exceptions which the rest of this API leverages
throw new WorkflowException(ex);
} finally {
try {
if (!terminated && autoSaveAfterEachWorkflowProcess && session.hasPendingChanges()) {
session.save();
}
log.debug("Executed synthetic workflow process [ {} ] on [ {} ] in [ " + String.valueOf(System.currentTimeMillis() - start) + " ] ms", workflowStep.getId(), payloadPath);
} catch (RepositoryException e) {
log.error("Could not save at end of synthetic workflow process execution" + " [ {} ] for payload path [ {} ]", workflowStep.getId(), payloadPath);
log.error("Synthetic workflow process save failed.", e);
throw new WorkflowException(e);
}
}
} else {
log.error("Synthetic workflow runner retrieved a null Workflow Process for process.label [ {} ]", workflowStep.getId());
}
}
try {
if (autoSaveAtEnd && session.hasPendingChanges()) {
session.save();
}
} catch (RepositoryException e) {
log.error("Could not complete save at end of synthetic workflow execution process" + " [ {} ]", payloadPath, e);
throw new WorkflowException(e);
}
}
use of com.adobe.acs.commons.workflow.synthetic.impl.cq.exceptions.SyntheticTerminateWorkflowException in project acs-aem-commons by Adobe-Consulting-Services.
the class SyntheticWorkflowRunnerImpl method runCqWorkflowProcess.
private void runCqWorkflowProcess(Session session, SyntheticWorkflow workflow, SyntheticMetaDataMap workflowProcessMetaDataMap, SyntheticWorkflowProcess workflowProcess) throws WorkflowException {
final WorkflowSession workflowSession = this.getCqWorkflowSession(session);
// Each Workflow Process Step gets its own workItem whose life starts and ends w the WF Process
final SyntheticWorkItem workItem = new SyntheticWorkItem(workflow.getWorkflowData());
workItem.setWorkflow(workflow);
log.trace("Executing CQ synthetic workflow process [ {} ] on [ {} ]", workflowProcess.getProcessId(), workflow.getWorkflowData().getPayload());
// Execute the Workflow Process
try {
workflowProcess.getCqWorkflowProcess().execute(workItem, workflowSession, workflowProcessMetaDataMap);
workItem.setTimeEnded(new Date());
} catch (SyntheticCompleteWorkflowException ex) {
// Workitem force-completed via a call to workflowSession.complete(..)
workItem.setTimeEnded(new Date());
log.trace(ex.getMessage());
} catch (SyntheticTerminateWorkflowException ex) {
workItem.setTimeEnded(new Date());
log.trace(ex.getMessage());
throw ex;
}
}
Aggregations