use of com.day.cq.workflow.WorkflowException 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.WorkflowException in project acs-aem-commons by Adobe-Consulting-Services.
the class DamMetadataPropertyResetProcess method execute.
@Override
public final void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
ResourceResolver resourceResolver = null;
String wfPayload = null;
try {
resourceResolver = this.getResourceResolver(workflowSession.getSession());
wfPayload = (String) workItem.getWorkflowData().getPayload();
final List<String> payloads = workflowPackageManager.getPaths(resourceResolver, wfPayload);
final Map<String, String> srcDestMap = this.getProcessArgsMap(metaDataMap);
for (final String payload : payloads) {
final Asset asset = DamUtil.resolveToAsset(resourceResolver.getResource(payload));
if (asset == null) {
log.debug("Payload path [ {} ] does not resolve to an asset", payload);
continue;
}
String metadataPath = String.format("%s/%s/%s", asset.getPath(), JcrConstants.JCR_CONTENT, DamConstants.METADATA_FOLDER);
Resource metadataResource = resourceResolver.getResource(metadataPath);
if (metadataResource == null) {
log.error("Could not find the metadata node for Asset [ " + asset.getPath() + " ]");
throw new WorkflowException("Could not find the metadata node for Asset [ " + asset.getPath() + " ]");
}
final ModifiableValueMap mvm = metadataResource.adaptTo(ModifiableValueMap.class);
for (final Map.Entry<String, String> entry : srcDestMap.entrySet()) {
final String srcProperty = entry.getValue();
final String destProperty = entry.getKey();
if (mvm.get(srcProperty) != null) {
// Remove dest property first in case Types differ
mvm.remove(destProperty);
// If the src value is NOT null, update the dest property
mvm.put(destProperty, mvm.get(srcProperty));
} else if (mvm.containsKey(srcProperty)) {
// Else if the src value IS null, AND the src property exists on the node, remove the dest property
mvm.remove(destProperty);
}
// Else leave the dest property alone since there is no source defined to overwrite it with
// Remove the source
mvm.remove(srcProperty);
}
}
} catch (LoginException e) {
throw new WorkflowException("Could not get a ResourceResolver object from the WorkflowSession", e);
} catch (RepositoryException e) {
throw new WorkflowException(String.format("Could not find the payload for '%s'", wfPayload), e);
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
}
use of com.day.cq.workflow.WorkflowException 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.day.cq.workflow.WorkflowException in project acs-aem-commons by Adobe-Consulting-Services.
the class ReplicatePackageProcess method execute.
/*
* (non-Javadoc)
*
* @see
* com.day.cq.workflow.exec.WorkflowProcess#execute(com.day.cq.workflow.exec
* .WorkItem, com.day.cq.workflow.WorkflowSession,
* com.day.cq.workflow.metadata.MetaDataMap)
*/
@Override
public void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException {
log.trace("execute");
String packagePath = args.get(WorkflowHelper.PROCESS_ARGS, String.class);
if (StringUtils.isNotEmpty(packagePath)) {
log.debug("Executing Automatic Package Replicator Job for package {}", packagePath);
AutomaticPackageReplicatorJob aprJob = new AutomaticPackageReplicatorJob(resourceResolverFactory, replicator, eventAdmin, packagePath);
try {
aprJob.excute();
} catch (Exception e) {
log.error("Exception executing Automatic Package Replicator Job for package " + packagePath, e);
throw new WorkflowException("Exception executing Automatic Package Replicator Job for package " + packagePath, e);
}
} else {
log.warn("No package path specified");
throw new WorkflowException("No package path specified for Automatic Package Replicator Job");
}
}
use of com.day.cq.workflow.WorkflowException 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());
}
}
Aggregations