Monday, November 11, 2013

Kaleo WorkFlow With Liferay 6.1



Introduction:
Before we start understand workflow a very first questions comes in our  mind is What and Why part of workflow ?? here I am trying to give brief answer of this questions.

 A workflow consists of a sequence of connected steps. It is a depiction of a sequence of operations, declared as work of a person, a group of persons, an organization of staff, or one or more simple or complex mechanisms.

Workflow may be seen as any abstraction of real work, segregated in workshare, work split or other types of ordering. For control purposes, workflow may be a view on real work under a chosen aspect. A workflow is a model to represent real work for further assessment, e.g. for describing a reliably repeatable sequence of operations. More abstractly, a workflow is a pattern of activity enabled by a systematic organization of resources defined roles and mass ,energy and information flows, into a work process.

Liferay 6 integrates workflow engines like jBPM or Kaleo on any assets finally. This feature has been expected for a while.By this feature, users are able to manage the content creation process with a workflow.

Especially, this feature helps content creators collaborate and go through the necessary steps in order to produce better and more accurate content like assets. Within a workflow, any type of assets like Document Library document, wiki entry or web content can go through review-approval processes.
Prerequisites:


  • Liferay 6.1 bundled with Tomcat Vanilla Instance
  • Kaleo Workflow Web Plugin
 

Installation:

  • Liferay Installation:
             Please refer to my earlier posts to check out steps for Liferay Installation
  • Kaleo Workflow:
If you are using Liferay 6.x or above then Kaleo Web plugin will come pre-installed, to confirm this you can take a look inside “webapps” folder. If u see a folder named “kaleo-web” it indicates that kaleo is already installed with the Liferay instance.

In case you don’t see the folder then you can download the war file from this link for CE version, if running a EE server then you can download this plugin by accessing Customer Portal.

Once you have downloaded the war file place that file in the deploy folder and the plugin will get hot deployed and make sure deployment happens with no error.

Understanding Kaleo Workflow:

Liferay’s Kaleo workflow plugin is driven by XML files and are configured for the Users of portal. Portal administrators can configure whole workflow from the control panel itself. Once we install the plugin following options get added to the control panel:

  • My Workflow Tasks
  • Workflow Configuration
  • My Submissions
  • Workflow
 
My Workflow Tasks: This option appears for those users who have a specific role which is a part of approval process. This option lists shows two sections “Assigned to Me” and “Assigned to My Role” as shown below:


The first sections displays list of all the workflow tasks assigned to the logged in user and the second section list down all the workflow tasks assigned to the Role to which user is assigned.

My Submissions: This option is provided to the user which are submitting contents for approval. So whenever user submits a content or document which falls under workflow then user can track the progress of approval from this options.

If no submissions are pending then user is provided the following screen:


Workflow Configurations:
This option provides various options to set workflow configurations for the site currently accessed in the control panel. following is the screenshot of workflow configuration screen:


Administrator can select which workflow to be applied for what type of content. By selecting the workflow from the dropdown admin can apply different workflow to all the different types of content.

 Workflow:
This is a portal level option available to users having Administrator or similar roles. This section allows the admin to add new workflow configurations. Under this section admin can manage the workflows currently installed with Kaleo Web Plugin.



Administrator can add/edit/deactivate/remove a workflow definition under this section. The process of adding new workflow definition is pretty simple. Click on the Add button to view following form , provide name to the workflow and upload a workflow XML file.

 


There is one default workflow that is bundled with the kaleo-web plugin: Single Approver Workflow. This workflow requires one approval before an asset can be published. One of the conveniences of using Liferay's workflow engine is that any roles that are specified in the workflow definition are created automatically when the definition is deployed. This provides a level of integration with the portal that third party engines cannot match. The Single Approver Workflow contains three roles each with different scopes. The scope of each role can be easily deduced by their names - Community Content Reviewer, Organization Content Reviewer, and Portal Content Reviewer.


In this article we are not going to understand this default workflow, rather we will work on a use case and try to understand each element of the workflow XML.




