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; `