Thursday, 24 July 2014

CQ5 Workflow Tutorial Part - II

In my last post you got a lot of information about CQ5 workflow basics. If you don't remember all of them then not to worry about that I will use all those term in this series of tutorial.

Agenda of this post
  1. Introduction to Process Step.
  2. Use of Inbuilt Processes through this Step.
  3. Use of Auto Advance Handler.
  4. Terminate a running Workflow Instance form workflow dashboard.

Let's start with that. In my last post we create a demo workflow model named as "blog". Let's continue with that.

Go to Workflow Dashboard -> double click on blog model

your screen looks like -

right click on Step 1 (participant step) and delete this step from your model. Select Workflow tab in you sidekick, when you scroll down you will see a Process Step there just drag and drop that step on to your workflow model. Double click on this step you will get a screen as -

In this dialog there are two tabs
  1. Common
  2. Process
Common tab contains the properties common to almost every workflow step or process step as title, description. Here you have three properties Title, Description & Time Out Settings.

I will take Time Out Setting in a separate blog as it's very useful while working with custom workflow. Till now you can think it as when the selected time has been expired then Timeout Handler process executes.

Process tab is our main concern Let's talk about that. This tab consist three fields
Process, Handler Advance  & Arguments

This field provides a list of all currently available process in this drop down field.

you can add your own custom processes as well, I will create a custom process in my next post in this post I will use a in built process named as "No Operation(Script)", Just select this process.

No Operation process does nothing i.e. it is blank process it doesn't effect any thing on your page or in content repository.

Argument Text Area represents the input arguments to this process step, I will show you how this field will be used use in my next post where I'll show you, how to create custom workflow process. Till then just leave it as blank.

There is a CheckBox named as Handler Advance. This checkbox box tell the workflow instance to move into next step when current step has been finished.

If you doesn't select it then after completion of this step your workflow doesn't move to next step. It means it will not transfer control to next step in the workflow.

First test this process step with selected checkbox.

Click OK on your Dialog window then save your workflow model by clicking Save button(top left corner).

Go to your /content/geometrixx/en.html page and in Sitekick go to workflow tab. Select blog workflow model and click on start workflow model.

You will see nothing will happen and your selected workflow field becomes blank it means your workflow has been completed successfully & if you configured your mailing service then you will get a workflow completion mail in your configured email id.

I will show you, how to configure email service when I will teach you, how to deal with email process step. It will be explained in detail in coming post.

Now go to your workflow model screen and in the process step just uncheck Handler Advance checkbox. then Click OK on your Dialog window then save your workflow model by clicking Save button(top left corner).
and again on your /content/geometrixx/en.html page hit your workflow then you will get a screen as -

Notification Message
This page is subject to workflow: <Workflow Name>.
It means your process step is completed but it doesn't advance control to next step so that your workflow doesn't completed.

So in every process step you must have to check this checkbox.

My Observation
Till now, I don't know any scenario where this checkbox will be useful but right now it is a key point in every process step.

For checking your workflow that it's still running just go to your workflow dashboardSelect instances tab.

You will see a running workflow instance. Now you have to terminate your running instance as it will not be completed by it's own. 

If you don't terminate this running instance, you are not able to start another workflow on same page as at a time a page can be a part of only one workflow instance.

you can terminate by right clicking on the running instance or by clicking on terminate button after selecting a running workflow process. your screen looks like-

Now refresh your /content/geometrixx/en.html page & this notification message becomes removed.

Happy Coding.
Namah Shivay

Wednesday, 23 July 2014

CQ5 Workflow Tutorial Part - I

From this post I am starting a series of tutorial that will cover CQ5 workflow in details. This is a introductory post that will explain different terminology used in workflow. 

Agenda in a Look
  1. Introduction to Workflow.
  2. Most used Workflow Terminology using interactive questionnaire.
  3. Creating  a Workflow Model.
  4. Node Structure of Workflow Model in crxde lite.
  5. Starting Workflow.
  6. Node Structure of Workflow Model instance in crxde lite.
  7. Participation Step in brief
  8. Completing Participant Step from Sidekick as well as from inbox.
