This website uses cookies to ensure you get the best experience. Learn More.
Workflow Customization - Deep Dive
Liferay Portal is fully connected in its core to support workflow uses. Majority of entities in Liferay have capability to utilize workflow covering Web Contents, Document & Media, Blogs, Calendar Events, Comments, KB Articles, Message boards, Page revisions, Wiki, Users, Forms etc. Liferay also provides possibilities to utilize workflow capabilities in your custom entities as well, which can be easily achieved.
How workflow can be designed… Liferay provides rich UI interface to design your workflow or get with more technical xml based generation. Versioning is also supported in workflow definitions to have more controlled management of workflow definition.
Whole workflow process works in different steps in Liferay:
Lets dive little more deeper...
Lets check high level and deep level execution for workflow process:
Workflow execution starts from your entity’s web module which provides option to user for submitting your entity for publication - "Submit for publication" button. Web modules calls the service module which further calls the WorkflowHandlerRegistryUtil class from portal-kernel workflow package.
Individual entity’s local service impl is the first kickoff point for workflow, which is further handled in WorkflowHandlerRegistryUtil to actually process the kickoff request. WorkflowHandlerRegistryUtil fetches the registered workflow handler (based on class name). Flow described in below diagram helps to understand how it gets processed:
WorkflowHandlerRegistryUtil
To enable workflow on custom entities, Liferay have enough information available in its documents/articles explaining how workflow can be enabled on custom entity. In summary, this needs to have :
WorkflowHandlerRegistryUtil.startWorkflowInstance
Have updateStatus method in xxxLocalServiceImpl to update the status of entity
updateStatus
Based on above mentioned flow for initialization of Workflow on entity, we can notice the two areas where easy implementation is possible for custom entities as it falls under the control of developer who developed the entity implementation. For already exiting Liferay out of the box entities, customization is possible on two areas, where both fulfills the different type of needs.
This customization can be applied to control some of the limited execution/steps while having the entity creation. Example of possible customization could be additional checks for entity addition and workflow initialization. For custom entity, accordingly the implementation can be done. For OOTB entity services implementation, additional checks can be applied to persist and start the workflow.
When there is need a to decide on the uses of specific workflow definition to be considered for workflow initialization, workflow handler takes this activity. Workflow handler have decision power to decide which workflow definition to be used. For example, in OOTB implementation, workflow handler for journal article decide if workflow definition configured on entity level, folder level or parent folder level etc. Similarly, other simple handler decides for respective entity if workflow definition is scoped to site or even deeper level (e.g. Folder).
To customize OOTB handler, this can be achieved by registering custom handler for OOTB entities. Steps:
model.class.name
BaseWorkflowHandler
getClassName
getWorkflowDefinitionLink
companyId, groupId, classPk
@Reference(target = "(&(model.class.name=com.liferay.journal.model.JournalArticle)" + "(component.name=com.liferay.journal.internal.workflow.JournalArticleWorkflowHandler))") protected void setOriginalJournalWorkflowHandler(WorkflowHandler<JournalArticle> originlJournalWorkflowHandler) { this.originlJournalWorkflowHandler = originlJournalWorkflowHandler; }
By using original OOTB component reference, hassle of implementation additional methods can be avoided and on same time, implementation becomes upgrade friendly and low complexity on maintenance.
Some use cases could be, having different workflow based on:
With above points, we can customize on workflow kickoff and initialization of expected workflow definition.
In next blog, I will be explaining about how specific task execution works in workflow and how we can visualize that for customization/additions.
Photo Credit: Photo by Jakob Owens