Author: tmortagne
Date: 2007-10-28 12:33:07 +0100 (Sun, 28 Oct 2007)
New Revision: 5530

Added:
   
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManageGroupsApi.java
   
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManageUsersApi.java
Modified:
   
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManager.java
   
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManagerPluginApi.java
Log:
XWIKI-1826:
- Move countAll* methods to respective sub api RightsManagerGroupsApi and 
RightsManagerUsersApi.
- Added matching pattern support to countAll* methods.

Added: 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManageGroupsApi.java
===================================================================
--- 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManageGroupsApi.java
                            (rev 0)
+++ 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManageGroupsApi.java
    2007-10-28 11:33:07 UTC (rev 5530)
@@ -0,0 +1,225 @@
+/*
+ * 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
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package com.xpn.xwiki.plugin.rightsmanager;
+
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.api.Api;
+
+/**
+ * API for managing groups.
+ * 
+ * @version $Id: $
+ * @since XWiki Core 1.1.2, XWiki Core 1.2M2
+ */
+public class RightsManageGroupsApi extends Api
+{
+    /**
+     * Field name of the last error code inserted in context.
+     */
+    public static final String CONTEXT_LASTERRORCODE =
+        RightsManagerPluginApi.CONTEXT_LASTERRORCODE;
+
+    /**
+     * Field name of the last api exception inserted in context.
+     */
+    public static final String CONTEXT_LASTEXCEPTION =
+        RightsManagerPluginApi.CONTEXT_LASTEXCEPTION;
+
+    /**
+     * Quote symbol.
+     */
+    public static final String QUOTE = RightsManagerPluginApi.QUOTE;
+
+    /**
+     * The logging toolkit.
+     */
+    protected static final Log LOG = 
LogFactory.getLog(RightsManageGroupsApi.class);
+
+    /**
+     * Create an instance of RightsManageRightsApi.
+     * 
+     * @param context the XWiki context.
+     */
+    public RightsManageGroupsApi(XWikiContext context)
+    {
+        super(context);
+    }
+
+    /**
+     * Log error and register [EMAIL PROTECTED] #CONTEXT_LASTERRORCODE} and 
[EMAIL PROTECTED] #CONTEXT_LASTEXCEPTION}.
+     * 
+     * @param comment the comment to use with [EMAIL PROTECTED] #LOG}.
+     * @param e the exception.
+     */
+    private void logError(String comment, XWikiException e)
+    {
+        LOG.error(comment, e);
+
+        this.context.put(CONTEXT_LASTERRORCODE, new Integer(e.getCode()));
+        this.context.put(CONTEXT_LASTEXCEPTION, e);
+    }
+
+    // Count
+
+    /**
+     * @return the number of groups in the current wiki.
+     * @throws XWikiException error when getting number of groups.
+     */
+    public int countAllGroups() throws XWikiException
+    {
+        return countAllMatchedGroups(null);
+    }
+
+    /**
+     * @param matchFields the fields to match. It is a Map with field name as 
key and for value :
+     *            <ul>
+     *            <li>"matching string" for document fields</li>
+     *            <li>or ["field type", "matching string"] for object 
fields</li>
+     *            </ul>
+     * @return the number of groups in the current wiki.
+     * @throws XWikiException error when getting number of groups.
+     */
+    public int countAllMatchedGroups(Map matchFields) throws XWikiException
+    {
+        int count = 0;
+
+        try {
+            count =
+                RightsManager.getInstance().countAllUsersOrGroups(false,
+                    RightsManagerPluginApi.createMatchingTable(matchFields), 
this.context);
+        } catch (RightsManagerException e) {
+            logError("Try to count all groups", e);
+        }
+
+        return count;
+    }
+
+    /**
+     * Get the number of groups in the provided wiki.
+     * 
+     * @param wikiName the name of the wiki where to search for groups.
+     * @return the number of groups in the provided wiki.
+     * @throws XWikiException error when getting number of groups.
+     */
+    public int countAllWikiGroups(String wikiName) throws XWikiException
+    {
+        return countAllMatchedWikiGroups(wikiName, null);
+    }
+
+    /**
+     * Get the number of groups in the provided wiki.
+     * 
+     * @param wikiName the name of the wiki where to search for groups.
+     * @param matchFields the fields to match. It is a Map with field name as 
key and for value :
+     *            <ul>
+     *            <li>"matching string" for document fields</li>
+     *            <li>or ["field type", "matching string"] for object 
fields</li>
+     *            </ul>
+     * @return the number of groups in the provided wiki.
+     * @throws XWikiException error when getting number of groups.
+     */
+    public int countAllMatchedWikiGroups(String wikiName, Map matchFields) 
throws XWikiException
+    {
+        int count = 0;
+
+        try {
+            count =
+                RightsManager.getInstance().countAllWikiUsersOrGroups(false, 
wikiName,
+                    RightsManagerPluginApi.createMatchingTable(matchFields), 
this.context);
+        } catch (RightsManagerException e) {
+            logError("Try to count all groups in wiki " + QUOTE + wikiName + 
QUOTE, e);
+        }
+
+        return count;
+    }
+
+    /**
+     * @return the number of groups in the main wiki.
+     * @throws XWikiException error when getting number of groups.
+     */
+    public int countAllGlobalGroups() throws XWikiException
+    {
+        return countAllMatchedGlobalGroups(null);
+    }
+
+    /**
+     * @param matchFields the fields to match. It is a Map with field name as 
key and for value :
+     *            <ul>
+     *            <li>"matching string" for document fields</li>
+     *            <li>or ["field type", "matching string"] for object 
fields</li>
+     *            </ul>
+     * @return the number of groups in the main wiki.
+     * @throws XWikiException error when getting number of groups.
+     */
+    public int countAllMatchedGlobalGroups(Map matchFields) throws 
XWikiException
+    {
+        int count = 0;
+
+        try {
+            count =
+                RightsManager.getInstance().countAllGlobalUsersOrGroups(false,
+                    RightsManagerPluginApi.createMatchingTable(matchFields), 
this.context);
+        } catch (RightsManagerException e) {
+            logError("Try to count all groups in main wiki", e);
+        }
+
+        return count;
+    }
+
+    /**
+     * @return the number of groups in the current wiki.
+     * @throws XWikiException error when getting number of groups.
+     */
+    public int countAllLocalGroups() throws XWikiException
+    {
+        return countAllMatchedLocalGroups(null);
+    }
+
+    /**
+     * @param matchFields the fields to match. It is a Map with field name as 
key and for value :
+     *            <ul>
+     *            <li>"matching string" for document fields</li>
+     *            <li>or ["field type", "matching string"] for object 
fields</li>
+     *            </ul>
+     * @return the number of groups in the current wiki.
+     * @throws XWikiException error when getting number of groups.
+     */
+    public int countAllMatchedLocalGroups(Map matchFields) throws 
XWikiException
+    {
+        int count = 0;
+
+        try {
+            count =
+                RightsManager.getInstance().countAllLocalUsersOrGroups(false,
+                    RightsManagerPluginApi.createMatchingTable(matchFields), 
this.context);
+        } catch (RightsManagerException e) {
+            logError("Try to count all groups in current wiki", e);
+        }
+
+        return count;
+    }
+}

