laszlocsontos/liferay-portal — pull request #17 by vilmospapp (2013-11-14 14:45:20+00:00)
Title: [TECHNICAL SUPPORT] LPS-30715 Fix User selection problem on non default shard

Hi Laci,

The story of this PR started a long time ago. The original PR was rejected by Zsolt Berentey and Daniel Kocsis though the pattern was used is the one we use all over the portal. First I've created a ShardAdvice specially for the
UserLocalSerivce methods, but both Zsolt and Dani and Zsigmond wanted a more general solution as our pattern is more like a spot fix than a solution. Hence Zsolt and Dani came up with the idea to create an Annotation driven
Shard Advice and annotate the Classes and Methods for Shard selection.

When I started to implement it, I found that we need to annotatate method parameters as well, as the rule that companyId must be the first is broken by us in some places, changing it would break the API further more we can have some Object which has getCompanyId() method to get the companyId.

This made me think how we could resolve this situation, and I implemented parameter annotation handling. Unfortunately it wasn't so easy as I first thought, as the parameter annotations are present only in the *ServiceImpl but the Advice can access to the Service interface from the MethodInvocation so I had to copy those into the *Service interfaces as well.

This is handled by a ServiceBuilder modification where I wanted to apply a new pattern, so if in some cases we need to add other annotations as well we need to add them to the _parameterAnnotations Set only.

During the testing I found that in some places we still need to apply the old pattern with ShardUtil.pushCompanyService(companyId) and ShardUtil.popCompanyService() calls when we need to call such methods where no companyId nor an Object with getCompanyId() declared method is present in the parameter list, hence I added the very same methods to the proper ServiceImpl class with leading companyId parameter and @ShardSelection annotation.

This solution is now only applied on the User*Service classes/interfaces, and if it's approved we can move on and implement it in the other places in the portal and remove the unnecessary ShardAdvices as well.

I discovered other issues during the fixing this issue:

- User is unable to upload a profile image if sharding is turned on.
I'll open a ticket for this as this already existed without my fix.

- Ticket loading could face the same shard selection problem when user updates his password
I'll open a ticket for this as well.

Should you have any concerns/ideas/suggestions please let me know.

Cheers,
Vilmos