sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sseif...@apache.org
Subject [sling-org-apache-sling-caconfig-impl] branch master updated: SLING-7230 CAConfig Impl: Allow to configure alterantive lookup resource names for configuration collection properties
Date Mon, 06 Nov 2017 17:11:49 GMT
This is an automated email from the ASF dual-hosted git repository.

sseifert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-caconfig-impl.git


The following commit(s) were added to refs/heads/master by this push:
     new 3e2166c  SLING-7230 CAConfig Impl: Allow to configure alterantive lookup resource
names for configuration collection properties
3e2166c is described below

commit 3e2166c03caa92eaacfc16daa099670b5b10030b
Author: sseifert <sseifert@pro-vision.de>
AuthorDate: Mon Nov 6 18:11:42 2017 +0100

    SLING-7230 CAConfig Impl: Allow to configure alterantive lookup resource names for configuration
collection properties
---
 .../management/ConfigurationManagementSettings.java |  6 ++++++
 .../impl/ConfigurationManagementSettingsImpl.java   | 21 +++++++++++++++++++++
 .../management/impl/ConfigurationManagerImpl.java   |  8 +++++++-
 .../sling/caconfig/management/package-info.java     |  2 +-
 .../ConfigurationManagementSettingsImplTest.java    | 14 +++++++-------
 ...figurationManagerImplCustomPersistence2Test.java | 14 ++++++++++++++
 .../impl/ConfigurationManagerImplTest.java          | 14 ++++++++++++--
 .../CustomConfigurationPersistenceStrategy2.java    |  3 ++-
 8 files changed, 70 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/apache/sling/caconfig/management/ConfigurationManagementSettings.java
b/src/main/java/org/apache/sling/caconfig/management/ConfigurationManagementSettings.java
index 7a0fc82..0b865cf 100644
--- a/src/main/java/org/apache/sling/caconfig/management/ConfigurationManagementSettings.java
+++ b/src/main/java/org/apache/sling/caconfig/management/ConfigurationManagementSettings.java
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.caconfig.management;
 
+import java.util.Collection;
 import java.util.Set;
 
 import org.osgi.annotation.versioning.ProviderType;
@@ -34,5 +35,10 @@ public interface ConfigurationManagementSettings {
      * @return Property names that should be ignored/filtered out from the given set of property
names.
      */
     Set<String> getIgnoredPropertyNames(Set<String> propertyNames);
+
+    /**
+     * @return Config collection parent properties resource names.
+     */
+    Collection<String> getConfigCollectionPropertiesResourceNames();
     
 }
diff --git a/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationManagementSettingsImpl.java
b/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationManagementSettingsImpl.java
index 11807df..94a99e0 100644
--- a/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationManagementSettingsImpl.java
+++ b/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationManagementSettingsImpl.java
@@ -19,6 +19,9 @@
 package org.apache.sling.caconfig.management.impl;
 
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -48,11 +51,17 @@ public class ConfigurationManagementSettingsImpl implements ConfigurationManagem
             "^jcr:.+$"
         };
 
+        @AttributeDefinition(name="Config collection parent properties resource names",
+                description = "Names of resource to try to look up configuration collection
properties in. If list is empty only the collection parent resource is checked." +
+                              " If the list is not empty than only those listed resources
are used for look up. If you want to include the collection parent resource you can use a
dot for the value.")
+        String[] configCollectionPropertiesResourceNames();
+        
     }
     
     private static final Logger log = LoggerFactory.getLogger(ConfigurationManagementSettingsImpl.class);
     
     private Pattern[] ignorePropertyNameRegex;
+    private Collection<String> configCollectionPropertiesResourceNames;
     
     
     @Activate
@@ -66,7 +75,14 @@ public class ConfigurationManagementSettingsImpl implements ConfigurationManagem
                log.warn("Ignoring invalid regex pattern: " + patternString, ex);
            }
         }
+        
         this.ignorePropertyNameRegex = patterns.toArray(new Pattern[patterns.size()]);
+
+        String[] configCollectionPropertiesResourceNames = config.configCollectionPropertiesResourceNames();
+        if (configCollectionPropertiesResourceNames == null || configCollectionPropertiesResourceNames.length
== 0) {
+            configCollectionPropertiesResourceNames = new String[] { "." };
+        }
+        this.configCollectionPropertiesResourceNames = Collections.unmodifiableList(Arrays.asList(configCollectionPropertiesResourceNames));
     }
     
     @Override
@@ -83,4 +99,9 @@ public class ConfigurationManagementSettingsImpl implements ConfigurationManagem
         return ignoredPropertyNames;
     }
 
+    @Override
+    public Collection<String> getConfigCollectionPropertiesResourceNames() {
+        return configCollectionPropertiesResourceNames;
+    }
+    
 }
