← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17416: factor out code for getting a local period identifier in DefaultResourceTableService

 

------------------------------------------------------------
revno: 17416
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-11-11 13:58:46 +0545
message:
  factor out code for getting a local period identifier in DefaultResourceTableService
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java
  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/JdbcAnalyticsManager.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.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/common/IdentifiableObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java	2014-09-29 16:10:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java	2014-11-11 08:13:46 +0000
@@ -28,6 +28,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.calendar.Calendar;
+import org.hisp.dhis.calendar.DateTimeUnit;
+import org.hisp.dhis.dataelement.DataElementCategory;
+import org.hisp.dhis.dataelement.DataElementCategoryCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryOption;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
+
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -39,13 +47,6 @@
 import java.util.ListIterator;
 import java.util.Map;
 
-import org.hisp.dhis.calendar.Calendar;
-import org.hisp.dhis.calendar.DateTimeUnit;
-import org.hisp.dhis.dataelement.DataElementCategory;
-import org.hisp.dhis.dataelement.DataElementCategoryCombo;
-import org.hisp.dhis.dataelement.DataElementCategoryOption;
-import org.hisp.dhis.period.Period;
-
 /**
  * @author Lars Helge Overland
  */
@@ -55,12 +56,15 @@
     private static final String SEPARATOR = "-";
     private static final SimpleDateFormat LONG_DATE_FORMAT = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss" );
 
-    public static final Map<String, String> CLASS_ALIAS = new HashMap<String, String>() {{
-        put( "CategoryOption", DataElementCategoryOption.class.getSimpleName() );
-        put( "Category", DataElementCategory.class.getSimpleName() );
-        put( "CategoryCombo", DataElementCategoryCombo.class.getSimpleName() );
-    } };
-    
+    public static final Map<String, String> CLASS_ALIAS = new HashMap<String, String>()
+    {
+        {
+            put( "CategoryOption", DataElementCategoryOption.class.getSimpleName() );
+            put( "Category", DataElementCategory.class.getSimpleName() );
+            put( "CategoryCombo", DataElementCategoryCombo.class.getSimpleName() );
+        }
+    };
+
     /**
      * Joins the names of the IdentifiableObjects in the given list and separates
      * them with a comma and space. Returns null if the given list is null or has
@@ -108,30 +112,50 @@
 
         return uids;
     }
-    
+
     /**
-     * Returns a list of iso period identifiers for the given collection of 
+     * Returns a list of calendar specific period identifiers for the given collection of
      * periods and calendar.
-     * 
-     * @param periods the list of periods.
+     *
+     * @param periods  the list of periods.
      * @param calendar the calendar to use for generation of iso periods.
      * @return a list of iso period identifiers.
      */
