Author: tmortagne
Date: 2007-10-29 14:35:00 +0100 (Mon, 29 Oct 2007)
New Revision: 5537

Modified:
   
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManager.java
   
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManagerPluginApi.java
   
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/user/api/XWikiGroupService.java
   
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiGroupServiceImpl.java
Log:
XWIKI-1826:
- Add new count methods for groups of a member and members of a group.
- Fix wrong calculation for sublist in getAllGroupsNamesForMember and 
getAllMembersNamesForGroup

Modified: 
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManager.java
===================================================================
--- 
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManager.java
     2007-10-29 13:16:29 UTC (rev 5536)
+++ 
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManager.java
     2007-10-29 13:35:00 UTC (rev 5537)
@@ -621,6 +621,36 @@
             start, context);
     }
 
+    /**
+     * Return the number of groups containing provided member.
+     * 
+     * @param member the name of the member (user or group).
+     * @param context the XWiki context.
+     * @return the number of groups.
+     * @throws XWikiException error when getting number of users.
+     */
+    public int countAllGroupsNamesForMember(String member, XWikiContext 
context)
+        throws XWikiException
+    {
+        return 
context.getWiki().getGroupService(context).countAllGroupsNamesForMember(member,
+            context);
+    }
+
+    /**
+     * Return the number of members provided group contains.
+     * 
+     * @param group the name of the group.
+     * @param context the XWiki context.
+     * @return the number of members.
+     * @throws XWikiException error when getting number of groups.
+     */
+    public int countAllMembersNamesForGroup(String group, XWikiContext context)
+        throws XWikiException
+    {
+        return 
context.getWiki().getGroupService(context).countAllMembersNamesForGroup(group,
+            context);
+    }
+
     // Rights management
 
     /**

Modified: 
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManagerPluginApi.java
===================================================================
--- 
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManagerPluginApi.java
    2007-10-29 13:16:29 UTC (rev 5536)
+++ 
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManagerPluginApi.java
    2007-10-29 13:35:00 UTC (rev 5537)
@@ -1911,4 +1911,45 @@
 
         return userList;
     }
+
+    /**
+     * Return the number of groups containing provided member.
+     * 
+     * @param member the name of the member (user or group).
+     * @return the number of groups.
+     * @throws XWikiException error when getting number of users.
+     */
+    public int countAllGroupsNamesForMember(String member) throws 
XWikiException
+    {
+        int count = 0;
+
+        try {
+            count =
+                
RightsManager.getInstance().countAllGroupsNamesForMember(member, this.context);
+        } catch (RightsManagerException e) {
+            logError("Try to count groups containing provided user", e);
+        }
+
+        return count;
+    }
+
+    /**
+     * Return the number of members provided group contains.
+     * 
+     * @param group the name of the group.
+     * @return the number of members.
+     * @throws XWikiException error when getting number of groups.
+     */
+    public int countAllMembersNamesForGroup(String group) throws XWikiException
+    {
+        int count = 0;
+
+        try {
+            count = 
RightsManager.getInstance().countAllMembersNamesForGroup(group, this.context);
+        } catch (RightsManagerException e) {
+            logError("Try to count all members provided group contains", e);
+        }
+
+        return count;
+    }
 }

Modified: 
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/user/api/XWikiGroupService.java
===================================================================
--- 
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/user/api/XWikiGroupService.java
     2007-10-29 13:16:29 UTC (rev 5536)
+++ 
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/user/api/XWikiGroupService.java
     2007-10-29 13:35:00 UTC (rev 5537)
@@ -1,6 +1,6 @@
 /*
- * Copyright 2006-2007, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
@@ -71,7 +71,8 @@
     public List listMemberForGroup(String s, XWikiContext context) throws 
XWikiException;
 
     /**
-     * @deprecated Use [EMAIL PROTECTED] #getAllMatchedGroups(Object[][], 
boolean, int, int, Object[][], XWikiContext)}.
+     * @deprecated Use
+     *             [EMAIL PROTECTED] #getAllMatchedGroups(Object[][], boolean, 
int, int, Object[][], XWikiContext)}.
      */
     public List listAllGroups(XWikiContext context) throws XWikiException;
 
@@ -170,9 +171,9 @@
      */
     int countAllMatchedGroups(Object[][] matchFields, int nb, int start, 
XWikiContext context)
         throws XWikiException;
