com.xpn.xwiki.user.impl.xwiki
Class XWikiGroupServiceImpl

java.lang.Object
  extended by com.xpn.xwiki.user.impl.xwiki.XWikiGroupServiceImpl
All Implemented Interfaces:
XWikiGroupService, org.xwiki.observation.EventListener

public class XWikiGroupServiceImpl
extends Object
implements XWikiGroupService, org.xwiki.observation.EventListener

Default implementation of XWikiGroupService users and groups manager.

Version:
$Id: 60769195ef72b513ddf3eceb4fd33c56746d39a8 $

Field Summary
static EntityReference GROUPCLASS_REFERENCE
           
protected  Cache<Collection<DocumentReference>> memberGroupsCache
           
 
Constructor Summary
XWikiGroupServiceImpl()
           
 
Method Summary
 void addUserToGroup(String username, String database, String group, XWikiContext context)
          Adding the user to the group cache.
 int countAllGroupsNamesForMember(String member, XWikiContext context)
          Return the number of groups containing provided member.
 int countAllMatchedGroups(Object[][] matchFields, XWikiContext context)
          Return number of groups with provided constraints.
 int countAllMatchedUsers(Object[][] matchFields, XWikiContext context)
          Return number of users with provided constraints.
protected  int countAllMatchedUsersOrGroups(boolean user, Object[][] matchFields, XWikiContext context)
          Return number of users or groups with provided constraints.
 int countAllMembersNamesForGroup(String group, XWikiContext context)
          Return the number of members provided group contains.
protected  String createMatchGroupMembersWhereClause(String groupFullName, String matchField, Boolean orderAsc, Map<String,Object> parameterValues)
          Create a query to filter provided group members.
protected  String createMatchUserOrGroupWhereClause(boolean user, Object[][] matchFields, Object[][] order, List<Object> parameterValues)
          Create a "where clause" to use with XWikiStoreInterface searchDocuments and searchDocumentsNames methods.
 void flushCache()
           
 Collection<String> getAllGroupsNamesForMember(String member, int nb, int start, XWikiContext context)
          Get all groups containing provided member in the provided member wiki.
 Collection<DocumentReference> getAllGroupsReferencesForMember(DocumentReference memberReference, int limit, int offset, XWikiContext context)
          Get all groups containing provided member in the current wiki.
 List<?> getAllMatchedGroups(Object[][] matchFields, boolean withdetails, int nb, int start, Object[][] order, XWikiContext context)
          Search for all groups with provided constraints and in a provided order.
 Collection<String> getAllMatchedMembersNamesForGroup(String group, String matchField, int nb, int start, Boolean orderAsc, XWikiContext context)
          Get members of provided group.
 List<?> getAllMatchedUsers(Object[][] matchFields, boolean withdetails, int nb, int start, Object[][] order, XWikiContext context)
          Search for all users with provided constraints and in a provided order.
protected  List<?> getAllMatchedUsersOrGroups(boolean user, Object[][] matchFields, boolean withdetails, int nb, int start, Object[][] order, XWikiContext context)
          Search for all users or group with provided constraints and in a provided order.
 Collection<String> getAllMembersNamesForGroup(String group, int nb, int start, XWikiContext context)
          Get all members provided group contains.
 List<org.xwiki.observation.event.Event> getEvents()
           
 String getName()
           
 void init(XWiki xwiki, XWikiContext context)
           
 void initCache(int iCapacity, XWikiContext context)
           
 void initCache(XWikiContext context)
           
protected  boolean isAllGroupImplicit(XWikiContext context)
          Check whether the configuration specifies that every user is implicitly in XWikiAllGroup.
 List<String> listAllGroups(XWikiContext context)
           
 Collection<String> listGroupsForUser(String member, XWikiContext context)
           
 List<String> listMemberForGroup(String group, XWikiContext context)
           
 void onEvent(org.xwiki.observation.event.Event event, Object source, Object data)
           
 void removeUserOrGroupFromAllGroups(String memberWiki, String memberSpace, String memberName, XWikiContext context)
          Remove user or group name from all groups.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GROUPCLASS_REFERENCE

public static final EntityReference GROUPCLASS_REFERENCE

memberGroupsCache

protected Cache<Collection<DocumentReference>> memberGroupsCache
Constructor Detail

XWikiGroupServiceImpl

public XWikiGroupServiceImpl()
Method Detail

init

public void init(XWiki xwiki,
                 XWikiContext context)
          throws XWikiException
