← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15998: DataValueStore, updated queries to use lastUpdated instead of timestamp. Impl method getDataValue...

 

------------------------------------------------------------
revno: 15998
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-07-07 13:00:35 +0200
message:
  DataValueStore, updated queries to use lastUpdated instead of timestamp. Impl method getDataValueCountLastUpdatedAfter.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java
  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/SynchronizationManager.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/statistics/GetStatisticsAction.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/datavalue/DataValueService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java	2014-06-27 16:27:09 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java	2014-07-07 11:00:35 +0000
@@ -300,6 +300,15 @@
     int getDataValueCount( int days );
 
     /**
+     * Gets the number of DataValues which have been updated after the given 
+     * date time.
+     * 
+     * @param date the date time.
+     * @return the number of DataValues.
+     */
+    int getDataValueCountLastUpdatedAfter( Date date );
+
+    /**
      * Returns a map of values for each attribute option combo found.
      * <p>
      * In the (unlikely) event that the same dataElement/optionCombo is found in

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java	2014-05-27 02:41:16 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java	2014-07-07 11:00:35 +0000
@@ -270,12 +270,13 @@
     DataValue getLatestDataValues( DataElement dataElement, PeriodType periodType, OrganisationUnit organisationUnit );
     
     /**
-     * Gets the number of DataValues persisted since the given data.
+     * Gets the number of DataValues which have been updated after the given 
+     * date time.
      * 
-     * @param date the date.
+     * @param date the date time.
      * @return the number of DataValues.
      */
-    int getDataValueCount( Date date );
+    int getDataValueCountLastUpdatedAfter( Date date );
 
     /**
      * Returns a map of values for each attribute option combo found.

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java	2014-06-30 13:54:03 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java	2014-07-07 11:00:35 +0000
@@ -260,7 +260,12 @@
         Calendar cal = PeriodType.createCalendarInstance();
         cal.add( Calendar.DAY_OF_YEAR, (days * -1) );
 
-        return dataValueStore.getDataValueCount( cal.getTime() );
+        return dataValueStore.getDataValueCountLastUpdatedAfter( cal.getTime() );
+    }
+    
+    public int getDataValueCountLastUpdatedAfter( Date date )
+    {
+        return dataValueStore.getDataValueCountLastUpdatedAfter( date );
     }
     
     public MapMap<Integer, DataElementOperand, Double> getDataValueMapByAttributeCombo( Collection<DataElement> dataElements, Date date,

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java	2014-06-27 14:15:51 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java	2014-07-07 11:00:35 +0000
@@ -450,11 +450,11 @@
         return (DataValue) query.uniqueResult();
     }
         
-    public int getDataValueCount( Date date )
+    public int getDataValueCountLastUpdatedAfter( Date date )
     {
         Criteria criteria = sessionFactory.getCurrentSession().createCriteria( DataValue.class );
         
-        criteria.add( Restrictions.ge( "timestamp", date ) );
+        criteria.add( Restrictions.ge( "lastUpdated", date ) );
         criteria.setProjection( Projections.rowCount() );
 
         Number rs = (Number) criteria.uniqueResult();

=== 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	2014-07-07 10:06:36 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.java	2014-07-07 11:00:35 +0000
@@ -36,8 +36,8 @@
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.configuration.Configuration;
 import org.hisp.dhis.configuration.ConfigurationService;
+import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
-import org.hisp.dhis.period.Cal;
 import org.hisp.dhis.setting.SystemSettingManager;
 import org.hisp.dhis.system.util.CodecUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -72,6 +72,9 @@
     private DataValueSetService dataValueSetService;
     
     @Autowired
+    private DataValueService dataValueService;
+    
+    @Autowired
     private ConfigurationService configurationService;
     
     @Autowired
@@ -160,7 +163,7 @@
     {        
     }
     
-    public boolean isDataSyncEnabled()
+    public boolean isDataSynchEnabled()
     {
         return false;
     }
@@ -171,9 +174,16 @@
         
         Date date = getLastSynchSuccess();
         
-        setLastSynchSuccess( now );
-        
-        return true;
+        int lastUpdatedCount = dataValueService.getDataValueCountLastUpdatedAfter( date );
+        
+        if ( lastUpdatedCount > 0 )
+        {
+            setLastSynchSuccess( now );
+            
+            return true;
+        }
+        
+        return false;
     }
     
     // -------------------------------------------------------------------------
@@ -181,13 +191,14 @@
     // -------------------------------------------------------------------------
 
     /**
-     * Gets the time of the last successful synchronization operation.
+     * Gets the time of the last successful synchronization operation. If not set,
+     * the current time is returned.
      */
     private Date getLastSynchSuccess()
     {
         Date date = (Date) systemSettingManager.getSystemSetting( KEY_LAST_SUCCESSFUL_SYNC );
         
-        return date != null ? date : new Cal().set( 0, 1, 1 ).time();
+        return date != null ? date : new Date();
     }
 
     /**

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/SynchronizationManager.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/SynchronizationManager.java	2014-07-07 10:06:36 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/SynchronizationManager.java	2014-07-07 11:00:35 +0000
@@ -1,5 +1,36 @@
 package org.hisp.dhis.dxf2.synch;
 
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author Lars Helge Overland
+ */
 public interface SynchronizationManager
 {
     AvailabilityStatus isRemoteServerAvailable();
@@ -9,4 +40,6 @@
     void enableDataSynch();
     
     void disableDataSynch();
+    
+    boolean isDataSynchEnabled();
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/statistics/GetStatisticsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/statistics/GetStatisticsAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/statistics/GetStatisticsAction.java	2014-07-07 11:00:35 +0000
@@ -44,7 +44,6 @@
 
 /**
  * @author Lars Helge Overland
- * @version $Id$
  */
 public class GetStatisticsAction
     implements Action