Posts

TRIGGERING A WORKFLOW USING EVENT LISTENERS IN AEM

AEM Version: 6.2
Target Audience: AEM Developers

Introduction

In AEM 6.2 Workflows, we can trigger a workflow when a DAM Asset is created, modified, or deleted within a given path. In this article, we will explore triggering workflows from our code based on events in the JCR.

Suppose you have a workflow that creates custom renditions of assets in addition to the default AEM renditions, when the asset is under “/content/dam/ProjectName/images/”. You would have set up two launchers for triggering this workflow: one with event type as “Node Create” and one with “Node Modified”. We can also achieve the same functionality through our code, without touching the GUI.

Requirement

When assets are moved into a certain folder structure in DAM, trigger a workflow that creates a 100px X 100px thumbnail of our image.

No-rendition-outside-imgs

Fig 1: Before Moving the asset, no custom thumbnail. Fig 2: Desired result after moving the asset, the new thumbnail.

Analysis

The intuitive thought is that when an asset is moved, a new node is created in the new location and the old one is deleted. However, experience shows that AEM does not create a new node in the destination folder on Node Move. We know this because the ‘jcr:Created’ property does not change. AEM does not even change the last modified date.

Creation Timestamp Before Moving the Asset Creation Timestamp is the same after moving

Fig 3: Creation Timestamp Before Moving the Asset. Fig 4: Creation Timestamp is the same after moving

Modification Timestamp Before Moving the Asset. Modification Timestamp is the same after moving

Fig 5: Modification Timestamp Before Moving the Asset. Fig 6: Modification Timestamp is the same after moving.

What if we copy the asset?

On copying the asset, a new version of the same is created. This triggers the Node Creation launcher.

No versions before copying the asset Version created after copy-pasting the asset

Fig. 7: No versions before copying the asset. Fig. 8: Version created after copy-pasting the asset.

Approach

Event Listeners

AEM supports observation, which enables us to receive notifications of persistent changes to the workspace. A persisted change to the workspace is represented by a set of one or more events. Each event reports a single simple change to the structure of the persistent workspace in terms of an item added, changed, moved or removed. There are thus 7 possible events at the JCR level, viz:

  1. Node Added
  2. Node Moved
  3. Node Modified
  4. Node Removed
  5. Property Added
  6. Property Removed
  7. Property Changed

We connect with the observation mechanism by registering an event listener with the workspace. An event listener is a class implementing the EventListener interface, that responds to the stream of events to which it has been subscribed. An event listener is added to a workspace with:

(A detailed explanation of each parameter is given with the code example in the package as well as the at the end of this article) As defined by the EventListener interface, listener must provide an implementation of the onEvent method:

When an event occurs that falls within the scope of the listener, the repository calls the onEvent method invoking our logic which processes/responds to the event. In our case, we will register an event listener to listen for “Node Moved” events under “/content/dam/images” so that when an asset is moved to that folder, our workflow can be triggered.

Implementation

When the component is activated, the activate(…) method is called. It contains a call to ObservationManager.addEventListener(…) for registering the event listener. The deactivate(…) method contains logic for deregistering the event listener, and is triggered when the bundle is being stopped.

When the relevant event occurs, the onEvent(…) method is called, which contains logic for processing the event. In our case, we trigger a workflow.

The following is the relevant code from ThumbnailNodeMovedListener.java:

Download this code (including the workflow):

Build it using

N.B: Creating a workflow is not part of this tutorial, and therefore a ready workflow has been provided in the code package. However, if you want to learn to create workflows, here is an excellent resource: ->

/workflow-in-aem/

References

Adobe Consulting Services. (2018, March 20). acs-aem-samples/SampleJcrEventListener.java at master · Adobe-Consulting-Services/acs-aem-samples. Retrieved from Github: https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/bundle/src/main/java/com/adobe/acs/samples/events/impl/SampleJcrEventListener.java

Day Software AG. (2018, March 20). JCR 2.0: 12 Observation (Content Repository for Java Technology API v2.0). Retrieved from Adobe Docs: https://docs.adobe.com/docs/en/spec/jcr/2.0/12_Observation.html

Magical Marketing Mechanism

You are munching your most loved hot hot crispy samosa, while checking your emails on mobile, you receive an email from your favorite e-commerce site and you spot your chosen “jeans” which you have been looking for some time now, is available at a steep discount. You were following that “jeans” on web and social for quite some time and always wished you get some discount on it. You had seen ads of it in your social networking and media sites and were always thought of buying it. You had in fact added it into your shopping cart but always felt it to be expensive.

You click the link in the email and see some nice photos of it and also some more suggestions based on your interest and find more attractive options.

You call you friend and tell the same but your friend has not received any such email or see any reduction in price or discounts on the site.

You are provoked more to buy it immediately as you do not want to lose the opportunity and don’t want to risk the out of stock scenario.

You go ahead get you credit card and buy it immediately. WOW, that’s the feeling you get and you are excited about your purchase for the next party you are going to have over the weekend. You feel thankful to the e-commerce site to give, only you the discounted price and feel great about your quick decision to purchase. You quickly share and tweet about your purchase and your friends are liking it.

WHAT HAPPENED BEHIND THE SCENES?

  • How your favorite e-commerce site knew you were looking for “jeans” from quite some time now?
  • How could only you could get the email and the discounts?
  • How could you see more suggestions and options which you had tried searching but could not get?
Adobe Marketing Cloud is one such solutions which is the answer for above questions.

Lets suppose, e-commerce site was using the Adobe Marketing Cloud to achieve this. Here is how they must have used different tools available in the suite.

