jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1033947 - in /jackrabbit/trunk: jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/ jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/...
Date Thu, 11 Nov 2010 14:17:39 GMT
Author: mduerig
Date: Thu Nov 11 14:17:39 2010
New Revision: 1033947

URL: http://svn.apache.org/viewvc?rev=1033947&view=rev
Log:
JCR-2800: Implement search facility for users and groups
enhanced selector mechanism
work in progress

Modified:
    jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/QueryBuilder.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryBuilder.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerSearchTest.java

Modified: jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/QueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/QueryBuilder.java?rev=1033947&r1=1033946&r2=1033947&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/QueryBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/QueryBuilder.java
Thu Nov 11 14:17:39 2010
@@ -46,11 +46,6 @@ public interface QueryBuilder<T> {
     }
 
     /**
-     * The selectors for a query. 
-     */
-    enum Selector { AUTHORIZABLE, USER, GROUP }
-
-    /**
      * Relational operators for comparing a property to a value. Correspond
      * to the general comparison operators as define in JSR-170.
      * The {@link #EX} tests for existence of a property.   
@@ -76,11 +71,12 @@ public interface QueryBuilder<T> {
     }
 
     /**
-     * Set the selector for the query.
+     * Set the selector for the query. The selector determines whether the query
+     * returns all {@link Authorizable}s or just {@link User}s respectively {@link Group}s.

      *
-     * @param selector  One of {@link Selector#AUTHORIZABLE}, {@link Selector#USER} or {@link
Selector#GROUP} 
+     * @param selector  The selector for the query
      */
-    void setSelector(Selector selector);
+    void setSelector(Class<? extends Authorizable> selector);
 
     /**
      * Set the scope for the query. If set, the query will only return members of a specific
group.

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryBuilder.java?rev=1033947&r1=1033946&r2=1033947&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryBuilder.java
Thu Nov 11 14:17:39 2010
@@ -17,6 +17,7 @@
 
 package org.apache.jackrabbit.core.security.user;
 
+import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.QueryBuilder;
 
 import javax.jcr.RepositoryException;
@@ -40,7 +41,7 @@ public class XPathQueryBuilder implement
         void visit(OrCondition condition) throws RepositoryException;
     }
 
-    private Selector selector = Selector.AUTHORIZABLE;
+    private Class<? extends Authorizable> selector = Authorizable.class;
     private String groupName;
     private boolean declaredMembersOnly;
     private Condition condition;
@@ -50,7 +51,7 @@ public class XPathQueryBuilder implement
     private long offset;
     private long maxCount = -1;
 
-    Selector getSelector() {
+    Class<? extends Authorizable> getSelector() {
         return selector;
     }
 
@@ -88,7 +89,7 @@ public class XPathQueryBuilder implement
     
     //------------------------------------------< QueryBuilder >---
 
-    public void setSelector(Selector selector) {
+    public void setSelector(Class<? extends Authorizable> selector) {
         this.selector = selector;
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java?rev=1033947&r1=1033946&r2=1033947&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.java
Thu Nov 11 14:17:39 2010
@@ -21,7 +21,7 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.api.security.user.Group;
 import org.apache.jackrabbit.api.security.user.QueryBuilder.Direction;
 import org.apache.jackrabbit.api.security.user.QueryBuilder.RelationOp;
-import org.apache.jackrabbit.api.security.user.QueryBuilder.Selector;
+import org.apache.jackrabbit.api.security.user.User;
 import org.apache.jackrabbit.core.NodeImpl;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.security.user.XPathQueryBuilder.Condition;
@@ -32,7 +32,10 @@ import org.apache.jackrabbit.spi.commons
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.*;
+import javax.jcr.Node;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import java.util.Iterator;
@@ -173,19 +176,15 @@ public class XPathQueryEvaluator impleme
 
     //------------------------------------------< private >---
 
-    private String getNtName(Selector selector) throws RepositoryException {
-        switch (selector) {
-            case AUTHORIZABLE:
-                return session.getJCRName(UserConstants.NT_REP_AUTHORIZABLE);
-
-            case USER:
-                return session.getJCRName(UserConstants.NT_REP_USER);
-
-            case GROUP:
-                return session.getJCRName(UserConstants.NT_REP_GROUP);
-
-            default:
-                throw new RepositoryException("Invalid selector: " + selector);
+    private String getNtName(Class<? extends Authorizable> selector) throws RepositoryException
{
+        if (User.class.isAssignableFrom(selector)) {
+            return session.getJCRName(UserConstants.NT_REP_USER);
+        }
+        else if (Group.class.isAssignableFrom(selector)) {
+            return session.getJCRName(UserConstants.NT_REP_GROUP);
+        }
+        else {
+            return session.getJCRName(UserConstants.NT_REP_AUTHORIZABLE);
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerSearchTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerSearchTest.java?rev=1033947&r1=1033946&r2=1033947&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerSearchTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/UserManagerSearchTest.java
Thu Nov 11 14:17:39 2010
@@ -19,7 +19,6 @@ package org.apache.jackrabbit.api.securi
 
 import org.apache.jackrabbit.api.security.user.QueryBuilder.Direction;
 import org.apache.jackrabbit.api.security.user.QueryBuilder.RelationOp;
-import org.apache.jackrabbit.api.security.user.QueryBuilder.Selector;
 import org.apache.jackrabbit.spi.commons.iterator.Iterators;
 import org.apache.jackrabbit.spi.commons.iterator.Predicate;
 
@@ -185,30 +184,27 @@ public class UserManagerSearchTest exten
     }
 
     public void testSelector() throws RepositoryException {
-        for (final Selector s : Selector.values()) {
+        List<Class<? extends Authorizable>> selectors = new ArrayList<Class<?
extends Authorizable>>();
+        selectors.add(Authorizable.class);
+        selectors.add(Group.class);
+        selectors.add(User.class);
+
+        for (final Class<? extends Authorizable> s : selectors) {
             Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {
                 public <T> void build(QueryBuilder<T> builder) {
                     builder.setSelector(s);
                 }
             });
 
-            switch (s) {
-                case AUTHORIZABLE:
-                    assertContainsAll(result, authorizables.iterator());
-                    break;
-
-                case USER:
-                    assertContainsAll(result, users.iterator());
-                    break;
-
-                case GROUP:
-                    assertContainsAll(result, groups.iterator());
-                    break;
-
-                default:
-                    fail("Fall through in switch");
+            if (User.class.isAssignableFrom(s)) {
+                assertContainsAll(result, users.iterator());
+            }
+            else if (Group.class.isAssignableFrom(s)) {
+                assertContainsAll(result, groups.iterator());
+            }
+            else {
+                assertContainsAll(result, authorizables.iterator());
             }
-
         }
     }
 
@@ -254,7 +250,7 @@ public class UserManagerSearchTest exten
             Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {
                 public <T> void build(QueryBuilder<T> builder) {
                     try {
-                        builder.setSelector(Selector.USER);
+                        builder.setSelector(User.class);
                         builder.setScope(g.getID(), false);
                     } catch (RepositoryException e) {
                         fail(e.getMessage());
@@ -278,7 +274,7 @@ public class UserManagerSearchTest exten
             Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {
                 public <T> void build(QueryBuilder<T> builder) {
                     try {
-                        builder.setSelector(Selector.GROUP);
+                        builder.setSelector(Group.class);
                         builder.setScope(g.getID(), true);
                     } catch (RepositoryException e) {
                         fail(e.getMessage());



Mime
View raw message