← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16988: Fixed bug with data sync and user statistics caused by Cal. Throwing UnsupportedOperationExceptio...

 

------------------------------------------------------------
revno: 16988
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-10-07 23:16:53 +0200
message:
  Fixed bug with data sync and user statistics caused by Cal. Throwing UnsupportedOperationException in Cal.add/subtract instead of silently ignoring.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Cal.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java
  dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ReportController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ReportTableController.java
  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-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GetDataSetReportOptionsAction.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/period/Cal.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Cal.java	2014-10-07 20:19:04 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Cal.java	2014-10-07 21:16:53 +0000
@@ -121,7 +121,11 @@
             case Calendar.MONTH:
                 dateTimeUnit = getCalendar().plusMonths( dateTimeUnit, amount );
             case Calendar.DAY_OF_MONTH:
+            case Calendar.DAY_OF_YEAR:
                 dateTimeUnit = getCalendar().plusDays( dateTimeUnit, amount );
+            break;
+            default:
+                throw new UnsupportedOperationException();
         }
 
         return this;
@@ -142,7 +146,11 @@
             case Calendar.MONTH:
                 dateTimeUnit = getCalendar().minusMonths( dateTimeUnit, amount );
             case Calendar.DAY_OF_MONTH:
+            case Calendar.DAY_OF_YEAR:
                 dateTimeUnit = getCalendar().minusDays( dateTimeUnit, amount );
+            break;
+            default:
+                throw new UnsupportedOperationException();
         }
 
         return this;

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2014-08-27 11:16:41 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2014-10-07 21:16:53 +0000
@@ -50,6 +50,7 @@
 import org.hisp.dhis.period.Cal;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.setting.SystemSettingManager;
+import org.joda.time.DateTime;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.BadSqlGrammarException;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -68,8 +69,8 @@
     public static final String PREFIX_ORGUNITLEVEL = "uidlevel";
     public static final String PREFIX_INDEX = "in_";
     
-    private static Date MIN_EARLIEST_DATE = new Cal().set( 1800, 1, 1 ).time();
-    private static Date MAX_LATEST_DATE = new Cal().set( 2100, 1, 1 ).time();
+    private static Date MIN_EARLIEST_DATE = new DateTime( 1800, 1, 1, 0, 0 ).toDate();
+    private static Date MAX_LATEST_DATE = new DateTime( 2100, 1, 1, 0, 0 ).toDate();
     
     @Autowired
     protected OrganisationUnitService organisationUnitService;

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java	2014-09-23 07:43:22 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java	2014-10-07 21:16:53 +0000
@@ -35,8 +35,8 @@
 import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
 import static org.hisp.dhis.common.NameableObjectUtils.getList;
 import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE_SUM;
+import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_NONE;
 import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_SUM;
-import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_NONE;
 import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_INT;
 import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_STRING;
 import static org.junit.Assert.assertEquals;
@@ -70,12 +70,12 @@
 import org.hisp.dhis.indicator.IndicatorService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.period.Cal;
 import org.hisp.dhis.period.MonthlyPeriodType;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.period.QuarterlyPeriodType;
 import org.hisp.dhis.period.YearlyPeriodType;
