Workflow is the series of the tasks executed in business process to produce the final outcome. Workflow will have multiple stages & at each stage, one individual or group is responsible for a specific task. Once the task is complete, the workflow software ensures that the individuals responsible for the next task are notified and generates the data they need to execute their stage of the process.

There are three different types of Workflows: -

Sequential Workflow (Typically Flow Chart based, progresses from one stage to next and does not step back)

State Machine Workflow (Progress from ‘State’ to ‘State’, these workflows are more complex and return to a previous point if required)

Rules-driven Workflow (Implemented based on a sequential workflow. The rules dictate the progress of the workflow)

Liferay also has workflow built on top of engine called Kaleo (called ones).  Liferay workflow allows a user to define any number of simple to complex business processes/workflows, deploy them, and manage them through a portal interface. You can create the workflow from scratch as we need to simply create one XML document.  Liferay EE provides graphical workflow designer which gives you a point and click interface to create workflows.

Below is the workflow architecture implemented in the Liferay: - 

 

We can implement the workflow on the above assets from control panel through Workflow configuration under site settings and Liferay by default comes with Single Approval workflow.

We can follow the below steps to add our custom asset or any portlets which was not there in the workflow configuration: - 

 

•             Step1: - Add following reference and column to your service.xml out of these some of fields must be there which will help in mapping between workflow tables and your custom table.

                                <column name="resourcePrimKey" type="long"></column>

                                <column name="title" type="String"></column>

                                <column name="status" type="int"></column>

                                <column name="statusByUserId" type="long"></column>

                                <column name="statusByUserName" type="String"></column>

                                <column name="statusDate" type="Date"></column>

                               

                                <!-- Finder methods -->

                                <finder name="Riitesh" return-type="Collection">

                                                <finder-column name="resourcePrimKey"></finder-column>

                                                <finder-column name="status"></finder-column>

                                </finder>

              <reference package-path="com.liferay.portal" entity="WorkflowInstanceLink"></reference>

 

 •             Step 2: - Build service to make sure there is no compile time error.

  

•             Step 3: Once you Confirm with service just add following line in liferay-portlet.xml <portlet> tag on which you wish to                 apply workflow.

 

                   <workflow-handler>path</workflow-handler>

 

                                - path: - This is path of your own workflow handler class

                                - Note: - This tag should before initialize of portlet.

 

E.x

    <workflow-handler>com.liferay.workflow.ArticleWorkflowHandler</workflow-handler>

 

 

•             Step 4: You need to extend com.liferay.portal.kernel.workflow.BaseWorkflowHandler

                          class and override four abstract method.

 

             String getClassName()

             String getType(Locale locale)

             Object updateStatus(int status,Map workflowContext)

             String getIconPath(ThemeDisplay themeDisplay)

 

                                public class ArticleWorkflowHandler extends BaseWorkflowHandler

                                { ----------- }             

 

Note : Here one thing is very important updateStatus() method called another method which we are going to developed in next step. 

                public Object updateStatus(int status, Map<String, Serializable> workflowContext)

              {                             

                   return DemoLocalServiceUtil.updateStatus(userId, resourcePrimKey, status, serviceContext);               

                }

 

•             Step 5: Now you need to implement one method called updateStatus() in you LocalServiceImpl class. which will return                object of your model class.

 

            

        public class DemoLocalServiceImpl extends DemoLocalServiceBaseImpl

                    {

        public Demo updateStatus(long userId, long resourcePrimKey, int status,ServiceContext serviceContext)                            

                    {

                                User user = userPersistence.findByPrimaryKey(userId);

                                Date now = new Date();

                                // Article

                                Demo dempObj = null;

                                dempObj.setStatus(status);

                                dempObj.setStatusByUserId(user.getUserId());

                                dempObj.setStatusByUserName(user.getFullName());

                                dempObj.setStatusDate(serviceContext.getModifiedDate(now));               

                                demoPersistence.update(dempObj, false); 

                                                if (status != WorkflowConstants.STATUS_APPROVED)

                                                { return dempObj; }

                                                return dempObj;

                                } 

                }}

•             Step6: Now Deploy service and portlet you will find out your asset in control panel , now you can apply any definition on                that.