not able to fetch the members of the group
Hi Nuxeo
i was trying to get the member of the group but it is not working it is returning null in all cases code is
Group group = new Group();
group.setGroupName(groupRequest.GroupName);
group.setGroupLabel(groupRequest.GroupLable);
group.setMemberUsers(groupRequest.userNameList);
// group.setParentGroups(parentGroups);
//group.setParentGroups(Arrays.asList("members"));
Group groupnew = client.userManager().createGroup(group);
groupnew = client.userManager().fetchGroup("New");
System.out.println(groupnew.getGroupName());
List<String> a = groupnew.getMemberUsers();
if (a != null) {
for (String item : a) {
System.out.println(item);
}
}
another way which i was trying is
Groups g = client.userManager().searchGroup("*");
System.out.println("size " + g.getTotalSize());
for (Group Gelement : g.getGroups()) {
System.out.println("lable " + Gelement.getGroupLabel());
System.out.println("Name " + Gelement.getGroupName());
System.out.println("ParentGroups");
for (Group iterable_element : Gelement.fetchMemberGroups().getGroups()) { // Returns null
System.out.println("lable " + iterable_element.getGroupLabel());
System.out.println("Name " + iterable_element.getGroupName());
}
System.out.println("MemberGroups");
Groups mg = Gelement.fetchMemberGroups(); // Returns null
for (Group iterable_element : mg.getGroups()) {
System.out.println("lable " + iterable_element.getGroupLabel());
System.out.println("Name " + iterable_element.getGroupName());
}
}
0 votes
1 answers
1020 views
Jackie A
You may need to wait for the next transaction, see TransactionalFeature nextTransaction()
01/21/2020
Hello,
why aren't you using the fetchMemberUsers() method as explained here: https://doc.nuxeo.com/client-java/3.2/user-group/#fetch
This is a very simple example, but it worked:
NuxeoClient nuxeoClient = new NuxeoClient.Builder()
.url(url)
.authentication(username, password)
.connect();
UserManager userManager = nuxeoClient.userManager();
Group group = userManager.fetchGroup("administrators");
String label = group.getGroupLabel();
System.out.println("Group: " + label);
Users users = group.fetchMemberUsers();
for(User u: users.getEntries()) {
System.out.println("User: " + u.getUserName() + "\n");
}
Result:
Group: Administrators group
User: Administrator
Regards.