Specified by:
init in interface XWikiGroupService
Throws:
XWikiException

initCache

public void initCache(XWikiContext context)
               throws XWikiException
Specified by:
initCache in interface XWikiGroupService
Throws:
XWikiException

initCache

public void initCache(int iCapacity,
                      XWikiContext context)
               throws XWikiException
Specified by:
initCache in interface XWikiGroupService
Throws:
XWikiException

flushCache

public void flushCache()
Specified by:
flushCache in interface XWikiGroupService

isAllGroupImplicit

protected boolean isAllGroupImplicit(XWikiContext context)
Check whether the configuration specifies that every user is implicitly in XWikiAllGroup. Configured by the xwiki.authentication.group.allgroupimplicit parameter in xwiki.cfg.

Parameters:
context - the current XWiki context
Returns:
true if the group is implicit and all users should be by default in it, false if the group behaves as all other groups, containing only the users/subgroups that are explicitly listed inside the document.

listGroupsForUser

public Collection<String> listGroupsForUser(String member,
                                            XWikiContext context)
                                     throws XWikiException
Specified by:
listGroupsForUser in interface XWikiGroupService
Throws:
XWikiException

addUserToGroup

public void addUserToGroup(String username,
                           String database,
                           String group,
                           XWikiContext context)
                    throws XWikiException
Description copied from interface: XWikiGroupService
Adding the user to the group cache.

Specified by:
addUserToGroup in interface XWikiGroupService
Throws:
XWikiException

removeUserOrGroupFromAllGroups

public void removeUserOrGroupFromAllGroups(String memberWiki,
                                           String memberSpace,
                                           String memberName,
                                           XWikiContext context)
                                    throws XWikiException
Description copied from interface: XWikiGroupService
Remove user or group name from all groups.

Specified by:
removeUserOrGroupFromAllGroups in interface XWikiGroupService
Parameters:
memberWiki - the name of the wiki of the member.
memberSpace - the name of the space of the member.
memberName - the name of the member.
context - the XWiki context.
Throws:
XWikiException - error when browsing groups.

listMemberForGroup

public List<String> listMemberForGroup(String group,
                                       XWikiContext context)
                                throws XWikiException
Specified by:
listMemberForGroup in interface XWikiGroupService
Throws:
XWikiException

listAllGroups

public List<String> listAllGroups(XWikiContext context)
                           throws XWikiException
Specified by:
listAllGroups in interface XWikiGroupService
Throws:
XWikiException

getName

public String getName()
Specified by:
getName in interface org.xwiki.observation.EventListener

getEvents

public List<org.xwiki.observation.event.Event> getEvents()
Specified by:
getEvents in interface org.xwiki.observation.EventListener

onEvent

public void onEvent(org.xwiki.observation.event.Event event,
                    Object source,
                    Object data)
Specified by:
onEvent in interface org.xwiki.observation.EventListener

getAllMatchedUsers

public List<?> getAllMatchedUsers(Object[][] matchFields,
                                  boolean withdetails,
                                  int nb,
                                  int start,
                                  Object[][] order,
                                  XWikiContext context)
                           throws XWikiException
Description copied from interface: XWikiGroupService
Search for all users with provided constraints and in a provided order.

Specified by:
getAllMatchedUsers in interface XWikiGroupService
Parameters:
matchFields - the field to math with values. It is a table of table with :
  • fiedname : the name of the field
  • fieldtype : for example StringProperty. If null the field is considered as document field
  • pattern matching : based on HQL "like" command
withdetails - indicate if a List containing String names is returned or List containing XWikiDocument.
nb - the maximum number of results to return. Infinite if 0.
start - the index of the first found user to return.
order - the fields to order from. It is a table of table with :
  • fieldname : the name of the field
  • fieldtype : for example StringProperty. If null the field is considered as document field
  • asc : a Boolean, if true the order is ascendent
context - the XWikiContext.
Returns:
the list of users.
Throws:
XWikiException - error when getting users.

getAllMatchedGroups

public List<?> getAllMatchedGroups(Object[][] matchFields,
                                   boolean withdetails,
                                   int nb,
                                   int start,
                                   Object[][] order,
                                   XWikiContext context)
                            throws XWikiException
Description copied from interface: XWikiGroupService
Search for all groups with provided constraints and in a provided order.

