掲示板

How to execute custom Workflow Tasks

11年前 に Jaume Paternoy によって更新されました。

How to execute custom Workflow Tasks

New Member 投稿: 2 参加年月日: 12/09/12 最新の投稿
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:

// Workflow
		
		if (idea.getStatus() == WorkflowConstants.STATUS_ON_EVALUATION) {
                        //Navigate to he Publish Task
			workflowInstance = WorkflowInstanceManagerUtil.signalWorkflowInstance(serviceContext.getCompanyId(), serviceContext.getUserId(),
					workflowInstanceLink.getWorkflowInstanceId(), "PUBLISH", workflowInstance.getWorkflowContext());

			 //Find and complete the task
			WorkflowTask publishTask =[b] WorkflowUtil.getWorkflowTaskByName(workflowInstance.getWorkflowInstanceId(), "PUBLISH", serviceContext);[/b]
			publishTask = WorkflowTaskManagerUtil.completeWorkflowTask(serviceContext.getCompanyId(), serviceContext.getUserId(),
                                             publishTask.getWorkflowTaskId(),"OK", "", workflowInstance.getWorkflowContext());
			
                         //Navigate to the next state
			workflowInstance = WorkflowInstanceManagerUtil.signalWorkflowInstance(serviceContext.getCompanyId(), serviceContext.getUserId(),
					workflowInstanceLink.getWorkflowInstanceId(), "OK", workflowInstance.getWorkflowContext());
			
		} else {
			//Navigate to he SAVE_AS_DRAFT Task
			workflowInstance = WorkflowInstanceManagerUtil.signalWorkflowInstance(serviceContext.getCompanyId(), serviceContext.getUserId(),
					workflowInstanceLink.getWorkflowInstanceId(), "SAVE_AS_DRAFT", workflowInstance.getWorkflowContext());

			 //Find and complete the task
			WorkflowTask saveAsDraftTask = [b]WorkflowUtil.getWorkflowTaskByName(workflowInstance.getWorkflowInstanceId(), "PUBLISH", serviceContext);[/b]
			saveAsDraftTask = WorkflowTaskManagerUtil.completeWorkflowTask(serviceContext.getCompanyId(), serviceContext.getUserId(),
                                             saveAsDraftTask .getWorkflowTaskId(),"OK", "", workflowInstance.getWorkflowContext());
			
                         //Navigate to the next state
			workflowInstance = WorkflowInstanceManagerUtil.signalWorkflowInstance(serviceContext.getCompanyId(), serviceContext.getUserId(),
					workflowInstanceLink.getWorkflowInstanceId(), "OK", workflowInstance.getWorkflowContext());
		}

		workflowInstance = WorkflowInstanceManagerUtil.getWorkflowInstance(serviceContext.getCompanyId(), workflowInstanceLink.getWorkflowInstanceId());
		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.

		List<workflowtask> workflowTasksByWorkflowInstance = WorkflowTaskManagerUtil.getWorkflowTasksByWorkflowInstance(serviceContext.getCompanyId(), 
                                               serviceContext.getUserId(), workflowInstanceId, false, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
</workflowtask>


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.
thumbnail
11年前 に Amit Doshi によって更新されました。

RE: How to execute custom Workflow Tasks

Liferay Master 投稿: 550 参加年月日: 10/12/29 最新の投稿
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
11年前 に Jaume Paternoy によって更新されました。

RE: How to execute custom Workflow Tasks

New Member 投稿: 2 参加年月日: 12/09/12 最新の投稿
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

// Workflow
        
        if (idea.getStatus() == WorkflowConstants.STATUS_ON_EVALUATION) {
                        //Navigate to he Publish Task
            workflowInstance = WorkflowInstanceManagerUtil.signalWorkflowInstance(serviceContext.getCompanyId(), serviceContext.getUserId(),
                    workflowInstanceLink.getWorkflowInstanceId(), "PUBLISH", workflowInstance.getWorkflowContext());

             //Find and complete the task
            WorkflowTask publishTask = WorkflowUtil.getWorkflowTaskByName(workflowInstance.getWorkflowInstanceId(), "PUBLISH", serviceContext);
            publishTask = WorkflowTaskManagerUtil.completeWorkflowTask(serviceContext.getCompanyId(), serviceContext.getUserId(),
                                             publishTask.getWorkflowTaskId(),"OK", "", workflowInstance.getWorkflowContext());
            
                         //Navigate to the next state
            workflowInstance = WorkflowInstanceManagerUtil.signalWorkflowInstance(serviceContext.getCompanyId(), serviceContext.getUserId(),
                    workflowInstanceLink.getWorkflowInstanceId(), "OK", workflowInstance.getWorkflowContext());
            
        } else {
            //Navigate to he SAVE_AS_DRAFT Task
            workflowInstance = WorkflowInstanceManagerUtil.signalWorkflowInstance(serviceContext.getCompanyId(), serviceContext.getUserId(),
                    workflowInstanceLink.getWorkflowInstanceId(), "SAVE_AS_DRAFT", workflowInstance.getWorkflowContext());

             //Find and complete the task
            WorkflowTask saveAsDraftTask = WorkflowUtil.getWorkflowTaskByName(workflowInstance.getWorkflowInstanceId(), "PUBLISH", serviceContext);
            saveAsDraftTask = WorkflowTaskManagerUtil.completeWorkflowTask(serviceContext.getCompanyId(), serviceContext.getUserId(),
                                             saveAsDraftTask .getWorkflowTaskId(),"OK", "", workflowInstance.getWorkflowContext());
            
                         //Navigate to the next state
            workflowInstance = WorkflowInstanceManagerUtil.signalWorkflowInstance(serviceContext.getCompanyId(), serviceContext.getUserId(),
                    workflowInstanceLink.getWorkflowInstanceId(), "OK", workflowInstance.getWorkflowContext());
        }

        workflowInstance = WorkflowInstanceManagerUtil.getWorkflowInstance(serviceContext.getCompanyId(), workflowInstanceLink.getWorkflowInstanceId());
        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.
10年前 に Abhay Chaware によって更新されました。

RE: How to execute custom Workflow Tasks

Junior Member 投稿: 36 参加年月日: 13/07/17 最新の投稿
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
5年前 に Bin Li によって更新されました。

RE: How to execute custom Workflow Tasks

New Member 投稿: 14 参加年月日: 12/01/17 最新の投稿
How to define WorkflowConstants.STATUS_ON_EVALUATION, which is not a default status?