← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21593: Removed smtp and remote instance settings/configuration from Configuration; Now to be defined in ...

 

Merge authors:
  Stian Sandvold (stian-sandvold)
------------------------------------------------------------
revno: 21593 [merge]
committer: Stian Sandvold <stian.sandvold@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2016-01-05 16:21:39 +0100
message:
  Removed smtp and remote instance settings/configuration from Configuration; Now to be defined in dhis.conf, as well as all smtp+remote instance settings(remote:url,user,password; smtp:host,user,pass,sender,tls,port); Refactored other classes to reflect these changes.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/Configuration.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/Configuration.hbm.xml
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.java
  dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/ConfigurationKey.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ConfigurationController.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-api/src/main/java/org/hisp/dhis/configuration/Configuration.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/Configuration.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/Configuration.java	2016-01-05 14:03:19 +0000
@@ -86,22 +86,6 @@
     private OrganisationUnit selfRegistrationOrgUnit;
     
     private Set<String> corsWhitelist = new HashSet<>();
-
-    // -------------------------------------------------------------------------
-    // Remote synch
-    // -------------------------------------------------------------------------
-
-    private String remoteServerUrl;
-    
-    private String remoteServerUsername;
-    
-    private String remoteServerPassword;
-
-    // -------------------------------------------------------------------------
-    // SMTP
-    // -------------------------------------------------------------------------
-    
-    private String smtpPassword;
     
     // -------------------------------------------------------------------------
     // Constructor
@@ -242,55 +226,10 @@
         this.selfRegistrationOrgUnit = selfRegistrationOrgUnit;
     }
 
-    @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public String getRemoteServerUrl()
-    {
-        return remoteServerUrl;
-    }
-
-    public void setRemoteServerUrl( String remoteServerUrl )
-    {
-        this.remoteServerUrl = remoteServerUrl;
-    }
-
-    @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public String getRemoteServerUsername()
-    {
-        return remoteServerUsername;
-    }
-
-    public void setRemoteServerUsername( String remoteServerUsername )
-    {
-        this.remoteServerUsername = remoteServerUsername;
-    }
-
-    /**
-     * Do not serialize.
-     */
-    public String getRemoteServerPassword()
-    {
-        return remoteServerPassword;
-    }
-
-    public void setRemoteServerPassword( String remoteServerPassword )
-    {
-        this.remoteServerPassword = remoteServerPassword;
-    }
-
-    /**
-     * Do not serialize.
-     */
-    public String getSmtpPassword()
-    {
-        return smtpPassword;
-    }
-    
-    public void setSmtpPassword( String smtpPassword )
-    {
-        this.smtpPassword = smtpPassword;
-    }
+
+    /**
+     * Do not serialize.
+     */
 
     @JsonProperty
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java	2016-01-05 14:03:19 +0000
@@ -41,6 +41,8 @@
 import org.apache.commons.mail.HtmlEmail;
 import org.hisp.dhis.commons.util.DebugUtils;
 import org.hisp.dhis.configuration.ConfigurationService;
+import org.hisp.dhis.external.conf.ConfigurationKey;
+import org.hisp.dhis.external.conf.DhisConfigurationProvider;
 import org.hisp.dhis.setting.SettingKey;
 import org.hisp.dhis.setting.SystemSettingManager;
 import org.hisp.dhis.system.velocity.VelocityManager;
@@ -81,12 +83,12 @@
     {
         this.systemSettingManager = systemSettingManager;
     }
-    
-    private ConfigurationService configurationService;
-    
-    public void setConfigurationService( ConfigurationService configurationService )
+
+    private DhisConfigurationProvider dhisConfigurationProvider;
+
+    public void setDhisConfigurationProvider( DhisConfigurationProvider dhisConfigurationProvider)
     {
-        this.configurationService = configurationService;
+        this.dhisConfigurationProvider = dhisConfigurationProvider;
     }
     
     private UserSettingService userSettingService;
