jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1422000 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user: UserQueryManager.java query/ResultRowToAuthorizable.java query/XPathQueryEvaluator.java
Date Fri, 14 Dec 2012 17:54:01 GMT
Author: angela
Date: Fri Dec 14 17:54:00 2012
New Revision: 1422000

URL: http://svn.apache.org/viewvc?rev=1422000&view=rev
Log:
OAK-50 : Implement User Management (WIP)
- simplify query code
- remove redundant check for null ntName

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/ResultRowToAuthorizable.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserQueryManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryEvaluator.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserQueryManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserQueryManager.java?rev=1422000&r1=1421999&r2=1422000&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserQueryManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserQueryManager.java
Fri Dec 14 17:54:00 2012
@@ -21,15 +21,14 @@ import java.util.Iterator;
 import javax.annotation.Nonnull;
 import javax.jcr.RepositoryException;
 
-import com.google.common.base.Function;
 import com.google.common.base.Predicates;
 import com.google.common.collect.Iterators;
 import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.Query;
+import org.apache.jackrabbit.oak.api.QueryEngine;
 import org.apache.jackrabbit.oak.api.Result;
-import org.apache.jackrabbit.oak.api.ResultRow;
 import org.apache.jackrabbit.oak.api.Root;
-import org.apache.jackrabbit.oak.api.QueryEngine;
+import org.apache.jackrabbit.oak.security.user.query.ResultRowToAuthorizable;
 import org.apache.jackrabbit.oak.security.user.query.XPathQueryBuilder;
 import org.apache.jackrabbit.oak.security.user.query.XPathQueryEvaluator;
 import org.apache.jackrabbit.oak.spi.security.user.AuthorizableType;
@@ -109,7 +108,8 @@ class UserQueryManager {
         QueryEngine queryEngine = root.getQueryEngine();
         try {
             Result result = queryEngine.executeQuery(statement, javax.jcr.query.Query.XPATH,
Long.MAX_VALUE, 0, null, userManager.getNamePathMapper());
-            return Iterators.filter(Iterators.transform(result.getRows().iterator(), new
ResultRowToAuthorizable()), Predicates.<Object>notNull());
+            Iterator<Authorizable> authorizables = Iterators.transform(result.getRows().iterator(),
new ResultRowToAuthorizable(userManager));
+            return Iterators.filter(authorizables, Predicates.<Object>notNull());
         } catch (ParseException e) {
             throw new RepositoryException(e);
         }
@@ -211,16 +211,4 @@ class UserQueryManager {
             return UserConstants.NT_REP_AUTHORIZABLE;
         }
     }
-
-    private class ResultRowToAuthorizable implements Function<ResultRow, Authorizable>
{
-        @Override
-        public Authorizable apply(ResultRow row) {
-            try {
-                return userManager.getAuthorizable(row.getPath());
-            } catch (RepositoryException e) {
-                log.debug("Failed to access authorizable " + row.getPath());
-                return null;
-            }
-        }
-    }
 }
\ No newline at end of file

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/ResultRowToAuthorizable.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/ResultRowToAuthorizable.java?rev=1422000&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/ResultRowToAuthorizable.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/ResultRowToAuthorizable.java
Fri Dec 14 17:54:00 2012
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.security.user.query;
+
+import javax.jcr.RepositoryException;
+
+import com.google.common.base.Function;
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.jackrabbit.oak.api.ResultRow;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ResultRowToAuthorizable... TODO
+ */
+public class ResultRowToAuthorizable implements Function<ResultRow, Authorizable> {
+
+    private static final Logger log = LoggerFactory.getLogger(ResultRowToAuthorizable.class);
+
+    private final UserManager userManager;
+
+    public ResultRowToAuthorizable(UserManager userManager) {
+        this.userManager = userManager;
+    }
+
+    @Override
+    public Authorizable apply(ResultRow row) {
+        if (row != null) {
+            try {
+                return userManager.getAuthorizableByPath(row.getPath());
+            } catch (RepositoryException e) {
+                log.debug("Failed to access authorizable " + row.getPath());
+            }
+        }
+        return null;
+    }
+}
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryEvaluator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryEvaluator.java?rev=1422000&r1=1421999&r2=1422000&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryEvaluator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryEvaluator.java
Fri Dec 14 17:54:00 2012
@@ -24,7 +24,6 @@ import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.query.Query;
 
-import com.google.common.base.Function;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
 import com.google.common.collect.Iterators;
@@ -46,6 +45,7 @@ import org.slf4j.LoggerFactory;
  * and some minimal client side filtering.
  */
 public class XPathQueryEvaluator implements ConditionVisitor {
+
     static final Logger log = LoggerFactory.getLogger(XPathQueryEvaluator.class);
 
     private final XPathQueryBuilder builder;
@@ -253,10 +253,6 @@ public class XPathQueryEvaluator impleme
         } else {
             ntName = namePathMapper.getJcrName(UserConstants.NT_REP_AUTHORIZABLE);
         }
-        if (ntName == null) {
-            log.warn("Failed to retrieve JCR name for authorizable node type.");
-            ntName = UserConstants.NT_REP_AUTHORIZABLE;
-        }
         return ntName;
     }
 
@@ -295,20 +291,8 @@ public class XPathQueryEvaluator impleme
     @Nonnull
     private Iterator<Authorizable> findAuthorizables(long limit, long offset) throws
ParseException {
         Iterable<? extends ResultRow> resultRows = root.getQueryEngine().executeQuery(xPath.toString(),
Query.XPATH, limit, offset, null, namePathMapper).getRows();
-
-        Function<ResultRow, Authorizable> transformer = new Function<ResultRow,
Authorizable>() {
-            public Authorizable apply(ResultRow resultRow) {
-                try {
-                    return userManager.getAuthorizableByPath(resultRow.getPath());
-                } catch (RepositoryException e) {
-                    log.warn("Cannot create authorizable from result row {}", resultRow);
-                    log.debug(e.getMessage(), e);
-                    return null;
-                }
-            }
-        };
-
-        return Iterators.filter(Iterators.transform(resultRows.iterator(), transformer),
Predicates.<Object>notNull());
+        Iterator<Authorizable> authorizbles = Iterators.transform(resultRows.iterator(),
new ResultRowToAuthorizable(userManager));
+        return Iterators.filter(authorizbles, Predicates.<Object>notNull());
     }
 
     @Nonnull



Mime
View raw message