Author: cziegeler
Date: Fri Oct 14 14:32:43 2016
New Revision: 1764915

URL: http://svn.apache.org/viewvc?rev=1764915&view=rev
Log:
SLING-6153 : Improve MapEntries implementation

Modified:
    
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
    
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java

Modified: 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java?rev=1764915&r1=1764914&r2=1764915&view=diff
==============================================================================
--- 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
 (original)
+++ 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
 Fri Oct 14 14:32:43 2016
@@ -188,7 +188,7 @@ public class MapEntries implements
             final Map<String, List<MapEntry>> newResolveMapsMap = new 
ConcurrentHashMap<String, List<MapEntry>>();
 
             //optimization made in SLING-2521
-            if (this.factory.isOptimizeAliasResolutionEnabled()){
+            if (this.factory.isOptimizeAliasResolutionEnabled()) {
                 final Map<String, Map<String, String>> aliasMap = 
this.loadAliases(resolver);
                 this.aliasMap = aliasMap;
             }
@@ -272,7 +272,7 @@ public class MapEntries implements
                 if (props.containsKey(PROP_VANITY_PATH)) {
                     changed |= doAddVanity(resource, props);
                 }
-                if (props.containsKey(ResourceResolverImpl.PROP_ALIAS)) {
+                if (this.factory.isOptimizeAliasResolutionEnabled() && 
props.containsKey(ResourceResolverImpl.PROP_ALIAS)) {
                     changed |= doAddAlias(resource);
                 }
                 return changed;
@@ -348,26 +348,22 @@ public class MapEntries implements
             return false;
         }
 
-        if (this.factory.isOptimizeAliasResolutionEnabled()) {
-            this.initializing.lock();
-            try {
-                final Map<String, String> aliasMapEntry = 
aliasMap.remove(contentPath);
-                if (aliasMapEntry != null && addParentPath != null ) {
-                    this.refreshResolverIfNecessary(resolverRefreshed);
-                    // we need to re-add
-                    // from a potential parent
-                    final Resource parent = 
this.resolver.getResource(addParentPath);
-                    if ( parent != null && 
parent.getValueMap().containsKey(ResourceResolverImpl.PROP_ALIAS)) {
-                        doAddAlias(parent);
-                    }
+        this.initializing.lock();
+        try {
+            final Map<String, String> aliasMapEntry = 
aliasMap.remove(contentPath);
+            if (aliasMapEntry != null && addParentPath != null ) {
+                this.refreshResolverIfNecessary(resolverRefreshed);
+                // we need to re-add
+                // from a potential parent
+                final Resource parent = 
this.resolver.getResource(addParentPath);
+                if ( parent != null && 
parent.getValueMap().containsKey(ResourceResolverImpl.PROP_ALIAS)) {
+                    doAddAlias(parent);
                 }
-                return aliasMapEntry != null;
-            } finally {
-                this.initializing.unlock();
             }
+            return aliasMapEntry != null;
+        } finally {
+            this.initializing.unlock();
         }
-
-        return false;
     }
 
     private boolean removeVanityPath(final String path) {
@@ -690,11 +686,13 @@ public class MapEntries implements
                             changed |= removeVanityPath(target);
                         }
                     }
-                    for (final String contentPath : this.aliasMap.keySet()) {
-                        if (path.startsWith(contentPath + "/") || 
path.equals(contentPath)) {
-                            changed |= removeAlias(contentPath, null, 
resolverRefreshed);
-                        } else if ( 
contentPath.startsWith(actualContentPathPrefix) ) {
-                            changed |= removeAlias(contentPath, path, 
resolverRefreshed);
+                    if (this.factory.isOptimizeAliasResolutionEnabled()) {
+                        for (final String contentPath : 
this.aliasMap.keySet()) {
+                            if (path.startsWith(contentPath + "/") || 
path.equals(contentPath)) {
+                                changed |= removeAlias(contentPath, null, 
resolverRefreshed);
+                            } else if ( 
contentPath.startsWith(actualContentPathPrefix) ) {
+                                changed |= removeAlias(contentPath, path, 
resolverRefreshed);
+                            }
                         }
                     }
                 }

Modified: 
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java?rev=1764915&r1=1764914&r2=1764915&view=diff
==============================================================================
--- 
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
 (original)
+++ 
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
 Fri Oct 14 14:32:43 2016
@@ -745,6 +745,7 @@ public class MapEntriesTest {
         assertEquals("/justVanityPath.html", iterator.next().getRedirect()[0]);
         assertFalse(iterator.hasNext());
     }
+*/
 
     //SLING-3727
     @Test
@@ -796,7 +797,6 @@ public class MapEntriesTest {
         Map<String, String> aliasMap = mapEntries.getAliasMap("/parent");
         assertNull(aliasMap);
     }
-*/
 
     //SLING-3727
     @Test
@@ -805,7 +805,6 @@ public class MapEntriesTest {
         removeAlias.setAccessible(true);
 
         
when(resourceResolverFactory.isOptimizeAliasResolutionEnabled()).thenReturn(false);
-        
when(this.resourceResolverFactory.getMapRoot()).thenReturn(MapEntries.DEFAULT_MAP_ROOT);
         mapEntries = new MapEntries(resourceResolverFactory, bundleContext, 
eventAdmin);
 
         Resource parent = mock(Resource.class);


Reply via email to