Added: 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManageUsersApi.java
===================================================================
--- 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManageUsersApi.java
                             (rev 0)
+++ 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManageUsersApi.java
     2007-10-28 11:33:07 UTC (rev 5530)
@@ -0,0 +1,225 @@
+/*
+ * 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
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package com.xpn.xwiki.plugin.rightsmanager;
+
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.api.Api;
+
+/**
+ * API for managing users.
+ * 
+ * @version $Id: $
+ * @since XWiki Core 1.1.2, XWiki Core 1.2M2
+ */
+public class RightsManageUsersApi extends Api
+{
+    /**
+     * Field name of the last error code inserted in context.
+     */
+    public static final String CONTEXT_LASTERRORCODE =
+        RightsManagerPluginApi.CONTEXT_LASTERRORCODE;
+
+    /**
+     * Field name of the last api exception inserted in context.
+     */
+    public static final String CONTEXT_LASTEXCEPTION =
+        RightsManagerPluginApi.CONTEXT_LASTEXCEPTION;
+
+    /**
+     * Quote symbol.
+     */
+    public static final String QUOTE = RightsManagerPluginApi.QUOTE;
+
+    /**
+     * The logging toolkit.
+     */
+    protected static final Log LOG = 
LogFactory.getLog(RightsManageUsersApi.class);
+
+    /**
+     * Create an instance of RightsManageRightsApi.
+     * 
+     * @param context the XWiki context.
+     */
+    public RightsManageUsersApi(XWikiContext context)
+    {
+        super(context);
+    }
+
+    /**
+     * Log error and register [EMAIL PROTECTED] #CONTEXT_LASTERRORCODE} and 
[EMAIL PROTECTED] #CONTEXT_LASTEXCEPTION}.
+     * 
+     * @param comment the comment to use with [EMAIL PROTECTED] #LOG}.
+     * @param e the exception.
+     */
+    private void logError(String comment, XWikiException e)
+    {
+        LOG.error(comment, e);
+
+        this.context.put(CONTEXT_LASTERRORCODE, new Integer(e.getCode()));
+        this.context.put(CONTEXT_LASTEXCEPTION, e);
+    }
+
+    // Count
+
+    /**
+     * @return the number of users in the current wiki.
+     * @throws XWikiException error when getting number of users.
+     */
+    public int countAllUsers() throws XWikiException
+    {
+        return countAllMatchedUsers(null);
+    }
+
+    /**
+     * @param matchFields the fields to match. It is a Map with field name as 
key and for value :
+     *            <ul>
+     *            <li>"matching string" for document fields</li>
+     *            <li>or ["field type", "matching string"] for object 
fields</li>
+     *            </ul>
+     * @return the number of users in the current wiki.
+     * @throws XWikiException error when getting number of users.
+     */
+    public int countAllMatchedUsers(Map matchFields) throws XWikiException
+    {
+        int count = 0;
+
+        try {
+            count =
+                RightsManager.getInstance().countAllUsersOrGroups(true,
+                    RightsManagerPluginApi.createMatchingTable(matchFields), 
this.context);
+        } catch (RightsManagerException e) {
+            logError("Try to count all users", e);
+        }
+
+        return count;
+    }
+
+    /**
+     * Get the number of users in the provided wiki.
+     * 
+     * @param wikiName the name of the wiki where to search for users.
+     * @return the number of users in the provided wiki.
+     * @throws XWikiException error when getting number of users.
+     */
+    public int countAllWikiUsers(String wikiName) throws XWikiException
+    {
+        return countAllMatchedWikiUsers(wikiName, null);
+    }
+
+    /**
+     * Get the number of users in the provided wiki.
+     * 
+     * @param wikiName the name of the wiki where to search for users.
+     * @param matchFields the fields to match. It is a Map with field name as 
key and for value :
+     *            <ul>
+     *            <li>"matching string" for document fields</li>
+     *            <li>or ["field type", "matching string"] for object 
fields</li>
+     *            </ul>
+     * @return the number of users in the provided wiki.
+     * @throws XWikiException error when getting number of users.
+     */
+    public int countAllMatchedWikiUsers(String wikiName, Map matchFields) 
throws XWikiException
+    {
+        int count = 0;
+
+        try {
+            count =
+                RightsManager.getInstance().countAllWikiUsersOrGroups(true, 
wikiName,
+                    RightsManagerPluginApi.createMatchingTable(matchFields), 
this.context);
+        } catch (RightsManagerException e) {
+            logError("Try to count all users in wiki " + QUOTE + wikiName + 
QUOTE, e);
+        }
+
+        return count;
+    }
+
+    /**
+     * @return the number of users in the main wiki.
+     * @throws XWikiException error when getting number of users.
+     */
+    public int countAllGlobalUsers() throws XWikiException
+    {
+        return countAllMatchedGlobalUsers(null);
+    }
+
+    /**
+     * @param matchFields the fields to match. It is a Map with field name as 
key and for value :
+     *            <ul>
+     *            <li>"matching string" for document fields</li>
+     *            <li>or ["field type", "matching string"] for object 
fields</li>
+     *            </ul>
+     * @return the number of users in the main wiki.
+     * @throws XWikiException error when getting number of users.
+     */
+    public int countAllMatchedGlobalUsers(Map matchFields) throws 
XWikiException
+    {
+        int count = 0;
+
+        try {
+            count =
+                RightsManager.getInstance().countAllGlobalUsersOrGroups(true,
+                    RightsManagerPluginApi.createMatchingTable(matchFields), 
this.context);
+        } catch (RightsManagerException e) {
+            logError("Try to count all users in main wiki", e);
+        }
+
+        return count;
+    }
+
+    /**
+     * @return the number of users in the current wiki.
+     * @throws XWikiException error when getting number of users.
+     */
+    public int countAllLocalUsers() throws XWikiException
+    {
+        return countAllMatchedLocalUsers(null);
+    }
+
+    /**
+     * @param matchFields the fields to match. It is a Map with field name as 
key and for value :
+     *            <ul>
+     *            <li>"matching string" for document fields</li>
+     *            <li>or ["field type", "matching string"] for object 
fields</li>
+     *            </ul>
+     * @return the number of users in the current wiki.
+     * @throws XWikiException error when getting number of users.
+     */
+    public int countAllMatchedLocalUsers(Map matchFields) throws XWikiException
+    {
+        int count = 0;
+
+        try {
+            count =
+                RightsManager.getInstance().countAllLocalUsersOrGroups(true,
+                    RightsManagerPluginApi.createMatchingTable(matchFields), 
this.context);
+        } catch (RightsManagerException e) {
+            logError("Try to count all users in current wiki", e);
+        }
+
+        return count;
+    }
+}

