← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21023: JCloudsFileResourceContentStore, using enums for configuration properties

 

------------------------------------------------------------
revno: 21023
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-11-11 00:04:08 +0100
message:
  JCloudsFileResourceContentStore, using enums for configuration properties
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/JCloudsFileResourceContentStore.java
  dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/ConfigurationKey.java
  dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/DefaultDhisConfigurationProvider.java
  dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/DhisConfigurationProvider.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/JCloudsFileResourceContentStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/JCloudsFileResourceContentStore.java	2015-11-10 18:26:21 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/JCloudsFileResourceContentStore.java	2015-11-10 23:04:08 +0000
@@ -34,6 +34,7 @@
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.external.conf.ConfigurationKey;
 import org.hisp.dhis.external.conf.DhisConfigurationProvider;
 import org.hisp.dhis.external.location.LocationManager;
 import org.jclouds.ContextBuilder;
@@ -58,7 +59,6 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Map;
 import java.util.Optional;
 import java.util.Properties;
 import java.util.regex.Pattern;
@@ -95,18 +95,6 @@
     }};
 
     // -------------------------------------------------------------------------
-    // Property keys
-    // -------------------------------------------------------------------------
-
-    private static final String FILE_STORE_CONFIG_NAMESPACE = "filestore";
-
-    private static final String KEY_FILE_STORE_PROVIDER  = FILE_STORE_CONFIG_NAMESPACE + ".provider";
-    private static final String KEY_FILE_STORE_CONTAINER = FILE_STORE_CONFIG_NAMESPACE + ".container";
-    private static final String KEY_FILE_STORE_LOCATION  = FILE_STORE_CONFIG_NAMESPACE + ".location";
-    private static final String KEY_FILE_STORE_IDENTITY  = FILE_STORE_CONFIG_NAMESPACE + ".identity";
-    private static final String KEY_FILE_STORE_SECRET    = FILE_STORE_CONFIG_NAMESPACE + ".secret";
-
-    // -------------------------------------------------------------------------
     // Defaults
     // -------------------------------------------------------------------------
 
@@ -140,12 +128,10 @@
         // Parse properties
         // ---------------------------------------------------------------------
 
-        Map<String, String> fileStoreConfiguration = configurationProvider.getProperties( FILE_STORE_CONFIG_NAMESPACE );
-
-        String provider = fileStoreConfiguration.getOrDefault( KEY_FILE_STORE_PROVIDER, JCLOUDS_PROVIDER_KEY_FILESYSTEM );
+        String provider = configurationProvider.getProperty( ConfigurationKey.FILESTORE_PROVIDER );
         provider = validateAndSelectProvider( provider );
 
-        container = fileStoreConfiguration.get( KEY_FILE_STORE_CONTAINER );
+        container = configurationProvider.getProperty( ConfigurationKey.FILE_STORE_CONTAINER );
 
         if ( !isValidContainerName( container ) )
         {
@@ -159,7 +145,9 @@
             container = DEFAULT_CONTAINER;
         }
 
-        String location = fileStoreConfiguration.get( KEY_FILE_STORE_LOCATION );
+        String location = configurationProvider.getProperty( ConfigurationKey.FILE_STORE_LOCATION );
+        String identity = configurationProvider.getProperty( ConfigurationKey.FILE_STORE_IDENTITY );
+        String secret = configurationProvider.getProperty( ConfigurationKey.FILE_STORE_SECRET );
 
         Properties overrides = new Properties();
 
@@ -175,8 +163,7 @@
         }
         else if ( provider.equals( JCLOUDS_PROVIDER_KEY_AWS_S3 ) )
         {
-            credentials = new Credentials( fileStoreConfiguration.getOrDefault(
-                KEY_FILE_STORE_IDENTITY, StringUtils.EMPTY ), fileStoreConfiguration.getOrDefault( KEY_FILE_STORE_SECRET, StringUtils.EMPTY ) );
+            credentials = new Credentials( identity, secret );
 
             if ( credentials.identity.isEmpty() || credentials.credential.isEmpty() )
             {

=== modified file 'dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/ConfigurationKey.java'
--- dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/ConfigurationKey.java	2015-11-10 17:36:28 +0000
+++ dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/ConfigurationKey.java	2015-11-10 23:04:08 +0000
@@ -1,5 +1,7 @@
 package org.hisp.dhis.external.conf;
 
+import org.apache.commons.lang3.StringUtils;
+
 /*
  * Copyright (c) 2004-2015, University of Oslo
  * All rights reserved.
@@ -48,8 +50,8 @@
     FILESTORE_PROVIDER( "filestore.provider", "filesystem" ),
     FILE_STORE_CONTAINER( "filestore.container" ),
     FILE_STORE_LOCATION( "filestore.location" ),
-    FILE_STORE_IDENTITY( "filestore.identity" ),
-    FILE_STORE_SECRET( "filestore.secret" );
+    FILE_STORE_IDENTITY( "filestore.identity", StringUtils.EMPTY ),
+    FILE_STORE_SECRET( "filestore.secret", StringUtils.EMPTY );
 
     private final String key;
     

=== modified file 'dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/DefaultDhisConfigurationProvider.java'
--- dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/DefaultDhisConfigurationProvider.java	2015-11-10 18:15:10 +0000
+++ dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/DefaultDhisConfigurationProvider.java	2015-11-10 23:04:08 +0000
@@ -30,8 +30,6 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
 import java.util.Properties;
 
 import org.apache.commons.logging.Log;
@@ -39,8 +37,6 @@
 import org.hisp.dhis.external.location.LocationManager;
 import org.hisp.dhis.external.location.LocationManagerException;
 
-import com.google.common.collect.ImmutableMap;
-
 /**
  * @author Lars Helge Overland
  */
@@ -117,24 +113,6 @@
     }
 
     @Override
-    public Map<String, String> getProperties( String keyBase )
-    {
-        Properties properties = getProperties();
-        
-        Map<String, String> map = new HashMap<>();
-        
-        for ( String key : properties.stringPropertyNames() )
-        {
-            if ( key != null && key.startsWith( keyBase ) )
-            {
-                map.put( key, properties.getProperty( key ) );
-            }
-        }
-        
-        return ImmutableMap.copyOf( map );
-    }
-    
-    @Override
     public String getProperty( ConfigurationKey key  )
     {
         return properties.getProperty( key.getKey(), key.getDefaultValue() );

=== modified file 'dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/DhisConfigurationProvider.java'
--- dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/DhisConfigurationProvider.java	2015-11-10 18:15:10 +0000
+++ dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/DhisConfigurationProvider.java	2015-11-10 23:04:08 +0000
@@ -1,7 +1,5 @@
 package org.hisp.dhis.external.conf;
 
-import java.util.Map;
-
 /*
  * Copyright (c) 2004-2015, University of Oslo
  * All rights reserved.
@@ -48,15 +46,6 @@
     Properties getProperties();
     
     /**
-     * Get configuration as an immutable map. The maps contains only properties 
-     * which keys are starting with the given key base.
-     * 
-     * @param keyBase the base for properties to include.
-     * @return an immutable map of the properties.
-     */
-    Map<String, String> getProperties( String keyBase );
-    
-    /**
      * Get the property value for the given key, or the default value for the
      * configuration key if not exists.
      *