You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by da...@apache.org on 2018/07/04 10:55:55 UTC

[sling-whiteboard] branch master updated: Initial implementation of a Feature Service

This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 23c526c  Initial implementation of a Feature Service
23c526c is described below

commit 23c526c2e54dfc33b7ee4d5fcca56764e6d04a15
Author: David Bosschaert <da...@gmail.com>
AuthorDate: Wed Jul 4 11:55:30 2018 +0100

    Initial implementation of a Feature Service
---
 .../sling/feature/service/FeatureService.java      |  2 +-
 .../feature/service/impl/FeatureServiceImpl.java   | 31 +++++++++++++++++++++-
 .../service/impl/FeatureServiceImplTest.java       | 28 ++++++++++++++++++-
 .../feature/whitelist/impl/ResolverHookImpl.java   |  4 +--
 4 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/FeatureService.java b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/FeatureService.java
index a9fe2de..97cdf4c 100644
--- a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/FeatureService.java
+++ b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/FeatureService.java
@@ -24,5 +24,5 @@ import java.util.Collection;
 
 public interface FeatureService {
     Collection<Feature> listFeatures();
-    Feature getFeature(long bundleId);
+    Feature getFeatureForBundle(long bundleId);
 }
diff --git a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeatureServiceImpl.java b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeatureServiceImpl.java
index cf138ae..a551343 100644
--- a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeatureServiceImpl.java
+++ b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeatureServiceImpl.java
@@ -18,6 +18,35 @@
  */
 package org.apache.sling.feature.service.impl;
 
-public class FeatureServiceImpl {
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.service.FeatureService;
 
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class FeatureServiceImpl implements FeatureService {
+    private final Set<Feature> features;
+    private final Map<Long, Feature> bundleFeatureMap;
+
+    FeatureServiceImpl(Map<Long, Feature> bundleIDFeatures) {
+        Map<Long, Feature> bfm = new HashMap<>(bundleIDFeatures);
+        bundleFeatureMap = Collections.unmodifiableMap(bfm);
+
+        Set<Feature> fs = new HashSet<>(bundleIDFeatures.values());
+        features = Collections.unmodifiableSet(fs);
+    }
+
+    @Override
+    public Collection<Feature> listFeatures() {
+        return features;
+    }
+
+    @Override
+    public Feature getFeatureForBundle(long bundleId) {
+        return bundleFeatureMap.get(bundleId);
+    }
 }
diff --git a/featuremodel/feature-service/src/test/java/org/apache/sling/feature/service/impl/FeatureServiceImplTest.java b/featuremodel/feature-service/src/test/java/org/apache/sling/feature/service/impl/FeatureServiceImplTest.java
index 6b6e486..7e15e07 100644
--- a/featuremodel/feature-service/src/test/java/org/apache/sling/feature/service/impl/FeatureServiceImplTest.java
+++ b/featuremodel/feature-service/src/test/java/org/apache/sling/feature/service/impl/FeatureServiceImplTest.java
@@ -18,11 +18,37 @@
  */
 package org.apache.sling.feature.service.impl;
 
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.service.FeatureService;
 import org.junit.Test;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
 public class FeatureServiceImplTest {
     @Test
     public void testFeatureService() {
-//        fail();
+        Map<Long, Feature> bif = new HashMap<>();
+
+        ArtifactId aid1 = new ArtifactId("gid", "aid", "1.0.0", "myfeature", "slingfeature");
+        Feature f1 = new Feature(aid1);
+        bif.put(123L, f1);
+        bif.put(456L, f1);
+
+        ArtifactId aid2 = new ArtifactId("gid", "aid", "1.0.0", "myotherfeature", "slingfeature");
+        Feature f2 = new Feature(aid2);
+        bif.put(789L, f2);
+
+        FeatureService fs = new FeatureServiceImpl(bif);
+        assertEquals(2, fs.listFeatures().size());
+
+        assertEquals(f1, fs.getFeatureForBundle(123));
+        assertEquals(f1, fs.getFeatureForBundle(456));
+        assertEquals(f2, fs.getFeatureForBundle(789));
+        assertNull(fs.getFeatureForBundle(999));
     }
 }
diff --git a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/ResolverHookImpl.java b/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/ResolverHookImpl.java
index 0c7e1a0..6327951 100644
--- a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/ResolverHookImpl.java
+++ b/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/ResolverHookImpl.java
@@ -71,7 +71,7 @@ public class ResolverHookImpl implements ResolverHook {
                 return;
             }
 
-            Feature reqFeat = fs.getFeature(reqBundleID);
+            Feature reqFeat = fs.getFeatureForBundle(reqBundleID);
             Set<String> regions = whitelistService.listRegions(reqFeat.getId().toMvnId());
 
             nextCapability:
@@ -85,7 +85,7 @@ public class ResolverHookImpl implements ResolverHook {
                 if (capBundleID == reqBundleID)
                     continue nextCapability;
 
-                Feature capFeat = fs.getFeature(capBundleID);
+                Feature capFeat = fs.getFeatureForBundle(capBundleID);
 
                 // Within a single feature everything can wire to everything else
                 if (capFeat.equals(reqFeat))