Hello,
Im using java and i want to retrieve all the sub groups of a particular role.
How can i do?
Thanks
I have the same problem.
All my usual ways of getting "members" of an object failed....
U get some errors or just an empty sub-set?
Just an empty subset (for me at least)....
Same for me....
Did u also worked on capabilities?
No, I just try to create an overview of groups / roles a specific user is in.
At the moment I get all groups and roles a user is in. But some groups are just subgroups of other groups / roles and I wanted to make this visible somehow... thus I try to find a way to determin subgroups of other groups.
I found a way of doing it:
Assuming you have the searchpath for the group you want the subgroups of.
Query the contentstore for it with following PropEnum:
PropEnum[] props = { PropEnum.defaultName, PropEnum.searchPath, PropEnum.members };
As result you get a BaseClass[] object (with only one element though...).
Import com.cognos.developer.schemas.bibus._3.Group <--- this is part of the Cognos SDK libraries
now you can cast the object[0] to Group.
object.getMembers().getValue()[] is an array of all members INCLUDING groups, roles, accounts.
In java it looks like this (query for the object already done):
Group group = (Group)object[0];
BaseClass obj = null;
for (int i = 0; i < group.getMembers().getValue().length; i++){
obj = group.getMembers().getValue()[ i ];
System.out.println(obj.getSearchPath().getValue());
}
Edit: I just read you want to do it for a role. Should work the same way, only the import differs: import com.cognos.developer.schemas.bibus._3.Role;
Edit2: autoformatting swallowed [ i ] in obj = group.getMembers().getValue()[ i ];
Thank you! I will try the soluction now :)
i tried it but it dose not work
my code is as this
BaseClass[] bc = cmService.query(
new SearchPathMultipleObject(Sorc_path),
new PropEnum[] {
PropEnum.defaultName,
PropEnum.searchPath,
PropEnum.objectClass,
PropEnum.parent,
PropEnum.owner,
PropEnum.members,
PropEnum.defaultDescription
},
sort ,
new QueryOptions()
);
if (bc != null && bc.length > 0)
{
recordCount = bc.length;
for (int i = 0; i < bc.length; i++)
{
Group group =(Group)bc[i];
BaseClass obj = null;
for (int ii = 0; ii < group.getMembers().getValue().length; ii++)
{
obj = group.getMembers().getValue()[ii];
itemViewr.add(obj.getSearchPath().getValue());
}
}
}
any suggestion
thank you
Hi a small change in your code will give u the results ..
for (int i = 0; i < bc.length; i++)
{
Group group =(Group)bc;
BaseClass obj = null;
for (int ii = 0; ii < group.getMembers().getValue().length; ii++)
{
obj = group.getMembers().getValue()[ii];
//Before Going to add the member check this is a group or not
if(obj instanceof Group)
{
// print or add the obj(ie Group) to stingarray or vector
}
if(obj instanceof Role)
{
// print or add the obj(ie role) to stingarray or vector
}
if(obj instanceof Account)
{
// print or add the obj(ie User) to stingarray or vector
}
// itemViewr.add(obj.getSearchPath().getValue());
}
}