Skip to main content

Posts

Workflows in AEM 04 - MetaDataMap

Sometimes we are faced with a situation where we need to pass data from one workflow step to the another. AEM's workflow API provides an easy way to achieve this using MetaDataMap.

Please note that only primitive data types like Integer, String etc. can be passed from one step to the another. If you have a requirement to pass non-primitive data then use the byte[] array.

Caution: If the data to be passed is too large, refrain passing InputStream. Instead, a better approach is to save the data in a JCR node in the step and retrieve it from the JCR node in a later step.

A MetaDataMap is the data structure which acts as a value map and allows users to set and get data among the steps.
Code example Let's see a code example to demonstrate this concept. Here we will be using two process steps. In the first, we will be passing data and in the second, we will be retrieving it. FirstProcessStep.javapackageorg.redquark.demo.core.workflows;importorg.osgi.service.component.annotations.Com…
Recent posts

Workflows in AEM 03 - Dynamic Participant Step

A participant is a step which enables a user to assign ownership of a task to another user. The workflow will only go further if that user manually acknowledges the step.

A simple use case of this workflow is a review step, i.e. if you have made some changes in an AEM page and then you want someone to review it then you can add it to the participant step and that user will get a notification in his/her inbox. Obviously, the reviewer should have access to the page in question.

Dynamic Participant Step is similar to the Participant Step with the exception that the user is selected at run time. There might be a use case where you want an item to be assigned to a user who has the lowest number of items to review.

The business logic of a Dynamic Participant Step can be written in a class that implements the Participant Chooser interface.

Following is a code example that selects the participant from either "admin" or a user from the "administrators" group based on the c…

Workflows in AEM 02 - Process Step

Hi everyone, it's been a long time since I wrote the first part of this blog. In the previous part, we discussed the fundamentals of workflows, their types and applications.

Today, we are going to discuss the most widely used Workflow step - the process step. This is generally used when we want our application to execute a certain logic.

It executes an ECMA script or an OSGi service to perform automatic processing. A process can be implemented using the following steps -
Create an OSGi service implementing the interface com.adobe.granite.workflow.exec.WorkflowProcess.Set the property process.label. This is the String value by which our workflow needs to be listed.Implement the execute(WorkItem, WorkflowSession, MetaDataMap) method with the implementation code.
The execute() method has three parameters - WorkItem - It is the unit that is passed through a Workflow instance of a WorkflowModel. It contains the WorkflowData. The instances act on and a reference to the WorkflowNode that …

Workflows in AEM 01 - Introduction

Introduction A workflow is a way to automate AEM activities by executing some steps in a specific order to achieve the desired results.

Each step performs an individual activity such as publishing a page, creating a version of the page, sending an email message etc.

For example, the most common activity in AEM is publishing the page from the author instance to the publish instance. But sometimes we want the approval of the changes by some reviewers before publishing. This can be easily achieved by implementing workflows in AEM.

There are many workflows provided out of the box in AEM. Apart from those, if we want, we can also define our custom workflows for our specific activities.
Workflow console The workflow console is the centralized location for workflow management in AEM. There are five tabs in this console - Models: Lists the workflow models that are currently available. We can also create, edit and delete a new workflow here.Instances: This tab shows the details of the currentl…

Sling Servlet 06 - Default and Opting Servlets

Sling ServletsPart 01 - What is a Servlet? Part 02 - What is a Sling Servlet Part 03 - Servlet Resource Provider Part 04 - Registration via Path or Resource Type Part 05 - Types of Servlets Part 06 - Default and Opting Servlets
In this post, we are going to discuss two important types of servlets in AEM - Default and Opting servlets, their uses and pros and cons.
Default Servlet A default servlet is selected if no servlet or script for the current resource type can be found. This servlet is registered with a special resource type sling/servlet/default.
The default servlet is resolved exactly the same way as for any resource type. That is, also for the default Servlet selection, the request selectors and extension or method are considered.
Also, the servlet may be a servlet registered as an OSGi service or it may be a script stored in the repository or provided by any bundle.
Finally, if not even a registered default Servlet may be resolved for the request because none has been registered…

Sling Servlets 05: Types of Servlets

Sling ServletsPart 01 - What is a Servlet? Part 02 - What is a Sling Servlet Part 03 - Servlet Resource Provider Part 04 - Registration via Path or Resource Type Part 05 - Types of Servlets Part 06 - Default and Opting Servlets Types of Sling Servlets There are two classes in Sling API which can be inherited to define our custom functionality. These two classes are - SlingSafeMethodsServlet [org.apache.sling.api.servlets.SlingSafeMethodsServlet]SlingAllMethodsServlet [org.apache.sling.api.servlets.SlingAllMethodsServlet] Let us discuss these types one by one SlingSafeMethodsServlet This is a helper base class for read-only Servlets used in Sling. This base class is actually just a better implementation of the Servlet API's HttpServlet class which accounts for extensibility.
So extensions of this class have great control over what methods to override.
If any of the default HTTP methods are to be implemented just override the respective doXXX (doGet(), doHead() etc.) method.
This base c…

Sling Servlet 04 - Registration via resourceType or Path

Sling ServletsPart 01 - What is a Servlet? Part 02 - What is a Sling Servlet Part 03 - Servlet Resource Provider Part 04 - Registration via Path or Resource Type Part 05 - Types of Servlets Part 06 - Default and Opting Servlets
From the previous post, we know that there are two ways by which a sling servlet can be registered -
Servlet registration via resourceType.Servlet registration via paths. In this post, we will see which approach is better and why. Registration via resourceType A servlet can be registered via resourceType using the following property - "sling.servlet.resourceTypes="+"redquark/servlets/example" Here, whenever the request executes anything with the specified resourceType, the servlet registered with it will be executed. This property can accept a String, an array of Strings or a Vector of Strings. Registration via path A servlet can be registered via path using the following property - "sling.servlet.paths="+"/bin/registeredbypathdemo&…

Sling Servlet 03: Servlet Resource Provider

Sling ServletsPart 01 - What is a Servlet? Part 02 - What is a Sling Servlet Part 03 - Servlet Resource Provider Part 04 - Registration via Path or Resource Type Part 05 - Types of Servlets Part 06 - Default and Opting Servlets Servlet Resource Provider A service listener org.apache.sling.servlets.resolver.internal.SlingServletResolver listens for the OSGi services implementing javax.servlet.Servlet interface and registers its reference.

When a request hits the server, this SlingServletResolver kicks in to execute its sling script resolution procedure to choose the right servlet to respond to the request.

Each individual servlet will have a dedicated service instance of ServletResourceProvider associated with it, which will provide ServletResources in the resource tree, based on the servlet's registration properties.

The actual resource path of such resources differs for servlets registered by type and those registered by path:

Servlet registered by Full Resource Path Path (given path)…