@@ -107,12 +109,12 @@
     @Override
     public String sendMessage( String subject, String text, String footer, User sender, Set<User> users, boolean forceSend )
     {
-        String hostName = systemSettingManager.getEmailHostName();
-        int port = systemSettingManager.getEmailPort();
-        String username = systemSettingManager.getEmailUsername();
-        String password = configurationService.getConfiguration().getSmtpPassword();
-        boolean tls = systemSettingManager.getEmailTls();
-        String from = systemSettingManager.getEmailSender();
+        String hostName = dhisConfigurationProvider.getProperty( ConfigurationKey.SMTP_HOSTNAME );
+        int port = Integer.parseInt( dhisConfigurationProvider.getProperty( ConfigurationKey.SMTP_PORT ) );
+        String username = dhisConfigurationProvider.getProperty( ConfigurationKey.SMTP_USERNAME );
+        String password = dhisConfigurationProvider.getProperty( ConfigurationKey.SMTP_PASSWORD );
+        boolean tls = Boolean.parseBoolean( dhisConfigurationProvider.getProperty( ConfigurationKey.SMTP_TLS ) );
+        String from = dhisConfigurationProvider.getProperty( ConfigurationKey.SMTP_SENDER );
 
         if ( hostName == null )
         {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2015-12-29 12:40:22 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2016-01-05 14:03:19 +0000
@@ -876,7 +876,7 @@
 
   <bean id="emailMessageSender" class="org.hisp.dhis.message.EmailMessageSender">
     <property name="systemSettingManager" ref="org.hisp.dhis.setting.SystemSettingManager" />
-    <property name="configurationService" ref="org.hisp.dhis.configuration.ConfigurationService" />
+    <property name="dhisConfigurationProvider" ref="dhisConfigurationProvider" />
     <property name="userSettingService" ref="org.hisp.dhis.user.UserSettingService" />
   </bean>
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/Configuration.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/Configuration.hbm.xml	2015-12-23 13:59:37 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/Configuration.hbm.xml	2016-01-05 14:03:19 +0000
@@ -35,14 +35,6 @@
     <many-to-one name="selfRegistrationOrgUnit" class="org.hisp.dhis.organisationunit.OrganisationUnit"
         column="selfRegistrationOrgUnit" foreign-key="fk_configuration_selfregistrationorgunit" />
 
-    <property name="remoteServerUrl" column="remoteserverurl" />
-
-    <property name="remoteServerUsername" column="remoteserverusername" />
-
-    <property name="remoteServerPassword" column="remoteserverpassword" type="encryptedString" />
-
-    <property name="smtpPassword" column="smtppassword" type="encryptedString" />
-
     <set name="corsWhitelist" table="configuration_corswhitelist">
       <cache usage="read-write" />
       <key column="configurationid" foreign-key="fk_configuration_corswhitelist" />

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.java	2016-01-05 14:03:19 +0000
@@ -46,6 +46,8 @@
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
 import org.hisp.dhis.dxf2.metadata.ImportService;
 import org.hisp.dhis.dxf2.metadata.MetaData;
+import org.hisp.dhis.external.conf.ConfigurationKey;
+import org.hisp.dhis.external.conf.DhisConfigurationProvider;
 import org.hisp.dhis.setting.SettingKey;
 import org.hisp.dhis.setting.SystemSettingManager;
 import org.hisp.dhis.system.util.CodecUtils;
@@ -76,6 +78,7 @@
     private static final Log log = LogFactory.getLog( DefaultSynchronizationManager.class );
 
     private static final String PING_PATH = "/api/system/ping";
+
     private static final String HEADER_AUTHORIZATION = "Authorization";
 
     @Autowired
@@ -99,6 +102,9 @@
     @Autowired
     private RestTemplate restTemplate;
 
+    @Autowired
+    private DhisConfigurationProvider dhisConfigurationProvider;
+
     // -------------------------------------------------------------------------
     // SynchronizatonManager implementation
     // -------------------------------------------------------------------------
@@ -113,11 +119,14 @@
             return new AvailabilityStatus( false, "Remote server is not configured" );
         }
 
-        String url = config.getRemoteServerUrl() + PING_PATH;
-
-        log.info( "Remote server ping URL: " + url + ", username: " + config.getRemoteServerUsername() );
-
-        HttpEntity<String> request = getBasicAuthRequestEntity( config.getRemoteServerUsername(), config.getRemoteServerPassword() );
+        String url = dhisConfigurationProvider.getProperty( ConfigurationKey.REMOTE_INSTANCE_URL ) + PING_PATH;
+
+        log.info( "Remote server ping URL: " + url + ", username: " + dhisConfigurationProvider.getProperty(
+            ConfigurationKey.REMOTE_INSTANCE_USERNAME ) );
+
+        HttpEntity<String> request = getBasicAuthRequestEntity( dhisConfigurationProvider.getProperty(
+            ConfigurationKey.REMOTE_INSTANCE_USERNAME ), dhisConfigurationProvider.getProperty(
+            ConfigurationKey.REMOTE_INSTANCE_PASSWORD ) );
 
         ResponseEntity<String> response = null;
         HttpStatus sc = null;
@@ -148,23 +157,28 @@
 
         if ( HttpStatus.FOUND.equals( sc ) )
         {
-            status = new AvailabilityStatus( false, "Server is available but no authentication was provided, status code: " + sc );
+            status = new AvailabilityStatus( false,
+                "Server is available but no authentication was provided, status code: " + sc );
         }
         else if ( HttpStatus.UNAUTHORIZED.equals( sc ) )
         {
-            status = new AvailabilityStatus( false, "Server is available but authentication failed, status code: " + sc );
+            status = new AvailabilityStatus( false,
+                "Server is available but authentication failed, status code: " + sc );
         }
         else if ( HttpStatus.INTERNAL_SERVER_ERROR.equals( sc ) )
         {
-            status = new AvailabilityStatus( false, "Server is available but experienced an internal error, status code: " + sc );
+            status = new AvailabilityStatus( false,
+                "Server is available but experienced an internal error, status code: " + sc );
         }
         else if ( HttpStatus.OK.equals( sc ) )
         {
-            status = new AvailabilityStatus( true, "Server is available and authentication was successful" );
+            status = new AvailabilityStatus( true,
+                "Server is available and authentication was successful" );
         }
         else
         {
-            status = new AvailabilityStatus( false, "Server is not available, status code: " + sc + ", text: " + st );
+            status = new AvailabilityStatus( false,
+                "Server is not available, status code: " + sc + ", text: " + st );
         }
 
         log.info( status );
@@ -203,24 +217,32 @@
 
         final Configuration config = configurationService.getConfiguration();
 
-        String url = config.getRemoteServerUrl() + "/api/dataValueSets";
+        String url = dhisConfigurationProvider.getProperty( ConfigurationKey.REMOTE_INSTANCE_URL ) +
+            "/api/dataValueSets";
 
         log.info( "Remote server POST URL: " + url );
 
         final RequestCallback requestCallback = new RequestCallback()
         {
             @Override
-            public void doWithRequest( ClientHttpRequest request ) throws IOException
+            public void doWithRequest( ClientHttpRequest request )
+                throws IOException
             {
                 request.getHeaders().setContentType( MediaType.APPLICATION_JSON );
-                request.getHeaders().add( HEADER_AUTHORIZATION, CodecUtils.getBasicAuthString( config.getRemoteServerUsername(), config.getRemoteServerPassword() ) );
-                dataValueSetService.writeDataValueSetJson( lastSuccessTime, request.getBody(), new IdSchemes() );
+                request.getHeaders().add( HEADER_AUTHORIZATION,
+                    CodecUtils.getBasicAuthString( dhisConfigurationProvider.getProperty(
+                            ConfigurationKey.REMOTE_INSTANCE_USERNAME ),
+                        dhisConfigurationProvider.getProperty(
+                            ConfigurationKey.REMOTE_INSTANCE_PASSWORD ) ) );
+                dataValueSetService
+                    .writeDataValueSetJson( lastSuccessTime, request.getBody(), new IdSchemes() );
             }
         };
 
         ResponseExtractor<ImportSummary> responseExtractor = new ImportSummaryResponseExtractor();
 
-        ImportSummary summary = restTemplate.execute( url, HttpMethod.POST, requestCallback, responseExtractor );
+        ImportSummary summary = restTemplate
+            .execute( url, HttpMethod.POST, requestCallback, responseExtractor );
 
         log.info( "Synch summary: " + summary );
 
@@ -243,15 +265,15 @@
     public org.hisp.dhis.dxf2.metadata.ImportSummary executeMetadataPull( String url )
     {
         User user = currentUserService.getCurrentUser();
-        
+
         String userUid = user != null ? user.getUid() : null;
-        
+
         log.info( "Metadata pull, url: " + url + ", user: " + userUid );
-        
+
         String json = restTemplate.getForObject( url, String.class );
-        
+
         MetaData metaData = null;
-        
+
         try
         {
             metaData = JacksonUtils.fromJson( json, MetaData.class );
@@ -260,12 +282,12 @@
         {
             throw new RuntimeException( "Failed to parse remote JSON document", ex );
         }
-        
+
         org.hisp.dhis.dxf2.metadata.ImportSummary summary = importService.importMetaData( userUid, metaData );
-        
+
         return summary;
     }
-    
+
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------
@@ -294,13 +316,17 @@
      */
     private boolean isRemoteServerConfigured( Configuration config )
     {
-        if ( trimToNull( config.getRemoteServerUrl() ) == null )
+        if ( trimToNull( dhisConfigurationProvider.getProperty( ConfigurationKey.REMOTE_INSTANCE_URL ) ) ==
+            null )
         {
             log.info( "Remote server URL not set" );
             return false;
         }
 
-        if ( trimToNull( config.getRemoteServerUsername() ) == null || trimToNull( config.getRemoteServerPassword() ) == null )
+        if ( trimToNull( dhisConfigurationProvider.getProperty( ConfigurationKey.REMOTE_INSTANCE_USERNAME ) ) ==
+            null ||
+            trimToNull( dhisConfigurationProvider.getProperty( ConfigurationKey.REMOTE_INSTANCE_URL ) ) ==
+                null )
         {
             log.info( "Remote server username or password not set" );
             return false;

=== 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	2016-01-04 16:58:59 +0000
+++ dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/ConfigurationKey.java	2016-01-05 14:03:19 +0000
@@ -50,7 +50,17 @@
     FILE_STORE_CONTAINER( "filestore.container", "files" ),
     FILE_STORE_LOCATION( "filestore.location" ),
     FILE_STORE_IDENTITY( "filestore.identity", "" ),
-    FILE_STORE_SECRET( "filestore.secret", "" );
+    FILE_STORE_SECRET( "filestore.secret", "" ),
+    SMTP_HOSTNAME( "smtp.hostname", "" ),
+    SMTP_PORT( "smtp.port", "587" ),
+    SMTP_TLS( "smtp.tls", "true" ),
+    SMTP_USERNAME( "smtp.username", "" ),
+    SMTP_PASSWORD( "smtp.password", "" ),
+    SMTP_SENDER( "smtp.sender", "" ),
+    REMOTE_INSTANCE_URL( "remote_instance.url", "" ),
+    REMOTE_INSTANCE_USERNAME( "remote_instance.username", "" ),
+    REMOTE_INSTANCE_PASSWORD( "remote_instance.password", "" );
+
 
     private final String key;
     

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ConfigurationController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ConfigurationController.java	2016-01-04 16:58:59 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ConfigurationController.java	2016-01-05 14:03:19 +0000
@@ -298,64 +298,17 @@
         configurationService.setConfiguration( config );
     }
 
-    @PreAuthorize( "hasRole('ALL') or hasRole('F_SYSTEM_SETTING')" )
-    @ResponseStatus( value = HttpStatus.OK )
-    @RequestMapping( value = "/smtpPassword", method = RequestMethod.POST )
-    public void setSmtpPassword( @RequestBody String password  )
-    {
-        Configuration config = configurationService.getConfiguration();
-        
-        config.setSmtpPassword( StringUtils.trimToNull( password ) );
-        
-        configurationService.setConfiguration( config );
-    }    
-
     @RequestMapping( value = "/remoteServerUrl", method = RequestMethod.GET )
     public String getRemoteServerUrl( Model model, HttpServletRequest request )
     {
-        return setModel( model, configurationService.getConfiguration().getRemoteServerUrl() );
-    }
-    
-    @PreAuthorize( "hasRole('ALL') or hasRole('F_SYSTEM_SETTING')" )
-    @ResponseStatus( value = HttpStatus.OK )
-    @RequestMapping( value = "/remoteServerUrl", method = RequestMethod.POST )
-    public void setRemoteServerUrl( @RequestBody String url )
-    {
-        Configuration config = configurationService.getConfiguration();
-        
-        config.setRemoteServerUrl( StringUtils.trimToNull( url ) );
-        
-        configurationService.setConfiguration( config );
-    }
+        return setModel( model, config.getProperty( ConfigurationKey.REMOTE_INSTANCE_URL ) );
+    }
+
 
     @RequestMapping( value = "/remoteServerUsername", method = RequestMethod.GET )
     public String getRemoteServerUsername( Model model, HttpServletRequest request )
     {
-        return setModel( model, configurationService.getConfiguration().getRemoteServerUsername() );
-    }
-    
-    @PreAuthorize( "hasRole('ALL') or hasRole('F_SYSTEM_SETTING')" )
-    @ResponseStatus( value = HttpStatus.OK )
-    @RequestMapping( value = "/remoteServerUsername", method = RequestMethod.POST )
-    public void setRemoteServerUsername( @RequestBody String username )
-    {
-        Configuration config = configurationService.getConfiguration();
-        
-        config.setRemoteServerUsername( StringUtils.trimToNull( username ) );
-        
-        configurationService.setConfiguration( config );
-    }
-    
-    @PreAuthorize( "hasRole('ALL') or hasRole('F_SYSTEM_SETTING')" )
-    @ResponseStatus( value = HttpStatus.OK )
-    @RequestMapping( value = "/remoteServerPassword", method = RequestMethod.POST )
-    public void setRemoteServerPassword( @RequestBody String password )
-    {
-        Configuration config = configurationService.getConfiguration();
-        
-        config.setRemoteServerPassword( StringUtils.trimToNull( password ) );
-        
-        configurationService.setConfiguration( config );
+        return setModel( model, config.getProperty( ConfigurationKey.REMOTE_INSTANCE_USERNAME) );
     }
 
     @RequestMapping( value = "/corsWhitelist", method = RequestMethod.GET, produces = "application/json" )