Workflow in General Terms
"Workflow is a well defined series of steps to produce a desired out, usually include many participants in between these steps and processes in an organization. "

Workflows enable you to automate AEM activities. It consist of a series of automated steps also called process steps that are executed in a specific order. When you want to use workflow in CQ5 then  first, you have to create workflow models.

Workflow model?
workflow models can be think as an architecture of a workflow that shows you how your workflow steps are arranged and how they connect with each other. Workflow model is made up of workflow step nodes and workflow transitions nodes. Workflow Model must have a start node and end node.

Workflow Step Nodes?
workflow nodes are created for each steps you create in a workflow model for ex. if you created three process steps in your model then it will create three different nodes for all of these steps. These nodes are called workflow nodes.

Workflow Transitions?
Workflow transitions are also nodes created in repository, they indicate how these process steps are related or you may think as these transition node define the path how these workflow process step will be executed. It can also be think as a link between two consecutive process steps.

Automated  Step?
These are the actual place where all the processing is done, there logic can be written in ECMA script or in process steps using Java. AEM itself provide some Out Of the Box processes. These step may be interactive or non interactive i.e. these step can get input from author or they can only do processing without any intervention of author. Due to all of these factor these steps are called automated steps.

Workflow Payload?
Workflow payload can be think of a resource on which a workflow instance is activated. i.e. payload could be any resource (node or page) or a collection of resources.

Above theoretical discussion is only for making your concept clear, but now I will show you where all of these node exist and how to play with them. I am also thinking that it's enough theory for getting started with workflow so Let's play with workflows-

Go to AEM welcome Screen -> Select workflow tab
you will see workflow dashboard as shown below - 

here you will see four tabs

1). Model
List of all workflow models available in AEM.

2). Instances
List of all active instances of workflow model i.e. when you start a workflow then it's instance will be displayed in instances tab with many properties, all properties will be covered in this series of tutorial.

3). Archive
When a workflow instance has been finished successfully or terminated then it's information is visible in this tab.

4). Launcher
This is a tab to define a condition for starting a workflow automatically i.e. when a condition is satisfied a workflow will be started automatically. I will discuss it in details just leave it for this introductory post.

5). Failure
This tab show all the workflow instances failed i.e. any error occur while executing a process step of workflow instance. This tab give you the facility to fix the error and resume the workflow. I will cover it in details later, just leave it for now.

Our first step is to create a workflow named as blog so at your Model tab click on New button and fill details as 
Name =  blog
Title = blog

you will see your model at the end of list in model tab, just double click on it you will see a screen as -

This the basic architecture of a workflow model consist of three nodes as show above

Just go to CRXDE Lite 
Go to 
/etc/workflow/models/blogModels directory.

This is the place where all models has been saved. Just expend your model i.e. blog you will see all nodes as-

This flow Node having only one sub node named as participant. All the nodes under this directory represents the intermediate steps nodes between Start and End step.

As I  told you a model is made up of process step nodes and transition node, here they are
i.e. node0, node1, node2 these are the nodes corresponding to all the steps in your workflow model Start, Participant, End steps  node respectively.

Each of these node have a subnode metaData which will hold the information, which is available only when the workflow execution will reach to that particular step. i.e.
Participant metaData information is available only at participant step not before this step and also not after this step
This information has been removed when workflow execution passes from this step.
Nodes under transitions node show how workflow steps are connected i.e. it shows that workflow will run through following path -

Note- this is only model representation when you execute a workflow then it's instance will be created under /etc/workflow/instance directory & all the real work has been down using that model instance node. 

your workflow model uses participant step, similarly there are lot of Out of the Box process step I will explain almost all steps in my coming tutorial of this series till then just leave them.

As participant step is present in it's default model structure so I briefly explain it in this tutorial.

Participant Step
Through this step you can introduce a manual intervention of a user or group i.e. it will restrict further execution of workflow steps till user or group doesn't permit to proceed. I will explain this step in details in my coming post till then just set the properties as I am showing.
Go to your workflow model tab and double click on blog model.
On this screen double click on participant step you will see a screen just like-

