Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Jaume Paternoy
How to execute custom Workflow Tasks
December 20, 2012 3:54 AM
Answer

Jaume Paternoy

Rank: New Member

Posts: 2

Join Date: September 12, 2012

Recent Posts

Hi all,

I am developing a Liferay Portlet Application for Liferay 6.0 EE SP1 on a JBoss server. I had some requirements on defining and developing Liferay Workflow to manage some business logic and, after some trials with JBPM I decided to use Kaleo, as jBPM is not currently supported by Liferay.
Finally, I have a good definition of my workflow and i am trying to integrate it with my custom assets, but after the lack of documentation it is being a real pain.

Let me explain a bit the scenario. On my workflow definition, I defined one start state called MATURING and a second one called ON_EVALUATION. There are also two tasks defined, SAVE_AS_DRAFT and PUBLISH and, to keep it simple, both are accessible from MATURING state (via two transitions with name of the task) and only the PUBLISH task is leading to the ON_EVALUATION state.
I have attached a descriptive image of my workflow so you can understand it better.

So, the point is to navigate a determined transition from the MATURING state and complete the following Task to navigate the next state (MATURING again, or ON_EVALUATION if you choose the PUBLISH task).

Below you can see the code I use on my LocalServiceImpl to manage my WorkflowInstance:
 1
 2// Workflow
 3       
 4        if (idea.getStatus() == WorkflowConstants.STATUS_ON_EVALUATION) {
 5                        //Navigate to he Publish Task
 6            workflowInstance = WorkflowInstanceManagerUtil.signalWorkflowInstance(serviceContext.getCompanyId(), serviceContext.getUserId(),
 7                    workflowInstanceLink.getWorkflowInstanceId(), "PUBLISH", workflowInstance.getWorkflowContext());
 8
 9             //Find and complete the task
10            WorkflowTask publishTask =[b] WorkflowUtil.getWorkflowTaskByName(workflowInstance.getWorkflowInstanceId(), "PUBLISH", serviceContext);[/b]
11            publishTask = WorkflowTaskManagerUtil.completeWorkflowTask(serviceContext.getCompanyId(), serviceContext.getUserId(),
12                                             publishTask.getWorkflowTaskId(),"OK", "", workflowInstance.getWorkflowContext());
13            
14                         //Navigate to the next state
15            workflowInstance = WorkflowInstanceManagerUtil.signalWorkflowInstance(serviceContext.getCompanyId(), serviceContext.getUserId(),
16                    workflowInstanceLink.getWorkflowInstanceId(), "OK", workflowInstance.getWorkflowContext());
17            
18        } else {
19            //Navigate to he SAVE_AS_DRAFT Task
20            workflowInstance = WorkflowInstanceManagerUtil.signalWorkflowInstance(serviceContext.getCompanyId(), serviceContext.getUserId(),
21                    workflowInstanceLink.getWorkflowInstanceId(), "SAVE_AS_DRAFT", workflowInstance.getWorkflowContext());
22
23             //Find and complete the task
24            WorkflowTask saveAsDraftTask = [b]WorkflowUtil.getWorkflowTaskByName(workflowInstance.getWorkflowInstanceId(), "PUBLISH", serviceContext);[/b]
25            saveAsDraftTask = WorkflowTaskManagerUtil.completeWorkflowTask(serviceContext.getCompanyId(), serviceContext.getUserId(),
26                                             saveAsDraftTask .getWorkflowTaskId(),"OK", "", workflowInstance.getWorkflowContext());
27            
28                         //Navigate to the next state
29            workflowInstance = WorkflowInstanceManagerUtil.signalWorkflowInstance(serviceContext.getCompanyId(), serviceContext.getUserId(),
30                    workflowInstanceLink.getWorkflowInstanceId(), "OK", workflowInstance.getWorkflowContext());
31        }
32
33        workflowInstance = WorkflowInstanceManagerUtil.getWorkflowInstance(serviceContext.getCompanyId(), workflowInstanceLink.getWorkflowInstanceId());
34        WorkflowHandlerRegistryUtil.updateStatus(WorkflowConstants.getStatusByName(workflowInstance.getState()), workflowInstance.getWorkflowContext());


The main problem is to find the desired task. It is done in the blackened method, using the Liferay function showed below.
1
2        List<WorkflowTask> workflowTasksByWorkflowInstance = WorkflowTaskManagerUtil.getWorkflowTasksByWorkflowInstance(serviceContext.getCompanyId(),
3                                               serviceContext.getUserId(), workflowInstanceId, false, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);


Unfortunately, it doesn't work as expected, because it only returns the SAVE_AS_DRAFT task, but not the PUBLISH task. I can imagine it is because of the default transition on SAVE_AS_DRAFT, but i can't find a way too retrieve the PUBLISH task and complete it.

I have done lots of efforts trying to find Liferay's documentation about the Workflow API but everything is only about very basic use cases, so I decided to try this forum.

