Getting the groups a user belong

Hi:

I need to add the groups the user belong to the column “Accepted By” in the task search results porlet.

What is the best way to get the groups the user belongs to based on the information provided by getTaskDisplayProvider().getAcceptedPrincipalsListProvider();

Thanks
Edgardo

There are two points to make:

  1. Task Engine does not support assigning task to groups. Only to individual users and roles
  2. It also does not support accepting a task by a group, only by individual users.

But it seems like what you are really looking for is for a way to discover and display just groups (or roles) which user who accepted a task is a member of.

TaskDisplayProvider.getAcceptedPrincipalsListProvider() returns you list of display names of accepted users, this is not what you need. Instead you need to obtain list of user IDs who accepted a task, from .getTaskInfo().getAcceptedByList() (where is managed bean representing current task)

Having the IDs of the user you now can determine groups and roles user is a member of using common directory service APIs. Details about this API can be found at:

http://www.ajax-softwareag.com/articles/Y4LCDN/Caf-7-1-1JavaDocs/com/webmethods/sc/directory/package-summary.html

The code you would need is something like this:
IDirectorySession s = DirectorySystemFactory.getDirectorySystem().createSession();
s.getGroupMembership(userID);

Thanks:

It seems that the format returned by getAcceptedByList() is not what getGroupMembership() needs. I get an Exception with the message

Invalid Object ID

getAcceptedByList() returns the user names as a String[]
getGroupMembership() expects a principalId: what format principalId must be (just the username, the DN…)? I tryied with different combinations and always got the same exception.

Thanks
Edgardo

Yes, you are correct. getAcceptedByList() returns array of usernames. So first you need to lookup a principal by its name:

IDirectoryPrincipal user = s.lookupPrincipalByName(name, IDirectoryPrincipal.TYPE_USER);

then

s.getGroupMembership(user.getID());

Alex

Thanks!

Here is the code if someone needs to implement it

IDirectorySession session = DirectorySystemFactory.getDirectorySystem().createSession();
:
:
ITaskInfo task = getTaskDisplayProvider().getTaskInfo();
String[] acceptedBy = task.getAcceptedByList();
IDirectoryPrincipal principal = session.lookupPrincipalByName(acceptedBy[0],IDirectoryPrincipal.TYPE_USER);
List groups = session.getGroupMembership(principal.getID());
for(IDirectoryGroup aGroup : groups) r += " - " + aGroup.getName();

Edgardo