+import org.joda.time.DateTime;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -714,11 +714,11 @@
     {
         Iterator<NameableObject> periods = new ArrayList<>( isoPeriods ).iterator();
         
-        int year = new Cal().set( ((Period) periods.next()).getStartDate() ).getYear();
+        int year = new DateTime( ((Period) periods.next()).getStartDate() ).getYear();
         
         while ( periods.hasNext() )
         {
-            int next = new Cal().set( ((Period) periods.next()).getStartDate() ).getYear();
+            int next = new DateTime( ((Period) periods.next()).getStartDate() ).getYear();
             
             if ( year != next )
             {   

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java	2014-09-30 13:03:38 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java	2014-10-07 21:16:53 +0000
@@ -47,6 +47,7 @@
 import org.hisp.dhis.user.UserCredentials;
 import org.hisp.dhis.user.UserService;
 import org.hisp.dhis.user.UserSettingService;
+import org.joda.time.DateTime;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.util.Arrays;
@@ -314,7 +315,7 @@
             return errorMessage;
         }
 
-        Date currentTime = new Cal().now().time();
+        Date currentTime = new DateTime().toDate();
         Date restoreExpiry = credentials.getRestoreExpiry();
 
         if ( currentTime.after( restoreExpiry ) )

=== 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-09-12 15:26:18 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/synch/DefaultSynchronizationManager.java	2014-10-07 21:16:53 +0000
@@ -32,7 +32,6 @@
 import static org.hisp.dhis.setting.SystemSettingManager.KEY_LAST_SUCCESSFUL_DATA_SYNC;
 
 import java.io.IOException;
-import java.util.Calendar;
 import java.util.Date;
 
 import org.apache.commons.logging.Log;
@@ -45,9 +44,9 @@
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
 import org.hisp.dhis.dxf2.metadata.ExportOptions;
 import org.hisp.dhis.dxf2.utils.ImportSummaryResponseExtractor;
-import org.hisp.dhis.period.Cal;
 import org.hisp.dhis.setting.SystemSettingManager;
 import org.hisp.dhis.system.util.CodecUtils;
+import org.joda.time.DateTime;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
@@ -214,7 +213,7 @@
         
         ImportSummary summary = restTemplate.execute( url, HttpMethod.POST, requestCallback, responseExtractor );
         
-        log.info( summary );
+        log.info( "Synch summary: " + summary );
         
         if ( summary != null && ImportStatus.SUCCESS.equals( summary.getStatus() ) )
         {
@@ -240,7 +239,7 @@
      */
     private Date getLastSynchSuccessFallback()
     {
-        Date fallback = new Cal().subtract( Calendar.DAY_OF_YEAR, 3 ).time();
+        Date fallback = new DateTime().minusDays( 3 ).toDate();
         
         return (Date) systemSettingManager.getSystemSetting( KEY_LAST_SUCCESSFUL_DATA_SYNC, fallback );
     }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ReportController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ReportController.java	2014-05-27 13:18:27 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ReportController.java	2014-10-07 21:16:53 +0000
@@ -28,13 +28,21 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.system.util.CodecUtils.filenameEncode;
+import static org.hisp.dhis.webapi.utils.ContextUtils.DATE_PATTERN;
+
+import java.util.Date;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import net.sf.jasperreports.engine.JasperPrint;
 import net.sf.jasperreports.j2ee.servlets.BaseHttpServlet;
 import net.sf.jasperreports.j2ee.servlets.ImageServlet;
+
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.i18n.I18nManager;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.period.Cal;
 import org.hisp.dhis.period.MonthlyPeriodType;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
@@ -44,6 +52,7 @@
 import org.hisp.dhis.system.util.CodecUtils;
 import org.hisp.dhis.webapi.utils.ContextUtils;
 import org.hisp.dhis.webapi.utils.ContextUtils.CacheStrategy;
+import org.joda.time.DateTime;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.format.annotation.DateTimeFormat;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -54,14 +63,6 @@
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.Calendar;
-import java.util.Date;
-
-import static org.hisp.dhis.system.util.CodecUtils.filenameEncode;
-import static org.hisp.dhis.webapi.utils.ContextUtils.DATE_PATTERN;
-
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  * @author Lars Helge Overland
@@ -215,7 +216,7 @@
         }
         else
         {
-            date = date != null ? date : new Cal().now().subtract( Calendar.MONTH, 1 ).time();
+            date = date != null ? date : new DateTime().minusMonths( 1 ).toDate();
 
             Period period = isoPeriod != null ? PeriodType.getPeriodFromIsoString( isoPeriod ) : new MonthlyPeriodType().createPeriod( date );
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ReportTableController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ReportTableController.java	2014-10-02 17:01:16 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ReportTableController.java	2014-10-07 21:16:53 +0000
@@ -28,6 +28,16 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.common.DimensionalObjectUtils.getUniqueDimensions;
+import static org.hisp.dhis.system.util.CodecUtils.filenameEncode;
+import static org.hisp.dhis.webapi.utils.ContextUtils.DATE_PATTERN;
+
+import java.io.InputStream;
+import java.util.Date;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import org.hisp.dhis.common.DimensionService;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
@@ -36,7 +46,6 @@
 import org.hisp.dhis.mapping.MappingService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.period.Cal;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.reporttable.ReportTableService;
@@ -44,6 +53,7 @@
 import org.hisp.dhis.system.grid.GridUtils;
 import org.hisp.dhis.webapi.utils.ContextUtils;
 import org.hisp.dhis.webapi.utils.ContextUtils.CacheStrategy;
+import org.joda.time.DateTime;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.format.annotation.DateTimeFormat;
 import org.springframework.http.HttpStatus;
@@ -55,16 +65,6 @@
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseStatus;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.InputStream;
-import java.util.Calendar;
-import java.util.Date;
-
-import static org.hisp.dhis.common.DimensionalObjectUtils.getUniqueDimensions;
-import static org.hisp.dhis.system.util.CodecUtils.filenameEncode;
-import static org.hisp.dhis.webapi.utils.ContextUtils.DATE_PATTERN;
-
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  * @author Lars Helge Overland
@@ -257,7 +257,7 @@
             organisationUnitUid = organisationUnitService.getRootOrganisationUnits().iterator().next().getUid();
         }
 
-        date = date != null ? date : new Cal().now().subtract( Calendar.MONTH, 1 ).time();
+        date = date != null ? date : new DateTime().minusMonths( 1 ).toDate();
 
         return reportTableService.getReportTableGrid( uid, i18nManager.getI18nFormat(), date, organisationUnitUid );
     }

=== 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-08-15 07:40:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/statistics/GetStatisticsAction.java	2014-10-07 21:16:53 +0000
@@ -28,17 +28,16 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Calendar;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.hisp.dhis.period.Cal;
-import org.hisp.dhis.statistics.StatisticsProvider;
 import org.hisp.dhis.common.Objects;
 import org.hisp.dhis.datavalue.DataValueService;
+import org.hisp.dhis.statistics.StatisticsProvider;
 import org.hisp.dhis.system.util.EnumMapWrapper;
 import org.hisp.dhis.user.UserService;
+import org.joda.time.DateTime;
 
 import com.opensymphony.xwork2.Action;
 
@@ -107,7 +106,7 @@
     {
         Map<Objects, Integer> counts = statisticsProvider.getObjectCounts();
         
-        Date lastHour = new Cal().now().subtract( Calendar.HOUR_OF_DAY, 1 ).time();
+        Date lastHour = new DateTime().minusHours( 1 ).toDate();
         
         objects = new EnumMapWrapper<>( Objects.class, counts );
         

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GetDataSetReportOptionsAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GetDataSetReportOptionsAction.java	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GetDataSetReportOptionsAction.java	2014-10-07 21:16:53 +0000
@@ -45,9 +45,9 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.oust.manager.SelectionTreeManager;
-import org.hisp.dhis.period.Cal;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
+import org.joda.time.DateTime;
 
 import com.opensymphony.xwork2.Action;
 
@@ -212,7 +212,7 @@
         {
             Period period = getPeriodFromIsoString( pe );
                         
-            offset = new Cal().set( period.getStartDate() ).getYear() - new Cal().now().getYear();
+            offset = new DateTime( period.getStartDate() ).getYear() - new DateTime().getYear();
             
             periodType = period.getPeriodType();