Combination View Flat View Tree View
Threads [ Previous | Next ]
RE: Strange behavior of WorkflowTaskManagerUtil.assignWorkflowTaskToUser me
Using Liferay 6.0.6 and activiti-web- plugin, I used the below method in a JSP page:

"Some note ...",

I'm able to assign a task to the specified assigneeUserId with success.

BUT if I use the SAME method inside a class that implements MessageListener, I get the below error:

at com.liferay.portal.workflow.WorkflowPermissionAdvice.invoke(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(
at $Proxy231.assignWorkflowTaskToUser(Unknown Source)
at com.liferay.portal.kernel.workflow.WorkflowTaskManagerUtil.assignWorkflowTaskToUser(
at o2.base.listener.NewUserDittaListener.assignWFtoGestoreDitta(
at o2.base.listener.NewUserDittaListener.doReceive(
at o2.base.listener.NewUserDittaListener.receive(
at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(
at com.liferay.portal.kernel.messaging.ParallelDestination$
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$ Source)
at Source)

Please, anyone can help me?
Thank you in advance!

Ivano C.
Flag Flag
it looks like classloader problem in Liferay - the thing is - in MessageListener there are different classloader used (not your portlet classloader)
I remember I had such problems - it is not related to activiti-web - but to Liferay itself (I suppose it should be reproduced with Kaleo too).

Need to see more details in debuger who exactly produce this NPE... and post bug into Liferay JIRA
Flag Flag
Hi Alexey! Thank you for your fast reply...

In fact I used the same method also in the service layer and it works very well, the same at JSP level.

I reported the problem in Liferay JIRA ...

I think the problem is about the permission checker stuff...

At the begin of the NPE I see:

at com.liferay.portal.workflow.WorkflowPermissionAdvice.invoke(

At line 40 of the above method there is:

40 if (permissionChecker.getUserId() != userId) {
41 throw new PrincipalException();
42 }

Probably the permissionChecker.getUserId() value is null ????

Flag Flag
Or permissionChecker is null.
AS I can see - it is got from PermissionThreadLocal - MessageListeners called in separate thread - so, probably just this PermissionThreadLocal is not correctly initialized and current permission checker is not added into thread locla variables.

BTW - fixes for bugs for CE is slow - so, if you like this bug to be fixed - only way to fix it by yourself (of course if you can)
If you send me sample simplest project demonstrated problem - I can try to work on it - but not sure about my time
Flag Flag
Thank you Alexey !

Due the long times I preferred to move the code from Message Listener class to the service layer....

But I hope you can help me about the below my problem:

I'm using Liferay 6.0.6 and your activiti-web- plugin .....

In my portlet I created an asset and started the workflow process to approve it.

My actual problem is that I need to assign the process directly to a certain portal's user just after I started the workflow process....

After I call the WorkflowHandlerRegistryUtil.startWorkflowInstance() method, I need to use the WorkflowTaskManagerUtil.assignWorkflowTaskToUser() method to assign the task to this UserId.

The problem is that I'm not able to find the WorkflowTaskId to assign .... and the .startWorkflowInstance() method don't return the Id of the instance just started ....

Please, could you address me how I can find the WorkflowTaskId of the just started process?

Thank you in advance!!!

Ivano C.
Flag Flag
I saw your question in another post. Need to think how to do it.

But - I think - more correct thing will be do design process, so, specific task (Review for example) will use your own specific assignment handler and implement logic by assigning review task like you need.

In project source in samples you can see some samples (for example - assign task depending to tags connected to the asset)
Flag Flag
Hi Alexey,

I understand that the best option is to do the assigement in the BPM process.

Actually write Java code for me is the faster option... I have to decide to assign the task to a Role or User based on a value in a table. If I need to assign to a specific User I have to read the userId from another table.... so, if I have the Task Id in Java are two method to write only...

Any help is appreciate!!

Thank you Ivano
Flag Flag
Hi! Sorry for delays - had no time to look at it.

So - here is sample code - it will give you idea how to get list of active tasks for specific asset:

 2        WorkflowInstanceLink workflowInstanceLink = WorkflowInstanceLinkLocalServiceUtil.getWorkflowInstanceLink(
 3                companyId, groupId, className, classPK);
 5        WorkflowInstance workflowInstance =
 6                WorkflowInstanceManagerUtil.getWorkflowInstance(
 7                    companyId, workflowInstanceLink.getWorkflowInstanceId());
 9        List<WorkflowTask> tasks = WorkflowTaskManagerUtil.getWorkflowTasksByWorkflowInstance(companyId, userId, workflowInstanceId, completed, start, end, orderByComparator);

You need to pass into getWorkflowTasksByWorkflowInstance userId = 0l and completed = false

But! Currently released version of activiti-web has problem with userId = 0l (it does not work). So, to make it working you need to wait for next release (expected after Activiti 5.7 released - second part of August) or build activiti-web by yourself from sources (hopefully it is standard web-plugin so, you can easily build it from plugins sdk)
Flag Flag
It is due to permission checker coming out to be null..

I was able to solve it by adding following code before call of the method.

2PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.getPermissionCheckerFactory().create(UserLocalServiceUtil.getUser(userId), true);

Hope this helps,

Thanks and Regards,
Hitesh Methani.
Flag Flag