Modified: 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManager.java
===================================================================
--- 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManager.java
    2007-10-28 11:33:03 UTC (rev 5529)
+++ 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManager.java
    2007-10-28 11:33:07 UTC (rev 5530)
@@ -45,7 +45,7 @@
 import com.xpn.xwiki.plugin.rightsmanager.utils.UsersGroups;
 
 /**
- * Hidden toolkit use by the plugin API that make all the plugins actions.
+ * Hidden toolkit use by the plugin API that make all the plugin's actions.
  * 
  * @version $Id: $
  * @since XWiki Core 1.1.2, XWiki Core 1.2M2
@@ -53,7 +53,7 @@
 final class RightsManager implements XWikiDocChangeNotificationInterface
 {
     /**
-     * Name of the defaut space where users and groups are stored.
+     * Name of the default space where users and groups are stored.
      */
     public static final String DEFAULT_USERORGROUP_SPACE = "XWiki";
 
@@ -279,18 +279,26 @@
      * Get the number of users or groups in the main wiki and the current wiki.
      * 
      * @param user indicate if methods search for users or groups.
+     * @param matchFields the field to math with values. It is a table of 
table with :
+     *            <ul>
+     *            <li>fiedname : the name of the field</li>
+     *            <li>fieldtype : for example StringProperty. If null the 
field is considered as
+     *            document field</li>
+     *            <li>pattern matching : based on HQL "like" command</li>
+     *            </ul>
      * @param context the XWiki context.
      * @return the number of groups in the main wiki and the current wiki.
      * @throws XWikiException error when getting number of users or groups.
      */
