← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16764: minor fix, add convenience method so that you don't have to convert to DateTimeUnit before using ...

 

------------------------------------------------------------
revno: 16764
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-09-22 11:51:49 +0700
message:
  minor fix, add convenience method so that you don't have to convert to DateTimeUnit before using fromIso
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.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/calendar/Calendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java	2014-09-21 07:49:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java	2014-09-22 04:51:49 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -119,7 +120,7 @@
     DateTimeUnit toIso( DateTimeUnit dateTimeUnit );
 
     /**
-     * Convert from local to ISO 8601 DateUnit.
+     * Convert from ISO 8601 to local DateUnit.
      *
      * @param year  ISO 8601 year
      * @param month ISO 8601 month
@@ -130,7 +131,7 @@
     DateTimeUnit fromIso( int year, int month, int day );
 
     /**
-     * Convert from local to ISO 8601 DateUnit.
+     * Convert from ISO 8601 to local DateUnit.
      *
      * @param dateTimeUnit DateUnit representing ISO 8601 year, month, day
      * @return DateUnit representing ISO 8601 in local
@@ -139,6 +140,15 @@
     DateTimeUnit fromIso( DateTimeUnit dateTimeUnit );
 
     /**
+     * Convert from ISO 8601 Jdk Date to local DateUnit.
+     *
+     * @param date Date to convert from
+     * @return DateUnit representing ISO 8601 in local
+     * @see <a href="http://en.wikipedia.org/wiki/ISO_8601";>http://en.wikipedia.org/wiki/ISO_8601</a>
+     */
+    DateTimeUnit fromIso( Date date );
+
+    /**
      * Gets interval of type based on DateUnit
      *
      * @param dateTimeUnit DateUnit representing local year, month, day

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java	2014-09-21 07:49:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java	2014-09-22 04:51:49 +0000
@@ -33,6 +33,8 @@
 import org.joda.time.LocalDate;
 import org.joda.time.chrono.ISOChronology;
 
+import java.util.Date;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -60,6 +62,12 @@
     }
 
     @Override
+    public DateTimeUnit fromIso( Date date )
+    {
+        return fromIso( DateTimeUnit.fromJdkDate( date ) );
+    }
+
+    @Override
     public DateTimeUnit fromIso( DateTimeUnit dateTimeUnit )
     {
         if ( !dateTimeUnit.isIso8601() )

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java	2014-08-29 15:45:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java	2014-09-22 04:51:49 +0000
@@ -38,6 +38,7 @@
 import org.joda.time.chrono.ISOChronology;
 import org.springframework.stereotype.Component;
 
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -94,6 +95,12 @@
     }
 
     @Override
+    public DateTimeUnit fromIso( Date date )
+    {
+        return fromIso( DateTimeUnit.fromJdkDate( date ) );
+    }
+
+    @Override
     public DateTimeUnit fromIso( DateTimeUnit dateTimeUnit )
     {
         DateTime start = startIso.toJodaDateTime();

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2014-09-21 07:49:12 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2014-09-22 04:51:49 +0000
@@ -28,53 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.analytics.AnalyticsTableManager.ANALYTICS_TABLE_NAME;
-import static org.hisp.dhis.analytics.AnalyticsTableManager.COMPLETENESS_TABLE_NAME;
-import static org.hisp.dhis.analytics.AnalyticsTableManager.COMPLETENESS_TARGET_TABLE_NAME;
-import static org.hisp.dhis.analytics.AnalyticsTableManager.ORGUNIT_TARGET_TABLE_NAME;
-import static org.hisp.dhis.analytics.DataQueryParams.DISPLAY_NAME_CATEGORYOPTIONCOMBO;
-import static org.hisp.dhis.analytics.DataQueryParams.DISPLAY_NAME_DATA_X;
-import static org.hisp.dhis.analytics.DataQueryParams.DISPLAY_NAME_LATITUDE;
-import static org.hisp.dhis.analytics.DataQueryParams.DISPLAY_NAME_LONGITUDE;
-import static org.hisp.dhis.analytics.DataQueryParams.DISPLAY_NAME_ORGUNIT;
-import static org.hisp.dhis.analytics.DataQueryParams.DISPLAY_NAME_PERIOD;
-import static org.hisp.dhis.analytics.DataQueryParams.FIXED_DIMS;
-import static org.hisp.dhis.common.DimensionalObject.CATEGORYOPTIONCOMBO_DIM_ID;
-import static org.hisp.dhis.common.DimensionalObject.DATAELEMENT_DIM_ID;
-import static org.hisp.dhis.common.DimensionalObject.DATASET_DIM_ID;
-import static org.hisp.dhis.common.DimensionalObject.DATA_X_DIM_ID;
-import static org.hisp.dhis.common.DimensionalObject.DIMENSION_SEP;
-import static org.hisp.dhis.common.DimensionalObject.INDICATOR_DIM_ID;
-import static org.hisp.dhis.common.DimensionalObject.LATITUDE_DIM_ID;
-import static org.hisp.dhis.common.DimensionalObject.LONGITUDE_DIM_ID;
-import static org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID;
-import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
-import static org.hisp.dhis.common.DimensionalObjectUtils.toDimension;
-import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
-import static org.hisp.dhis.common.NameableObjectUtils.asList;
-import static org.hisp.dhis.common.NameableObjectUtils.asTypedList;
-import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_LEVEL;
-import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_ORGUNIT_GROUP;
-import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_USER_ORGUNIT;
-import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_USER_ORGUNIT_CHILDREN;
-import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_USER_ORGUNIT_GRANDCHILDREN;
-import static org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap;
-import static org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap;
-import static org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString;
-import static org.hisp.dhis.reporttable.ReportTable.IRT2D;
-import static org.hisp.dhis.reporttable.ReportTable.addIfEmpty;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.Future;
-
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -143,6 +96,29 @@
 import org.hisp.dhis.user.User;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Future;
+
+import static org.hisp.dhis.analytics.AnalyticsTableManager.*;
+import static org.hisp.dhis.analytics.DataQueryParams.*;
+import static org.hisp.dhis.common.DimensionalObject.*;
+import static org.hisp.dhis.common.DimensionalObjectUtils.toDimension;
+import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
+import static org.hisp.dhis.common.NameableObjectUtils.asList;
+import static org.hisp.dhis.common.NameableObjectUtils.asTypedList;
+import static org.hisp.dhis.organisationunit.OrganisationUnit.*;
+import static org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString;
+import static org.hisp.dhis.reporttable.ReportTable.IRT2D;
+import static org.hisp.dhis.reporttable.ReportTable.addIfEmpty;
+
 /**
  * @author Lars Helge Overland
  */
