Liferay Devcon presentation on Workflow & Dynamic Forms
-
Upload
willem-vermeer -
Category
Technology
-
view
252 -
download
7
description
Transcript of Liferay Devcon presentation on Workflow & Dynamic Forms
Dynamic forms processing with Liferay workflow
Overview and lessons learnt
Willem Vermeer
Worth IT Den Haag, The Netherlands
10 October 2013
Presenter overview
Willem Vermeer
Java developer Based in The Netherlands Working for Worth IT Back-end oriented Liferay enthusiast
Presentation overview
Kaleo Workflow overview + demo
Integration with Orbeon forms + demo
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.”
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Prerequisites
Install Kaleo from Marketplace (CE or EE)into your Liferay Installation
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
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)
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
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Example start
submit
review
accepted
rejectstate
task
user
reviewerrole
transition accept
submit
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Workflow Definition
Liferay EE has a graphical editor to create/modify workflows
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.“
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.“
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>
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>
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>
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>
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
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
How to apply a workflow to a custom asset
your portlet app
WorkflowHandler
workflow engine
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>
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...}
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);}
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>
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);
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
);
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
);
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
How to re-assign a task to another user
long[] userIds = WorkflowTaskManagerUtil.getPooledActorsIds(companyId,workflowTaskId
);
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
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Orbeon Xforms Builder
Insert User Group Logo (please resize)
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
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Integration with Orbeon - demo
DEMO
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
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?
WWW.LIFERAY.COM WWW.FACEBOOK.COOM/LIFERAY @LIFERAY
Questions?
@willemvermeer
For more information on Orbeon please visit orbeon.com