How to get users of specific role of multiple groups ?

1
0
-1

Hello,

I would like to get user list which the users have the specific role of specific groups.
For example, I get the list of specific groups first, then, I would like to get users of the "approver" role of each group.

I created a groovy script as follow, I would like to know how to retrieve each group id in order to use SearchOptionsBuilder group filter.

Any help would be appreciated.
Thanks in advance.

`
import org.bonitasoft.engine.api.IdentityAPI;
import org.bonitasoft.engine.identity.Group;
import org.bonitasoft.engine.identity.GroupCriterion;
import org.bonitasoft.engine.identity.User;
import org.bonitasoft.engine.search.SearchOptionsBuilder
import org.bonitasoft.engine.search.SearchResult

import org.bonitasoft.engine.identity.UserCriterion;
import org.bonitasoft.engine.identity.UserMembership;
import org.bonitasoft.engine.identity.UserMembershipCriterion;
import org.bonitasoft.engine.identity.UserSearchDescriptor;

IdentityAPI identity = apiAccessor.getIdentityAPI();

Group groupSelected=apiAccessor.getIdentityAPI().getGroups(groupIDs);

long specificRoleId=apiAccessor.identityAPI.getRoleByName("approver").getId();
final SearchOptionsBuilder builder = new SearchOptionsBuilder(0, 100);
builder.filter(UserSearchDescriptor.GROUP_ID, groupSelected);
builder.filter(UserSearchDescriptor.ROLE_ID, specificRoleId);

final SearchResult userResults = apiAccessor.identityAPI.searchUsers(builder.done());
List reviewerList = new ArrayList();
for(User user:userResults.getResult()){
reviewerList.add(user.getId())
}
return reviewerList; `

Comments

Submitted by HarleyFlynn on Sun, 04/07/2019 - 20:00

Try to search in google!

Submitted by delphine.coille on Tue, 04/09/2019 - 16:50

Hi HarleyFlinn,

Bonita follows the same code of conduct as Stackoverflow ( https://stackoverflow.com/conduct ) Where answers like yours are pointed as not acceptable by this code of conduct because they look unfriendly. We expect helpful answers on our Community.

Thanks

1 answer

1
+1
-1
This one is the BEST answer!

If I understand correctly you want to get Group information based on the group name. If my understanding is correct I recommend to use the IdentityAPI getGroupByPath in order to retrieve Group information (including id) based on the path of the group. A group has a path that includes parent group names e.g.: /top/parent/mygroup

Here is an example that you can use: Group group = apiAccessor.identityAPI.getGroupByPath('/acme/sales/europe')

Comments

Submitted by donghee.baik on Wed, 04/10/2019 - 17:04

Thanks for the answer.
As you recommended, I could get selected groups information based on group path.

Then, in order to get each approval from the selected group,
How to return each group id to use SearchOptionsBuilder?

builder.filter(UserSearchDescriptor.GROUP_ID, **group **);

Thanks in advance.

Submitted by donghee.baik on Wed, 04/10/2019 - 19:41

I got the answer as you recommended.
Thanks a lot

Notifications