jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1041765 - in /jackrabbit/branches/2.2: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerSearchTest.java
Date Fri, 03 Dec 2010 10:31:56 GMT
Author: mduerig
Date: Fri Dec  3 10:31:56 2010
New Revision: 1041765

URL: http://svn.apache.org/viewvc?rev=1041765&view=rev
Log:
2.2: Merged revision 1041761 (JCR-2829)

Modified:
    jackrabbit/branches/2.2/   (props changed)
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java
    jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerSearchTest.java

Propchange: jackrabbit/branches/2.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Dec  3 10:31:56 2010
@@ -1 +1 @@
-/jackrabbit/trunk:1040661,1040958
+/jackrabbit/trunk:1040661,1040958,1041761

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java?rev=1041765&r1=1041764&r2=1041765&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java
Fri Dec  3 10:31:56 2010
@@ -110,11 +110,21 @@ public class XPathQueryEvaluator impleme
             query.setLimit(maxCount);
         }
 
-        if (offset > 0) {
-            query.setOffset(offset);
+        // If we are scoped to a group and have an offset, we need to skip to that offset
+        // here (inefficient!) otherwise we can apply the offset in the query
+        if (builder.getGroupName() == null) {
+            if (offset > 0) {
+                query.setOffset(offset);
+            }
+            return toAuthorizables(execute(query));
+        }
+        else {
+            Iterator<Authorizable> result = filter(toAuthorizables(execute(query)),
builder.getGroupName(), builder.isDeclaredMembersOnly());
+            for (int c = 0; c < offset && result.hasNext(); c++) {
+                result.next();
+            }
+            return result;
         }
-
-        return filter(toAuthorizables(execute(query)), builder.getGroupName(), builder.isDeclaredMembersOnly());
     }
 
     //------------------------------------------< ConditionVisitor >---
@@ -300,43 +310,38 @@ public class XPathQueryEvaluator impleme
                                           boolean declaredMembersOnly) throws RepositoryException
{
 
         Predicate<Authorizable> predicate;
-        if (groupName == null) {
-            predicate = Predicates.TRUE();
+        Authorizable groupAuth = userManager.getAuthorizable(groupName);
+        if (groupAuth == null || !groupAuth.isGroup()) {
+            predicate = Predicates.FALSE();
         }
         else {
-            Authorizable groupAuth = userManager.getAuthorizable(groupName);
-            if (groupAuth == null || !groupAuth.isGroup()) {
-                predicate = Predicates.FALSE();
-            }
-            else {
-                final Group group = (Group) groupAuth;
-                if (declaredMembersOnly) {
-                    predicate = new Predicate<Authorizable>() {
-                        public boolean evaluate(Authorizable authorizable) {
-                            try {
-                                return authorizable != null && group.isDeclaredMember(authorizable);
-                            } catch (RepositoryException e) {
-                                log.warn("Cannot determine whether {} is member of group
{}", authorizable, group);
-                                log.debug(e.getMessage(), e);
-                                return false;
-                            }
+            final Group group = (Group) groupAuth;
+            if (declaredMembersOnly) {
+                predicate = new Predicate<Authorizable>() {
+                    public boolean evaluate(Authorizable authorizable) {
+                        try {
+                            return authorizable != null && group.isDeclaredMember(authorizable);
+                        } catch (RepositoryException e) {
+                            log.warn("Cannot determine whether {} is member of group {}",
authorizable, group);
+                            log.debug(e.getMessage(), e);
+                            return false;
                         }
-                    };
+                    }
+                };
 
-                }
-                else {
-                    predicate = new Predicate<Authorizable>() {
-                        public boolean evaluate(Authorizable authorizable) {
-                            try {
-                                return authorizable != null && group.isMember(authorizable);
-                            } catch (RepositoryException e) {
-                                log.warn("Cannot determine whether {} is member of group
{}", authorizable, group);
-                                log.debug(e.getMessage(), e);
-                                return false;
-                            }
+            }
+            else {
+                predicate = new Predicate<Authorizable>() {
+                    public boolean evaluate(Authorizable authorizable) {
+                        try {
+                            return authorizable != null && group.isMember(authorizable);
+                        } catch (RepositoryException e) {
+                            log.warn("Cannot determine whether {} is member of group {}",
authorizable, group);
+                            log.debug(e.getMessage(), e);
+                            return false;
                         }
-                    };
-                }
+                    }
+                };
             }
         }
 

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerSearchTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerSearchTest.java?rev=1041765&r1=1041764&r2=1041765&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerSearchTest.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerSearchTest.java
Fri Dec  3 10:31:56 2010
@@ -702,6 +702,30 @@ public class UserManagerSearchTest exten
         }
     }
 
+    public void testScopeWithOffset() throws RepositoryException {
+        final int offset = 5;
+        final int count = 10000;
+
+        Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {
+            public <T> void build(QueryBuilder<T> builder) {
+                builder.setScope("vertebrates", false);
+                builder.setSortOrder("profile/@weight", Direction.ASCENDING);
+                builder.setLimit(offset, count);
+            }
+        });
+
+        Iterator<Authorizable> expected = userMgr.findAuthorizables(new Query() {
+            public <T> void build(QueryBuilder<T> builder) {
+                builder.setScope("vertebrates", false);
+                builder.setSortOrder("profile/@weight", Direction.ASCENDING);
+            }
+        });
+
+        skip(expected, offset);
+        assertSame(expected, result, count);
+        assertFalse(result.hasNext());
+    }
+
     //------------------------------------------< private >---
 
     private static void addMembers(Group group, Authorizable... authorizables) throws RepositoryException
{



Mime
View raw message