← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19020: Added time isnce last analytics update in system info web api resource + about page

 

------------------------------------------------------------
revno: 19020
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-04-24 18:07:03 +0200
message:
  Added time isnce last analytics update in system info web api resource + about page
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
  dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java
  dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/DateUtilsTest.java
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/about/about.vm


--
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-04-15 21:50:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/system/DefaultSystemService.java	2015-04-24 16:07:03 +0000
@@ -47,6 +47,7 @@
 import org.hisp.dhis.external.location.LocationManagerException;
 import org.hisp.dhis.setting.SystemSettingManager;
 import org.hisp.dhis.system.database.DatabaseInfoProvider;
+import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.system.util.SystemUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ClassPathResource;
@@ -88,13 +89,21 @@
         {
             systemInfo = getFixedSystemInfo();
         }
+
+        // ---------------------------------------------------------------------
+        // Set volatile properties
+        // ---------------------------------------------------------------------
+
+        Date lastAnalyticsTableSuccess = (Date) systemSettingManager.getSystemSetting( KEY_LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE );
+        Date now = new Date();
         
         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() );
+        info.setLastAnalyticsTableSuccess( lastAnalyticsTableSuccess );
+        info.setIntervalSinceLastAnalyticsTableSuccess( DateUtils.getPrettyInterval( lastAnalyticsTableSuccess, now ) );
         
         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-04-16 07:59:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/system/SystemInfo.java	2015-04-24 16:07:03 +0000
@@ -59,10 +59,12 @@
     private String calendar;
 
     private String dateFormat;
-        
+
+    private Date serverDate;
+    
     private Date lastAnalyticsTableSuccess;
-
-    private Date serverDate;
+    
+    private String intervalSinceLastAnalyticsTableSuccess;
 
     // -------------------------------------------------------------------------
     // Stable properties