-    public int countAllUsersOrGroups(boolean user, XWikiContext context) 
throws XWikiException
+    public int countAllUsersOrGroups(boolean user, Object[][] matchFields, 
XWikiContext context)
+        throws XWikiException
     {
         if (isInMainWiki(context)) {
-            return countAllLocalUsersOrGroups(user, context);
+            return countAllLocalUsersOrGroups(user, matchFields, context);
         }
 
-        return countAllGlobalUsersOrGroups(user, context)
-            + countAllLocalUsersOrGroups(user, context);
+        return countAllGlobalUsersOrGroups(user, matchFields, context)
+            + countAllLocalUsersOrGroups(user, matchFields, context);
     }
 
     /**
@@ -298,22 +306,29 @@
      * 
      * @param user indicate if methods search for users or groups.
      * @param wikiName the name of the wiki where to search for users or 
groups.
+     * @param matchFields the field to math with values. It is a table of 
table with :
+     *            <ul>
+     *            <li>fiedname : the name of the field</li>
+     *            <li>fieldtype : for example StringProperty. If null the 
field is considered as
+     *            document field</li>
+     *            <li>pattern matching : based on HQL "like" command</li>
+     *            </ul>
      * @param context the XWiki context.
      * @return the number of groups in the provided wiki.
      * @throws XWikiException error when getting number of users or groups.
      */