-    
+
     /**
-     * Get all groups containing provided user.
+     * Get all groups containing provided member.
      * 
      * @param member the name of the member (user or group).
      * @param nb the maximum number of result to return.
@@ -184,9 +185,9 @@
      */
     public Collection getAllGroupsNamesForMember(String member, int nb, int 
start,
         XWikiContext context) throws XWikiException;
-    
+
     /**
-     * Get all users provided group contains.
+     * Get all members provided group contains.
      * 
      * @param group the name of the group.
      * @param nb the maximum number of result to return.
@@ -198,4 +199,26 @@
      */
     public Collection getAllMembersNamesForGroup(String group, int nb, int 
start,
         XWikiContext context) throws XWikiException;
+
+    /**
+     * Return the number of groups containing provided member.
+     * 
+     * @param member the name of the member (user or group).
+     * @param context the XWiki context.
+     * @return the number of groups.
+     * @throws XWikiException error when getting number of users.
+     * @since XWiki Core 1.1.2, XWiki Core 1.2M2
+     */
+    int countAllGroupsNamesForMember(String member, XWikiContext context) 
throws XWikiException;
+
+    /**
+     * Return the number of members provided group contains.
+     * 
+     * @param group the name of the group.
+     * @param context the XWiki context.
+     * @return the number of members.
+     * @throws XWikiException error when getting number of groups.
+     * @since XWiki Core 1.1.2, XWiki Core 1.2M2
+     */
+    int countAllMembersNamesForGroup(String group, XWikiContext context) 
throws XWikiException;
 }

Modified: 
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiGroupServiceImpl.java
===================================================================
--- 
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiGroupServiceImpl.java
  2007-10-29 13:16:29 UTC (rev 5536)
+++ 
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiGroupServiceImpl.java
  2007-10-29 13:35:00 UTC (rev 5537)
@@ -1,6 +1,6 @@
 /*
- * Copyright 2006-2007, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
@@ -679,9 +679,19 @@
     public Collection getAllGroupsNamesForMember(String member, int nb, int 
start,
         XWikiContext context) throws XWikiException
     {
+        //TODO: improve using real request
         List groupNameList = new ArrayList(listGroupsForUser(member, context));
 
-        return groupNameList.subList(start, start + nb);
+        if (start <= 0 & (nb <= 0 || nb >= groupNameList.size()))
+            return groupNameList;
+
+        if (nb == 0 && start == 0)
+            return groupNameList;
+
+        if (start + nb > groupNameList.size())
+            return groupNameList.subList(start, groupNameList.size() - 1);
+        else
+            return groupNameList.subList(start, start + nb);
     }
 
     /**
@@ -693,8 +703,38 @@
     public Collection getAllMembersNamesForGroup(String group, int nb, int 
start,
         XWikiContext context) throws XWikiException
     {
+        //TODO: improve using real request
         List userNameList = listMemberForGroup(group, context);
 
-        return userNameList.subList(start, start + nb);
+        if (nb == 0 && start == 0)
+            return userNameList;
+
+        if (start + nb > userNameList.size())
+            return userNameList.subList(start, userNameList.size() - 1);
+        else
+            return userNameList.subList(start, start + nb);
     }
+    
+    /**
+     * [EMAIL PROTECTED]
+     *
+     * @see 
com.xpn.xwiki.user.api.XWikiGroupService#countAllGroupsNamesForMember(java.lang.String,
 com.xpn.xwiki.XWikiContext)
+     * TODO: improve using real request
+     */
+    public int countAllGroupsNamesForMember(String member, XWikiContext 
context) throws XWikiException
+    {
+        //TODO: improve using real request
+        return getAllGroupsNamesForMember(member, 0, 0, context).size();
+    }
+    
+    /**
+     * [EMAIL PROTECTED]
+     *
+     * @see 
com.xpn.xwiki.user.api.XWikiGroupService#countAllMembersNamesForGroup(java.lang.String,
 com.xpn.xwiki.XWikiContext)
+     */
+    public int countAllMembersNamesForGroup(String group, XWikiContext 
context) throws XWikiException
+    {
+        //TODO: improve using real request
+        return getAllMembersNamesForGroup(group, 0, 0, context).size();
+    }
 }

_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to