COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => SDK => Topic started by: BfoBiz on 23 Dec 2009 03:22:41 AM

Title: How to get sub groups
Post by: BfoBiz on 23 Dec 2009 03:22:41 AM
Hello,
Im using java and i want to retrieve all the sub groups of a particular role.
How can i do?
Thanks
Title: Re: How to get sub groups
Post by: birliban on 12 Jan 2010 06:56:31 AM
I have the same problem.

All my usual ways of getting "members" of an object failed....
Title: Re: How to get sub groups
Post by: newbee2 on 12 Jan 2010 07:38:22 AM
U get some errors or just an empty sub-set?
Title: Re: How to get sub groups
Post by: birliban on 12 Jan 2010 07:57:37 AM
Just an empty subset (for me at least)....
Title: Re: How to get sub groups
Post by: newbee2 on 12 Jan 2010 08:03:07 AM
Same for me....
Did u also worked on capabilities?
Title: Re: How to get sub groups
Post by: birliban on 12 Jan 2010 08:25:44 AM
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.
Title: Re: How to get sub groups
Post by: birliban on 13 Jan 2010 09:44:27 AM
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 ];
Title: Re: How to get sub groups
Post by: newbee2 on 14 Jan 2010 02:06:21 AM
Thank you! I will try the soluction now  :)
Title: Re: How to get sub groups
Post by: Aljasmi on 27 Mar 2012 03:58:03 AM
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
Title: Re: How to get sub groups
Post by: murali999 on 07 Jun 2012 02:31:21 AM
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());
         }
  }