-    public int countAllWikiUsersOrGroups(boolean user, String wikiName, 
XWikiContext context)
-        throws XWikiException
+    public int countAllWikiUsersOrGroups(boolean user, String wikiName, 
Object[][] matchFields,
+        XWikiContext context) throws XWikiException
     {
         if (isInMainWiki(context)) {
-            return countAllLocalUsersOrGroups(user, context);
+            return countAllLocalUsersOrGroups(user, matchFields, context);
         }
 
         String database = context.getDatabase();
 
         try {
             context.setDatabase(wikiName);
-            return countAllLocalUsersOrGroups(user, context);
+            return countAllLocalUsersOrGroups(user, matchFields, context);
         } finally {
             context.setDatabase(database);
         }
@@ -323,37 +338,51 @@
      * Get the number of users or groups in the main wiki.
      * 
      * @param user indicate if methods search for users or groups.
+     * @param matchFields the field to math with values. It is a table of 
table with :
+     *            <ul>
+     *            <li>fiedname : the name of the field</li>
+     *            <li>fieldtype : for example StringProperty. If null the 
field is considered as
+     *            document field</li>
+     *            <li>pattern matching : based on HQL "like" command</li>
+     *            </ul>
      * @param context the XWiki context.
      * @return the number of groups in the main wiki.
      * @throws XWikiException error when getting number of users or groups.
      */
-    public int countAllGlobalUsersOrGroups(boolean user, XWikiContext context)
-        throws XWikiException
+    public int countAllGlobalUsersOrGroups(boolean user, Object[][] 
matchFields,
+        XWikiContext context) throws XWikiException
     {
         if (isInMainWiki(context)) {
-            return countAllLocalUsersOrGroups(user, context);
+            return countAllLocalUsersOrGroups(user, matchFields, context);
         }
 
-        return countAllWikiUsersOrGroups(user, context.getMainXWiki(), 
context);
+        return countAllWikiUsersOrGroups(user, context.getMainXWiki(), 
matchFields, context);
     }
 
     /**
      * Get the number of users or groups in the current wiki.
      * 
      * @param user indicate if methods search for users or groups.
+     * @param matchFields the field to math with values. It is a table of 
table with :
+     *            <ul>
+     *            <li>fiedname : the name of the field</li>
+     *            <li>fieldtype : for example StringProperty. If null the 
field is considered as
+     *            document field</li>
+     *            <li>pattern matching : based on HQL "like" command</li>
+     *            </ul>
      * @param context the XWiki context.
      * @return the number of groups in the current wiki.
      * @throws XWikiException error when getting number of users or groups.
      */
-    public int countAllLocalUsersOrGroups(boolean user, XWikiContext context)
-        throws XWikiException
+    public int countAllLocalUsersOrGroups(boolean user, Object[][] matchFields,
+        XWikiContext context) throws XWikiException
     {
         if (user) {
-            return 
context.getWiki().getGroupService(context).countAllMatchedUsers(null, 0, 0,
-                context);
+            return 
context.getWiki().getGroupService(context).countAllMatchedUsers(matchFields,
+                0, 0, context);
         } else {
-            return 
context.getWiki().getGroupService(context).countAllMatchedUsers(null, 0, 0,
-                context);
+            return 
context.getWiki().getGroupService(context).countAllMatchedUsers(matchFields,
+                0, 0, context);
         }
     }
 
@@ -394,7 +423,7 @@
 
         List groupList = new ArrayList();
 
-        int nbGlobalUsersOrGroups = countAllGlobalUsersOrGroups(user, context);
+        int nbGlobalUsersOrGroups = countAllGlobalUsersOrGroups(user, null, 
context);
 
         int newstart = limit.getStart();
 
@@ -1151,13 +1180,14 @@
             groupCache = new Hashtable();
         }
 
-        List memberList;
+        Collection memberList;
 
         if (groupCache.containsKey(groupName)) {
             memberList = (List) groupCache.get(groupName);
         } else {
             memberList =
-                
context.getWiki().getGroupService(context).listMemberForGroup(groupName, 
context);
+                
context.getWiki().getGroupService(context).getAllMembersNamesForGroup(groupName,
+                    0, 0, context);
             groupCache.put(groupName, memberList);
         }
 

Modified: 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManagerPluginApi.java
===================================================================
--- 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManagerPluginApi.java
   2007-10-28 11:33:03 UTC (rev 5529)
