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

WorkflowTaskManagerUtil.assignWorkflowTaskToUser(
companyId,
userId,
workflowTasks.get(i).getWorkflowTaskId(),
assigneeUserId,
"Some note ...",
now,
workflowContext);

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:

java.lang.NullPointerException
at com.liferay.portal.workflow.WorkflowPermissionAdvice.invoke(WorkflowPermissionAdvice.java:40)
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(AbstractAspectJAdvice.java:621)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy231.assignWorkflowTaskToUser(Unknown Source)
at com.liferay.portal.kernel.workflow.WorkflowTaskManagerUtil.assignWorkflowTaskToUser(WorkflowTaskManagerUtil.java:50)
at o2.base.listener.NewUserDittaListener.assignWFtoGestoreDitta(NewUserDittaListener.java:421)
at o2.base.listener.NewUserDittaListener.doReceive(NewUserDittaListener.java:111)
at o2.base.listener.NewUserDittaListener.receive(NewUserDittaListener.java:60)
at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:63)
at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:61)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

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

Ivano C.
Flag Flag
Hi!
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:

java.lang.NullPointerException
at com.liferay.portal.workflow.WorkflowPermissionAdvice.invoke(WorkflowPermissionAdvice.java:40)

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 ????

Ciao,
Ivano
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-6.0.6.8 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:

 1
 2        WorkflowInstanceLink workflowInstanceLink = WorkflowInstanceLinkLocalServiceUtil.getWorkflowInstanceLink(
 3                companyId, groupId, className, classPK);
 4
 5        WorkflowInstance workflowInstance =
 6                WorkflowInstanceManagerUtil.getWorkflowInstance(
 7                    companyId, workflowInstanceLink.getWorkflowInstanceId());
 8       
 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.

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


Hope this helps,

Thanks and Regards,
Hitesh Methani.
Flag Flag