cancel
Showing results for 
Search instead for 
Did you mean: 

Get group members properties

azivotic
Champ in-the-making
Champ in-the-making
Hi,

I need to fetch in my JavaDelegate class properties of some user which is member of some group.

When i have node ref to the user i can fetch his properties on this way for example

final QName PROP_QNAME_EMAIL = QName.createQName("http://www.alfresco.org/model/content/1.0", "email");
final Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
properties.get(PROP_QNAME_EMAIL)

But the problem is now that i only have GROUP NAME, and i don't know how to get NodeRef of the user which is in that group? Any idea on this?

Regards,
Aleksandar
3 REPLIES 3

afaust
Legendary Innovator
Legendary Innovator
Hello Aleksandar,

you can use the AuthorityService to retrieve the members of a specific group via getContainedAuthorities. Each user name you retrieve can be resolved to a person nodeRef via the PersonService afterwards.

A small suggestion: Try to use the QName constants provided by Alfresco in the ContentModel interface (and similar other interfaces for specific models). You avoid any issues with typos when constructing the QName yourself. It also is a tad more efficient for the size of your classfiles / PermGen, although this in itself may only be attractive enough for purists / perfectionists.

Regards
Axel

azivotic
Champ in-the-making
Champ in-the-making
Thank's man a lot on your help.  Smiley Very Happy

I wrote:

final Set<String> authorities = authorityService.getContainedAuthorities(AuthorityType.GROUP, "GROUP_PMO support", false);
where PMO support is the name of my group, but size of authorities is 0 and i am sure that there is two members of this group. What i am doing wrong?

Regards,
Aleksadnar

azivotic
Champ in-the-making
Champ in-the-making
lol, dumb me  Smiley Surprisedops: .

Instead of AuthorityType.GROUP it should be AuthorityType.User.

Working solution is:

final Set<String> authorities = authorityService.getContainedAuthorities(AuthorityType.USER, "GROUP_PMO support", false);
for (final String authority : authorities) {
            final NodeRef person = personService.getPerson(authority);
            final Map<QName, Serializable> properties = nodeService.getProperties(person);
            LOGGER.debug(properties.get(ContentModel.PROP_EMAIL).toString());
}
Thanks Axel once again on your help and for pointing me to the ContentModel interface.

Cheers,
Aleksandar