+++ 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManagerPluginApi.java
   2007-10-28 11:33:07 UTC (rev 5530)
@@ -70,6 +70,16 @@
     private RightsManageRightsApi rightsApi;
 
     /**
+     * API for managing users.
+     */
+    private RightsManageUsersApi usersApi;
+
+    /**
+     * API for managing groups.
+     */
+    private RightsManageGroupsApi groupsApi;
+
+    /**
      * Create an instance of the Rights Manager plugin user api.
      * 
      * @param plugin the entry point of the Rights Manager plugin.
@@ -79,7 +89,9 @@
     {
         super(plugin, context);
 
-        rightsApi = new RightsManageRightsApi(context);
+        this.rightsApi = new RightsManageRightsApi(context);
+        this.usersApi = new RightsManageUsersApi(context);
+        this.groupsApi = new RightsManageGroupsApi(context);
     }
 
     /**
@@ -87,17 +99,33 @@
      */
     public RightsManageRightsApi getRightsApi()
     {
-        return rightsApi;
+        return this.rightsApi;
     }
 
     /**
+     * @return the API for managing rights and inheritance.
+     */
+    public RightsManageUsersApi getUsersApi()
+    {
+        return this.usersApi;
+    }
+
+    /**
+     * @return the API for managing rights and inheritance.
+     */
+    public RightsManageGroupsApi getGroupsApi()
+    {
+        return this.groupsApi;
+    }
+
+    /**
      * Convert Map/List pattern matching parameter from Velocity to [][] used 
in
      * [EMAIL PROTECTED] RightsManager}.
      * 
      * @param map a map of list from Velocity.
      * @return a table of table for [EMAIL PROTECTED] RightsManager} methods.
      */
