jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1033535 - 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/
Date Wed, 10 Nov 2010 15:46:26 GMT
Author: mduerig
Date: Wed Nov 10 15:46:25 2010
New Revision: 1033535

URL: http://svn.apache.org/viewvc?rev=1033535&view=rev
Log:
JCR-2800: Implement search facility for users and groups
removed implementation details from API
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/UserManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/XPathQueryEvaluator.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=1033535&r1=1033534&r2=1033535&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
Wed Nov 10 15:46:25 2010
@@ -29,47 +29,33 @@ public interface QueryBuilder<T> {
         DESCENDING("descending", RelationOp.LT);
 
         private final String direction;
-        private RelationOp relOp;
+        private final RelationOp collation;
 
-        Direction(String direction, RelationOp relOp) {
+        Direction(String direction, RelationOp collation) {
             this.direction = direction;
-            this.relOp = relOp;
+            this.collation = collation;
         }
 
         public String getDirection() {
             return direction;
         }
 
-        public RelationOp getRelOp() {
-            return relOp;
+        public RelationOp getCollation() {
+            return collation;
         }
     }
 
     /**
      * The selectors for a query. 
      */
-    enum Selector { 
-        AUTHORIZABLE("rep:Authorizable"), 
-        USER("rep:User"), 
-        GROUP("rep:Group");
-
-        private final String ntName;
-
-        Selector(String ntName) {
-            this.ntName = ntName;
-        }
-
-        public String getNtName() {
-            return ntName;   
-        }
-    }
+    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.   
      */
-    enum RelationOp {
+    enum RelationOp { 
         NE("!="),
         EQ("="),
         LT("<"),

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java?rev=1033535&r1=1033534&r2=1033535&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
Wed Nov 10 15:46:25 2010
@@ -469,7 +469,7 @@ public class UserManagerImpl extends Pro
     public Iterator<Authorizable> findAuthorizables(Query query) throws RepositoryException
{
         XPathQueryBuilder builder = new XPathQueryBuilder();
         query.build(builder);
-        return new XPathQueryEvaluator(builder, this, session.getWorkspace().getQueryManager()).eval();
+        return new XPathQueryEvaluator(builder, this, session).eval();
     }
 
     /**

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=1033535&r1=1033534&r2=1033535&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
Wed Nov 10 15:46:25 2010
@@ -19,10 +19,12 @@ package org.apache.jackrabbit.core.secur
 
 import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.Group;
-import org.apache.jackrabbit.core.security.user.XPathQueryBuilder.Condition;
 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.core.NodeImpl;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.security.user.XPathQueryBuilder.Condition;
 import org.apache.jackrabbit.spi.commons.iterator.Iterators;
 import org.apache.jackrabbit.spi.commons.iterator.Predicate;
 import org.apache.jackrabbit.spi.commons.iterator.Predicates;
@@ -30,10 +32,7 @@ import org.apache.jackrabbit.spi.commons
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.Node;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
+import javax.jcr.*;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import java.util.Iterator;
@@ -47,18 +46,18 @@ public class XPathQueryEvaluator impleme
 
     private final XPathQueryBuilder builder;
     private final UserManagerImpl userManager;
-    private final QueryManager queryManager;
+    private final SessionImpl session;
     private final StringBuilder xPath = new StringBuilder();
 
-    public XPathQueryEvaluator(XPathQueryBuilder builder, UserManagerImpl userManager, QueryManager
queryManager) {
+    public XPathQueryEvaluator(XPathQueryBuilder builder, UserManagerImpl userManager, SessionImpl
session) {
         this.builder = builder;
         this.userManager = userManager;
-        this.queryManager = queryManager;
+        this.session = session;
     }
 
     public Iterator<Authorizable> eval() throws RepositoryException {
         xPath.append("//element(*,")
-             .append(builder.getSelector().getNtName())
+             .append(getNtName(builder.getSelector()))
              .append(')');
 
         Value bound = builder.getBound();
@@ -76,7 +75,7 @@ public class XPathQueryEvaluator impleme
                 log.warn("Ignoring bound {} since no sort order is specified");
             }
             else {
-                Condition boundCondition = builder.property(sortCol, sortDir.getRelOp(),
bound);
+                Condition boundCondition = builder.property(sortCol, sortDir.getCollation(),
bound);
                 condition = condition == null 
                         ? boundCondition
                         : builder.and(condition, boundCondition);
@@ -96,6 +95,7 @@ public class XPathQueryEvaluator impleme
                  .append(sortDir.getDirection());
         }
 
+        QueryManager queryManager = session.getWorkspace().getQueryManager();
         Query query = queryManager.createQuery(xPath.toString(), Query.XPATH);
         long maxCount = builder.getMaxCount();
         if (maxCount == 0) {
@@ -121,7 +121,7 @@ public class XPathQueryEvaluator impleme
             xPath.append(condition.getRelPath());
         }
         else {
-            xPath.append(condition.getRelPath())    
+            xPath.append(condition.getRelPath())
                  .append(condition.getOp().getOp())
                  .append(format(condition.getValue()));
         }
@@ -129,7 +129,7 @@ public class XPathQueryEvaluator impleme
 
     public void visit(XPathQueryBuilder.ContainsCondition condition) {
         xPath.append("jcr:contains(")
-             .append(condition.getRelPath())     
+             .append(condition.getRelPath())
              .append(",'")
              .append(condition.getSearchExpr())
              .append("')");
@@ -173,6 +173,22 @@ 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 static String format(Value value) throws RepositoryException {
         switch (value.getType()) {
             case PropertyType.STRING:



Mime
View raw message