-    public static <T extends IdentifiableObject> List<String> getIsoPeriods( Collection<T> periods, Calendar calendar )
+    public static <T extends IdentifiableObject> List<String> getLocalPeriods( Collection<T> periods, Calendar calendar )
     {
         List<String> isoPeriods = new ArrayList<>();
-        
+
         for ( IdentifiableObject object : periods )
         {
             Period period = (Period) object;
             DateTimeUnit dateTimeUnit = calendar.fromIso( period.getStartDate() );
             isoPeriods.add( period.getPeriodType().getIsoDate( dateTimeUnit ) );
         }
-        
+
         return isoPeriods;
     }
 
     /**
+     * Returns a local period identifier for a specific date / periodType / calendar.
+     *
+     * @param date Date to create from
+     * @param periodType PeriodType to create from
+     * @param calendar Calendar to create from
+     * @return Period identifier based on given calendar
+     */
+    public static String getLocalPeriod( Date date, PeriodType periodType, Calendar calendar )
+    {
+        Period period = periodType.createPeriod( date, calendar );
+
+        if ( calendar.isIso8601() )
+        {
+            return period.getIsoDate();
+        }
+
+        return periodType.getIsoDate( calendar.fromIso( period.getStartDate() ) );
+    }
+
+    /**
      * Returns a list of internal identifiers for the given collection of IdentifiableObjects.
      *
      * @param objects the list of IdentifiableObjects.
@@ -224,7 +248,7 @@
      * @param collection the collection.
      * @return a list.
      */
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings( "unchecked" )
     public static <T extends IdentifiableObject> List<T> asTypedList( Collection<IdentifiableObject> collection )
     {
         List<T> list = new ArrayList<>();

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2014-11-11 03:58:32 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2014-11-11 08:13:46 +0000
@@ -66,6 +66,7 @@
 import java.util.List;
 import java.util.Map;
 
+import static org.hisp.dhis.common.IdentifiableObjectUtils.getLocalPeriod;
 import static org.hisp.dhis.dataapproval.DataApprovalLevelService.APPROVAL_LEVEL_UNAPPROVED;
 import static org.hisp.dhis.resourcetable.ResourceTableStore.*;
 
@@ -480,7 +481,7 @@
                 {
                     if ( rowType.getFrequencyOrder() <= periodType.getFrequencyOrder() )
                     {
-                        values.add( getPeriodString( startDate, periodType, calendar ) );
+                        values.add( getLocalPeriod( startDate, periodType, calendar ) );
                     }
                     else
                     {
@@ -497,18 +498,6 @@
         log.info( "Date period table generated" );
     }
 
-    private String getPeriodString( Date date, PeriodType periodType, Calendar calendar )
-    {
-        Period period = periodType.createPeriod( date, calendar );
-
-        if ( calendar.isIso8601() )
-        {
-            return period.getIsoDate();
-        }
-
-        return periodType.getIsoDate( calendar.fromIso( period.getStartDate() ) );
-    }
-
     // -------------------------------------------------------------------------
     // DataElementCategoryOptionComboTable
     // -------------------------------------------------------------------------

=== 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-11-06 07:25:08 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2014-11-11 08:13:46 +0000
@@ -50,7 +50,7 @@
 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.getIsoPeriods;
+import static org.hisp.dhis.common.IdentifiableObjectUtils.getLocalPeriods;
 import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
 import static org.hisp.dhis.common.NameableObjectUtils.asList;
 import static org.hisp.dhis.common.NameableObjectUtils.asTypedList;
@@ -503,7 +503,7 @@
             }
             else
             {
-                periodUids = getIsoPeriods( params.getDimensionOrFilter( PERIOD_DIM_ID ), calendar );
+                periodUids = getLocalPeriods( params.getDimensionOrFilter( PERIOD_DIM_ID ), calendar );
             }
 
             metaData.put( PERIOD_DIM_ID, periodUids );

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java	2014-11-11 03:58:32 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java	2014-11-11 08:13:46 +0000
@@ -69,7 +69,7 @@
 import static org.hisp.dhis.analytics.MeasureFilter.*;
 import static org.hisp.dhis.common.DimensionalObject.DIMENSION_SEP;
 import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
-import static org.hisp.dhis.common.IdentifiableObjectUtils.getIsoPeriods;
+import static org.hisp.dhis.common.IdentifiableObjectUtils.getLocalPeriods;
 import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
 import static org.hisp.dhis.system.util.TextUtils.*;
 
@@ -316,7 +316,7 @@
 
                 if ( !calendar.isIso8601() && PERIOD_DIM_ID.equals( dim.getDimension() ) )
                 {
-                    sql += sqlHelper.whereAnd() + " " + col + " in (" + getQuotedCommaDelimitedString( getIsoPeriods( dim.getItems(), calendar ) ) + ") ";
+                    sql += sqlHelper.whereAnd() + " " + col + " in (" + getQuotedCommaDelimitedString( getLocalPeriods( dim.getItems(), calendar ) ) + ") ";
                 }
                 else
                 {
@@ -343,7 +343,7 @@
 
                         if ( !calendar.isIso8601() && PERIOD_DIM_ID.equals( filter.getDimension() ) )
                         {
-                            sql += col + " in (" + getQuotedCommaDelimitedString( getIsoPeriods( filter.getItems(), calendar ) ) + ") or ";
+                            sql += col + " in (" + getQuotedCommaDelimitedString( getLocalPeriods( filter.getItems(), calendar ) ) + ") or ";
                         }
                         else
                         {

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java	2014-10-16 06:17:19 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java	2014-11-11 08:13:46 +0000
@@ -266,7 +266,7 @@
             }
             else
             {
-                periods = IdentifiableObjectUtils.getIsoPeriods( report.getRelatives().getRelativePeriods( date, format, true ), calendar );
+                periods = IdentifiableObjectUtils.getLocalPeriods( report.getRelatives().getRelativePeriods( date, format, true ), calendar );
             }
         }