-    private static Object[][] createMatchingTable(Map map)
+    static Object[][] createMatchingTable(Map map)
     {
         if (map == null || map.size() == 0) {
             return null;
@@ -131,7 +159,7 @@
      * @param list a list of list from Velocity.
      * @return a table of table for [EMAIL PROTECTED] RightsManager} methods.
      */
-    private static Object[][] createOrderTable(List list)
+    static Object[][] createOrderTable(List list)
     {
         if (list == null || list.size() == 0) {
             return null;
@@ -179,18 +207,11 @@
     /**
      * @return the number of groups in the current wiki.
      * @throws XWikiException error when getting number of groups.
+     * @deprecated Use [EMAIL PROTECTED] #getGroupsApi()}: [EMAIL PROTECTED] 
RightsManageGroupsApi#countAllGroups()}.
      */
     public int countAllGroups() throws XWikiException
     {
-        int count = 0;
-
-        try {
-            count = RightsManager.getInstance().countAllUsersOrGroups(false, 
this.context);
-        } catch (RightsManagerException e) {
-            logError("Try to count all groups", e);
-        }
-
-        return count;
+        return this.groupsApi.countAllGroups();
     }
 
     /**
@@ -199,54 +220,33 @@
      * @param wikiName the name of the wiki where to search for groups.
      * @return the number of groups in the provided wiki.
      * @throws XWikiException error when getting number of groups.
+     * @deprecated Use [EMAIL PROTECTED] #getGroupsApi()}:
+     *             [EMAIL PROTECTED] 
RightsManageGroupsApi#countAllWikiGroups(String wikiName)}.
      */
     public int countAllWikiGroups(String wikiName) throws XWikiException
     {
-        int count = 0;
-
-        try {
-            count =
-                RightsManager.getInstance().countAllWikiUsersOrGroups(false, 
wikiName,
-                    this.context);
-        } catch (RightsManagerException e) {
-            logError("Try to count all groups in wiki " + QUOTE + wikiName + 
QUOTE, e);
-        }
-
-        return count;
+        return this.groupsApi.countAllWikiGroups(wikiName);
     }
 
     /**
      * @return the number of groups in the main wiki.
      * @throws XWikiException error when getting number of groups.
+     * @deprecated Use [EMAIL PROTECTED] #getGroupsApi()}:
+     *             [EMAIL PROTECTED] 
RightsManageGroupsApi#countAllGlobalGroups()}.
      */
     public int countAllGlobalGroups() throws XWikiException
     {
-        int count = 0;
-
-        try {
-            count = 
RightsManager.getInstance().countAllGlobalUsersOrGroups(false, this.context);
-        } catch (RightsManagerException e) {
-            logError("Try to count all groups in main wiki", e);
-        }
-
-        return count;
+        return this.groupsApi.countAllGlobalGroups();
     }
 
     /**
      * @return the number of groups in the current wiki.
      * @throws XWikiException error when getting number of groups.
+     * @deprecated Use [EMAIL PROTECTED] #getGroupsApi()}: [EMAIL PROTECTED] 
RightsManageGroupsApi#countAllLocalGroups()}.
      */
     public int countAllLocalGroups() throws XWikiException
     {
-        int count = 0;
-
-        try {
-            count = 
RightsManager.getInstance().countAllLocalUsersOrGroups(false, this.context);
-        } catch (RightsManagerException e) {
-            logError("Try to count all groups in current wiki", e);
-        }
-
-        return count;
+        return this.groupsApi.countAllLocalGroups();
     }
 
     /**
@@ -1032,18 +1032,11 @@
     /**
      * @return the number of users in the main wiki and the current wiki.
      * @throws XWikiException error when getting number of users.
+     * @deprecated Use [EMAIL PROTECTED] #getUsersApi()}: [EMAIL PROTECTED] 
RightsManageUsersApi#countAllUsers()}.
      */
     public int countAllUsers() throws XWikiException
     {
-        int count = 0;
-
-        try {
-            count = RightsManager.getInstance().countAllUsersOrGroups(true, 
this.context);
-        } catch (RightsManagerException e) {
-            logError("Try to count all users", e);
-        }
-
-        return count;
+        return this.usersApi.countAllUsers();
     }
 
     /**
@@ -1052,54 +1045,32 @@
      * @param wikiName the wiki where to search for users.
      * @return the number of users in the provided wiki.
      * @throws XWikiException error when getting number of users.
+     * @deprecated Use [EMAIL PROTECTED] #getUsersApi()}:
+     *             [EMAIL PROTECTED] 
RightsManageUsersApi#countAllWikiUsers(String wikiName)}.
      */
     public int countAllWikiUsers(String wikiName) throws XWikiException
     {
-        int count = 0;
-
-        try {
-            count =
-                RightsManager.getInstance().countAllWikiUsersOrGroups(true, 
wikiName,
-                    this.context);
-        } catch (RightsManagerException e) {
-            logError("Try to count all wiki users", e);
-        }
-
-        return count;
+        return this.usersApi.countAllWikiUsers(wikiName);
     }
 
     /**
      * @return the number of users in the main wiki.
      * @throws XWikiException error when getting number of users.
+     * @deprecated Use [EMAIL PROTECTED] #getUsersApi()}: [EMAIL PROTECTED] 
RightsManageUsersApi#countAllGlobalUsers()}.
      */
     public int countAllGlobalUsers() throws XWikiException
     {
-        int count = 0;
-
-        try {
-            count = 
RightsManager.getInstance().countAllGlobalUsersOrGroups(true, this.context);
-        } catch (RightsManagerException e) {
-            logError("Try to count all global users", e);
-        }
-
-        return count;
+        return this.usersApi.countAllGlobalUsers();
     }
 
     /**
      * @return the number of users in the current wiki.
      * @throws XWikiException error when getting number of users.
+     * @deprecated Use [EMAIL PROTECTED] #getUsersApi()}: [EMAIL PROTECTED] 
RightsManageUsersApi#countAllLocalUsers()}.
      */
     public int countAllLocalUsers() throws XWikiException
     {
-        int count = 0;
-
-        try {
-            count = 
RightsManager.getInstance().countAllLocalUsersOrGroups(true, this.context);
-        } catch (RightsManagerException e) {
-            logError("Try to count all local users", e);
-        }
-
-        return count;
+        return this.usersApi.countAllLocalUsers();
     }
 
     /**
@@ -1894,7 +1865,8 @@
 
         try {
             userList =
-                RightsManager.getInstance().getAllGroupsNamesForMember(member, 
0, 0, this.context);
+                RightsManager.getInstance()
+                    .getAllGroupsNamesForMember(member, 0, 0, this.context);
         } catch (RightsManagerException e) {
             logError("Try to get all groups containing user " + QUOTE + member 
+ QUOTE
                 + ") users from local wiki", e);

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

Reply via email to