use of com.day.cq.workflow.WorkflowSession in project acs-aem-commons by Adobe-Consulting-Services.
the class ReplicateWithOptionsWorkflowProcess method execute.
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
ResourceResolver resourceResolver = null;
final long start = System.currentTimeMillis();
try {
resourceResolver = workflowHelper.getResourceResolver(workflowSession);
final String originalPayload = (String) workItem.getWorkflowData().getPayload();
final List<String> payloads = workflowPackageManager.getPaths(resourceResolver, originalPayload);
final ProcessArgs processArgs = new ProcessArgs(metaDataMap);
final AtomicInteger count = new AtomicInteger(0);
// Anonymous inner class to facilitate counting of processed payloads
final ResourceRunnable replicatorRunnable = new ResourceRunnable() {
@Override
public void run(final Resource resource) throws Exception {
if (processArgs.isThrottle()) {
throttledTaskRunner.waitForLowCpuAndLowMemory();
}
replicator.replicate(resource.getResourceResolver().adaptTo(Session.class), processArgs.getReplicationActionType(), resource.getPath(), processArgs.getReplicationOptions(resource));
count.incrementAndGet();
}
};
final ContentVisitor visitor = new ContentVisitor(replicatorRunnable);
for (final String payload : payloads) {
final Resource resource = resourceResolver.getResource(payload);
if (processArgs.isTraverseTree()) {
// Traverse the tree
visitor.accept(resource);
} else {
// Only execute on the provided payload
replicatorRunnable.run(resource);
}
}
log.info("Replicate with Options processed [ {} ] total payloads in {} ms", count.get(), System.currentTimeMillis() - start);
} catch (Exception e) {
throw new WorkflowException(e);
}
}
use of com.day.cq.workflow.WorkflowSession 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;
}
}
use of com.day.cq.workflow.WorkflowSession in project acs-aem-commons by Adobe-Consulting-Services.
the class InitFormServlet method doGet.
@Override
protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
final JsonObject json = new JsonObject();
// Runners
accumulate(json, KEY_RUNNER_TYPES, withLabelValue("AEM Workflow", AEMWorkflowRunnerImpl.class.getName()));
accumulate(json, KEY_RUNNER_TYPES, withLabelValue("Synthetic Workflow (Single-threaded)", SyntheticWorkflowRunnerImpl.class.getName()));
accumulate(json, KEY_RUNNER_TYPES, withLabelValue("Synthetic Workflow (Multi-threaded)", FastActionManagerRunnerImpl.class.getName()));
// Query Types
accumulate(json, KEY_QUERY_TYPES, withLabelValue("QueryBuilder", "queryBuilder"));
accumulate(json, KEY_QUERY_TYPES, withLabelValue("List", "list"));
accumulate(json, KEY_QUERY_TYPES, withLabelValue("xPath", "xpath"));
accumulate(json, KEY_QUERY_TYPES, withLabelValue("JCR-SQL2", "JCR-SQL2"));
accumulate(json, KEY_QUERY_TYPES, withLabelValue("JCR-SQL", "JCR-SQL"));
// User Event Data
accumulate(json, KEY_USER_EVENT_DATA, withLabelValue("Custom user-event-data", ""));
accumulate(json, KEY_USER_EVENT_DATA, withLabelValue("changedByWorkflowProcess", "changedByWorkflowProcess"));
accumulate(json, KEY_USER_EVENT_DATA, withLabelValue("acs-aem-commons.bulk-workflow-manager", "acs-aem-commons.bulk-workflow-manager"));
// Workflow Models
final WorkflowSession workflowSession = workflowService.getWorkflowSession(request.getResourceResolver().adaptTo(Session.class));
try {
final WorkflowModel[] workflowModels = workflowSession.getModels();
for (final WorkflowModel workflowModel : workflowModels) {
boolean transientWorkflow = isTransient(request.getResourceResolver(), workflowModel.getId());
String workflowLabel = workflowModel.getTitle();
if (transientWorkflow) {
workflowLabel += " ( Transient )";
}
JsonObject jsonWorkflow = withLabelValue(workflowLabel, workflowModel.getId());
jsonWorkflow.addProperty("transient", transientWorkflow);
accumulate(json, "workflowModels", jsonWorkflow);
}
response.getWriter().write(json.toString());
} catch (WorkflowException e) {
log.error("Could not create workflow model drop-down.", e);
JSONErrorUtil.sendJSONError(response, SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not collect workflows", e.getMessage());
}
}
use of com.day.cq.workflow.WorkflowSession 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.WorkflowSession 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;
}
Aggregations