Just set title as "blog participant step" , add some description "working with participant step." in second tab i.e. user/group tab you will see a search bar just click on it and select a admin user as show below-

Click OK button. Again Click on OK button of your main dialogThen Save your workflow model, Save button is present at top left corner of the screen.
open any content page in my case I have opened /content/geometrixx/en.html
you will get a Sitekick on this page go to workflow tag your screen looks like -

select blog workflow and click on start workflow button. As you logged in as admin so it will show you three menu in your Sitekick as show below.

before doing further processing just have a look what will this workflow instance do in crxde. So go to your crxde lite and explore /etc/workflow/instance directory.
here you will see a new node structure created as shown below - 

this node represent the instance of your workflow model. it provide different information related to your workflow steps. Payload node defines the payload of this workflow instance.

History node maintains all the data related to all the steps completed.

WorkItems represent the current workflow step node data.

There are two metaData node one inside data and second is metadata under your model node.

difference between these two is -
model/data/metaData represent the information available at all the steps present in this workflow. while model/metaData represent the information available to particular workflow step. model/metaData node copies data from model/data/metaData node.

Now start further processing -
click on complete button you will get a dialog showing your next step as End and comment text area. Just add some comment in this text area and click on submit button. your workflow has been completed.

if you select a user other then admin then these option are not visible here. That is information will be send to that particular user inbox. 

as You can complete this workflow from here as well as you can complete this workflow from admin inbox.

for this just again start your workflow & don't complete from here.

Now go to CQ welcome screen and select inbox tab.

you will see a work item in this inbox with different options & your screen looks like this-

Just complete this step using complete button. This is done for starting with workflow basics. 

Your comments/suggestions are welcome for improving my knowledge as well as my writing skills. 
Happy Coding

Namah Shivay

Monday, 14 July 2014

Scenario for Abstract Classes & Interfaces in Java

During java interviews a common question has been asked i.e.

Tell us the scenario where we should use Abstract class and where we should use an interface?

In this post I will explain this question in a easy to understand manner, so lets start. 

Key Point about Abstract Class & Interface
Both of them are used for generalization & in java abstraction is achieved by both of these two.

"Abstract classes are used when behaviour of different objects are known & interface are used when behaviour of different objects are not known. Objects belongs to different classes."

Here the term behaviour means methods definition in a class, but for some time just skip this definition.

Lets have a look on an example. Let's consider three different classes Employee, BusinessMan, Singer. All of these are the categories of Person Abstract Class/ Interface. Lets consider these classes having common behaviour i.e. eat(), drink(), sleep(). i.e. method definition of these methods are same.

Note: method definition means inner logic of a method.

In this case as all of these classes have common behaviour so we can place there definition at one place to avoid code redundancy. This is the scenario where we should use a Abstract class & all sub classes of this Abstract class will get the common definition of these behaviors.

In terms of coding
Create a Abstract class Person having a definition for these methods eat(), drink(), sleep() as shown

