Author: sseifert
Date: Fri Dec  2 06:46:10 2016
New Revision: 1772306

URL: http://svn.apache.org/viewvc?rev=1772306&view=rev
Log:
SLING-6347 filter out internal properties in configuration collection data

Added:
    
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/PropertiesFilter.java
   (with props)
Modified:
    
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationCollectionDataImpl.java
    
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationDataImpl.java
    
sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationCollectionDataImplTest.java

Modified: 
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationCollectionDataImpl.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationCollectionDataImpl.java?rev=1772306&r1=1772305&r2=1772306&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationCollectionDataImpl.java
 (original)
+++ 
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationCollectionDataImpl.java
 Fri Dec  2 06:46:10 2016
@@ -19,6 +19,7 @@
 package org.apache.sling.caconfig.management.impl;
 
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.sling.caconfig.management.ConfigurationCollectionData;
@@ -30,6 +31,7 @@ final class ConfigurationCollectionDataI
     private final Collection<ConfigurationData> items;
     private final String resourcePath;
     private final Map<String,Object> properties;
+    private Map<String,Object> filteredPropertiesCache;
     
     public ConfigurationCollectionDataImpl(String configName, 
Collection<ConfigurationData> items,
             String resourcePath, Map<String, Object> properties) {
@@ -56,7 +58,11 @@ final class ConfigurationCollectionDataI
 
     @Override
     public Map<String, Object> getProperties() {
-        return properties;
+        if (filteredPropertiesCache == null) {
+            filteredPropertiesCache = new HashMap<>(properties);
+            PropertiesFilter.removeIgnoredProperties(filteredPropertiesCache);
+        }
+        return filteredPropertiesCache;
     }
 
 }

Modified: 
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationDataImpl.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationDataImpl.java?rev=1772306&r1=1772305&r2=1772306&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationDataImpl.java
 (original)
+++ 
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationDataImpl.java
 Fri Dec  2 06:46:10 2016
@@ -18,7 +18,6 @@
  */
 package org.apache.sling.caconfig.management.impl;
 
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -59,9 +58,6 @@ final class ConfigurationDataImpl implem
     private ValueMap valuesCache;
     private ValueMap effectiveValuesCache;
     
-    private static final Set<String> PROPERTIES_TO_IGNORE = new 
HashSet<>(Arrays.asList(
-            "jcr:primaryType"));
-    
     @SuppressWarnings("unchecked")
     public ConfigurationDataImpl(ConfigurationMetadata configMetadata,
             Resource resolvedConfigurationResource, Resource 
writebackConfigurationResource,
@@ -127,7 +123,7 @@ final class ConfigurationDataImpl implem
             if (resolvedConfigurationResource != null) {
                 
propertyNamesCache.addAll(ResourceUtil.getValueMap(resolvedConfigurationResource).keySet());
             }
-            removeIgnoredProperties(propertyNamesCache);
+            PropertiesFilter.removeIgnoredProperties(propertyNamesCache);
         }
         return propertyNamesCache;
     }
@@ -139,7 +135,7 @@ final class ConfigurationDataImpl implem
             if (writebackConfigurationResource != null) {
                 props.putAll( 
ResourceUtil.getValueMap(writebackConfigurationResource));
             }
-            removeIgnoredProperties(props);
+            PropertiesFilter.removeIgnoredProperties(props);
             resolveNestedConfigs(props);
             valuesCache = new ValueMapDecorator(props);
         }
@@ -160,23 +156,13 @@ final class ConfigurationDataImpl implem
             if (resolvedConfigurationResource != null) {
                 
props.putAll(ResourceUtil.getValueMap(resolvedConfigurationResource));
             }
-            removeIgnoredProperties(props);
+            PropertiesFilter.removeIgnoredProperties(props);
             resolveNestedConfigs(props);
             effectiveValuesCache = new ValueMapDecorator(props);
         }
         return effectiveValuesCache;
     }
-    
-    private void removeIgnoredProperties(Set<String> propertyNames) {
-        propertyNames.removeAll(PROPERTIES_TO_IGNORE);
-    }
-
-    private void removeIgnoredProperties(Map<String,Object> props) {
-        for (String propertyName : PROPERTIES_TO_IGNORE) {
-            props.remove(propertyName);
-        }
-    }
-    
+        
     private void resolveNestedConfigs(Map<String,Object> props) {
         if (configMetadata == null) {
             return;

Added: 
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/PropertiesFilter.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/PropertiesFilter.java?rev=1772306&view=auto
==============================================================================
--- 
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/PropertiesFilter.java
 (added)
+++ 
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/PropertiesFilter.java
 Fri Dec  2 06:46:10 2016
@@ -0,0 +1,48 @@
+/*
+ * 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.sling.caconfig.management.impl;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Filter internal properties from ConfigManager API output.
+ */
+final class PropertiesFilter {
+
+    private static final Set<String> PROPERTIES_TO_IGNORE = new 
HashSet<>(Arrays.asList(
+            "jcr:primaryType"));
+    
+    private PropertiesFilter() {
+        // static methods only
+    }
+
+    public static void removeIgnoredProperties(Set<String> propertyNames) {
+        propertyNames.removeAll(PROPERTIES_TO_IGNORE);
+    }
+
+    public static void removeIgnoredProperties(Map<String,Object> props) {
+        for (String propertyName : PROPERTIES_TO_IGNORE) {
+            props.remove(propertyName);
+        }
+    }
+    
+}

Propchange: 
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/PropertiesFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/PropertiesFilter.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Fri Dec  2 06:46:10 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: 
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/PropertiesFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationCollectionDataImplTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationCollectionDataImplTest.java?rev=1772306&r1=1772305&r2=1772306&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationCollectionDataImplTest.java
 (original)
+++ 
sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationCollectionDataImplTest.java
 Fri Dec  2 06:46:10 2016
@@ -31,22 +31,23 @@ import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 
+import com.google.common.collect.ImmutableMap;
+
 @RunWith(MockitoJUnitRunner.class)
 public class ConfigurationCollectionDataImplTest {
     
     @Mock
     private Collection<ConfigurationData> items;
-    @Mock
-    private Map<String, Object> props;
 
     @Test
     public void testProperties() {
+        Map<String,Object> props = 
ImmutableMap.<String,Object>of("jcr:primaryType", "test", "prop1", "value1"); 
         ConfigurationCollectionData underTest = new 
ConfigurationCollectionDataImpl("name1", items, "/path1", props);
         
         assertEquals("name1", underTest.getConfigName());;
         assertSame(items, underTest.getItems());
         assertEquals("/path1", underTest.getResourcePath());
-        assertSame(props, underTest.getProperties());
+        assertEquals(ImmutableMap.<String,Object>of("prop1", "value1"), 
underTest.getProperties());
     }
 
 }


Reply via email to