@@ -184,6 +186,18 @@
 
     @JsonProperty
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public Date getServerDate()
+    {
+        return serverDate;
+    }
+
+    public void setServerDate( Date serverDate )
+    {
+        this.serverDate = serverDate;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public Date getLastAnalyticsTableSuccess()
     {
         return lastAnalyticsTableSuccess;
@@ -196,6 +210,18 @@
 
     @JsonProperty
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public String getIntervalSinceLastAnalyticsTableSuccess()
+    {
+        return intervalSinceLastAnalyticsTableSuccess;
+    }
+
+    public void setIntervalSinceLastAnalyticsTableSuccess( String intervalSinceLastAnalyticsTableSuccess )
+    {
+        this.intervalSinceLastAnalyticsTableSuccess = intervalSinceLastAnalyticsTableSuccess;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public String getVersion()
     {
         return version;
@@ -232,18 +258,6 @@
 
     @JsonProperty
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public Date getServerDate()
-    {
-        return serverDate;
-    }
-
-    public void setServerDate( Date serverDate )
-    {
-        this.serverDate = serverDate;
-    }
-
-    @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public String getEnvironmentVariable()
     {
         return environmentVariable;

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties	2015-04-20 10:37:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties	2015-04-24 16:07:03 +0000
@@ -469,6 +469,7 @@
 system_overview=System Overview
 server_date=Server date
 last_analytics_table_generation=Last analytics table generation
+time_since_last_analytics_table_generation=Time since last analytics table generation
 online_release_page=online release page
 edit_profile=Edit profile
 view_profile=View profile

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java	2015-04-24 14:15:03 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java	2015-04-24 16:07:03 +0000
@@ -28,6 +28,15 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.period.Period.DEFAULT_DATE_FORMAT;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.period.Period;
@@ -35,15 +44,8 @@
 import org.joda.time.DateTime;
 import org.joda.time.Days;
 import org.joda.time.Months;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.TimeZone;
-
-import static org.hisp.dhis.period.Period.DEFAULT_DATE_FORMAT;
+import org.joda.time.format.PeriodFormatter;
+import org.joda.time.format.PeriodFormatterBuilder;
 
 /**
  * @author Lars Helge Overland
@@ -63,7 +65,15 @@
         new SimpleDateFormat( "yyyy" )
     };
 
-    //TODO replace with FastDateParser, SimpleDateFormat is not thead-safe
+    private static final String SEP = ", ";
+    
+    public static final PeriodFormatter DAY_SECOND_FORMAT = new PeriodFormatterBuilder()
+        .appendDays().appendSuffix( " d" ).appendSeparator( SEP )
+        .appendHours().appendSuffix( " h" ).appendSeparator( SEP )
+        .appendMinutes().appendSuffix( " m" ).appendSeparator( SEP )
+        .appendSeconds().appendSuffix( " s" ).appendSeparator( SEP ).toFormatter();
+
+    //TODO replace with FastDateParser, SimpleDateFormat is not thread-safe
 
     /**
      * Used by web API and utility methods.
@@ -75,9 +85,8 @@
     public static final SimpleDateFormat ACCESS_DATE_FORMAT = new SimpleDateFormat( "yyyy/MM/dd HH:mm:ss" );
     public static final SimpleDateFormat HTTP_DATE_FORMAT = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss" );
 
-
     public static final double DAYS_IN_YEAR = 365.0;
-
+    
     private static final long MS_PER_DAY = 86400000;
     private static final long MS_PER_S = 1000;
 
@@ -573,6 +582,26 @@
 
         return periods;
     }
+    
+    /**
+     * Returns a pretty string representing the interval between the given
+     * start and end dates using a day, month, second format.
+     * 
+     * @param start the start date.
+     * @param end the end date.
+     * @return a string, or null if the given start or end date is null.
+     */
+    public static String getPrettyInterval( Date start, Date end )
+    {
+        if ( start == null || end == null )
+        {
+            return null;
+        }
+        
+        long diff = end.getTime() - start.getTime();
+        
+        return DAY_SECOND_FORMAT.print( new org.joda.time.Period( diff ) );
+    }
 
     /**
      * Parses the given string into a Date using the supported date formats.

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/DateUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/DateUtilsTest.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/DateUtilsTest.java	2015-04-24 16:07:03 +0000
@@ -33,6 +33,7 @@
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
 
 import java.util.Date;
 
@@ -41,7 +42,6 @@
 
 /**
  * @author Lars Helge Overland
- * @version $Id$
  */
 public class DateUtilsTest
 {
@@ -105,4 +105,15 @@
         
         assertNull( DateUtils.max( date4, date5, date6 ) );
     }
+    
+    @Test
+    public void testGetPrettyInterval()
+    {
+        Date start = new DateTime( 2014, 5, 18, 15, 10, 5, 12 ).toDate();
+        Date end = new DateTime( 2014, 5, 19, 11, 45, 42, 56 ).toDate();
+        
+        String interval = DateUtils.getPrettyInterval( start, end );
+        
+        assertNotNull( interval );
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/about/about.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/about/about.vm	2015-04-07 09:49:17 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/about/about.vm	2015-04-24 16:07:03 +0000
@@ -9,6 +9,7 @@
   <dt>$i18n.getString( "user_agent" ):</dt><dd>$!userAgent</dd>
   <dt>$i18n.getString( "server_date" ):</dt><dd>$!format.formatDateTime( $!info.serverDate )</dd>
   <dt>$i18n.getString( "last_analytics_table_generation" ):</dt><dd>$!format.formatDateTime( $!info.lastAnalyticsTableSuccess )</dd>
+  <dt>$i18n.getString( "time_since_last_analytics_table_generation" ):</dt><dd>$!info.intervalSinceLastAnalyticsTableSuccess</dd>
   <dt>$i18n.getString( "environment_variable" ):</dt><dd>$!info.environmentVariable</dd>
   #if ( $currentUserIsSuper )
   <dt>$i18n.getString( "external_configuration_directory" ):</dt><dd>$!info.externalDirectory</dd>