Thanks in advance.
Any help will be appreciated.
Attachment

Attachments: idea-process-definition.xml (4.4k), workflow.png (8.4k)
Amit Doshi
RE: How to execute custom Workflow Tasks
December 26, 2012 3:47 AM
Answer

Amit Doshi

Rank: Liferay Master

Posts: 549

Join Date: December 29, 2010

Recent Posts

Jaume,

I checked your idea-process-definition.xml file and found that you use fork and other thing that made it too complicated.

So far I know you just need to do is that, you need to make the conditional base workflow. I didn't get much time to fully review it.

If I will get time, I will make the definition file for you. But start working on the conditional base workflow.

You need to put condtion on the MATURING PART.

Thanks & Regards,
Amit Doshi
Jaume Paternoy
RE: How to execute custom Workflow Tasks
January 3, 2013 3:58 AM
Answer

Jaume Paternoy

Rank: New Member

Posts: 2

Join Date: September 12, 2012

Recent Posts

Hi Amit.

Thanks a lot for your answer and interest.
I have simplified the workflow definition to get rid of other problems not related to the main point of this question. I removed the fork and those other complicated elements and now, my only goal is to complete a task assigned to the asset creator user. After task completion, the workflow engine should take me to the next state via the only possible transition, but it still doesn't work.

I am still using the same code in my LocalServiceImpl
 1
 2// Workflow
 3       
 4        if (idea.getStatus() == WorkflowConstants.STATUS_ON_EVALUATION) {
 5                        //Navigate to he Publish Task
 6            workflowInstance = WorkflowInstanceManagerUtil.signalWorkflowInstance(serviceContext.getCompanyId(), serviceContext.getUserId(),
 7                    workflowInstanceLink.getWorkflowInstanceId(), "PUBLISH", workflowInstance.getWorkflowContext());
 8
 9             //Find and complete the task
10            WorkflowTask publishTask = WorkflowUtil.getWorkflowTaskByName(workflowInstance.getWorkflowInstanceId(), "PUBLISH", serviceContext);
11            publishTask = WorkflowTaskManagerUtil.completeWorkflowTask(serviceContext.getCompanyId(), serviceContext.getUserId(),
12                                             publishTask.getWorkflowTaskId(),"OK", "", workflowInstance.getWorkflowContext());
13            
14                         //Navigate to the next state
15            workflowInstance = WorkflowInstanceManagerUtil.signalWorkflowInstance(serviceContext.getCompanyId(), serviceContext.getUserId(),
16                    workflowInstanceLink.getWorkflowInstanceId(), "OK", workflowInstance.getWorkflowContext());
17            
18        } else {
19            //Navigate to he SAVE_AS_DRAFT Task
20            workflowInstance = WorkflowInstanceManagerUtil.signalWorkflowInstance(serviceContext.getCompanyId(), serviceContext.getUserId(),
21                    workflowInstanceLink.getWorkflowInstanceId(), "SAVE_AS_DRAFT", workflowInstance.getWorkflowContext());
22
23             //Find and complete the task
24            WorkflowTask saveAsDraftTask = WorkflowUtil.getWorkflowTaskByName(workflowInstance.getWorkflowInstanceId(), "PUBLISH", serviceContext);
25            saveAsDraftTask = WorkflowTaskManagerUtil.completeWorkflowTask(serviceContext.getCompanyId(), serviceContext.getUserId(),
26                                             saveAsDraftTask .getWorkflowTaskId(),"OK", "", workflowInstance.getWorkflowContext());
27            
28                         //Navigate to the next state
29            workflowInstance = WorkflowInstanceManagerUtil.signalWorkflowInstance(serviceContext.getCompanyId(), serviceContext.getUserId(),
30                    workflowInstanceLink.getWorkflowInstanceId(), "OK", workflowInstance.getWorkflowContext());
31        }
32
33        workflowInstance = WorkflowInstanceManagerUtil.getWorkflowInstance(serviceContext.getCompanyId(), workflowInstanceLink.getWorkflowInstanceId());
34        WorkflowHandlerRegistryUtil.updateStatus(WorkflowConstants.getStatusByName(workflowInstance.getState()), workflowInstance.getWorkflowContext());


Now it is a very simple workflow and the main problem is, as always, to find the right methods in an undocumented API. I am even thinking it simply doesn't work for that Liferay version.

I have attached my new workflow definition for reference.

Thanks in advance.
Attachment

Attachments: idea-process-definition.png (6.7k), idea-process-definition.xml (3.0k)
Abhay Chaware
RE: How to execute custom Workflow Tasks
April 22, 2014 5:35 AM
Answer

Abhay Chaware

Rank: Junior Member

Posts: 36

Join Date: July 17, 2013

Recent Posts

Hello
Did you ever get this resolved ? I was facing similar challenge, but just calling "completeWorkflowTask" seems to be doing two things :
1. completing current task
2. transitioning into new state

Can you share your solution please ?

Thanks
abhay