← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22153: DefaultSmsConfigurationManager. Using ApplicationListener instead of @PostConstruct as transactio...

 

------------------------------------------------------------
revno: 22153
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2016-03-07 15:25:33 +0100
message:
  DefaultSmsConfigurationManager. Using ApplicationListener instead of @PostConstruct as transactions are used in init method
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/DefaultSmsConfigurationManager.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/sms/config/DefaultSmsConfigurationManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/DefaultSmsConfigurationManager.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/DefaultSmsConfigurationManager.java	2016-03-07 14:25:33 +0000
@@ -29,7 +29,6 @@
  */
 
 import java.util.List;
-import javax.annotation.PostConstruct;
 
 import org.apache.commons.lang.NotImplementedException;
 import org.apache.commons.logging.Log;
@@ -39,6 +38,8 @@
 import org.hisp.dhis.setting.SystemSettingManager;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
 
 /**
  * Manages the {@link SmsConfiguration} for the DHIS instance.
@@ -47,7 +48,7 @@
  * context, initializing them on startup and on any SMS configuration changes.
  */
 public class DefaultSmsConfigurationManager
-    implements SmsConfigurationManager
+    implements ApplicationListener<ContextRefreshedEvent>, SmsConfigurationManager
 {
     private static final Log log = LogFactory.getLog( DefaultSmsConfigurationManager.class );
 
@@ -57,19 +58,23 @@
     @Autowired( required = false )
     private List<SmsConfigurable> smsConfigurables;
 
-    @PostConstruct
-    public String initializeSmsConfigurables()
+    public void onApplicationEvent( ContextRefreshedEvent contextRefreshedEvent )
+    {
+        initializeSmsConfigurables();
+    }
+    
+    public void initializeSmsConfigurables()
     {
         if ( smsConfigurables == null )
         {
-            return null;
+            return;
         }
 
         SmsConfiguration smsConfiguration = getSmsConfiguration();
 
         if ( smsConfiguration == null )
         {
-            return null;
+            return;
         }
 
         String message = null;
@@ -84,19 +89,18 @@
 
                 if ( message != null && !message.equals( "success" ) )
                 {
-                    return message;
+                    return;
                 }
             }
             catch ( Throwable t )
             {
                 log.warn( "Unable to initialize service " + smsConfigurable.getClass().getSimpleName()
                     + " with configuration " + smsConfiguration, t );
-                return "Unable to initialize service " + smsConfigurable.getClass().getSimpleName()
-                    + " with configuration " + smsConfiguration + t.getMessage();
+                return;
             }
         }
 
-        return message;
+        return;
     }
 
     @Override