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();
}
}
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);
}
}
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);
}
}
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;
}
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);
}
}
Aggregations