cancel
Showing results for 
Search instead for 
Did you mean: 

How to get all User Groups of a Site programmatically using Java API?

mbel
Star Contributor
Star Contributor

Hello,

Is there any way of getting the list of all UserGroups and SubUserGroups of a Site?

Currently I see only method listMembers() which returns only the list of Users, not the groups.

Thank you in advance.

1 ACCEPTED ANSWER

afaust
Legendary Innovator
Legendary Innovator

When you want to get all the users and/or groups within sites you may also always use the AuthorityService API to list them. The SiteService API only provides the convenience operations that are needed e.g. to provide site management functionality in the UI. SiteService.getSiteGroup(shortName) gets you the Alfresco group that contains all the roles of the site, and transitively all the groups / users. You can use that in conjunction with AuthorityService.getContainedAuthorities(authorityType, name, immediate) to retrieve members.

View answer in original post

17 REPLIES 17

kaynezhang
World-Class Innovator
World-Class Innovator

You can try listMembers method and set argument collapseGroups=true.

mbel
Star Contributor
Star Contributor

This again returns all users, but not the group of users.

I want to get for example ->  <GROUP_test, role> (which contain users: user1, user2) and after that get the List of that group which should return - user1, user2;

Instead I get -> <user1, role>, <user2, role> from the map which return that method.

mbel
Star Contributor
Star Contributor

Ok, so for my case it should be =false and it works

afaust
Legendary Innovator
Legendary Innovator

When you want to get all the users and/or groups within sites you may also always use the AuthorityService API to list them. The SiteService API only provides the convenience operations that are needed e.g. to provide site management functionality in the UI. SiteService.getSiteGroup(shortName) gets you the Alfresco group that contains all the roles of the site, and transitively all the groups / users. You can use that in conjunction with AuthorityService.getContainedAuthorities(authorityType, name, immediate) to retrieve members.

mbel
Star Contributor
Star Contributor

Is there any way not specifying the authorityType? Otherwise I have to foreach them role by role, right?

afaust
Legendary Innovator
Legendary Innovator

You can simply provide authorityType as null and both groups AND users will be returned. The authorityType has nothing to do with the site role - these can be differentiated via SiteService.getSiteRoleGroup(shortName, roleName)

mbel
Star Contributor
Star Contributor

For the method - authorityService.getContainedAuthorities(authorityType, name, immediate);

Could you please tell me what exactly the paramether name (the name of the containing authority) means.

The GroupName of a Site or ? As I receive nullpointer exception...

afaust
Legendary Innovator
Legendary Innovator

Obviously it refers to the name of the authority of which to get the contained authorities. In this case it needs the full authority name as returned by the SiteService.getSiteRoleGroup(shortName, role) or SiteService.getSiteGroup(shortName)

mbel
Star Contributor
Star Contributor

Yes, I tried with both, but currently trying to investigate from where it returns null pointer exception.