Specified by:
getAllMatchedGroups in interface XWikiGroupService
Parameters:
matchFields - the field to math with values. It is a table of table with :
  • fiedname : the name of the field
  • fieldtype : for example StringProperty. If null the field is considered as document field
  • pattern matching : based on HQL "like" command
.
withdetails - indicate if a List containing String names is returned or List containing XWikiDocument.
nb - the maximum number of result to return. Infinite if 0.
start - the index of the first found group to return.
order - the field to order from. It is a table of table with :
  • fieldname : the name of the field
  • fieldtype : for example StringProperty. If null the field is considered as document field
  • asc : a Boolean, if true the order is ascendent
context - the XWikiContext.
Returns:
the list of groups.
Throws:
XWikiException - error when getting groups.

createMatchUserOrGroupWhereClause

protected String createMatchUserOrGroupWhereClause(boolean user,
                                                   Object[][] matchFields,
                                                   Object[][] order,
                                                   List<Object> parameterValues)
Create a "where clause" to use with XWikiStoreInterface searchDocuments and searchDocumentsNames methods.

Parameters:
user - if true search for users, otherwise search for groups.
matchFields - the field to math with values. It is a table of table with :
  • fiedname : the name of the field
  • fieldtype : for example StringProperty. If null the field is considered as document field
  • pattern matching : based on HQL "like" command
order - the field to order from. It is a table of table with :
  • fieldname : the name of the field
  • fieldtype : for example StringProperty. If null the field is considered as document field
  • asc : a Boolean, if true the order is ascendent
parameterValues - the list of values to fill for use with HQL named request.
Returns:
the formated HQL named request.

getAllMatchedUsersOrGroups

protected List<?> getAllMatchedUsersOrGroups(boolean user,
                                             Object[][] matchFields,
                                             boolean withdetails,
                                             int nb,
                                             int start,
                                             Object[][] order,
                                             XWikiContext context)
                                      throws XWikiException
Search for all users or group with provided constraints and in a provided order.

Parameters:
user - if true search for users, otherwise search for groups.
matchFields - the field to math with values. It is a table of table with :
  • fiedname : the name of the field
  • fieldtype : for example StringProperty. If null the field is considered as document field
  • pattern matching : based on HQL "like" command
withdetails - indicate if a List containing String names is returned or List containing XWikiDocument.
nb - the maximum number of results to return. Infinite if 0.
start - the index of the first found user or group to return.
order - the field to order from. It is a table of table with :
  • fieldname : the name of the field
  • fieldtype : for example StringProperty. If null the field is considered as document field
context - the XWikiContext.
Returns:
the list of users or groups.
Throws:
XWikiException - error when calling for XWikiStoreInterface#searchDocuments(String, int, int, List, XWikiContext) or XWikiStoreInterface#searchDocumentsNames(String, int, int, List, XWikiContext)

countAllMatchedUsersOrGroups

protected int countAllMatchedUsersOrGroups(boolean user,
                                           Object[][] matchFields,
                                           XWikiContext context)
                                    throws XWikiException
Return number of users or groups with provided constraints.

Parameters:
user - if true search for users, otherwise search for groups.
matchFields - the field to math with values. It is a table of table with :
  • fiedname : the name of the field
  • fieldtype : for example StringProperty. If null the field is considered as document field
  • pattern matching : based on HQL "like" command
context - the XWikiContext.
Returns:
the of found users or groups.
Throws:
XWikiException - error when calling for XWikiStoreInterface#search(String, int, int, List, XWikiContext)

countAllMatchedUsers

public int countAllMatchedUsers(Object[][] matchFields,
                                XWikiContext context)
                         throws XWikiException
Description copied from interface: XWikiGroupService
Return number of users with provided constraints.

Specified by:
countAllMatchedUsers in interface XWikiGroupService
Parameters:
matchFields - the field to math with values. It is a table of table with :
  • fiedname : the name of the field
  • fieldtype : for example StringProperty. If null the field is considered as document field
  • pattern matching : based on HQL "like" command
.
context - the XWikiContext.
Returns:
the of found users.
Throws:
XWikiException - error when getting number of users.

countAllMatchedGroups

public int countAllMatchedGroups(Object[][] matchFields,
                                 XWikiContext context)
                          throws XWikiException
Description copied from interface: XWikiGroupService
Return number of groups with provided constraints.

Specified by:
countAllMatchedGroups in interface XWikiGroupService
Parameters:
matchFields - the field to math with values. It is a table of table with :
  • fiedname : the name of the field
  • fieldtype : for example StringProperty. If null the field is considered as document field
  • pattern matching : based on HQL "like" command
