← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18919: SystemService, fixed bug, certain time-sensitive properties were not updated properly

 

------------------------------------------------------------
revno: 18919
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-04-15 23:50:33 +0200
message:
  SystemService, fixed bug, certain time-sensitive properties were not updated properly
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/system/DefaultSystemService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/system/SystemInfo.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/system/DefaultSystemService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/system/DefaultSystemService.java	2015-03-10 12:37:21 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/system/DefaultSystemService.java	2015-04-15 21:50:33 +0000
@@ -72,6 +72,9 @@
     @Autowired
     private SystemSettingManager systemSettingManager;
     
+    /**
+     * Variable holding fixed system info state.
+     */
     private SystemInfo systemInfo = null;
 
     // -------------------------------------------------------------------------
@@ -81,18 +84,24 @@
     @Override
     public SystemInfo getSystemInfo()
     {
-        if ( systemInfo != null )
+        if ( systemInfo == null )
         {
-            systemInfo.setServerDate( new Date() );
-            
-            return systemInfo;
+            systemInfo = getFixedSystemInfo();
         }
-
-        systemInfo = new SystemInfo();
-
-        systemInfo.setCalendar( calendarService.getSystemCalendar().name() );
-        systemInfo.setDateFormat( calendarService.getSystemDateFormat().getJs() );
-        systemInfo.setLastAnalyticsTableSuccess( (Date) systemSettingManager.getSystemSetting( KEY_LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE ) );
+        
+        SystemInfo info = systemInfo.instance();
+        
+        info.setCalendar( calendarService.getSystemCalendar().name() );
+        info.setDateFormat( calendarService.getSystemDateFormat().getJs() );
+        info.setLastAnalyticsTableSuccess( (Date) systemSettingManager.getSystemSetting( KEY_LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE ) );
+        info.setServerDate( new Date() );
+        
+        return info;
+    }
+    
+    private SystemInfo getFixedSystemInfo()
+    {
+        SystemInfo info = new SystemInfo();
 
         // ---------------------------------------------------------------------
         // Version
@@ -112,14 +121,14 @@
 
                 properties.load( in );
 
-                systemInfo.setVersion( properties.getProperty( "build.version" ) );
-                systemInfo.setRevision( properties.getProperty( "build.revision" ) );
+                info.setVersion( properties.getProperty( "build.version" ) );
+                info.setRevision( properties.getProperty( "build.revision" ) );
 
                 String buildTime = properties.getProperty( "build.time" );
 
                 DateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
 
-                systemInfo.setBuildTime( dateFormat.parse( buildTime ) );
+                info.setBuildTime( dateFormat.parse( buildTime ) );
             }
             catch ( IOException ex )
             {
@@ -139,24 +148,24 @@
         // External directory
         // ---------------------------------------------------------------------
 
-        systemInfo.setEnvironmentVariable( locationManager.getEnvironmentVariable() );
+        info.setEnvironmentVariable( locationManager.getEnvironmentVariable() );
 
         try
         {
             File directory = locationManager.getExternalDirectory();
 
-            systemInfo.setExternalDirectory( directory.getAbsolutePath() );
+            info.setExternalDirectory( directory.getAbsolutePath() );
         }
         catch ( LocationManagerException ex )
         {
-            systemInfo.setExternalDirectory( "Not set" );
+            info.setExternalDirectory( "Not set" );
         }
 
         // ---------------------------------------------------------------------
         // Database
         // ---------------------------------------------------------------------
 
-        systemInfo.setDatabaseInfo( databaseInfoProvider.getDatabaseInfo() );
+        info.setDatabaseInfo( databaseInfoProvider.getDatabaseInfo() );
 
         // ---------------------------------------------------------------------
         // System env variables and properties
@@ -164,31 +173,30 @@
 
         try
         {
-            systemInfo.setJavaOpts( System.getenv( "JAVA_OPTS" ) );
+            info.setJavaOpts( System.getenv( "JAVA_OPTS" ) );
         }
         catch ( SecurityException ex )
         {
-            systemInfo.setJavaOpts( "Unknown" );
+            info.setJavaOpts( "Unknown" );
         }
 
         Properties props = System.getProperties();
 
-        systemInfo.setJavaHome( props.getProperty( "java.home" ) );
-        systemInfo.setJavaIoTmpDir( props.getProperty( "java.io.tmpdir" ) );
-        systemInfo.setJavaVersion( props.getProperty( "java.version" ) );
-        systemInfo.setJavaVendor( props.getProperty( "java.vendor" ) );
-        systemInfo.setOsName( props.getProperty( "os.name" ) );
-        systemInfo.setOsArchitecture( props.getProperty( "os.arch" ) );
-        systemInfo.setOsVersion( props.getProperty( "os.version" ) );
+        info.setJavaHome( props.getProperty( "java.home" ) );
+        info.setJavaIoTmpDir( props.getProperty( "java.io.tmpdir" ) );
+        info.setJavaVersion( props.getProperty( "java.version" ) );
+        info.setJavaVendor( props.getProperty( "java.vendor" ) );
+        info.setOsName( props.getProperty( "os.name" ) );
+        info.setOsArchitecture( props.getProperty( "os.arch" ) );
+        info.setOsVersion( props.getProperty( "os.version" ) );
 
-        systemInfo.setMemoryInfo( SystemUtils.getMemoryString() );
-        systemInfo.setCpuCores( SystemUtils.getCpuCores() );
-        systemInfo.setServerDate( new Date() );
+        info.setMemoryInfo( SystemUtils.getMemoryString() );
+        info.setCpuCores( SystemUtils.getCpuCores() );
 
         Configuration config = configurationService.getConfiguration();
 
-        systemInfo.setSystemId( config.getSystemId() );
+        info.setSystemId( config.getSystemId() );
 
-        return systemInfo;
+        return info;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/system/SystemInfo.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/system/SystemInfo.java	2015-03-10 12:37:21 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/system/SystemInfo.java	2015-04-15 21:50:33 +0000
@@ -32,6 +32,7 @@
 
 import org.hisp.dhis.common.DxfNamespaces;
 import org.hisp.dhis.system.database.DatabaseInfo;
+import org.springframework.beans.BeanUtils;
 
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
@@ -51,12 +52,18 @@
 
     private String userAgent;
 
+    // -------------------------------------------------------------------------
+    // Volatile properties
+    // -------------------------------------------------------------------------
+
     private String calendar;
 
     private String dateFormat;
         
     private Date lastAnalyticsTableSuccess;
-    
+
+    private Date serverDate;
+
     // -------------------------------------------------------------------------
     // Stable properties
     // -------------------------------------------------------------------------
@@ -67,8 +74,6 @@
 
     private Date buildTime;
 
-    private Date serverDate;
-
     private String environmentVariable;
 
     private String javaVersion;
@@ -97,6 +102,13 @@
 
     private String systemId;
 
+    public SystemInfo instance()
+    {
+        SystemInfo info = new SystemInfo();
+        BeanUtils.copyProperties( this, info );        
+        return info;
+    }
+
     // -------------------------------------------------------------------------
     // Logic
     // -------------------------------------------------------------------------
@@ -118,7 +130,7 @@
         this.cpuCores = null;
         this.systemId = null;
     }
-
+    
     // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------