Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Ken Driscoll
Get User Group of User?
16 de Julho de 2012 13:56
Resposta

Ken Driscoll

Ranking: Junior Member

Mensagens: 44

Data de entrada: 2 de Julho de 2012

Mensagens recentes

I set/get the User Group of a Liferay user. As an admin, I assigned a user to a user group. I've even check the user's profile to make sure it was assigned to him, and it was. Now in my portlet, I am able to get the user no problem, but the following method is saying that the user isn't assigned to a User Group...

1List<Group> groups = GroupLocalServiceUtil.getUserGroups(user.getUserId());
2System.out.println("Group count: "+groups.size());


Which prints out:
1Group count: 0


I'm not sure what I'm doing wrong...it may be the way I'm assigning the user to the group, or the way I'm retrieving the group. Any assistance would be greatly appreciated.
Hitoshi Ozawa
RE: Get User Group of User?
16 de Julho de 2012 14:22
Resposta

Hitoshi Ozawa

Ranking: Liferay Legend

Mensagens: 8000

Data de entrada: 23 de Março de 2010

Mensagens recentes

You're looking at the wrong method.

To get group which a user is assigned to, just get the user and just doe getGroups()

User user= themeDisplay.getUser();
List<Group> groups = user.getGroups();
Ken Driscoll
RE: Get User Group of User?
16 de Julho de 2012 15:17
Resposta

Ken Driscoll

Ranking: Junior Member

Mensagens: 44

Data de entrada: 2 de Julho de 2012

Mensagens recentes

Hitoshi Ozawa:
You're looking at the wrong method.

To get group which a user is assigned to, just get the user and just doe getGroups()

User user= themeDisplay.getUser();
List<Group> groups = user.getGroups();


I've tried this and am having the same problem. That list is also empty. Any other ideas?
Tejas Kanani
RE: Get User Group of User?
16 de Julho de 2012 21:34
Resposta

Tejas Kanani

Ranking: Liferay Master

Mensagens: 546

Data de entrada: 6 de Janeiro de 2009

Mensagens recentes

Hi Ken,

You can get all the userGroup assigned to particular user using getUserUserGroups method of UserGroupLocalServiceUtil.

1List<UserGroup> userGroups = UserGroupLocalServiceUtil.getUserUserGroups(themeDisplay.getUserId());


HTH.

Regards,
Tejas
Sachin Mane
RE: Get User Group of User?
16 de Julho de 2012 21:45
Resposta

Sachin Mane

Ranking: Junior Member

Mensagens: 76

Data de entrada: 9 de Abril de 2012

Mensagens recentes

GroupLocalServiceUtil.getGroups () will return you the logical group of the user, group id of the communities, organization that user belongs to.

GroupLocalServiceUtil.getUserGroups () will return the user groups - which is the grouping of users done for role assignment/authorization purpose.
Ken Driscoll
RE: Get User Group of User?
17 de Julho de 2012 12:17
Resposta

Ken Driscoll

Ranking: Junior Member

Mensagens: 44

Data de entrada: 2 de Julho de 2012

Mensagens recentes

I've tried all of these methods with no success. Perhaps I'm not setting the user group correctly? Even though it shows up in the profile...what am I doing wrong?
Hitoshi Ozawa
RE: Get User Group of User?
17 de Julho de 2012 16:01
Resposta

Hitoshi Ozawa

Ranking: Liferay Legend

Mensagens: 8000

Data de entrada: 23 de Março de 2010

Mensagens recentes

Sorry, you wanted user groups instead of just groups. Tested and worked properly for me with Liferay 6.1.0 CE

User user3 = themeDisplay.getUser();
long[] groups = user3.getUserGroupIds();
System.out.println("groups.size:" + groups.length);
System.out.println("userGroup:" + UserGroupLocalServiceUtil.getUserGroup(groups[0]).getName());
Ken Driscoll
RE: Get User Group of User?
18 de Julho de 2012 07:13
Resposta

Ken Driscoll

Ranking: Junior Member

Mensagens: 44

Data de entrada: 2 de Julho de 2012

Mensagens recentes

And we have a winner! Thank you so much for your time Hitoshi.