.
context - the XWikiContext.
Returns:
the of found groups.
Throws:
XWikiException - error when getting number of groups.

createMatchGroupMembersWhereClause

protected String createMatchGroupMembersWhereClause(String groupFullName,
                                                    String matchField,
                                                    Boolean orderAsc,
                                                    Map<String,Object> parameterValues)
Create a query to filter provided group members. Generate the entire HQL query except the select part.

Parameters:
groupFullName - the fill wiki name of the group.
matchField - a string to search in result to filter.
orderAsc - if true, the result is ordered ascendent, if false it descendant. If null no order is applied.
parameterValues - the values to insert in names query.
Returns:
the HQL query.
Since:
1.6M1

getAllGroupsNamesForMember

public Collection<String> getAllGroupsNamesForMember(String member,
                                                     int nb,
                                                     int start,
                                                     XWikiContext context)
                                              throws XWikiException
Description copied from interface: XWikiGroupService
Get all groups containing provided member in the provided member wiki.

Specified by:
getAllGroupsNamesForMember in interface XWikiGroupService
Parameters:
member - the name of the member (user or group).
nb - the maximum number of result to return.
start - the index of the first found member to return.
context - the XWiki context.
Returns:
the Collection of String containing group name.
Throws:
XWikiException - error when browsing groups.

getAllGroupsReferencesForMember

public Collection<DocumentReference> getAllGroupsReferencesForMember(DocumentReference memberReference,
                                                                     int limit,
                                                                     int offset,
                                                                     XWikiContext context)
                                                              throws XWikiException
Description copied from interface: XWikiGroupService
Get all groups containing provided member in the current wiki.

Specified by:
getAllGroupsReferencesForMember in interface XWikiGroupService
Parameters:
memberReference - the member. Can be either user or group.
limit - the maximum number of result to return.
offset - the index of the first found member to return.
context - the XWiki context.
Returns:
the Collection of DocumentReference containing representing groups.
Throws:
XWikiException - error when browsing groups.

getAllMembersNamesForGroup

public Collection<String> getAllMembersNamesForGroup(String group,
                                                     int nb,
                                                     int start,
                                                     XWikiContext context)
                                              throws XWikiException
Description copied from interface: XWikiGroupService
Get all members provided group contains.

Specified by:
getAllMembersNamesForGroup in interface XWikiGroupService
Parameters:
group - the name of the group.
nb - the maximum number of result to return.
start - the index of the first found user to return.
context - the XWiki context.
Returns:
the Collection of String containing member name.
Throws:
XWikiException - error when browsing groups.

getAllMatchedMembersNamesForGroup

public Collection<String> getAllMatchedMembersNamesForGroup(String group,
                                                            String matchField,
                                                            int nb,
                                                            int start,
                                                            Boolean orderAsc,
                                                            XWikiContext context)
                                                     throws XWikiException
Description copied from interface: XWikiGroupService
Get members of provided group.

Specified by:
getAllMatchedMembersNamesForGroup in interface XWikiGroupService
Parameters:
group - the group.
matchField - a string to search in result to filter.
nb - the maximum number of result to return.
start - the index of the first found user to return.
orderAsc - if true, the result is ordered ascendent, if false it descendant. If null no order is applied.
context - the XWiki context.
Returns:
the Collection of String containing member name.
Throws:
XWikiException - error when browsing groups.

countAllGroupsNamesForMember

public int countAllGroupsNamesForMember(String member,
                                        XWikiContext context)
                                 throws XWikiException
Description copied from interface: XWikiGroupService
Return the number of groups containing provided member.

Specified by:
countAllGroupsNamesForMember in interface XWikiGroupService
Parameters:
member - the name of the member (user or group).
context - the XWiki context.
Returns:
the number of groups.
Throws:
XWikiException - error when getting number of users.

countAllMembersNamesForGroup

public int countAllMembersNamesForGroup(String group,
                                        XWikiContext context)
                                 throws XWikiException
Description copied from interface: XWikiGroupService
Return the number of members provided group contains.

Specified by:
countAllMembersNamesForGroup in interface XWikiGroupService
Parameters:
group - the name of the group.
context - the XWiki context.
Returns:
the number of members.
Throws:
XWikiException - error when getting number of groups.


Copyright © 2004–2014 XWiki. All rights reserved.