abstract class Person{
       void eat(){...}
       void sleep(){...}
       void dring(){...}
& now all sub-classes of this abstract class have common definition of these methods and may also have new methods.
class Singer extends Person{

same for all other classes.

Lets have a look on another scenario, consider three different classes Employee, BusinessMan, Singer. All of these are the categories of Person Abstract Class/ Interface.
All of these classes have a common behaviour income()  but how they earn it, is different i.e. behaviour name is same but definition changes from person to person. So this is a scenario where we should use interface. By doing this we will have a common behaviour name but able to provide different definition. 
If we use abstract class in this scenario then code redundancy will take place & it's not a good coding practice. 
In terms of coding, Let's create a interface named as Person having only one method income().

interface Person{
     void income();

class Employee implements Person{


same for all other classes.

Now I think the above explanation make sense to you & explain you where we should use Abstract class and where we should use Interfaces.

Namah Shivay

Tuesday, 8 July 2014

Dialog Vs Design Dialog in CQ5

In this post, I will explain dialogs and design dialogs in details. When we talk about dialogs then first question comes in our mind is 

What are dialog and design dialogs in CQ & why we should use them?
Dialogs & Design Dialogs are the collection of widgets used to get input from author. these are the key elements of a component as they provides a way of interaction between author and a CQ5 component. It means values inserted via author in these dialog, works as input for a component in CQ5.

Note : "Design dialogs are special kind of dialog those are available only at page design mode".

Next question comes in our mind is - 

Difference between dialog and design dialog?
Some Differences between these two are listed below-
1). Availability
dialog are available to an author in edit mode of the page while design dialog are available to an author only at page design mode.

2). Naming Convention
For creating a dialog you have to create a cq:Dialog node with name dialog but for creating a design dialog you have to create a cq:Dialog node with name design_dialog.

3). Value Storage
If you want to save the values of widget of a Dialog or Design Dialog then you have to specify
"./<property name>" ex. ./title Here
"./"  : Represent the location of the current component. 

For Dialogs 
dialog values are stored under pages jcr:content node, located under /content directory.
The values of ./<property name> will be stored at 

/content/page/jcr:content/par/<component node> or
/content/page/jcr:content/<component node>

as a key value pair & if you define ./<dummy node>/<property name> then First <dummy node> will be created under component node and then property will be stored under that newly created <dummy node> node, so that new location becomes 

/content/page/jcr:content/par/<component node>/<dummy Node> or
/content/page/jcr:content/<component node>/<dummy Node>

may be you drop you component under a parsys or you directly include it to the page component JSP then it will be available directly under jcr:content node.

For design dialog
Design dialog values are stored under design page located under /etc/design directory. If you set the a template level property named as cq:desingPath pointing to design page ex. /etc/design/geometrixx, then all the design dialog property will be stored at 

/etc/design/geometrixx/jcr:content/<ComponentName>/par/<component> or

<ComponentName> refer to the component to which your template points ex. PageContent. &
<Component> refer to the component whose values are to be stored at this location. 
ex. title component, text component etc.
may be you drop you component under a parsys or you directly include it to the page component JSP then it will be available directly under jcr:content node.

if you don't define cq:desingPath property then default location for design properties will be selected i.e. it uses default design page under /etc/design directory. New location becomes 

/etc/design/default/jcr:content/<ComponentName>/par/<component> or

./<dummy node>/<property node> this case will be treated similar to a dialog property. i.e. it will create a <dummy node> & then save the properties values so that new location becomes

/etc/design/default/jcr:content/<ComponentName>/par/<component>/<dummy Node> or 
/etc/design/default/jcr:content/<ComponentName>/<component>/<dummy Node> 

4). Accessing Values in CQ5 JSPs
the value of dialog are accessible via properties object & a design dialog properties are accessed using currentStyle object

Namah Shivay

Friday, 4 July 2014

Page without Template in CQ5

During CQ5 interviews, a general question has been asked -

Can we create a page without template?

in this post I will explain it's answer in detail. before knowing the answer of this question just rethink the definition of a Template.

"A template is used to create a Page and defines which components can be used within the selected scope. A template is a hierarchy of nodes that has the same structure as the page to be created, but without any actual content"

when you create a template using crxde lite then it creates two nodes by default having primaryTypes 
cq:Template as parent
cq:PageContent as child

When we create a page using template via siteadmin then siteadmin uses  content page component  & it copies all the child nodes under the template to a newly created page node.

and once the page has been created it doesn't require cq:Template as all the child node of the template copied under cq:Page node & these nodes contains all the required properties to display a component group for that page.

It means if you want to create a page without template you can do that but it's not possible using siteadmin console as it's content page component uses templates to create pages.

you have to do all this stuff manually from crxde i.e.

create a node of type cq:Page and save, add cq:PageContent node under page node, add required properties to show the component & if you want to add some default node under this cq:PageContent node add all of them manually.

It's not a good practice to create a page manually, always use templates as it provides different set of properties which are very helpful while creating pages or websites.
Some of important properties are - 
allowedPaths (deprecated Now)

these properties can be used for filtering the page structure using siteadmin console. but if you are creating a page manually then you have to take care about all of these restriction by your own.

Your comments are heartily welcome. As these comments will update me about my mistakes.
Namah Shivay