akankshajain18 commented on a change in pull request #24:
URL: 
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/24#discussion_r553896390



##########
File path: 
src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
##########
@@ -1038,22 +1016,69 @@ private boolean addEntry(final Map<String, 
List<MapEntry>> entryMap, final Strin
      */
     private Map<String, Map<String, String>> loadAliases(final 
ResourceResolver resolver) {
         final Map<String, Map<String, String>> map = new ConcurrentHashMap<>();
-        final String queryString = ALIAS_QUERY_DEFAULT;
-                       final Iterator<Resource> i = 
resolver.findResources(queryString, "sql");
-                       while (i.hasNext()) {
+        final String queryString = updateAliasQuery();
+        final Iterator<Resource> i = resolver.findResources(queryString, 
"sql");
+                    while (i.hasNext()) {
                            final Resource resource = i.next();
                            loadAlias(resource, map);
                        }
         return map;
     }
 
-       /**
+
+    /*
+    * Update alias query based on configured alias locations
+    */
+    private String updateAliasQuery(){
+        final Set<String> allowedLocations = 
this.factory.getAllowedAliasLocations();
+
+        StringBuilder baseQuery = new StringBuilder(ALIAS_BASE_QUERY_DEFAULT);
+        baseQuery.append(" ").append("WHERE");
+
+        if(allowedLocations.isEmpty()){
+            baseQuery.append(" ").append("(").append("NOT 
ISDESCENDANTNODE(page,")
+                    
.append("\"").append(JCR_SYSTEM_PREFIX).append("\"").append("))");
+
+        }else{
+            Iterator<String> pathIterator = allowedLocations.iterator();
+            baseQuery.append("(");
+            while(pathIterator.hasNext()){
+                String prefix = pathIterator.next();
+                baseQuery.append(" ").append("ISDESCENDANTNODE(page,")
+                        .append("\"").append(prefix).append("\"")
+                        .append(")").append(" ").append("OR");
+            }
+            //Remove last "OR" keyword
+            int orLastIndex = baseQuery.lastIndexOf("OR");
+            baseQuery.delete(orLastIndex,baseQuery.length());
+            baseQuery.append(")");
+        }
+
+        baseQuery.append(" AND sling:alias IS NOT NULL ");
+        String aliasQuery = baseQuery.toString();
+        logger.debug("Query to fetch alias [{}] ", aliasQuery);
+
+        return aliasQuery;
+    }
+
+    /**
+     *
+     *  validate alias path based on configuration provided
+     */
+    protected boolean isValidAliasPath(final String path){

Review comment:
       I removed that method and put the if condition inside loadalias method 
itself.Please check my updated PR




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to