diff --git a/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationManagerImpl.java
b/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationManagerImpl.java
index 0fc6d9e..615d195 100644
--- a/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationManagerImpl.java
+++ b/src/main/java/org/apache/sling/caconfig/management/impl/ConfigurationManagerImpl.java
@@ -216,7 +216,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager
{
         if (writebackConfigResourceCollectionParentPath != null) {
             Resource writebackConfigResourceCollectionParent = resource.getResourceResolver().getResource(writebackConfigResourceCollectionParentPath);
             if (writebackConfigResourceCollectionParent != null) {
-                resourceCollectionParentProps = writebackConfigResourceCollectionParent.getValueMap();
+                for (String resourceName : configurationManagementSettings.getConfigCollectionPropertiesResourceNames())
{
+                    Resource propsResource = writebackConfigResourceCollectionParent.getChild(resourceName);
+                    if (propsResource != null) {
+                        resourceCollectionParentProps = propsResource.getValueMap();
+                        break;
+                    }
+                }
             }
         }
         
diff --git a/src/main/java/org/apache/sling/caconfig/management/package-info.java b/src/main/java/org/apache/sling/caconfig/management/package-info.java
index 432ec29..adde79c 100644
--- a/src/main/java/org/apache/sling/caconfig/management/package-info.java
+++ b/src/main/java/org/apache/sling/caconfig/management/package-info.java
@@ -21,5 +21,5 @@
  * This API is only indented for advanced use cases like writing a configuration editor,
  * not for "normal" applications just reading configuration.
  */
-@org.osgi.annotation.versioning.Version("2.2.0")
+@org.osgi.annotation.versioning.Version("2.3.0")
 package org.apache.sling.caconfig.management;
diff --git a/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationManagementSettingsImplTest.java
b/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationManagementSettingsImplTest.java
index 2cd5e06..cacb4de 100644
--- a/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationManagementSettingsImplTest.java
+++ b/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationManagementSettingsImplTest.java
@@ -22,10 +22,10 @@ import static org.junit.Assert.assertEquals;
 
 import org.apache.sling.caconfig.management.ConfigurationManagementSettings;
 import org.apache.sling.testing.mock.sling.junit.SlingContext;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 
 public class ConfigurationManagementSettingsImplTest {
@@ -33,11 +33,6 @@ public class ConfigurationManagementSettingsImplTest {
     @Rule
     public SlingContext context = new SlingContext();
     
-    @Before
-    public void setUp() {
-        
-    }
-    
     @Test
     public void testDefault() {
         ConfigurationManagementSettings underTest = context.registerInjectActivateService(new
ConfigurationManagementSettingsImpl());
@@ -45,16 +40,21 @@ public class ConfigurationManagementSettingsImplTest {
         assertEquals(ImmutableSet.<String>of(), underTest.getIgnoredPropertyNames(ImmutableSet.<String>of()));
         assertEquals(ImmutableSet.<String>of(), underTest.getIgnoredPropertyNames(ImmutableSet.<String>of("abc",
"def")));
         assertEquals(ImmutableSet.<String>of("jcr:xyz", "jcr:def"), underTest.getIgnoredPropertyNames(ImmutableSet.<String>of("abc",
"jcr:xyz", "jcr:def")));
+        
+        assertEquals(ImmutableList.of("."), underTest.getConfigCollectionPropertiesResourceNames());
     }
 
     @Test
     public void testCustomConfig() {
         ConfigurationManagementSettings underTest = context.registerInjectActivateService(new
ConfigurationManagementSettingsImpl(),
-                "ignorePropertyNameRegex", new String[] { "^.*e.*$", "^.*b.*$" });
+                "ignorePropertyNameRegex", new String[] { "^.*e.*$", "^.*b.*$" },
+                "configCollectionPropertiesResourceNames", new String[] { "a", "b" });
         
         assertEquals(ImmutableSet.<String>of(), underTest.getIgnoredPropertyNames(ImmutableSet.<String>of()));
         assertEquals(ImmutableSet.<String>of("abc", "def"), underTest.getIgnoredPropertyNames(ImmutableSet.<String>of("abc",
"def")));
         assertEquals(ImmutableSet.<String>of("abc", "jcr:def"), underTest.getIgnoredPropertyNames(ImmutableSet.<String>of("abc",
"jcr:xyz", "jcr:def")));
+
+        assertEquals(ImmutableList.of("a", "b"), underTest.getConfigCollectionPropertiesResourceNames());
     }
 
 }
diff --git a/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationManagerImplCustomPersistence2Test.java
b/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationManagerImplCustomPersistence2Test.java
index a548cb3..11605e2 100644
--- a/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationManagerImplCustomPersistence2Test.java
+++ b/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationManagerImplCustomPersistence2Test.java
@@ -20,12 +20,16 @@ package org.apache.sling.caconfig.management.impl;
 
 import static org.apache.sling.caconfig.management.impl.CustomConfigurationPersistenceStrategy2.containsJcrContent;
 
+import java.util.Dictionary;
+import java.util.Hashtable;
+
 import org.apache.commons.lang3.StringUtils;
 import org.apache.sling.caconfig.spi.ConfigurationPersistenceStrategy2;
 import org.junit.Before;
 import org.junit.runner.RunWith;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.osgi.framework.Constants;
+import org.osgi.service.cm.ConfigurationAdmin;
 
 /**
  * Test {@link ConfigurationManagerImpl} with custom persistence.
@@ -33,6 +37,16 @@ import org.osgi.framework.Constants;
 @RunWith(MockitoJUnitRunner.class)
 public class ConfigurationManagerImplCustomPersistence2Test extends ConfigurationManagerImplTest
{
     
+    @Override
+    protected void provideCustomOsgiConfig() throws Exception {
+        // provide custom lookup resource name for collection properties
+        ConfigurationAdmin configAdmin = context.getService(ConfigurationAdmin.class);
+        org.osgi.service.cm.Configuration mgmtSettingsConfig = configAdmin.getConfiguration(ConfigurationManagementSettingsImpl.class.getName());
+        Dictionary<String, Object> mgmtSettings = new Hashtable<>();
+        mgmtSettings.put("configCollectionPropertiesResourceNames", new String[] { "colPropsResource",
"." });
+        mgmtSettingsConfig.update(mgmtSettings);
+    }
+
     @Before
     public void setUpCustomPersistence() {
         // custom strategy which redirects all config resources to a jcr:content subnode
diff --git a/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationManagerImplTest.java
b/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationManagerImplTest.java
index fbed72f..8017ebd 100644
--- a/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationManagerImplTest.java
+++ b/src/test/java/org/apache/sling/caconfig/management/impl/ConfigurationManagerImplTest.java
@@ -81,7 +81,9 @@ public class ConfigurationManagerImplTest {
     private static final String CONFIG_NESTED_NAME = "testConfigNested";
    
     @Before
-    public void setUp() {
+    public void setUp() throws Exception {
+        provideCustomOsgiConfig();
+        
         context.registerService(ConfigurationMetadataProvider.class, configurationMetadataProvider);
         ConfigurationTestUtils.registerConfigurationResolver(context,
                 "configBucketNames", getAlternativeBucketNames());
@@ -196,6 +198,10 @@ public class ConfigurationManagerImplTest {
         when(configurationMetadataProvider.getConfigurationNames()).thenReturn(ImmutableSortedSet.of(CONFIG_NAME,
CONFIG_COL_NAME, CONFIG_NESTED_NAME));
     }
     
+    protected void provideCustomOsgiConfig() throws Exception {
+        // may be overwritten by sublcasses
+    }
+    
     protected String getConfigResolvePath(String path) {
         return path;
     }
@@ -590,7 +596,8 @@ public class ConfigurationManagerImplTest {
                 new ConfigurationCollectionPersistData(ImmutableList.of(
                         new ConfigurationPersistData(ImmutableMap.<String, Object>of("prop1",
"value1")).collectionItemName("0"),
                         new ConfigurationPersistData(ImmutableMap.<String, Object>of("prop2",
5)).collectionItemName("1"))
-        ));
+                ).properties(ImmutableMap.<String, Object>of("sling:configCollectionInherit",
true))
+        );
         context.resourceResolver().commit();
 
         String configPath0 = getConfigCollectionItemPersistPath(getConfigCollectionParentPersistPath("/conf/testNoConfig/sling:configs/"
+ CONFIG_COL_NAME) + "/0");
@@ -600,6 +607,9 @@ public class ConfigurationManagerImplTest {
         String configPath1 = getConfigCollectionItemPersistPath(getConfigCollectionParentPersistPath("/conf/testNoConfig/sling:configs/"
+ CONFIG_COL_NAME) + "/1");
         ValueMap props1 = context.resourceResolver().getResource(configPath1).getValueMap();
         assertEquals((Integer)5, props1.get("prop2"));
+        
+        ConfigurationCollectionData colData = underTest.getConfigurationCollection(contextResourceNoConfig,
CONFIG_COL_NAME);
+        assertEquals(true, colData.getProperties().get("sling:configCollectionInherit"));
     }
 
     @Test
diff --git a/src/test/java/org/apache/sling/caconfig/management/impl/CustomConfigurationPersistenceStrategy2.java
b/src/test/java/org/apache/sling/caconfig/management/impl/CustomConfigurationPersistenceStrategy2.java
index 733495c..da64c00 100644
--- a/src/test/java/org/apache/sling/caconfig/management/impl/CustomConfigurationPersistenceStrategy2.java
+++ b/src/test/java/org/apache/sling/caconfig/management/impl/CustomConfigurationPersistenceStrategy2.java
@@ -158,7 +158,8 @@ public class CustomConfigurationPersistenceStrategy2 implements ConfigurationPer
         
         // if resource collection parent properties are given replace them as well
         if (data.getProperties() != null) {
-            replaceProperties(configResourceParent, data.getProperties());
+            Resource propsResource = getOrCreateResource(resourceResolver, parentPath + "/colPropsResource",
ValueMap.EMPTY);
+            replaceProperties(propsResource, data.getProperties());
         }
         
         commit(resourceResolver);

-- 
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <commits@sling.apache.org>'].

Mime
View raw message