RE: Take name of a GROUP

Lorenzo Leonori, modified 7 Years ago. Junior Member Posts: 31 Join Date: 10/29/18 Recent Posts

I want take the name of a GROUP where a user or Admin belong.

EXAMPLE: Group(A;B;C;D)

User Nicolas belong to group named A, I want take value A;

 

I prove this way but not have a desired result because this is the id and i want the name:

User currentUser = PortalUtil.getUser(request);

currentUser.getGroup().getGroupId();  

thumbnail
Olaf Kock, modified 7 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
Lorenzo Leonori:

I want take the name of a GROUP where a user or Admin belong.

EXAMPLE: Group(A;B;C;D)

User Nicolas belong to group named A, I want take value A;

 

I prove this way but not have a desired result because this is the id and i want the name:

User currentUser = PortalUtil.getUser(request);

currentUser.getGroup().getGroupId();  


I'm assuming that you're looking for a UserGroup? Note that "Group" is the API name for Sites and similar collections of content - as the User API also has getGroup (like you stated), this is the user's personal group (read: site). I currently have no good option to look up the API, before my answer is slightly off: you'll need to look for the "UserGroup*" API, e.g. UserGroupLocalService or UserGroupService
Lorenzo Leonori, modified 7 Years ago. Junior Member Posts: 31 Join Date: 10/29/18 Recent Posts

-I'm assuming that you're looking for a UserGroup? 

Yes it's UserGroup.

I prove this API UserGroupLocalService or UserGroupService but I don't get the name of group where user belong.

Example:

1- take a user e.g MARIO ROSSI

2- NAME GROUP USERS who mario belong is Administrative process, my result must be:  Administrative process

Reguard to everyone.

thumbnail
Minhchau Dang, modified 7 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
Lorenzo Leonori:

I prove this API UserGroupLocalService or UserGroupService but I don't get the name of group where user belong.

It sounds like you'll want to read the User Groups section of the administrator guide in order to better understand the difference between a Group and a UserGroup. Essentially, you're calling user.getGroup(), which returns an object representing the user's personal site, which is not what you're looking for at all.

Given what you've stated, you want UserGroupLocalService.getUserUserGroups(long), which provides a list of the user's UserGroup memberships.

List userGroups = userGroupLocalService.getUserUserGroups(user.getUserId());

for (UserGroup userGroup : userGroups) {
    System.out.println(userGroup.getName());
}