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

danhaywood pushed a commit to branch CAUSEWAY-3669
in repository https://gitbox.apache.org/repos/asf/causeway.git

commit d9d1ed4a1a6ff95e8bc4e49bd47df744cc293c7d
Author: danhaywood <[email protected]>
AuthorDate: Mon Jan 15 13:05:08 2024 +0000

    CAUSEWAY-3669: adds CausewayConfiguration#streamConfigurationPropertyNames
    
    and refactors ConfigurationViewServiceDefault to use
---
 .../core/config/CausewayConfiguration.java         | 36 ++++++++++++++++++++++
 .../confmenu/ConfigurationViewServiceDefault.java  | 21 +++----------
 2 files changed, 40 insertions(+), 17 deletions(-)

diff --git 
a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
 
b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
index 2244a195e4..9a3c730941 100644
--- 
a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
+++ 
b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
@@ -34,6 +34,8 @@ import java.util.Objects;
 import java.util.Optional;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
 
 import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
 import static java.lang.annotation.ElementType.FIELD;
@@ -59,6 +61,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.boot.info.BuildProperties;
 import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.MapPropertySource;
+import org.springframework.core.env.MutablePropertySources;
 import org.springframework.validation.annotation.Validated;
 
 import org.apache.causeway.applib.CausewayModuleApplib;
@@ -156,6 +161,37 @@ public class CausewayConfiguration {
         this.buildProperties = buildProperties;
     }
 
+
+    /**
+     * All known configuration property names.
+     *
+     * <p>
+     *     Or at least, from the {@link 
org.springframework.core.env.PropertySource} obtained from
+     *     {@link ConfigurableEnvironment#getPropertySources()} that are also 
{@link EnumerablePropertySource}s.
+     * </p>
+     * @return
+     */
+    public Stream<String> streamConfigurationPropertyNames() {
+        MutablePropertySources propertySources = 
environment.getPropertySources();
+        return StreamSupport
+                .stream(propertySources.spliterator(), false)
+                .filter(EnumerablePropertySource.class::isInstance)
+                .map(EnumerablePropertySource.class::cast)
+                
.filter(ps->!"systemEnvironment".equalsIgnoreCase(ps.getName())) // exclude 
system env
+                .map(EnumerablePropertySource::getPropertyNames)
+                .flatMap(_NullSafe::stream);
+    }
+
+    /**
+     * The value of a specific configuration property
+     *
+     * @param configurationPropertyName  - eg as obtained from {@link 
#streamConfigurationPropertyNames()}.
+     */
+    public Optional<String> valueOf(String configurationPropertyName) {
+        return 
Optional.ofNullable(environment.getProperty(configurationPropertyName));
+    }
+
+
     private final Security security = new Security();
     @Data
     public static class Security {
diff --git 
a/core/webapp/src/main/java/org/apache/causeway/core/webapp/confmenu/ConfigurationViewServiceDefault.java
 
b/core/webapp/src/main/java/org/apache/causeway/core/webapp/confmenu/ConfigurationViewServiceDefault.java
index 14e958be31..06f9a27bb1 100644
--- 
a/core/webapp/src/main/java/org/apache/causeway/core/webapp/confmenu/ConfigurationViewServiceDefault.java
+++ 
b/core/webapp/src/main/java/org/apache/causeway/core/webapp/confmenu/ConfigurationViewServiceDefault.java
@@ -195,11 +195,10 @@ implements
     private Map<String, ConfigurationProperty> loadPrimary(final List<String> 
primaryPrefixes) {
         final Map<String, ConfigurationProperty> map = _Maps.newTreeMap();
         if(isShowConfigurationProperties()) {
-            final ConfigurableEnvironment springEnv = 
configuration.getEnvironment();
-            streamConfigurationPropertyNames(springEnv)
+            configuration.streamConfigurationPropertyNames()
             
.filter(propName->primaryPrefixes.stream().anyMatch(propName::startsWith))
             .forEach(propName -> {
-                String propertyValue = springEnv.getProperty(propName);
+                String propertyValue = 
configuration.valueOf(propName).orElse(null);
                 add(propName, propertyValue, map);
             });
 
@@ -222,11 +221,10 @@ implements
     private Map<String, ConfigurationProperty> loadSecondary(final Set<String> 
toBeExcluded) {
         final Map<String, ConfigurationProperty> map = _Maps.newTreeMap();
         if(isShowConfigurationProperties()) {
-            final ConfigurableEnvironment springEnv = 
configuration.getEnvironment();
-            streamConfigurationPropertyNames(springEnv)
+            configuration.streamConfigurationPropertyNames()
             .filter(propName->!toBeExcluded.contains(propName))
             .forEach(propName -> {
-                String propertyValue = springEnv.getProperty(propName);
+                String propertyValue = 
configuration.valueOf(propName).orElse(null);
                 add(propName, propertyValue, map);
             });
 
@@ -267,15 +265,4 @@ implements
                 .orElseGet(()->new 
CausewayConfiguration.Core.Config().getConfigurationPropertyVisibilityPolicy());
     }
 
-    private static Stream<String> streamConfigurationPropertyNames(final 
ConfigurableEnvironment springEnv) {
-        MutablePropertySources propertySources = 
springEnv.getPropertySources();
-            return StreamSupport
-            .stream(propertySources.spliterator(), false)
-            .filter(EnumerablePropertySource.class::isInstance)
-            .map(EnumerablePropertySource.class::cast)
-            .filter(ps->!"systemEnvironment".equalsIgnoreCase(ps.getName())) 
// exclude system env
-            .map(EnumerablePropertySource::getPropertyNames)
-            .flatMap(_NullSafe::stream);
-    }
-
 }

Reply via email to