@@ -276,7 +252,7 @@
      * parameters.
      *
      * @param params the data query parameters.
-     * @param grid the grid.
+     * @param grid   the grid.
      */
     private void addIndicatorValues( DataQueryParams params, Grid grid )
     {
@@ -352,7 +328,7 @@
      * parameters.
      *
      * @param params the data query parameters.
-     * @param grid the grid.
+     * @param grid   the grid.
      */
     private void addDataElementValues( DataQueryParams params, Grid grid )
     {
@@ -378,7 +354,7 @@
      * parameters.
      *
      * @param params the data query parameters.
-     * @param grid the grid.
+     * @param grid   the grid.
      */
     private void addDataSetValues( DataQueryParams params, Grid grid )
     {
@@ -452,7 +428,7 @@
      * data query parameters.
      *
      * @param params the data query parameters.
-     * @param grid the grid.
+     * @param grid   the grid.
      */
     private void addDynamicDimensionValues( DataQueryParams params, Grid grid )
     {
@@ -474,7 +450,7 @@
      * parameters.
      *
      * @param params the data query parameters.
-     * @param grid the grid.
+     * @param grid   the grid.
      */
     private void addMetaData( DataQueryParams params, Grid grid )
     {
@@ -503,7 +479,7 @@
                 for ( NameableObject nameableObject : params.getDimensionOrFilter( PERIOD_DIM_ID ) )
                 {
                     Period period = (Period) nameableObject;
-                    DateTimeUnit dateTimeUnit = calendar.fromIso( DateTimeUnit.fromJdkDate( period.getStartDate() ) );
+                    DateTimeUnit dateTimeUnit = calendar.fromIso( period.getStartDate() );
                     periodUids.add( period.getPeriodType().getIsoDate( dateTimeUnit ) );
                 }
             }
@@ -605,9 +581,9 @@
      * Generates a mapping of permutations keys (organisation unit id or null)
      * and mappings of organisation unit group and counts.
      *
-     * @param params the data query parameters.
+     * @param params     the data query parameters.
      * @param indicators the indicators for which formulas to scan for organisation
-     *        unit groups.
+     *                   unit groups.
      * @return a map of maps.
      */
     private Map<String, Map<String, Integer>> getOrgUnitTargetMap( DataQueryParams params, Collection<Indicator> indicators )
@@ -694,7 +670,7 @@
      *
      * @param params the data query parameters.
      * @return a mapping between the the data set dimension key and the count of
-     *         expected data sets to report.
+     * expected data sets to report.
      */
     private Map<String, Double> getAggregatedCompletenessTargetMap( DataQueryParams params )
     {
@@ -708,7 +684,7 @@
      *
      * @param params the data query parameters.
      * @return a mapping between the the data set dimension key and the count of
-     *         expected data sets to report.
+     * expected data sets to report.
      */
     private Map<String, Double> getAggregatedOrganisationUnitTargetMap( DataQueryParams params )
     {
@@ -872,7 +848,8 @@
             List<NameableObject> dataSets = new ArrayList<>();
             List<NameableObject> operandDataElements = new ArrayList<>();
 
-            options : for ( String uid : items )
+            options:
+            for ( String uid : items )
             {
                 Indicator in = indicatorService.getIndicator( uid );
 
@@ -1140,7 +1117,7 @@
      * Replaces the indicator dimension including items with the data elements
      * part of the indicator expressions.
      *
-     * @param params the data query parameters.
+     * @param params         the data query parameters.
      * @param indicatorIndex the index of the indicator dimension in the given query.
      */
     private DataQueryParams replaceIndicatorsWithDataElements( DataQueryParams params, int indicatorIndex )
@@ -1174,9 +1151,9 @@
      * Returns a mapping between identifiers and names for the given dimensional
      * objects.
      *
-     * @param dimensions the dimensional objects.
+     * @param dimensions    the dimensional objects.
      * @param hierarchyMeta indicates whether to include meta data of the
-     *        organisation unit hierarchy.
+     *                      organisation unit hierarchy.
      */
     private Map<String, String> getUidNameMap( List<DimensionalObject> dimensions, boolean hierarchyMeta )
     {
@@ -1223,7 +1200,7 @@
                 if ( !calendar.isIso8601() && Period.class.isInstance( idObject ) )
                 {
                     Period period = (Period) idObject;
-                    DateTimeUnit dateTimeUnit = calendar.fromIso( DateTimeUnit.fromJdkDate( period.getStartDate() ) );
+                    DateTimeUnit dateTimeUnit = calendar.fromIso( period.getStartDate() );
                     map.put( period.getPeriodType().getIsoDate( dateTimeUnit ), idObject.getDisplayName() );
                 }
                 else
@@ -1253,7 +1230,7 @@
      * in the given grid. Returns an empty map if the grid or cocIndex parameters
      * are null.
      *
-     * @param grid the grid.
+     * @param grid     the grid.
      * @param cocIndex the category option combo index in the grid.
      */
     private Map<String, String> getCocNameMap( Grid grid, Integer cocIndex )
@@ -1284,6 +1261,6 @@
     {
         Integer cores = (Integer) systemSettingManager.getSystemSetting( SystemSettingManager.KEY_DATABASE_SERVER_CPUS );
 
-        return ( cores == null || cores == 0 ) ? SystemUtils.getCpuCores() : cores;
+        return (cores == null || cores == 0) ? SystemUtils.getCpuCores() : cores;
     }
 }