Dtabase list - how can i write HQL query for listing a specific group users

Hi,
I have created an XWiki application, and now I would need a property to list all the users belonging to a specific group. i am using a Database list property so that there is a provision to use an HQL query. but I am unable to find which is the class used for the user group. can anybody give me any guidance here thank you.

Hi!

You can identify the groups by the XWiki.XWikiGroups object the XWiki page has. Also, each group member (subgroup or user) is identified with the XWiki.XWikiGroups, having the proper value in the member field.
To get all the members of a group, you can use $services.user.group.getMembers(DocumentReference group)

Hope it helps,
Alex

1 Like

Thank you for the reply, actually, I am completely new in this area,

I just found to write it this way for fetching all users or member of a group, but not working.

select obj.name from BaseObject obj, StringProperty prop where obj.className='XWiki.XWikiGroups' and prop.id.id=obj.id and prop.name='BAFI001KBS'

where prop.name is my group name. could you please guide me to where am I wrong in my query? or how can I write such a query, please?

so that I can use hql query for my database list property to list only that group members.

Here is something that would work for your need
select distinct memberDoc.fullName from XWikiDocument doc, XWikiDocument memberDoc, BaseObject obj, StringProperty as prop where doc.fullName = obj.name and doc.fullName = 'XWiki.XWikiAdminGroup' and obj.className = 'XWiki.XWikiGroups' and prop.id.id=obj.id and prop.name='member' and memberDoc.fullName = prop.value.
Replace XWiki.XWikiAdminGroup with your group full name XWiki.BAFI001KBS
Your group is identified by full name so it would be XWiki.BAFI001KBS. And the members of your group are also identified by full name XWiki.Admin → the default admin user.

1 Like

Thank you :), it is working for me. could you please tell me how can I fetch the full correct name instead of having XWiki.name meaning (first name last name )

also, can you give me a hint on where can i find these class names and properties so that I can understand the table (classes) structure? if need any more queries in future…Thank you in advance

Hi, about DB structure, you can find out here with the links to each table with the following columns name of each table. And instead of XWiki.name use XWiki.fullName.

1 Like

both memberDoc.name or memberDoc.fullname is giving me the just user id or a short name

I would like to have the (first name + last name ) this way

example: Jhon Brittas
Is any way we can get it this way?

currently, I am getting: xwiki.jbrittas or jbrittas

The first name and the last name are properties in the XWiki.XWikiUsers object from the page with the name returned by the query. Your xwiki.jbrittas is the name of the user profile document so you can obtain the document by using $xwiki.getDocument('xwiki.jbrittas') and you can do either get directly the values with$doc.first_name and $doc.last_name or get the object and get values from object.

xwiki-screenshot

but I am not sure if I can write here both Hibernate Query and $xwiki. api ?

is there any way possible to write it in a query to get the list of first names and last names or at least first names? instead of user id, from a specific group