← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21892: Data synch, code structure improvement

 

------------------------------------------------------------
revno: 21892
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2016-02-05 13:17:21 +0100
message:
  Data synch, code structure improvement
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.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-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-02-02 06:34:22 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.java	2016-02-05 12:17:21 +0000
@@ -28,7 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.apache.commons.lang3.StringUtils.trimToNull;
+import static org.apache.commons.lang3.StringUtils.isEmpty;
 
 import java.io.IOException;
 import java.util.Date;
@@ -115,13 +115,12 @@
         }
 
         String url = systemSettingManager.getSystemSetting( SettingKey.REMOTE_INSTANCE_URL ) + PING_PATH;
-
-        log.info( "Remote server ping URL: " + url + ", username: " + systemSettingManager.getSystemSetting(
-            SettingKey.REMOTE_INSTANCE_USERNAME ) );
-
-        HttpEntity<String> request = getBasicAuthRequestEntity( (String) systemSettingManager.getSystemSetting(
-            SettingKey.REMOTE_INSTANCE_USERNAME ), (String) systemSettingManager.getSystemSetting(
-            SettingKey.REMOTE_INSTANCE_PASSWORD ) );
+        String username = (String) systemSettingManager.getSystemSetting( SettingKey.REMOTE_INSTANCE_USERNAME );
+        String password = (String) systemSettingManager.getSystemSetting( SettingKey.REMOTE_INSTANCE_PASSWORD );
+
+        log.info( "Remote server ping URL: " + url + ", username: " + username );
+
+        HttpEntity<String> request = getBasicAuthRequestEntity( username, password );
 
         ResponseEntity<String> response = null;
         HttpStatus sc = null;
@@ -243,6 +242,10 @@
             setLastSynchSuccess( startTime );
             log.info( "Synch successful, setting last success time: " + startTime );
         }
+        else
+        {
+            log.debug( "Sync failed: " + summary );
+        }
 
         return summary;
     }
@@ -308,18 +311,17 @@
      */
     private boolean isRemoteServerConfigured( Configuration config )
     {
-        if ( trimToNull( (String) systemSettingManager.getSystemSetting(
-            SettingKey.REMOTE_INSTANCE_URL ) ) ==
-            null )
+        String url = (String) systemSettingManager.getSystemSetting( SettingKey.REMOTE_INSTANCE_URL );
+        String username = (String) systemSettingManager.getSystemSetting( SettingKey.REMOTE_INSTANCE_USERNAME );
+        String password = (String) systemSettingManager.getSystemSetting( SettingKey.REMOTE_INSTANCE_PASSWORD );
+        
+        if ( isEmpty( url ) )
         {
             log.info( "Remote server URL not set" );
             return false;
         }
 
-        if ( trimToNull( (String) systemSettingManager.getSystemSetting( SettingKey.REMOTE_INSTANCE_USERNAME ) ) ==
-            null ||
-            trimToNull( (String) systemSettingManager.getSystemSetting( SettingKey.REMOTE_INSTANCE_URL ) ) ==
-                null )
+        if ( isEmpty( username ) || isEmpty( password ) )
         {
             log.info( "Remote server username or password not set" );
             return false;
@@ -338,4 +340,4 @@
         headers.set( HEADER_AUTHORIZATION, CodecUtils.getBasicAuthString( username, password ) );
         return new HttpEntity<>( headers );
     }
-}
\ No newline at end of file
+}