liferay devcon presentation on workflow & dynamic forms
DESCRIPTION
In this presentation we first present an overview of Liferay workflow. How to define a worklfow and how to use it together with your custom assets. Then we show how to use workflow to manage a business process, in this case the processing of application forms. The forms are defined in Orbeon XForms and integrated into your Liferay portlet app using the Orbeon Proxy Portlet. It allows you to leverage the role-based user management for evaluation of the form submissions.TRANSCRIPT
![Page 1: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/1.jpg)
Dynamic forms processing with Liferay workflow
Overview and lessons learnt
Willem Vermeer
Worth IT Den Haag, The Netherlands
10 October 2013
![Page 2: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/2.jpg)
Presenter overview
Willem Vermeer
Java developer Based in The Netherlands Working for Worth IT Back-end oriented Liferay enthusiast
![Page 3: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/3.jpg)
Presentation overview
Kaleo Workflow overview + demo
Integration with Orbeon forms + demo
![Page 4: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/4.jpg)
Kaleo Workflow
“allows a user to define any number of simple to complex business
processes/workflows, deploy them, and manage them through a portal interface. The processes have knowledge of users, groups and roles. You don’t have to write a single line of code to accomplish this: all
you have to do is create a single XML document.”
![Page 5: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/5.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Prerequisites
Install Kaleo from Marketplace (CE or EE)into your Liferay Installation
![Page 6: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/6.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Terminology
A workflow
- is a directed graph of states, tasks, transitions, actions and notifications
- can be applied to Liferay Assets such as Web Content or even Custom Assets
- is executed by an asynchronous engine
![Page 7: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/7.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Start and finish
A workflow
- starts in an initial state
- must finish at the end state
- can contain any number of tasks, including parallel tasks (fork-join)
![Page 8: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/8.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Task assignation
A task can be assigned to
- a certain user
- a role
Important: only user with assigned task can transition it to the next task or state
![Page 9: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/9.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Example start
submit
review
accepted
rejectstate
task
user
reviewerrole
transition accept
submit
![Page 10: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/10.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Workflow Definition
Liferay EE has a graphical editor to create/modify workflows
![Page 11: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/11.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Workflow Definition
Liferay EE has a graphical editor to create/modify workflows
pulled from marketplace
From Liferay Support:“Unfortunately we had to pull it from the Marketplace as many major issues were discovered with it.“
![Page 12: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/12.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Workflow Definition
Liferay EE has a graphical editor to create/modify workflows
Liferay CE has XML
pulled from marketplace
From Liferay Support:“Unfortunately we had to pull it from the Marketplace as many major issues were discovered with it.“
![Page 13: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/13.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Workflow definition part 1
<workflow-definitionxmlns="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">
<name>DevCon Demo</name><description>Workflow example</description><version>1</version><state>
<name>created</name><initial>true</initial><transitions>
<transition><name>submit</name><target>submit</target>
</transition></transitions>
</state>
![Page 14: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/14.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Workflow definition part 2<task>
<name>submit</name><actions>
<action><name>submit</name><script>
<![CDATA[Packages.com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil.updateStatus(Packages.com.liferay.portal.kernel.workflow.WorkflowConstants.toStatus("pending"), workflowContext); ]]>
</script><script-language>javascript</script-language><execution-type>onAssignment</execution-type>
</action></actions><assignments>
<user /></assignments><transitions>
<transition><name>submit</name><target>review</target>
</transition></transitions>
</task>
![Page 15: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/15.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Workflow definition part 3<task>
<name>review</name><actions>
<notification><name>Review Notification</name><template>You have a new submission waiting
for your review in the workflow.</template><template-language>text</template-language><notification-type>email</notification-type><execution-type>onAssignment</execution-type>
</notification></actions><assignments>
<roles><role>
<role-type>regular</role-type><name>Application Reviewer</name>
</role></roles>
</assignments><!-- left out the transitions -->
</task>
![Page 16: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/16.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Workflow definition part 4<state>
<name>approved</name><actions>
<action><name>approve</name><script>
<![CDATA[Packages.com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil.updateStatus(Packages.com.liferay.portal.kernel.workflow.WorkflowConstants.toStatus("approved"), workflowContext);]]>
</script><script-language>javascript</script-language><execution-type>onEntry</execution-type>
</action></actions>
</state></workflow-definition>
![Page 17: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/17.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Demo app
Extremely simplified version of customer case
CreateApplication portlet to apply for a grant
ListApplication portlet to display overview of applications
DEMO
![Page 18: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/18.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
How to apply a workflow to a custom asset
your portlet app
WorkflowHandler
workflow engine
![Page 19: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/19.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Workflow handler declaration
In liferay-portlet.xml add the following to your portlet:
<portlet>..<workflow-handler>
demo.workflow.ApplicationWorkflowHandler</workflow-handler>..
</portlet>
![Page 20: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/20.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Workflow handler
public abstract interface WorkflowHandler {
public String getClassName();
public abstract java.lang.Object updateStatus(int status, Map workflowContext) throws PortalException, SystemException;
// more...}
![Page 21: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/21.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Workflow handler implementation
@Overridepublic Object updateStatus(int status, Map<String, Serializable> workflowContext)
throws PortalException, SystemException {
Object applicationId = workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK);
long appId = Long.parseLong(applicationId.toString());
Application application = ApplicationLocalServiceUtil.fetchApplication(appId);
application.setStatus(status); return ApplicationLocalServiceUtil.updateApplication(application);}
![Page 22: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/22.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Workflow handler invocation
<action><name>submit</name><script>
<![CDATA[Packages.com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil.updateStatus(Packages.com.liferay.portal.kernel.workflow.WorkflowConstants.toStatus("pending"), workflowContext);
]]></script><script-language>javascript</script-language><execution-type>onAssignment</execution-type>
</action>
![Page 23: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/23.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
How to start the workflowServiceContext serviceContext =
ServiceContextFactory.getInstance(Application.class.getName(), request);
Map<String, Serializable> context = new HashMap<String, Serializable>();context.put(WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME,
Application.class.getName());
context.put(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK, Long.toString(app.getApplicationId()));
context.put(WorkflowConstants.CONTEXT_SERVICE_CONTEXT, serviceContext);
WorkflowInstanceManagerUtil.startWorkflowInstance(companyId,groupId,userId,workflowDefinitionName,workflowDefinitionVersion,phase,context);
![Page 24: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/24.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
How to move the workflow
WorkflowTaskManagerUtil.completeWorkflowTask(companyId,owningUserId,workflowTaskId,nextPhase, // "submit" or "reject" or .."comment",context
);
![Page 25: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/25.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
How to assign a task to a user
WorkflowTaskManagerUtil.assignWorkflowTaskToUser(companyId,userId, // ownerworkflowTaskId,userId, // assignee"comment", dueDate,context // can be an empty Map
);
![Page 26: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/26.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
How to re-assign a task to another user
long[] userIds = WorkflowTaskManagerUtil.getPooledActorsIds(companyId,workflowTaskId
);
![Page 27: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/27.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Integration with Orbeon XForms
Orbeon Forms Builder & Forms Runner
Proxy portlet to execute the form runner
Combination with workflow
![Page 28: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/28.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Orbeon Xforms Builder
Insert User Group Logo (please resize)
![Page 29: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/29.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Integration with Orbeon - architecture
Insert User Group Logo (please resize)
application group page
proxy portlet
custom portlet
(drives workflow)javascrip
t
![Page 30: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/30.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Integration with Orbeon - demo
DEMO
![Page 31: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/31.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Things to like about Kaleo workflow
Nice, deep integration with Liferay (users, roles)
Control panel access to workflow tasks
Simplicity
![Page 32: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/32.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Room for improvementExtensibility- limited to scripting in workflow definition
Flexibility- can't change definition once a workflow has started
Thread safety- workflow engine is thread UNsafe
Error recovery- What's wrong with my XML?
![Page 33: Liferay Devcon presentation on Workflow & Dynamic Forms](https://reader038.vdocuments.site/reader038/viewer/2022102605/548c4bf8b479597b698b4912/html5/thumbnails/33.jpg)
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Questions?
@willemvermeer
For more information on Orbeon please visit orbeon.com