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

cziegeler pushed a commit to branch issues/SLING-11900
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-event.git


The following commit(s) were added to refs/heads/issues/SLING-11900 by this 
push:
     new 3d9f67f  SLING-11900 : Provide alternative terminology for inequitable 
terms
3d9f67f is described below

commit 3d9f67f58bad92c55bbe281fae27309951b32476
Author: Carsten Ziegeler <cziege...@apache.org>
AuthorDate: Sun Jun 4 14:44:19 2023 +0200

    SLING-11900 : Provide alternative terminology for inequitable terms
---
 .../sling/event/impl/jobs/JobConsumerManager.java  | 71 +++++++++++++++++-----
 .../event/impl/jobs/JobConsumerManagerTest.java    | 37 ++++++++---
 2 files changed, 85 insertions(+), 23 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/event/impl/jobs/JobConsumerManager.java 
b/src/main/java/org/apache/sling/event/impl/jobs/JobConsumerManager.java
index 5aa4eb3..1682104 100644
--- a/src/main/java/org/apache/sling/event/impl/jobs/JobConsumerManager.java
+++ b/src/main/java/org/apache/sling/event/impl/jobs/JobConsumerManager.java
@@ -76,18 +76,23 @@ public class JobConsumerManager {
                     + "only used on the current instance. This option should 
always be disabled!")
         boolean org_apache_sling_installer_configuration_persist() default 
false;
 
-        @AttributeDefinition(name = "Topic Whitelist",
+        @AttributeDefinition(name = "Topic Allow List",
               description="This is a list of topics which currently should be "
                         + "processed by this instance. Leaving it empty, all 
job consumers are disabled. Putting a '*' as "
                         + "one entry, enables all job consumers. Adding 
separate topics enables job consumers for exactly "
                         + "this topic.")
-        String[] job_consumermanager_whitelist() default "*";
+        String[] job_consumermanager_allowlist();
 
-        @AttributeDefinition(name = "Topic Blacklist",
+        @AttributeDefinition(name = "Topic Deny List",
               description="This is a list of topics which currently shouldn't 
be "
                         + "processed by this instance. Leaving it empty, all 
job consumers are enabled. Putting a '*' as "
                         + "one entry, disables all job consumers. Adding 
separate topics disables job consumers for exactly "
                         + "this topic.")
+        String[] job_consumermanager_denylist();
+    }
+
+    public @interface DeprecatedConfig {
+        String[] job_consumermanager_whitelist();
         String[] job_consumermanager_blacklist();
     }
 
@@ -101,9 +106,9 @@ public class JobConsumerManager {
 
     private String topics;
 
-    private TopicMatcher[] whitelistMatchers;
+    private TopicMatcher[] allowListMatchers;
 
-    private TopicMatcher[] blacklistMatchers;
+    private TopicMatcher[] denyListMatchers;
 
     private volatile long changeCount;
 
@@ -123,18 +128,54 @@ public class JobConsumerManager {
     }
 
     @Activate
-    protected void activate(final BundleContext bc, final Config config) {
+    protected void activate(final BundleContext bc, final Config config, final 
DeprecatedConfig deprecatedConfig) {
         this.bundleContext = bc;
-        this.modified(bc, config);
+        this.modified(bc, config, deprecatedConfig);
+    }
+
+    private boolean isDefined(final String[] value) {
+        return value != null && value.length > 0;
+    }
+
+    private String[] getAllowListConfig(final Config config, final 
DeprecatedConfig deprecatedConfig) {
+        if (isDefined(config.job_consumermanager_allowlist()) && 
isDefined(deprecatedConfig.job_consumermanager_whitelist()) ) {
+            logger.error("Both properties, job.consumermanager.allowlist and 
job.consumermanager.whitelist"
+                + ", were defined. Using job.consumermanager.allowlist for 
configuring job consumers."
+                + "Please remove the other property from your configuration.");
+            return config.job_consumermanager_allowlist();
+        } else if (isDefined(config.job_consumermanager_allowlist())) {
+            return config.job_consumermanager_allowlist();
+        } else if 
(isDefined(deprecatedConfig.job_consumermanager_whitelist())) {
+            logger.warn("The property job.consumermanager.allowlist is not 
set. Using the provided property " +
+                "job.consumermanager.whitelist instead. Please update your 
configuration to use job.consumermanager.allowlist.");
+            return deprecatedConfig.job_consumermanager_whitelist();
+        }
+        return new String[] {"*"}; // default
+    }
+
+    private String[] getDenyListConfig(final Config config, final 
DeprecatedConfig deprecatedConfig) {
+        if (isDefined(config.job_consumermanager_denylist()) && 
isDefined(deprecatedConfig.job_consumermanager_blacklist()) ) {
+            logger.error("Both properties, job.consumermanager.denylist and 
job.consumermanager.blacklist"
+                + ", were defined. Using job.consumermanager.denylist for 
configuring job consumers."
+                + "Please remove the other property from your configuration.");
+            return config.job_consumermanager_denylist();
+        } else if (isDefined(config.job_consumermanager_denylist())) {
+            return config.job_consumermanager_denylist();
+        } else if 
(isDefined(deprecatedConfig.job_consumermanager_blacklist())) {
+            logger.warn("The property job.consumermanager.denylist is not set. 
Using the provided property " +
+                "job.consumermanager.blacklist instead. Please update your 
configuration to use job.consumermanager.denylist.");
+            return deprecatedConfig.job_consumermanager_blacklist();
+        }
+        return null; // default
     }
 
     @Modified
-    protected void modified(final BundleContext bc, final Config config) {
+    protected void modified(final BundleContext bc, final Config config, final 
DeprecatedConfig deprecatedConfig) {
         final boolean wasEnabled = this.propagationService != null;
-        this.whitelistMatchers = 
TopicMatcherHelper.buildMatchers(config.job_consumermanager_whitelist());
-        this.blacklistMatchers = 
TopicMatcherHelper.buildMatchers(config.job_consumermanager_blacklist());
+        this.allowListMatchers = 
TopicMatcherHelper.buildMatchers(getAllowListConfig(config, deprecatedConfig));
+        this.denyListMatchers = 
TopicMatcherHelper.buildMatchers(getDenyListConfig(config, deprecatedConfig));
 
-        final boolean enable = this.whitelistMatchers != null && 
this.blacklistMatchers != TopicMatcherHelper.MATCH_ALL;
+        final boolean enable = this.allowListMatchers != null && 
this.denyListMatchers != TopicMatcherHelper.MATCH_ALL;
         if ( wasEnabled != enable ) {
             synchronized ( this.topicToConsumerMap ) {
                 this.calculateTopics(enable);
@@ -371,10 +412,10 @@ public class JobConsumerManager {
             // is always the same for the same topics.
             final List<String> topicList = new ArrayList<>();
             for(final String topic : this.topicToConsumerMap.keySet() ) {
-                // check whitelist
-                if ( this.match(topic, this.whitelistMatchers) ) {
-                    // and blacklist
-                    if ( this.blacklistMatchers == null || !this.match(topic, 
this.blacklistMatchers) ) {
+                // check allow list
+                if ( this.match(topic, this.allowListMatchers) ) {
+                    // and deny list
+                    if ( this.denyListMatchers == null || !this.match(topic, 
this.denyListMatchers) ) {
                         topicList.add(topic);
                     }
                 }
diff --git 
a/src/test/java/org/apache/sling/event/impl/jobs/JobConsumerManagerTest.java 
b/src/test/java/org/apache/sling/event/impl/jobs/JobConsumerManagerTest.java
index a9d1b83..fb41ca3 100644
--- a/src/test/java/org/apache/sling/event/impl/jobs/JobConsumerManagerTest.java
+++ b/src/test/java/org/apache/sling/event/impl/jobs/JobConsumerManagerTest.java
@@ -48,20 +48,41 @@ public class JobConsumerManagerTest {
             }
 
             @Override
-            public String[] job_consumermanager_whitelist() {
+            public String[] job_consumermanager_allowlist() {
                 return new String[] {"*"};
             }
 
+            @Override
+            public String[] job_consumermanager_denylist() {
+                return null;
+            }
+        };
+    }
+
+    private JobConsumerManager.DeprecatedConfig getDeprecatedConfig() {
+        return new JobConsumerManager.DeprecatedConfig() {
+                
+            @Override
+            public Class<? extends Annotation> annotationType() {
+                return JobConsumerManager.DeprecatedConfig.class;
+            }
+
+            @Override
+            public String[] job_consumermanager_whitelist() {
+                return null;
+            }
+
             @Override
             public String[] job_consumermanager_blacklist() {
                 return null;
             }
         };
     }
+
     @Test public void testSimpleMappingConsumer() {
         final BundleContext bc = Mockito.mock(BundleContext.class);
         final JobConsumerManager jcs = new JobConsumerManager();
-        jcs.activate(bc, getDefaultConfig());
+        jcs.activate(bc, getDefaultConfig(), getDeprecatedConfig());
 
         final JobConsumer jc1 = Mockito.mock(JobConsumer.class);
         final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
@@ -80,7 +101,7 @@ public class JobConsumerManagerTest {
     @Test public void testCategoryMappingConsumer() {
         final BundleContext bc = Mockito.mock(BundleContext.class);
         final JobConsumerManager jcs = new JobConsumerManager();
-        jcs.activate(bc, getDefaultConfig());
+        jcs.activate(bc, getDefaultConfig(), getDeprecatedConfig());
 
         final JobConsumer jc1 = Mockito.mock(JobConsumer.class);
         final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
@@ -99,7 +120,7 @@ public class JobConsumerManagerTest {
     @Test public void testSubCategoryMappingConsumer() {
         final BundleContext bc = Mockito.mock(BundleContext.class);
         final JobConsumerManager jcs = new JobConsumerManager();
-        jcs.activate(bc, getDefaultConfig());
+        jcs.activate(bc, getDefaultConfig(), getDeprecatedConfig());
 
         final JobConsumer jc1 = Mockito.mock(JobConsumer.class);
         final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
@@ -118,7 +139,7 @@ public class JobConsumerManagerTest {
     @Test public void testSimpleMappingExecutor() {
         final BundleContext bc = Mockito.mock(BundleContext.class);
         final JobConsumerManager jcs = new JobConsumerManager();
-        jcs.activate(bc, getDefaultConfig());
+        jcs.activate(bc, getDefaultConfig(), getDeprecatedConfig());
 
         final JobExecutor jc1 = Mockito.mock(JobExecutor.class);
         final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
@@ -137,7 +158,7 @@ public class JobConsumerManagerTest {
     @Test public void testCategoryMappingExecutor() {
         final BundleContext bc = Mockito.mock(BundleContext.class);
         final JobConsumerManager jcs = new JobConsumerManager();
-        jcs.activate(bc, getDefaultConfig());
+        jcs.activate(bc, getDefaultConfig(), getDeprecatedConfig());
 
         final JobExecutor jc1 = Mockito.mock(JobExecutor.class);
         final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
@@ -156,7 +177,7 @@ public class JobConsumerManagerTest {
     @Test public void testSubCategoryMappingExecutor() {
         final BundleContext bc = Mockito.mock(BundleContext.class);
         final JobConsumerManager jcs = new JobConsumerManager();
-        jcs.activate(bc, getDefaultConfig());
+        jcs.activate(bc, getDefaultConfig(), getDeprecatedConfig());
 
         final JobExecutor jc1 = Mockito.mock(JobExecutor.class);
         final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
@@ -175,7 +196,7 @@ public class JobConsumerManagerTest {
     @Test public void testRanking() {
         final BundleContext bc = Mockito.mock(BundleContext.class);
         final JobConsumerManager jcs = new JobConsumerManager();
-        jcs.activate(bc, getDefaultConfig());
+        jcs.activate(bc, getDefaultConfig(), getDeprecatedConfig());
 
         final JobExecutor jc1 = Mockito.mock(JobExecutor.class);
         final JobExecutor jc2 = Mockito.mock(JobExecutor.class);

Reply via email to