Adobe Audience Manager consolidate audience information from all available sources and create profiles of audience segment to send email only to you.

 Adobe Campaign used analysis done by Adobe Social and Audience Manager to send you a personalized email. Adobe  Target and Personalization provided you with more suggestions and compelling offers and options. 

You shared your purchase through social sites and the e-commerce site could do more promotions based on the links and shares and could get more people know about the purchase and could listen to the social activity using Adobe Social.

Nice looking website and all the graphics, content along with the personalized options were hosted on Adobe Experience Manager.

Adobe Media Optimizer helps e-commerce site to get maximum return on their investments.

e-commerce site benefited by acquiring the customer by providing a good experience and it can go a long way retaining the customer.

It helped converting a potential user to a customer and sold the product and also received a good follow on social networking sites, which can only lead to more users getting converted to loyal customers.

It is very important to not just reach customers but also need to know them and Adobe Marketing Cloud solutions helps in the same.

Adobe Marketing Cloud is a comprehensive marketing solution which enables marketers to measure, personalize and optimize marketing campaigns and digital experiences for optimal marketing performance. Adobe Marketing Cloud includes a set of analytics, social, advertising, media optimization, targeting, Web experience management and content management aimed at digital marketing.

 It is the most comprehensive & integrated marketing solution for digital marketers.

 Adobe Marketing Cloud Solution consists of –

  1. Adobe Analytics
  2. Adobe Audience Manger
  3. Adobe Campaign
  4. Adobe Experience Manger
  5. Adobe Media Optimiser
  6. Adobe Primetime
  7. Adobe Social
  8. Adobe Target

 We will explore each product in detail in upcoming blogs.

The Performance Guidepost

Imagine on a bright sunny day you open up your analytics dashboard and you notice the visitors graph going high and high and high and suddenly drops all of a sudden.

You will be wondering what is happening, only to find that your colleague had started a nice promotion and due to the promotion the website load increased multifold.

But what happened all of a sudden? Why the drop in visits? Ah… the promotion became too popular as it had gone viral in the social network and print media. And due to the heavy demand more number of users visited and the site could not take up the anticipated load and crashed.

A poor show, in spite the excellent job by marketing team.

What could have been done to avoid such situation and do not let the customer suffer and the drop in sales and site visitors?

Performance testing is the answer on anticipated site load.

 

What is Performance Testing?

Triple “S” check is a must for the public facing websites.

  • Speed – Determines whether the application responds quickly.
  • Scalability – Determines maximum user load the software application can handle.
  • Stability – Determines if the application is stable under varying loads.

And all three can be measured using performance testing.

Performance testing is the investigation done either to determine or to prove the response time, scalability and performance of the website to ensure that they will perform well under their expected regular workload, at peak load and uncover inconsistencies across different operating systems/devices.

The goal of performance testing is not to find bugs but to eliminate performance bottlenecks and tune the system for maximum load. This is also to determine the maximum threshold the website can take.

Common Performance Problems

Poor Response Time:

Once the user performs an action and user has to wait for so long before the response is provided. This can lead to poor user experience.

Poor Load Distribution:

Poor load distribution can cause slow response time by incorrectly assigning new site visitors to hanged up servers. If too many people are on the same server, they’re going to experience difficulties, even if the overall system is well under capacity. Check the sites of some of the big players and you will notice the site loads in a flash of moments.

Types of Performance Testing

Load Test:

Generally a load test is conducted to understand the behaviour of a system under the specific expected load. It helps to identify the maximum operating capacity of an application as well as any bottlenecks and determine which element is causing degradation. E.g. If the number of users are increased then how much CPU, memory will be consumed, what is the network and bandwidth response time.

It also helps in measuring the response time, throughput rates, and resource-utilization levels, and to identify the breaking point, and the peak load the website can handle.

This can answer questions like, what is the maximum number of users that can use the system without any impact on performance and acceptable response time.

Stress Test:

Stress testing refers to the testing of website to determine whether its performance is satisfactory under any extreme and unfavourable conditions, which may occur as a result of heavy network traffic, process loading and maximum requests for resource utilization. Stress testing enables to identify how the website behaves under extreme load conditions.

This will answer questions like, what is the maximum peak load the system can handle and determine if the system will perform sufficiently if the current load goes well above the expected maximum limits.

Soak / Endurance Test:

This is usually done to determine if the system can sustain the continuous expected load, this helps in detecting potential memory leaks and utilization. Also to check the performance degradation when the system is being used for long duration.

This can answer questions like, if the promotion becomes very popular and the load of system is way beyond for a very long duration, can the system handle such situations?

Spike Test:

Spike testing is a subset of stress testing.  A spike test is a type of performance test focused on determining reaction to a sudden large spikes in the load generated by users.

This can answer questions like, if the competitor, runs a promotion and we are unaware of it, due to such situations users visiting the site for similar promotions on our site, there could be sudden spike of users and if the system can handle such situations.

Tools

Lot of performance testing tools are available for different types of tests and it is quite difficult to cover all types of test using one.

Jmeter is one of the renowned open source tool designed to load test functional behaviour and measure performance.

Lets explore more about Jmeter and its functioning in the upcoming blog.

Conclusion

Performance Testing is a must before the website goes to market, as poor performance and inconsistent behaviour of the site may lead to inadequate reputation, poor user experience and will not meet the sales goals.

Hence its concluded that it’s a must to perform performance testing at initial stage of building website and regularly in different intervals. Analytics can help monitor the peak loads and help plan for performance testing. This can go a long way building customer trust, relation and not only retain but expand customer base. Lets read about that too in another upcoming blog.