You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2019/05/16 15:03:42 UTC

[isis] branch 2112_SpringBoot updated: ISIS-2112: utilizing Spring's @PropertySource with 'Presets'

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

ahuber pushed a commit to branch 2112_SpringBoot
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/2112_SpringBoot by this push:
     new 6f5b5cf  ISIS-2112: utilizing Spring's @PropertySource with 'Presets'
6f5b5cf is described below

commit 6f5b5cfefd3fa7a3d9c6a6e73510e3b071c31f39
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu May 16 17:03:36 2019 +0200

    ISIS-2112: utilizing Spring's @PropertySource with 'Presets'
    
    - however still some boilerplate ...
    
    @Configuration
    @PropertySources({
        @PropertySource("classpath:/domainapp/application/isis-non-changing.properties"),
        @PropertySource(name=Presets.H2InMemory, factory =
    Presets.Factory.class, value = { "" })
    })
    public class HelloWorldAppManifest {
    	...
    }
    
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-2112
---
 .../main/java/org/apache/isis/config/Presets.java  | 109 +++++++++++++++++++++
 .../core/metamodel/facetapi/MetaModelRefiner.java  |  15 +--
 .../application/HelloWorldAppManifest.java         |   7 +-
 .../application/isis-non-changing.properties       |   5 -
 4 files changed, 118 insertions(+), 18 deletions(-)

diff --git a/core/config/src/main/java/org/apache/isis/config/Presets.java b/core/config/src/main/java/org/apache/isis/config/Presets.java
new file mode 100644
index 0000000..b356950
--- /dev/null
+++ b/core/config/src/main/java/org/apache/isis/config/Presets.java
@@ -0,0 +1,109 @@
+/*
+ *  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.isis.config;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Consumer;
+
+import org.springframework.core.env.MapPropertySource;
+import org.springframework.core.env.PropertySource;
+import org.springframework.core.io.support.EncodedResource;
+import org.springframework.core.io.support.PropertySourceFactory;
+
+import org.apache.isis.applib.AppManifest;
+
+import lombok.val;
+
+/**
+ * Introduced to support Spring's {@code @PrepertySource} annotation.
+ * 
+ * @since 2.0.0
+ *
+ */
+public final class Presets  {
+
+    private static enum Providers implements Consumer<Map<String, String>> {
+    
+        H2InMemory {
+    
+            @Override
+            public void accept(Map<String, String> map) {
+                AppManifest.Presets.withH2InMemoryProperties(map);
+            }
+            
+        },
+        
+        HsqlDbInMemory {
+    
+            @Override
+            public void accept(Map<String, String> map) {
+                AppManifest.Presets.withHsqlDbInMemoryProperties(map);
+            }
+            
+        },
+        
+        DataNucleus {
+    
+            @Override
+            public void accept(Map<String, String> map) {
+                AppManifest.Presets.withDataNucleusProperties(map);
+            }
+            
+        },
+        
+        IsisIntegTest {
+    
+            @Override
+            public void accept(Map<String, String> map) {
+                AppManifest.Presets.withIsisIntegTestProperties(map);
+            }
+            
+        },
+    
+    }
+    
+    public static final String H2InMemory = "H2InMemory";
+    public static final String HsqlDbInMemory = "HsqlDbInMemory";
+    public static final String DataNucleus = "DataNucleus";
+    public static final String IsisIntegTest = "IsisIntegTest";
+    
+    
+    public static class Factory implements PropertySourceFactory {
+
+        @Override
+        public PropertySource<?> createPropertySource(
+                String name,
+                EncodedResource resource) throws IOException {
+            
+            val map = new HashMap<String, String>(); 
+            Providers.valueOf(name).accept(map);
+            
+            val widenedMap = new HashMap<String, Object>();
+            widenedMap.putAll(map);
+            
+            val propSource = new MapPropertySource(name, widenedMap);
+            
+            return propSource;
+        }
+       
+    }
+    
+}
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/MetaModelRefiner.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/MetaModelRefiner.java
index f8f6661..191006a 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/MetaModelRefiner.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facetapi/MetaModelRefiner.java
@@ -19,15 +19,11 @@
 
 package org.apache.isis.core.metamodel.facetapi;
 
-import java.util.List;
-import java.util.stream.Collectors;
-
 import org.apache.isis.applib.services.registry.ServiceRegistry;
+import org.apache.isis.core.commons.collections.Bin;
 import org.apache.isis.core.metamodel.progmodel.ProgrammingModel;
 import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidator;
 
-import lombok.val;
-
 
 /**
  * Provides the ability for components to inform/alter/adjust/refine the metamodel
@@ -41,13 +37,8 @@ public interface MetaModelRefiner extends MetaModelValidatorRefiner {
 
     // -- LOOKUP ALL REFINERS
     
-	static List<MetaModelRefiner> getAll(ServiceRegistry serviceRegistry) {
-		
-		val refiners = serviceRegistry.select(MetaModelRefiner.class)
-				.stream()
-				.collect(Collectors.toList());
-		
-		return refiners;
+	static Bin<MetaModelRefiner> getAll(ServiceRegistry serviceRegistry) {
+		return serviceRegistry.select(MetaModelRefiner.class);
 	}
 
 }
diff --git a/example/application/helloworld/src/main/java/domainapp/application/HelloWorldAppManifest.java b/example/application/helloworld/src/main/java/domainapp/application/HelloWorldAppManifest.java
index 38dfb66..3ff69b2 100644
--- a/example/application/helloworld/src/main/java/domainapp/application/HelloWorldAppManifest.java
+++ b/example/application/helloworld/src/main/java/domainapp/application/HelloWorldAppManifest.java
@@ -23,9 +23,11 @@ import javax.inject.Singleton;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.PropertySource;
+import org.springframework.context.annotation.PropertySources;
 import org.springframework.core.io.ClassPathResource;
 
 import org.apache.isis.config.IsisConfiguration;
+import org.apache.isis.config.Presets;
 import org.apache.isis.config.beans.WebAppConfigBean;
 import org.apache.isis.config.internal._Config;
 import org.apache.isis.core.runtime.authorization.standard.AuthorizationManagerStandard;
@@ -40,7 +42,10 @@ import org.apache.isis.core.security.authorization.standard.Authorizor;
  * Bootstrap the application.
  */
 @Configuration
-@PropertySource("classpath:/domainapp/application/isis-non-changing.properties")
+@PropertySources({
+    @PropertySource("classpath:/domainapp/application/isis-non-changing.properties"),
+    @PropertySource(name=Presets.H2InMemory, factory = Presets.Factory.class, value = { "" })
+})
 public class HelloWorldAppManifest {
     
     @Bean @Singleton
diff --git a/example/application/helloworld/src/main/java/domainapp/application/isis-non-changing.properties b/example/application/helloworld/src/main/java/domainapp/application/isis-non-changing.properties
index 463d7d4..e9fdba6 100644
--- a/example/application/helloworld/src/main/java/domainapp/application/isis-non-changing.properties
+++ b/example/application/helloworld/src/main/java/domainapp/application/isis-non-changing.properties
@@ -15,11 +15,6 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-
-# -- auto wired by plugins --
-#isis.services.eventbus.implementation=guava
-#isis.services.eventbus.implementation=axon
-
 isis.reflector.validator.allowDeprecated=false
 isis.reflector.validator.noParamsOnly=true
 isis.reflector.validator.explicitObjectType=true