sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpet...@apache.org
Subject svn commit: r1748558 - in /sling/trunk/contrib/extensions/distribution: core/src/main/java/org/apache/sling/distribution/component/impl/ core/src/main/java/org/apache/sling/distribution/resources/impl/ core/src/main/java/org/apache/sling/distribution/r...
Date Wed, 15 Jun 2016 11:20:25 GMT
Author: mpetria
Date: Wed Jun 15 11:20:25 2016
New Revision: 1748558

URL: http://svn.apache.org/viewvc?rev=1748558&view=rev
Log:
SLING-5785: allow to store some distribution properties in content

Added:
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/OsgiConfigurationManager.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/ResourceConfigurationManager.java
    sling/trunk/contrib/extensions/distribution/sample/src/main/resources/SLING-CONTENT/etc/
    sling/trunk/contrib/extensions/distribution/sample/src/main/resources/SLING-CONTENT/etc/distribution.json
    sling/trunk/contrib/extensions/distribution/sample/src/main/resources/SLING-CONTENT/libs/sling/distribution/org.apache.sling.distribution.component.impl.DistributionConfigurationManager.json
Modified:
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/DefaultDistributionConfigurationManager.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/DistributionConfigurationManager.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/DistributionConfigurationResourceProvider.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/DistributionServiceResourceProvider.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/common/AbstractModifyingResourceProvider.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/common/AbstractReadableResourceProvider.java
    sling/trunk/contrib/extensions/distribution/it/src/test/java/org/apache/sling/distribution/it/DistributionAgentResourcesIntegrationTest.java
    sling/trunk/contrib/extensions/distribution/sample/pom.xml
    sling/trunk/contrib/extensions/distribution/sample/src/main/java/org/apache/sling/distribution/test/Init.java

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/DefaultDistributionConfigurationManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/DefaultDistributionConfigurationManager.java?rev=1748558&r1=1748557&r2=1748558&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/DefaultDistributionConfigurationManager.java (original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/DefaultDistributionConfigurationManager.java Wed Jun 15 11:20:25 2016
@@ -19,23 +19,19 @@
 package org.apache.sling.distribution.component.impl;
 
 
-import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
+import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.commons.osgi.PropertiesUtil;
-import org.apache.sling.distribution.resources.impl.OsgiUtils;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -48,213 +44,198 @@ import org.slf4j.LoggerFactory;
 @Component
 @Service(DistributionConfigurationManager.class)
 public class DefaultDistributionConfigurationManager implements DistributionConfigurationManager {
+
     private final Logger log = LoggerFactory.getLogger(getClass());
 
+    @Property(label = "Resource Config Enabled", description = "If storing config in resource tree is enabled.", boolValue = false)
+    public static final String CONFIG_ENABLED = "resource.config.enabled";
+
+    @Property(label = "Resource Config Prefix", description = "The prefix of properties to be stored in content", value = "etc.")
+    public static final String CONFIG_PREFIX = "resource.config.prefix";
+
+    @Property(label = "Resource Config Root", description = "The resource config root", value = "/etc/distribution")
+    public static final String CONFIG_ROOT = "resource.config.root";
+
+    @Property(label = "Resource Config Properties", description = "The resource config properties", value = { "enabled" } )
+    public static final String CONFIG_PROPERTIES= "resource.config.properties";
+
+    @Property(label = "Resource Config Defaults", description = "The default values for resource config properties", value = { "serializationType=distribution" } )
+    public static final String CONFIG_DEFAULTS = "resource.config.defaults";
+
     @Reference
-    private
     ConfigurationAdmin configurationAdmin;
 
+    DistributionConfigurationManager osgiManager;
+    DistributionConfigurationManager resourceManager;
 
-    public List<DistributionConfiguration> getConfigs(DistributionComponentKind kind) {
-        List<Configuration> configurations = getOsgiConfigurations(kind, null);
-
-        List<DistributionConfiguration> result = new ArrayList<DistributionConfiguration>();
-        if (configurations == null || configurations.size() == 0) {
-            return result;
-        }
+    static String resourcePrefix;
+    static String OSGI_PREFIX = "";
 
 
-        for (Configuration configuration : configurations) {
-            Dictionary propertiesDict = configuration.getProperties();
-            Map<String, Object> properties = OsgiUtils.fromDictionary(propertiesDict);
 
-            properties = filterBeforeRead(properties);
-            String name = PropertiesUtil.toString(properties.get(DistributionComponentConstants.PN_NAME), null);
-            result.add(new DistributionConfiguration(kind, name, properties));
+    @Activate
+    void activate(Map<String, Object> properties) {
+        boolean configEnabled = PropertiesUtil.toBoolean(properties.get(CONFIG_ENABLED), false);
 
-        }
+        String configRoot = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(properties.get(CONFIG_ROOT), null));
+        resourcePrefix = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(properties.get(CONFIG_PREFIX), null));
 
-        return result;
-    }
+        String[] configProperties = SettingsUtils.removeEmptyEntries(PropertiesUtil.toStringArray(properties.get(CONFIG_PROPERTIES), null));
 
-    public DistributionConfiguration getConfig(DistributionComponentKind kind, String name) {
-        List<Configuration> configurations = getOsgiConfigurations(kind, name);
+        if (configEnabled && configRoot != null && configProperties != null) {
+            Map<String, String> configDefaults = PropertiesUtil.toMap(properties.get(CONFIG_DEFAULTS), new String[0]);
 
-        if (configurations == null || configurations.size() == 0) {
-            return null;
+            resourceManager = new ResourceConfigurationManager(configRoot, configProperties, configDefaults);
         }
 
-        Configuration configuration = configurations.get(0);
+        osgiManager = new OsgiConfigurationManager(configurationAdmin);
+    }
+
+    @Deactivate
+    void deactivate() {
+        resourceManager = null;
+        osgiManager = null;
+    }
 
-        if (configuration != null) {
-            Dictionary properties = configuration.getProperties();
-            Map<String, Object> result = OsgiUtils.fromDictionary(properties);
 
-            String factoryPid = PropertiesUtil.toString(result.get(ConfigurationAdmin.SERVICE_FACTORYPID), null);
-            String type = kind.getType(factoryPid);
+    @Override
+    public List<DistributionConfiguration> getConfigs(ResourceResolver resolver, DistributionComponentKind kind) {
+        List<DistributionConfiguration> osgiConfigs = osgiManager.getConfigs(resolver, kind);
+        List<DistributionConfiguration> result = osgiConfigs;
 
-            result.put(DistributionComponentConstants.PN_TYPE, type);
-            result = filterBeforeRead(result);
-            return new DistributionConfiguration(kind, name, result);
+        if (resourceManager != null) {
+            List<DistributionConfiguration> resourceConfigs = resourceManager.getConfigs(resolver, kind);
+            result = mergeConfigs(result, resourceConfigs, resourcePrefix);
         }
 
-        return null;
+        return result;
     }
 
-    public void saveConfig(DistributionConfiguration config) {
-        String componentName = config.getName();
-        DistributionComponentKind componentKind = config.getKind();
-        Map<String, Object> properties = config.getProperties();
-        String componentType = PropertiesUtil.toString(properties.get(DistributionComponentConstants.PN_TYPE), null);
+    @Override
+    public DistributionConfiguration getConfig(ResourceResolver resolver, DistributionComponentKind kind, String name) {
+        DistributionConfiguration osgiConfig = osgiManager.getConfig(resolver, kind, name);
 
-        if (componentKind == null || componentType == null) {
-            throw new IllegalArgumentException("kind and type are required");
-        }
+        DistributionConfiguration resultConfig = osgiConfig;
 
-        String factoryPid = componentKind.getFactory(componentType);
-        if (factoryPid != null) {
-            properties.put(DistributionComponentConstants.PN_NAME, componentName);
-            Configuration configuration = saveOsgiConfig(factoryPid, componentName, properties);
+        if (resourceManager != null) {
+            DistributionConfiguration resourceConfig = resourceManager.getConfig(resolver, kind, name);
+            resultConfig = mergeConfig(resultConfig, resourceConfig, resourcePrefix);
         }
 
+        return resultConfig;
     }
 
-    public void deleteConfig(DistributionComponentKind kind, String name) {
-        List<Configuration> configs = getOsgiConfigurations(kind, name);
+    @Override
+    public void saveConfig(ResourceResolver resolver, DistributionConfiguration config) {
 
-        deleteOsgiConfigs(configs);
 
-        log.info("Delete component {}", name);
 
-    }
+        if (resourceManager != null) {
+            Map<String, DistributionConfiguration> splitConfig = splitConfig(config, resourcePrefix);
+
+            DistributionConfiguration defaultConfig = splitConfig.get(OSGI_PREFIX);
 
+            osgiManager.saveConfig(resolver, defaultConfig);
 
-    private void deleteOsgiConfigs(List<Configuration> configurations) {
-        for (Configuration configuration : configurations) {
-            String pid = configuration.getPid();
+            DistributionConfiguration resourceConfig = splitConfig.get(resourcePrefix);
 
-            try {
-                configuration.delete();
-                log.info("Deleted configuration {}", pid);
-            } catch (IOException e) {
-                log.warn("Cannot delete configuration {}", pid, e);
+            if (resourceConfig != null) {
+                resourceManager.saveConfig(resolver, resourceConfig);
             }
+        } else {
+            osgiManager.saveConfig(resolver, config);
         }
     }
 
-    private List<Configuration> getOsgiConfigurations(DistributionComponentKind kind, String componentName) {
-        List<String> factoryPids = kind.getFactories();
+    @Override
+    public void deleteConfig(ResourceResolver resolver, DistributionComponentKind kind, String name) {
+        osgiManager.deleteConfig(resolver, kind, name);
 
-        List<Configuration> allConfigurations = new ArrayList<Configuration>();
-        for (String factoryPid : factoryPids) {
-            List<Configuration> configurations = getOsgiConfigurationsFromFactory(factoryPid, componentName);
-            allConfigurations.addAll(configurations);
+        if (resourceManager != null) {
+            resourceManager.deleteConfig(resolver, kind, name);
         }
-
-        return allConfigurations;
     }
 
 
-    private Configuration saveOsgiConfig(String factoryPid, String componentName, Map<String, Object> properties) {
-        try {
-            List<Configuration> configurations = getOsgiConfigurationsFromFactory(factoryPid, componentName);
-            Configuration configuration = null;
-            if (configurations == null || configurations.size() == 0) {
-                configuration = configurationAdmin.createFactoryConfiguration(factoryPid);
-            } else {
-                configuration = configurations.get(0);
-            }
+    static DistributionConfiguration mergeConfig(DistributionConfiguration main, DistributionConfiguration extension, String prefix) {
 
-            properties = filterBeforeSave(properties);
+        if (main == null) {
+            return null;
+        }
 
-            configuration.update(OsgiUtils.toDictionary(properties));
+        Map<String, DistributionConfiguration> configMap = new HashMap<String, DistributionConfiguration>();
 
-            return configuration;
-        } catch (IOException e) {
-            log.error("Cannot create configuration with factory {}", factoryPid, e);
-        }
+        configMap.put(OSGI_PREFIX, main);
+        configMap.put(prefix, extension);
 
-        return null;
+        return mergeConfig(main.getKind(), main.getName(), configMap);
     }
 
-    private List<Configuration> getOsgiConfigurationsFromFactory(String factoryPid, String componentName) {
-        List<Configuration> result = new ArrayList<Configuration>();
 
-        try {
-            String filter = OsgiUtils.getFilter(factoryPid, DistributionComponentConstants.PN_NAME, componentName);
 
-            Configuration[] configurations = configurationAdmin.listConfigurations(filter);
-            if (configurations != null) {
-                result.addAll(Arrays.asList(configurations));
+    static DistributionConfiguration mergeConfig(DistributionComponentKind kind, String name, Map<String, DistributionConfiguration> configMap) {
+        Map<String, Object> result = new HashMap<String, Object>();
+        for (String prefixKey : configMap.keySet()) {
+            DistributionConfiguration config = configMap.get(prefixKey);
+            if (config == null) {
+                continue;
+            }
+            Map<String, Object> properties = config.getProperties();
+
+            if (prefixKey.equals(OSGI_PREFIX)) {
+                result.putAll(properties);
+            } else {
+                for (String propertyKey : properties.keySet()) {
+                    Object propertyValue = properties.get(propertyKey);
+                    result.put(prefixKey + propertyKey, propertyValue);
+                }
             }
-        } catch (IOException e) {
-            log.error("cannot get osgi configs", e);
-        } catch (InvalidSyntaxException e) {
-            log.error("cannot parse filter", e);
         }
 
-        return result;
+        return new DistributionConfiguration(kind, name, result);
     }
 
-    private Map<String, Object> filterBeforeSave(Map<String, Object> properties) {
-        Map<String, Object> result = new HashMap<String, Object>();
-
-        for (Map.Entry<String, Object> entry : properties.entrySet()) {
-            if (entry.getKey().endsWith(".target")) {
-                String entryValue = (String) entry.getValue();
-                entryValue = packOsgiFilter(entryValue);
-                if (entryValue != null) {
-                    result.put(entry.getKey(), entryValue);
-                }
-            } else {
-                result.put(entry.getKey(), entry.getValue());
-            }
+    static List<DistributionConfiguration> mergeConfigs(List<DistributionConfiguration> target, List<DistributionConfiguration> source, String prefix) {
+        List<DistributionConfiguration> result = new ArrayList<DistributionConfiguration>();
 
+        Map<String, DistributionConfiguration> sourceMap = new HashMap<String, DistributionConfiguration>();
+        for (DistributionConfiguration config : source) {
+            sourceMap.put(config.getName(), config);
         }
 
-        result = OsgiUtils.sanitize(result);
-        return result;
-    }
 
-    private Map<String, Object> filterBeforeRead(Map<String, Object> properties) {
-        Map<String, Object> result = new HashMap<String, Object>();
+        for (DistributionConfiguration targetConfig : target) {
+            DistributionConfiguration sourceConfig = sourceMap.get(targetConfig.getName());
 
-        for (Map.Entry<String, Object> entry : properties.entrySet()) {
-            if (entry.getKey().endsWith(".target")) {
-                String entryValue = (String) entry.getValue();
-                entryValue = unpackOsgiFilter(entryValue);
-                if (entryValue != null) {
-                    result.put(entry.getKey(), entryValue);
-                }
-            } else {
-                result.put(entry.getKey(), entry.getValue());
-            }
+            DistributionConfiguration mergedConfig = mergeConfig(targetConfig, sourceConfig, prefix);
 
+            result.add(mergedConfig);
         }
 
-        result = OsgiUtils.sanitize(result);
         return result;
     }
 
+    static Map<String, DistributionConfiguration> splitConfig(DistributionConfiguration config, String prefix) {
+        Map<String, Object> properties = config.getProperties();
 
-    private String unpackOsgiFilter(String propertyValue) {
-
-        String result = null;
+        Map<String, Object> defaultMap = new HashMap<String, Object>();
+        Map<String, Object> prefixMap = new HashMap<String, Object>();
 
-        String namePattern = "\\(" + DistributionComponentConstants.PN_NAME + "=(.*?)\\)";
 
-        Pattern r = Pattern.compile(namePattern);
-        Matcher m = r.matcher(propertyValue);
+        for (String propertyKey : properties.keySet()) {
+            if (propertyKey.startsWith(prefix)) {
+                prefixMap.put(propertyKey.substring(prefix.length()), properties.get(propertyKey));
+            } else {
+                defaultMap.put(propertyKey, properties.get(propertyKey));
+            }
+        }
 
-        if (m.matches()) {
-            result = m.group(1);
+        Map<String, DistributionConfiguration> result = new HashMap<String, DistributionConfiguration>();
+        result.put(OSGI_PREFIX, new DistributionConfiguration(config.getKind(), config.getName(), defaultMap));
+        if (prefixMap.size() > 0) {
+            result.put(prefix, new DistributionConfiguration(config.getKind(), config.getName(), prefixMap));
         }
 
         return result;
     }
-
-    private String packOsgiFilter(String propertyValue) {
-        return "(" + DistributionComponentConstants.PN_NAME + "=" + OsgiUtils.escape(propertyValue) + ")";
-    }
-
 }

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/DistributionConfigurationManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/DistributionConfigurationManager.java?rev=1748558&r1=1748557&r2=1748558&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/DistributionConfigurationManager.java (original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/DistributionConfigurationManager.java Wed Jun 15 11:20:25 2016
@@ -19,6 +19,8 @@
 
 package org.apache.sling.distribution.component.impl;
 
+import org.apache.sling.api.resource.ResourceResolver;
+
 import java.util.List;
 
 /**
@@ -26,11 +28,11 @@ import java.util.List;
  */
 public interface DistributionConfigurationManager {
 
-    List<DistributionConfiguration> getConfigs(DistributionComponentKind kind);
+    List<DistributionConfiguration> getConfigs(ResourceResolver resolver, DistributionComponentKind kind);
 
-    DistributionConfiguration getConfig(DistributionComponentKind kind, String name);
+    DistributionConfiguration getConfig(ResourceResolver resolver, DistributionComponentKind kind, String name);
 
-    void saveConfig(DistributionConfiguration config);
+    void saveConfig(ResourceResolver resolver, DistributionConfiguration config);
 
-    void deleteConfig(DistributionComponentKind kind, String name);
+    void deleteConfig(ResourceResolver resolver, DistributionComponentKind kind, String name);
 }

Added: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/OsgiConfigurationManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/OsgiConfigurationManager.java?rev=1748558&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/OsgiConfigurationManager.java (added)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/OsgiConfigurationManager.java Wed Jun 15 11:20:25 2016
@@ -0,0 +1,257 @@
+/*
+ * 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.distribution.component.impl;
+
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.apache.sling.distribution.resources.impl.OsgiUtils;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Created by mpetria on 5/31/16.
+ */
+public class OsgiConfigurationManager implements DistributionConfigurationManager {
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+
+    final ConfigurationAdmin configurationAdmin;
+
+    public OsgiConfigurationManager(ConfigurationAdmin configurationAdmin) {
+
+        this.configurationAdmin = configurationAdmin;
+    }
+
+
+    public List<DistributionConfiguration> getConfigs(ResourceResolver resolver, DistributionComponentKind kind) {
+        List<Configuration> configurations = getOsgiConfigurations(kind, null);
+
+        List<DistributionConfiguration> result = new ArrayList<DistributionConfiguration>();
+        if (configurations == null || configurations.size() == 0) {
+            return result;
+        }
+
+
+        for (Configuration configuration : configurations) {
+            Dictionary propertiesDict = configuration.getProperties();
+            Map<String, Object> properties = OsgiUtils.fromDictionary(propertiesDict);
+
+            properties = filterBeforeRead(properties);
+            String name = PropertiesUtil.toString(properties.get(DistributionComponentConstants.PN_NAME), null);
+            result.add(new DistributionConfiguration(kind, name, properties));
+
+        }
+
+        return result;
+    }
+
+    public DistributionConfiguration getConfig(ResourceResolver resolver, DistributionComponentKind kind, String name) {
+        List<Configuration> configurations = getOsgiConfigurations(kind, name);
+
+        if (configurations == null || configurations.size() == 0) {
+            return null;
+        }
+
+        Configuration configuration = configurations.get(0);
+
+        if (configuration != null) {
+            Dictionary properties = configuration.getProperties();
+            Map<String, Object> result = OsgiUtils.fromDictionary(properties);
+
+            String factoryPid = PropertiesUtil.toString(result.get(ConfigurationAdmin.SERVICE_FACTORYPID), null);
+            String type = kind.getType(factoryPid);
+
+            result.put(DistributionComponentConstants.PN_TYPE, type);
+            result = filterBeforeRead(result);
+            return new DistributionConfiguration(kind, name, result);
+        }
+
+        return null;
+    }
+
+    public void saveConfig(ResourceResolver resolver, DistributionConfiguration config) {
+        String componentName = config.getName();
+        DistributionComponentKind componentKind = config.getKind();
+        Map<String, Object> properties = config.getProperties();
+        String componentType = PropertiesUtil.toString(properties.get(DistributionComponentConstants.PN_TYPE), null);
+
+        if (componentKind == null || componentType == null) {
+            throw new IllegalArgumentException("kind and type are required " + componentKind + componentType);
+        }
+
+        String factoryPid = componentKind.getFactory(componentType);
+        if (factoryPid != null) {
+            properties.put(DistributionComponentConstants.PN_NAME, componentName);
+            Configuration configuration = saveOsgiConfig(factoryPid, componentName, properties);
+        }
+
+    }
+
+    public void deleteConfig(ResourceResolver resolver, DistributionComponentKind kind, String name) {
+        List<Configuration> configs = getOsgiConfigurations(kind, name);
+
+        deleteOsgiConfigs(configs);
+
+        log.info("Delete component {}", name);
+
+    }
+
+
+    private void deleteOsgiConfigs(List<Configuration> configurations) {
+        for (Configuration configuration : configurations) {
+            String pid = configuration.getPid();
+
+            try {
+                configuration.delete();
+                log.info("Deleted configuration {}", pid);
+            } catch (IOException e) {
+                log.warn("Cannot delete configuration {}", pid, e);
+            }
+        }
+    }
+
+    private List<Configuration> getOsgiConfigurations(DistributionComponentKind kind, String componentName) {
+        List<String> factoryPids = kind.getFactories();
+
+        List<Configuration> allConfigurations = new ArrayList<Configuration>();
+        for (String factoryPid : factoryPids) {
+            List<Configuration> configurations = getOsgiConfigurationsFromFactory(factoryPid, componentName);
+            allConfigurations.addAll(configurations);
+        }
+
+        return allConfigurations;
+    }
+
+
+    private Configuration saveOsgiConfig(String factoryPid, String componentName, Map<String, Object> properties) {
+        try {
+            List<Configuration> configurations = getOsgiConfigurationsFromFactory(factoryPid, componentName);
+            Configuration configuration = null;
+            if (configurations == null || configurations.size() == 0) {
+                configuration = configurationAdmin.createFactoryConfiguration(factoryPid);
+            } else {
+                configuration = configurations.get(0);
+            }
+
+            properties = filterBeforeSave(properties);
+
+            configuration.update(OsgiUtils.toDictionary(properties));
+
+            return configuration;
+        } catch (IOException e) {
+            log.error("Cannot create configuration with factory {}", factoryPid, e);
+        }
+
+        return null;
+    }
+
+    private List<Configuration> getOsgiConfigurationsFromFactory(String factoryPid, String componentName) {
+        List<Configuration> result = new ArrayList<Configuration>();
+
+        try {
+            String filter = OsgiUtils.getFilter(factoryPid, DistributionComponentConstants.PN_NAME, componentName);
+
+            Configuration[] configurations = configurationAdmin.listConfigurations(filter);
+            if (configurations != null) {
+                result.addAll(Arrays.asList(configurations));
+            }
+        } catch (IOException e) {
+            log.error("cannot get osgi configs", e);
+        } catch (InvalidSyntaxException e) {
+            log.error("cannot parse filter", e);
+        }
+
+        return result;
+    }
+
+    private Map<String, Object> filterBeforeSave(Map<String, Object> properties) {
+        Map<String, Object> result = new HashMap<String, Object>();
+
+        for (Map.Entry<String, Object> entry : properties.entrySet()) {
+            if (entry.getKey().endsWith(".target")) {
+                String entryValue = (String) entry.getValue();
+                entryValue = packOsgiFilter(entryValue);
+                if (entryValue != null) {
+                    result.put(entry.getKey(), entryValue);
+                }
+            } else {
+                result.put(entry.getKey(), entry.getValue());
+            }
+
+        }
+
+        result = OsgiUtils.sanitize(result);
+        return result;
+    }
+
+    private Map<String, Object> filterBeforeRead(Map<String, Object> properties) {
+        Map<String, Object> result = new HashMap<String, Object>();
+
+        for (Map.Entry<String, Object> entry : properties.entrySet()) {
+            if (entry.getKey().endsWith(".target")) {
+                String entryValue = (String) entry.getValue();
+                entryValue = unpackOsgiFilter(entryValue);
+                if (entryValue != null) {
+                    result.put(entry.getKey(), entryValue);
+                }
+            } else {
+                result.put(entry.getKey(), entry.getValue());
+            }
+
+        }
+
+        result = OsgiUtils.sanitize(result);
+        return result;
+    }
+
+
+    private String unpackOsgiFilter(String propertyValue) {
+
+        String result = null;
+
+        String namePattern = "\\(" + DistributionComponentConstants.PN_NAME + "=(.*?)\\)";
+
+        Pattern r = Pattern.compile(namePattern);
+        Matcher m = r.matcher(propertyValue);
+
+        if (m.matches()) {
+            result = m.group(1);
+        }
+
+        return result;
+    }
+
+    private String packOsgiFilter(String propertyValue) {
+        return "(" + DistributionComponentConstants.PN_NAME + "=" + OsgiUtils.escape(propertyValue) + ")";
+    }
+}

Added: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/ResourceConfigurationManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/ResourceConfigurationManager.java?rev=1748558&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/ResourceConfigurationManager.java (added)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/component/impl/ResourceConfigurationManager.java Wed Jun 15 11:20:25 2016
@@ -0,0 +1,195 @@
+/*
+ * 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.distribution.component.impl;
+
+
+import org.apache.sling.api.resource.ModifiableValueMap;
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ValueMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ResourceConfigurationManager implements DistributionConfigurationManager {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+
+    final String CONTENT_NODE = "jcr:content";
+    final String configRootPath;
+    private final String[] configProperties;
+    private final Map<String, String> configDefaults;
+
+    public ResourceConfigurationManager(String configRootPath, String[] configProperties, Map<String, String> configDefaults) {
+        this.configRootPath = configRootPath;
+        this.configProperties = configProperties;
+        this.configDefaults = configDefaults;
+    }
+
+    @Override
+    public List<DistributionConfiguration> getConfigs(ResourceResolver resolver, DistributionComponentKind kind) {
+
+        List<DistributionConfiguration> configurations = new ArrayList<DistributionConfiguration>();
+
+        Resource configRoot = resolver.getResource(configRootPath);
+
+        if (configRoot == null) {
+            return new ArrayList<DistributionConfiguration>();
+        }
+
+        for (Resource configResource : configRoot.getChildren()) {
+            Map<String, Object> configMap = getFilteredMap(configResource);
+
+            configurations.add(new DistributionConfiguration(kind, configResource.getName(), configMap));
+
+        }
+
+        return configurations;
+    }
+
+    @Override
+    public DistributionConfiguration getConfig(ResourceResolver resolver, DistributionComponentKind kind, String name) {
+
+        Resource configRoot = resolver.getResource(configRootPath);
+
+        if (configRoot == null) {
+            return null;
+        }
+
+        Resource configResource = configRoot.getChild(name);
+
+        if (configResource == null) {
+            return null;
+        }
+
+
+        Map<String, Object> configMap = getFilteredMap(configResource);
+
+        return new DistributionConfiguration(kind, configResource.getName(), configMap);
+    }
+
+    @Override
+    public void saveConfig(ResourceResolver resolver, DistributionConfiguration config) {
+        Resource configRoot = resolver.getResource(configRootPath);
+
+        if (configRoot == null) {
+            return;
+        }
+
+        Resource configResource = configRoot.getChild(config.getName());
+        Resource contentResource = null;
+
+        try {
+            if (configResource == null) {
+                Map<String, Object> configMap = new HashMap<String, Object>();
+                configMap.put("jcr:primaryType", "sling:Folder");
+                configResource = resolver.create(configRoot, config.getName(), configMap);
+            }
+
+            if (contentResource == null) {
+                Map<String, Object> contentMap = new HashMap<String, Object>();
+                contentMap.put("jcr:primaryType", "nt:unstructured");
+                contentResource = resolver.create(configResource, CONTENT_NODE, contentMap);
+            }
+
+            Map<String, Object> properties = config.getProperties();
+            properties = filterMap(properties);
+            properties.putAll(configDefaults);
+
+            ModifiableValueMap valueMap = contentResource.adaptTo(ModifiableValueMap.class);
+            valueMap.putAll(properties);
+            resolver.commit();
+        } catch (PersistenceException e) {
+            log.error("cannot save config {}", config.getName(),  e);
+        }
+
+    }
+
+    @Override
+    public void deleteConfig(ResourceResolver resolver, DistributionComponentKind kind, String name) {
+        Resource configRoot = resolver.getResource(configRootPath);
+
+        Resource configResource = configRoot.getChild(name);
+
+        if (configResource == null) {
+            return;
+        }
+
+        try {
+            resolver.delete(configResource);
+            resolver.commit();
+        } catch (PersistenceException e) {
+            log.error("cannot delete config {}", name,  e);
+        }
+
+    }
+
+    Map<String, Object> getMap(Resource resource) {
+        Map<String, Object> result = new HashMap<String, Object>();
+        Resource contentResource = resource.getChild(CONTENT_NODE);
+
+        if (contentResource != null) {
+            ValueMap configMap = contentResource.adaptTo(ValueMap.class);
+
+            result.putAll(configMap);
+        }
+
+        return result;
+    }
+
+    Map<String, Object> getFilteredMap(Resource resource) {
+        Map<String, Object> result = getMap(resource);
+
+        result = filterMap(result);
+
+        return result;
+    }
+
+    Map<String, Object> filterMap(Map<String, Object> configMap) {
+        Map<String, Object> result = new HashMap<String, Object>();
+
+        for (String key: configMap.keySet()) {
+            if (isAccepted(key)) {
+                result.put(key, configMap.get(key));
+            }
+        }
+
+        return result;
+    }
+
+    boolean isAccepted(String key) {
+        for (String property : configProperties) {
+           if (property.equals(key)) {
+               return true;
+           }
+        }
+        return false;
+    }
+
+
+
+
+}

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/DistributionConfigurationResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/DistributionConfigurationResourceProvider.java?rev=1748558&r1=1748557&r2=1748558&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/DistributionConfigurationResourceProvider.java (original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/DistributionConfigurationResourceProvider.java Wed Jun 15 11:20:25 2016
@@ -29,6 +29,7 @@ import org.apache.sling.api.resource.Mod
 import org.apache.sling.api.resource.PersistenceException;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.distribution.component.impl.DistributionComponent;
 import org.apache.sling.distribution.component.impl.DistributionComponentKind;
 import org.apache.sling.distribution.component.impl.DistributionConfiguration;
 import org.apache.sling.distribution.component.impl.DistributionConfigurationManager;
@@ -60,8 +61,8 @@ public class DistributionConfigurationRe
     }
 
     @Override
-    protected void save(ResourceResolver resourceResolver, Map<String, Map<String, Object>> changedResources,
-                        Set<String> deletedResources) throws PersistenceException {
+    protected void saveInternalResources(ResourceResolver resourceResolver, Map<String, Map<String, Object>> changedResources,
+                                         Set<String> deletedResources) throws PersistenceException {
         for (Map.Entry<String, Map<String, Object>> entry : changedResources.entrySet()) {
             String resourceName = entry.getKey();
             Map<String, Object> properties = entry.getValue();
@@ -69,34 +70,60 @@ public class DistributionConfigurationRe
             String componentName = getConfigName(resourceName);
 
             DistributionConfiguration config = new DistributionConfiguration(kind, componentName, properties);
-            configurationManager.saveConfig(config);
+            configurationManager.saveConfig(resourceResolver, config);
         }
 
         for (String resourceName : deletedResources) {
             String componentName = getConfigName(resourceName);
 
-            configurationManager.deleteConfig(kind, componentName);
+            configurationManager.deleteConfig(resourceResolver, kind, componentName);
         }
     }
 
     @Override
-    protected Map<String, Object> getResourceProperties(SimplePathInfo pathInfo) {
+    protected Map<String, Object> getInternalResourceProperties(ResourceResolver resolver, SimplePathInfo pathInfo) {
         if (pathInfo.isRoot()) {
-            return getResourceRootProperties();
+            return getResourceRootProperties(resolver);
         } else if (pathInfo.isMain()) {
-            return getResourceProperties(pathInfo.getMainResourceName());
+            return getResourceProperties(resolver, pathInfo.getMainResourceName());
+        } else if (pathInfo.isChild()) {
+            String configName = getConfigName(pathInfo.getMainResourceName());
+
+            DistributionConfiguration config = configurationManager.getConfig(resolver, kind, configName);
+
+            if (config != null) {
+                return getChildResourceProperties(config, pathInfo.getChildResourceName());
+            }
         }
 
         return null;
     }
 
     @Override
-    protected Iterable<String> getResourceChildren(SimplePathInfo pathInfo) {
+    protected Iterable<String> getInternalResourceChildren(ResourceResolver resolver, SimplePathInfo pathInfo) {
+        if (pathInfo.isMain()) {
+            String configName = getConfigName(pathInfo.getMainResourceName());
+
+            DistributionConfiguration config = configurationManager.getConfig(resolver, kind, configName);
+
+            if (config != null) {
+                return getChildResourceChildren(config, pathInfo.getChildResourceName());
+            }
+        }
+
+        return null;
+    }
+
+    protected Map<String, Object> getChildResourceProperties(DistributionConfiguration config, String childResourceName) {
+        return null;
+    }
+
+    protected Iterable<String> getChildResourceChildren(DistributionConfiguration config, String childResourceName) {
         return null;
     }
 
-    private Map<String, Object> getResourceRootProperties() {
-        List<DistributionConfiguration> configsList = configurationManager.getConfigs(kind);
+    private Map<String, Object> getResourceRootProperties(ResourceResolver resolver) {
+        List<DistributionConfiguration> configsList = configurationManager.getConfigs(resolver, kind);
 
         List<String> nameList = new ArrayList<String>();
         for (DistributionConfiguration config : configsList) {
@@ -113,11 +140,11 @@ public class DistributionConfigurationRe
     }
 
 
-    private Map<String, Object> getResourceProperties(String resourceName) {
+    private Map<String, Object> getResourceProperties(ResourceResolver resolver, String resourceName) {
 
         String componentName = getConfigName(resourceName);
 
-        DistributionConfiguration config = configurationManager.getConfig(kind, componentName);
+        DistributionConfiguration config = configurationManager.getConfig(resolver, kind, componentName);
 
         if (config != null) {
 

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/DistributionServiceResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/DistributionServiceResourceProvider.java?rev=1748558&r1=1748557&r2=1748558&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/DistributionServiceResourceProvider.java (original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/DistributionServiceResourceProvider.java Wed Jun 15 11:20:25 2016
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.distribution.component.impl.DistributionComponent;
 import org.apache.sling.distribution.component.impl.DistributionComponentConstants;
 import org.apache.sling.distribution.component.impl.DistributionComponentKind;
@@ -55,11 +56,11 @@ public class DistributionServiceResource
     }
 
     @Override
-    protected Map<String, Object> getResourceProperties(SimplePathInfo pathInfo) {
+    protected Map<String, Object> getInternalResourceProperties(ResourceResolver resolver, SimplePathInfo pathInfo) {
         if (pathInfo.isRoot()) {
             return getResourceRootProperties();
         } else if (pathInfo.isMain()) {
-            return getResourceProperties(pathInfo.getMainResourceName());
+            return getResourceProperties(resolver, pathInfo.getMainResourceName());
         } else if (pathInfo.isChild()) {
             DistributionComponent component = componentProvider.getComponent(kind, pathInfo.getMainResourceName());
 
@@ -73,7 +74,7 @@ public class DistributionServiceResource
 
 
     @Override
-    protected Iterable<String> getResourceChildren(SimplePathInfo pathInfo) {
+    protected Iterable<String> getInternalResourceChildren(ResourceResolver resolver, SimplePathInfo pathInfo) {
         if (pathInfo.isMain()) {
             DistributionComponent component = componentProvider.getComponent(kind, pathInfo.getMainResourceName());
 
@@ -85,7 +86,7 @@ public class DistributionServiceResource
         return null;
     }
 
-    private Map<String, Object> getResourceProperties(String resourceName) {
+    private Map<String, Object> getResourceProperties(ResourceResolver resolver, String resourceName) {
 
         DistributionComponent component = componentProvider.getComponent(kind, resourceName);
 

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/common/AbstractModifyingResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/common/AbstractModifyingResourceProvider.java?rev=1748558&r1=1748557&r2=1748558&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/common/AbstractModifyingResourceProvider.java (original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/common/AbstractModifyingResourceProvider.java Wed Jun 15 11:20:25 2016
@@ -56,7 +56,7 @@ public abstract class AbstractModifyingR
 
         String resourceName = pathInfo.getMainResourceName();
 
-        boolean added = addToChangedResources(resourceName, properties, true);
+        boolean added = addToChangedResources(resolver, resourceName, properties, true);
 
         if (!added) {
             throw new PersistenceException("Resource already exists at " + path, null, resourceName, null);
@@ -93,7 +93,7 @@ public abstract class AbstractModifyingR
             return;
         }
 
-        save(resolver, changedResources, deletedResources);
+        saveInternalResources(resolver, changedResources, deletedResources);
 
         reset();
     }
@@ -115,13 +115,16 @@ public abstract class AbstractModifyingR
 
         String resourceName = pathInfo.getMainResourceName();
 
-        addToChangedResources(resourceName, properties, false);
+        addToChangedResources(resourceResolver, resourceName, properties, false);
     }
 
-    private boolean addToChangedResources(String resourceName, Map<String, Object> newProperties, boolean failIfAlreadyExists) {
+    private boolean addToChangedResources(ResourceResolver resolver, String resourceName, Map<String, Object> newProperties, boolean failIfAlreadyExists) {
         final boolean deleted = this.deletedResources.remove(resourceName);
+
         SimplePathInfo pathInfo = SimplePathInfo.parsePathInfo(resourceRoot, resourceRoot + "/" + resourceName);
-        Map<String, Object> existingResource = getMainResourceProperties(pathInfo);
+
+        Map<String, Object> existingResource = getResourceProperties(resolver, pathInfo);
+
         if (failIfAlreadyExists && !deleted && existingResource != null) {
             return false;
         }
@@ -140,21 +143,25 @@ public abstract class AbstractModifyingR
         return true;
     }
 
+
     @Override
-    protected Map<String, Object> getMainResourceProperties(SimplePathInfo pathInfo) {
+    protected Map<String, Object> getResourceProperties(ResourceResolver resolver, SimplePathInfo pathInfo) {
 
-        String resourceName = pathInfo.getMainResourceName();
-        if (deletedResources.contains(resourceName)) {
-            return null;
-        }
+        if (pathInfo.isMain()) {
+            String resourceName = pathInfo.getMainResourceName();
+            if (deletedResources.contains(resourceName)) {
+                return null;
+            }
 
-        if (changedResources.containsKey(resourceName)) {
-            return changedResources.get(resourceName);
+            if (changedResources.containsKey(resourceName)) {
+                return changedResources.get(resourceName);
+            }
         }
 
-        return getResourceProperties(pathInfo);
+        return super.getResourceProperties(resolver, pathInfo);
     }
 
+    @Override
     Resource buildMainResource(ResourceResolver resourceResolver,
                                SimplePathInfo pathInfo,
                                Map<String, Object> properties,
@@ -168,9 +175,9 @@ public abstract class AbstractModifyingR
     }
 
 
-    protected abstract void save(ResourceResolver resourceResolver,
-                                 Map<String, Map<String, Object>> changedResources,
-                                 Set<String> deletedResources) throws PersistenceException;
+    protected abstract void saveInternalResources(ResourceResolver resourceResolver,
+                                                  Map<String, Map<String, Object>> changedResources,
+                                                  Set<String> deletedResources) throws PersistenceException;
 
 
 }

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/common/AbstractReadableResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/common/AbstractReadableResourceProvider.java?rev=1748558&r1=1748557&r2=1748558&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/common/AbstractReadableResourceProvider.java (original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/common/AbstractReadableResourceProvider.java Wed Jun 15 11:20:25 2016
@@ -76,7 +76,8 @@ public abstract class AbstractReadableRe
 
         Resource resource = null;
 
-        Map<String, Object> properties = getMainResourceProperties(pathInfo);
+        Map<String, Object> properties = getResourceProperties(resourceResolver,  pathInfo);
+
 
         if (properties != null) {
             Object adaptable = properties.remove(INTERNAL_ADAPTABLE);
@@ -88,12 +89,6 @@ public abstract class AbstractReadableRe
         return resource;
     }
 
-    protected Map<String, Object> getMainResourceProperties(SimplePathInfo pathInfo) {
-
-        return getResourceProperties(pathInfo);
-    }
-
-
 
     Resource buildMainResource(ResourceResolver resourceResolver,
                                SimplePathInfo pathInfo,
@@ -143,11 +138,11 @@ public abstract class AbstractReadableRe
         }
 
         List<Resource> resourceList = new ArrayList<Resource>();
-        Iterable<String> childrenList = getResourceChildren(pathInfo);
+        Iterable<String> childrenList = getResourceChildren(resourceResolver, pathInfo);
         Iterator<Map<String,Object>> childrenProperties = null;
 
         if (childrenList == null) {
-            Map<String, Object> properties = getResourceProperties(pathInfo);
+            Map<String, Object> properties = getResourceProperties(resourceResolver, pathInfo);
 
             if (properties != null && properties.containsKey(ITEMS)
                     && properties.get(ITEMS) instanceof String[]) {
@@ -175,8 +170,19 @@ public abstract class AbstractReadableRe
     }
 
 
-    protected abstract Map<String, Object> getResourceProperties(SimplePathInfo pathInfo);
+    protected Map<String, Object> getResourceProperties(ResourceResolver resolver, SimplePathInfo pathInfo) {
+        return getInternalResourceProperties(resolver, pathInfo);
+    }
+
+    protected Iterable<String> getResourceChildren(ResourceResolver resolver, SimplePathInfo pathInfo) {
+        return getInternalResourceChildren(resolver, pathInfo);
+    }
+
+
+
+
+    protected abstract Map<String, Object> getInternalResourceProperties(ResourceResolver resolver, SimplePathInfo pathInfo);
 
-    protected abstract Iterable<String> getResourceChildren(SimplePathInfo pathInfo);
+    protected abstract Iterable<String> getInternalResourceChildren(ResourceResolver resolver, SimplePathInfo pathInfo);
 
 }

Modified: sling/trunk/contrib/extensions/distribution/it/src/test/java/org/apache/sling/distribution/it/DistributionAgentResourcesIntegrationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/it/src/test/java/org/apache/sling/distribution/it/DistributionAgentResourcesIntegrationTest.java?rev=1748558&r1=1748557&r2=1748558&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/it/src/test/java/org/apache/sling/distribution/it/DistributionAgentResourcesIntegrationTest.java (original)
+++ sling/trunk/contrib/extensions/distribution/it/src/test/java/org/apache/sling/distribution/it/DistributionAgentResourcesIntegrationTest.java Wed Jun 15 11:20:25 2016
@@ -163,6 +163,25 @@ public class DistributionAgentResourcesI
     }
 
 
+
+    @Test
+    public void testAgentConfigurationResourceExtended() throws Exception {
+        String agentName = "sample-create-config" + UUID.randomUUID();
+        String newConfigResource = authorAgentConfigUrl(agentName);
+
+        authorClient.createNode(newConfigResource, "name", agentName, "type", "forward", "etc.enabled", "true");
+        assertExists(authorClient, newConfigResource);
+        assertExists(authorClient, "/etc/distribution/" + agentName);
+        assertResponseContains(author, newConfigResource,
+                "sling:resourceType", "sling/distribution/setting",
+                "name", agentName);
+
+        deleteNode(author, newConfigResource);
+        assertNotExists(authorClient, newConfigResource);
+        assertNotExists(authorClient, "/etc/distribution/" + agentName);
+    }
+
+
     @Test
     @Ignore
     public void testAgentConfigurationResourceUpdate() throws Exception {

Modified: sling/trunk/contrib/extensions/distribution/sample/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/sample/pom.xml?rev=1748558&r1=1748557&r2=1748558&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/sample/pom.xml (original)
+++ sling/trunk/contrib/extensions/distribution/sample/pom.xml Wed Jun 15 11:20:25 2016
@@ -69,7 +69,8 @@
                         <Bundle-SymbolicName>org.apache.sling.distribution.sample</Bundle-SymbolicName>
                         <Sling-Initial-Content>
                             SLING-CONTENT/libs/sling/distribution;path:=/libs/sling/distribution;overwrite:=true,
-                            SLING-CONTENT/var/sling/distribution;path:=/var/sling/distribution;overwrite:=true
+                            SLING-CONTENT/var/sling/distribution;path:=/var/sling/distribution;overwrite:=true,
+                            SLING-CONTENT/etc/distribution;path:=/etc/distribution;overwrite:=true
                         </Sling-Initial-Content>
                     </instructions>
                 </configuration>

Modified: sling/trunk/contrib/extensions/distribution/sample/src/main/java/org/apache/sling/distribution/test/Init.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/sample/src/main/java/org/apache/sling/distribution/test/Init.java?rev=1748558&r1=1748557&r2=1748558&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/sample/src/main/java/org/apache/sling/distribution/test/Init.java (original)
+++ sling/trunk/contrib/extensions/distribution/sample/src/main/java/org/apache/sling/distribution/test/Init.java Wed Jun 15 11:20:25 2016
@@ -78,6 +78,7 @@ public class Init {
                 AccessControlUtils.addAccessControlEntry(session, "/var/sling/distribution/packages", distributorUser.getPrincipal(), new String[]{ Privilege.JCR_ALL }, true);
                 AccessControlUtils.addAccessControlEntry(session, "/content", distributorUser.getPrincipal(), new String[]{ Privilege.JCR_ALL }, true);
                 AccessControlUtils.addAccessControlEntry(session, "/libs/sling/distribution", distributorUser.getPrincipal(), new String[]{ Privilege.JCR_ALL }, true);
+                AccessControlUtils.addAccessControlEntry(session, "/etc/distribution", distributorUser.getPrincipal(), new String[]{ Privilege.JCR_ALL }, true);
 
                 AccessControlUtils.addAccessControlEntry(session, null, distributorUser.getPrincipal(), new String[]{ Privilege.JCR_ALL }, true);
 

Added: sling/trunk/contrib/extensions/distribution/sample/src/main/resources/SLING-CONTENT/etc/distribution.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/sample/src/main/resources/SLING-CONTENT/etc/distribution.json?rev=1748558&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/distribution/sample/src/main/resources/SLING-CONTENT/etc/distribution.json (added)
+++ sling/trunk/contrib/extensions/distribution/sample/src/main/resources/SLING-CONTENT/etc/distribution.json Wed Jun 15 11:20:25 2016
@@ -0,0 +1,3 @@
+{
+  "jcr:primaryType": "sling:Folder"
+}
\ No newline at end of file

Added: sling/trunk/contrib/extensions/distribution/sample/src/main/resources/SLING-CONTENT/libs/sling/distribution/org.apache.sling.distribution.component.impl.DistributionConfigurationManager.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/sample/src/main/resources/SLING-CONTENT/libs/sling/distribution/org.apache.sling.distribution.component.impl.DistributionConfigurationManager.json?rev=1748558&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/distribution/sample/src/main/resources/SLING-CONTENT/libs/sling/distribution/org.apache.sling.distribution.component.impl.DistributionConfigurationManager.json (added)
+++ sling/trunk/contrib/extensions/distribution/sample/src/main/resources/SLING-CONTENT/libs/sling/distribution/org.apache.sling.distribution.component.impl.DistributionConfigurationManager.json Wed Jun 15 11:20:25 2016
@@ -0,0 +1,4 @@
+{
+    "jcr:primaryType": "sling:OsgiConfig",
+    "resource.config.enabled": true
+}
\ No newline at end of file



Mime
View raw message