Use Case: Multiple Approval Workflow for Blogs

So the use case that if a blog needs to be published it has to approved at two levels, so if a user Blogs Writer who has permission to create blog will submit for publication. Then this blog will be sent for First review to user having permission of reviewing blog. Once the Blog Reviewer is done reviewing content can be approved or rejected based on the review. If the content gets approved then content is sent as a workflow task to those users having role of Blog Publisher. Once the content Blog is approved then the portal administrator or site admin can configure the blog to be shown on the specific portlets.

Please have a look at the workflow XML attached with the article which has been programmed to support multiple approval workflow.

I will explain the contents of the XML as much as possible or whatever I could understand J

Workflow definition schema configuration:
<workflow-definition xmlns="urn:liferay.com:liferay-workflow_6.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:liferay.com:liferay-workflow_6.1.0
http://www.liferay.com/dtd/liferay-workflow-definition_6_1_0.xsd"
>



We can define name, provide description and version of the workflow definition in the following way:
 <name>Multiple Approver</name>
    <description>A Multiple approver can approve Blogs through workflow definitions.</description>
    <version>1</version>


After that, we need to define our initial state. States can contain actions and transitions. Let’s examine the initial state for our use case:

<state>
        <name>created</name>
        <metadata>
            <![CDATA[{"xy":[78,53]}]]>
        </metadata>
        <initial>true</initial>
        <transitions>
            <transition>
                <name>review</name>
                <target>review</target>
            </transition>
        </transitions>
    </state>



So in the above state transitions provide moving from one task to another. Like the above state tells that when a new content is created send it to review task.

Let have a closer look to “update” task:

This task will be invoked if the content is rejected at any level of reviewing. It will be a default task and when this task will be triggered the workflow process will also be reset.

The first task in the workflow process is the “review” task which is invoked once a content is created and assigned to the user who are having roles mentioned in the role section of the task. If you observe that this task transitions into another task called as “second_review” and this provides us one more level of approval. Both the tasks “review” and “second_review” are similar but make sure you include the roles which will be responsible for second_review task.

Once the second_review task is completed the flow transitions to “approved” state, which executes a script to update the state of the content to “Approved”.

 Once we have created the workflow definition xml we need to follow the steps mentioned below for configuring the portal to fulfill our use case:

  • Create Users                                                                                                                            Create three users like Blog Writer, Blog Reviewer and Blog Publisher
  • Create User Groups                                                                                                                 Create three user groups like Blog Writer, Blog Reviewer and Blog Publisher. You can pick your own name to avoid confusion. After creating the user groups assign them to site for which you are configuring workflow.
  • Create Custom Role 
Create a custom role named “Blog Writer” of type “Site”. Once the role is created define the permissions as shown in the screenshot below:


  • Add Workflow Definition
Go to portal section of the control panel and open workflow section. Click on “Add” button and provide a name to the workflow definition like “Multiple Approval”. Then browse to the workflow definition XML file and click on save. Before saving your screen should look similar to the following:
 
Once the workflow definition gets uploaded successfully, it will auto generated roles mentioned in the workflow definition XML file.
 


  • Assigning Role to User Groups

Navigate to Site Membership section and open User Group Tab you should see something similar to the following screenshot:



Click on “Assign Site Role” and assign the role Blog_Writer to user group Blog_Writer user group, similarly do for other two user groups.

After assigning the roles you will see following screen:



  • Associate User with User Group

In this step we will be associating the users with specific user group so that the users inherit the roles associated with user groups.

For our case let’s associate Blog Writer with Blog_Writer User Group, Blog Reviewer user with Blog_Reviewer User Group and Blog Publisher with Blog Publisher User Group.


  • Workflow Configuration Now we need to enable the workflow definition for the Blogs Entry. Navigate to “Workflow Configuration” section and select “Multiple Approver (Version 1)” option from the combo box in front of “Blogs Entry” as shown below:
 
After selecting Click on Save button.

After completing all the above steps you are good to start testing the configurations.

So this is how you can achieve multiple workflow process using Kaleo Web Plugin.