Basics of AEM Workflow Model
Creating a workflow allows the user to define and execute a series of steps. In AEM we call workflow as Workflow models. Below are the basic terms used in the AEM workflow model.
Model: It is made up of WorkflowNodes and WorkflowTransitions. Workflow models are versioned. Running Workflow Instances keep the initial workflow model version that is set when the workflow is started.
Step: There are different types of workflow steps:
WorkItem: A workflow instance can have one or many WorkItems at the same time (depending on the workflow model).
Payload: References the resource that has to be advanced through a workflow. The payload implementation references a resource in the repository (by either a path or a UUID) or a resource by a URL or by a serialized java object. Referencing a resource in the repository is very flexible and in conjunction with sling very productive: for example, the referenced node could be rendered as a form.
Lifecycle: It is created when a new workflow is started and ends when the end node is processed. The following actions are possible on a workflow instance:
Inbox: Each logged-in user has its own workflow inbox in which the assigned WorkItems are accessible.
Launcher: Allows you to define a workflow to be launched if a specific node has been updated. When we create a new workflow model it consists of three default steps Flow Start, Flow End, and a dummy participant step named as step 1.
Creating a workflow allows the user to define and execute a series of steps. In AEM we call workflow as Workflow models. Below are the basic terms used in the AEM workflow model.
Model: It is made up of WorkflowNodes and WorkflowTransitions. Workflow models are versioned. Running Workflow Instances keep the initial workflow model version that is set when the workflow is started.
Step: There are different types of workflow steps:
- Participant (User/Group): These types of steps generate a work item and assigns it to a user or group. A user must complete the work item to advance the workflow.
- Process (Script, Java method call): This type of step is executed automatically by the system. An ECMA script or Java class implements the step. Container (Sub Workflow): This step starts with another workflow model.
- OR Split/Join: Uses logic to decide which step to execute next in the workflow.
- AND Split/Join Executes multiple steps simultaneously. All the steps share the following common properties: Autoadvance and Timeout alerts (scriptable).
WorkItem: A workflow instance can have one or many WorkItems at the same time (depending on the workflow model).
Payload: References the resource that has to be advanced through a workflow. The payload implementation references a resource in the repository (by either a path or a UUID) or a resource by a URL or by a serialized java object. Referencing a resource in the repository is very flexible and in conjunction with sling very productive: for example, the referenced node could be rendered as a form.
Lifecycle: It is created when a new workflow is started and ends when the end node is processed. The following actions are possible on a workflow instance:
- Terminate
- Suspend
- Resume
- Restart
Inbox: Each logged-in user has its own workflow inbox in which the assigned WorkItems are accessible.
Launcher: Allows you to define a workflow to be launched if a specific node has been updated. When we create a new workflow model it consists of three default steps Flow Start, Flow End, and a dummy participant step named as step 1.
- Flow Start and Flow End represent the start and end of the workflow.
- Step1 Participant Step is assigned to the admin user to configure a work step. We can edit or delete this step and add new steps as required.
Custom WorkFlow
//This is a component so it can provide or consume services
@Component
@Service
@Properties({
@Property(name = Constants.SERVICE_DESCRIPTION, value = "Test Email workflow process implementation."),
@Property(name = Constants.SERVICE_VENDOR, value = "Adobe"),
@Property(name = "process.label", value = "Test Email Workflow Process") })
public class CustomStep implements WorkflowProcess
{
/** Default log. */
protected final Logger log = LoggerFactory.getLogger(this.getClass());
//Inject a MessageGatewayService
@Reference
private MessageGatewayService messageGatewayService;
public void execute(WorkItem item, WorkflowSession wfsession,MetaDataMap args) throws WorkflowException {
try
{
log.info("Here in execute method"); //ensure that the execute method is invoked
//Declare a MessageGateway service
MessageGateway<Email> messageGateway;
//Set up the Email message
Email email = new SimpleEmail();
//Set the mail values
String emailToRecipients = "tblue@nomailserver.com";
String emailCcRecipients = "wblue@nomailserver.com";
email.addTo(emailToRecipients);
email.addCc(emailCcRecipients);
email.setSubject("AEM Custom Step");
email.setFrom("scottm@adobe.com");
email.setMsg("This message is to inform you that the CQ content has been deleted");
//Inject a MessageGateway Service and send the message
messageGateway = messageGatewayService.getGateway(Email.class);
// Check the logs to see that messageGateway is not null
messageGateway.send((Email) email);
}
catch (Exception e)
{
e.printStackTrace() ;
}
}
}
//This is a component so it can provide or consume services
@Component
@Service
@Properties({
@Property(name = Constants.SERVICE_DESCRIPTION, value = "Test Email workflow process implementation."),
@Property(name = Constants.SERVICE_VENDOR, value = "Adobe"),
@Property(name = "process.label", value = "Test Email Workflow Process") })
public class CustomStep implements WorkflowProcess
{
/** Default log. */
protected final Logger log = LoggerFactory.getLogger(this.getClass());
//Inject a MessageGatewayService
@Reference
private MessageGatewayService messageGatewayService;
public void execute(WorkItem item, WorkflowSession wfsession,MetaDataMap args) throws WorkflowException {
try
{
log.info("Here in execute method"); //ensure that the execute method is invoked
//Declare a MessageGateway service
MessageGateway<Email> messageGateway;
//Set up the Email message
Email email = new SimpleEmail();
//Set the mail values
String emailToRecipients = "tblue@nomailserver.com";
String emailCcRecipients = "wblue@nomailserver.com";
email.addTo(emailToRecipients);
email.addCc(emailCcRecipients);
email.setSubject("AEM Custom Step");
email.setFrom("scottm@adobe.com");
email.setMsg("This message is to inform you that the CQ content has been deleted");
//Inject a MessageGateway Service and send the message
messageGateway = messageGatewayService.getGateway(Email.class);
// Check the logs to see that messageGateway is not null
messageGateway.send((Email) email);
}
catch (Exception e)
{
e.printStackTrace() ;
}
}
}
No comments:
Post a Comment
If you have any doubts or questions, please let us know.