← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19715: BaseAnalyticalObject, simplified impl of getDimensionalObject

 

------------------------------------------------------------
revno: 19715
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-08-04 18:05:37 +0200
message:
  BaseAnalyticalObject, simplified impl of getDimensionalObject
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventchart/EventChart.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventreport/EventReport.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.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/chart/Chart.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java	2015-08-04 13:40:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java	2015-08-04 16:05:37 +0000
@@ -120,12 +120,12 @@
     @Override
     public void populateAnalyticalProperties()
     {
-        columns.addAll( getDimensionalObjectList( series ) );
-        rows.addAll( getDimensionalObjectList( category ) );
+        columns.add( getDimensionalObject( series ) );
+        rows.add( getDimensionalObject( category ) );
 
         for ( String filter : filterDimensions )
         {
-            filters.addAll( getDimensionalObjectList( filter ) );
+            filters.add( getDimensionalObject( filter ) );
         }
     }
 

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java	2015-08-04 15:11:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java	2015-08-04 16:05:37 +0000
@@ -210,11 +210,6 @@
         return relatives != null && !relatives.isEmpty();
     }
     
-    public boolean hasOrganisationUnits()
-    {
-        return organisationUnits != null && !organisationUnits.isEmpty();
-    }
-
     public boolean hasOrganisationUnitLevels()
     {
         return organisationUnitLevels != null && !organisationUnitLevels.isEmpty();
@@ -225,11 +220,6 @@
         return itemOrganisationUnitGroups != null && !itemOrganisationUnitGroups.isEmpty();
     }
     
-    public boolean hasAnyOrganisationUnits()
-    {
-        return hasOrganisationUnits() || hasOrganisationUnitLevels() || hasItemOrganisationUnitGroups() || hasUserOrgUnit();
-    }
-
     public boolean hasSortOrder()
     {
         return sortOrder != 0;
@@ -535,17 +525,15 @@
      * @param dimension the dimension identifier.
      * @return a list of DimensionalObjects.
      */
-    protected List<DimensionalObject> getDimensionalObjectList( String dimension )
+    protected DimensionalObject getDimensionalObject( String dimension )
     {
-        List<DimensionalObject> objects = new ArrayList<>();
-
         List<String> categoryDims = getCategoryDims();
 
         if ( DATA_X_DIM_ID.equals( dimension ) )
         {
-            objects.add( new BaseDimensionalObject( dimension, DimensionType.DATA_X, getDataDimensionNameableObjects() ) );
+            return new BaseDimensionalObject( dimension, DimensionType.DATA_X, getDataDimensionNameableObjects() );
         }
-        else if ( PERIOD_DIM_ID.equals( dimension ) && ( !periods.isEmpty() || hasRelativePeriods() ) )
+        else if ( PERIOD_DIM_ID.equals( dimension ) )
         {
             List<Period> periodList = new ArrayList<>( periods );
 
@@ -561,9 +549,9 @@
 
             Collections.sort( periodList, new AscendingPeriodComparator() );
 
-            objects.add( new BaseDimensionalObject( dimension, DimensionType.PERIOD, periodList ) );
+            return new BaseDimensionalObject( dimension, DimensionType.PERIOD, periodList );
         }
-        else if ( ORGUNIT_DIM_ID.equals( dimension ) && ( hasAnyOrganisationUnits() || !transientOrganisationUnits.isEmpty() ) )
+        else if ( ORGUNIT_DIM_ID.equals( dimension ) )
         {
             List<NameableObject> ouList = new ArrayList<>();
             ouList.addAll( organisationUnits );
@@ -604,25 +592,25 @@
                 }
             }
 
-            objects.add( new BaseDimensionalObject( dimension, DimensionType.ORGANISATIONUNIT, ouList ) );
+            return new BaseDimensionalObject( dimension, DimensionType.ORGANISATIONUNIT, ouList );
         }
         else if ( CATEGORYOPTIONCOMBO_DIM_ID.equals( dimension ) )
         {
-            objects.add( new BaseDimensionalObject( dimension, DimensionType.CATEGORY_OPTION_COMBO, new ArrayList<BaseNameableObject>() ) );
+            return new BaseDimensionalObject( dimension, DimensionType.CATEGORY_OPTION_COMBO, new ArrayList<BaseNameableObject>() ) ;
         }
         else if ( categoryDims.contains( dimension ) )
         {
             DataElementCategoryDimension categoryDimension = categoryDimensions.get( categoryDims.indexOf( dimension ) );
 
-            objects.add( new BaseDimensionalObject( dimension, DimensionType.CATEGORY, categoryDimension.getItems() ) );
+            return new BaseDimensionalObject( dimension, DimensionType.CATEGORY, categoryDimension.getItems() );
         }
         else if ( DATA_COLLAPSED_DIM_ID.contains( dimension ) )
         {
-            objects.add( new BaseDimensionalObject( dimension, DimensionType.DATA_COLLAPSED, new ArrayList<NameableObject>() ) );
+            return new BaseDimensionalObject( dimension, DimensionType.DATA_COLLAPSED, new ArrayList<NameableObject>() );
         }
         else if ( STATIC_DIMS.contains( dimension ) )
         {
-            objects.add( new BaseDimensionalObject( dimension, DimensionType.STATIC, new ArrayList<NameableObject>() ) );
+            return new BaseDimensionalObject( dimension, DimensionType.STATIC, new ArrayList<NameableObject>() );
         }
         else
         {
@@ -640,7 +628,7 @@
 
             if ( deGroupMap.containsKey( dimension ) )
             {
-                objects.add( new BaseDimensionalObject( dimension, DimensionType.DATAELEMENT_GROUPSET, deGroupMap.get( dimension ) ) );
+                return new BaseDimensionalObject( dimension, DimensionType.DATAELEMENT_GROUPSET, deGroupMap.get( dimension ) );
             }
 
             // Organisation unit group set
@@ -657,7 +645,7 @@
 
             if ( ouGroupMap.containsKey( dimension ) )
             {
-                objects.add( new BaseDimensionalObject( dimension, DimensionType.ORGANISATIONUNIT_GROUPSET, ouGroupMap.get( dimension ) ) );
+                return new BaseDimensionalObject( dimension, DimensionType.ORGANISATIONUNIT_GROUPSET, ouGroupMap.get( dimension ) );
             }
 
             // Category option group set
@@ -674,7 +662,7 @@
 
             if ( coGroupMap.containsKey( dimension ) )
             {
-                objects.add( new BaseDimensionalObject( dimension, DimensionType.CATEGORYOPTION_GROUPSET, coGroupMap.get( dimension ) ) );
+                return new BaseDimensionalObject( dimension, DimensionType.CATEGORYOPTION_GROUPSET, coGroupMap.get( dimension ) );
             }
 
             // Tracked entity attribute
@@ -690,7 +678,7 @@
             {
                 TrackedEntityAttributeDimension tead = attributes.get( dimension );
 
-                objects.add( new BaseDimensionalObject( dimension, DimensionType.PROGRAM_ATTRIBUTE, null, tead.getDisplayName(), tead.getLegendSet(), tead.getFilter() ) );
+                return new BaseDimensionalObject( dimension, DimensionType.PROGRAM_ATTRIBUTE, null, tead.getDisplayName(), tead.getLegendSet(), tead.getFilter() );
             }
 
             // Tracked entity data element
@@ -706,11 +694,11 @@
             {
                 TrackedEntityDataElementDimension tedd = dataElements.get( dimension );
 
-                objects.add( new BaseDimensionalObject( dimension, DimensionType.PROGRAM_DATAELEMENT, null, tedd.getDisplayName(), tedd.getLegendSet(), tedd.getFilter() ) );
+                return new BaseDimensionalObject( dimension, DimensionType.PROGRAM_DATAELEMENT, null, tedd.getDisplayName(), tedd.getLegendSet(), tedd.getFilter() );
             }
         }
 
-        return objects;
+        throw new IllegalArgumentException( "Not a valid dimension: " + dimension );
     }
 
     private List<String> getCategoryDims()

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventchart/EventChart.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventchart/EventChart.java	2015-08-02 14:59:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventchart/EventChart.java	2015-08-04 16:05:37 +0000
@@ -167,17 +167,17 @@
     {
         for ( String column : columnDimensions )
         {
-            columns.addAll( getDimensionalObjectList( column ) );
+            columns.add( getDimensionalObject( column ) );
         }
 
         for ( String row : rowDimensions )
         {
-            rows.addAll( getDimensionalObjectList( row ) );
+            rows.add( getDimensionalObject( row ) );
         }
 
         for ( String filter : filterDimensions )
         {
-            filters.addAll( getDimensionalObjectList( filter ) );
+            filters.add( getDimensionalObject( filter ) );
         }
         
         value = ObjectUtils.firstNonNull( dataElementValueDimension, attributeValueDimension );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventreport/EventReport.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventreport/EventReport.java	2015-08-02 14:59:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventreport/EventReport.java	2015-08-04 16:05:37 +0000
@@ -220,17 +220,17 @@
     {
         for ( String column : columnDimensions )
         {
-            columns.addAll( getDimensionalObjectList( column ) );
+            columns.add( getDimensionalObject( column ) );
         }
 
         for ( String row : rowDimensions )
         {
-            rows.addAll( getDimensionalObjectList( row ) );
+            rows.add( getDimensionalObject( row ) );
         }
 
         for ( String filter : filterDimensions )
         {
-            filters.addAll( getDimensionalObjectList( filter ) );
+            filters.add( getDimensionalObject( filter ) );
         }
         
         value = ObjectUtils.firstNonNull( dataElementValueDimension, attributeValueDimension );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java	2015-06-26 16:44:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java	2015-08-04 16:05:37 +0000
@@ -153,9 +153,13 @@
     @Override
     public void populateAnalyticalProperties()
     {
-        columns.addAll( getDimensionalObjectList( DimensionalObject.DATA_X_DIM_ID ) );
-        rows.addAll( getDimensionalObjectList( DimensionalObject.ORGUNIT_DIM_ID ) );
-        filters.addAll( getDimensionalObjectList( DimensionalObject.PERIOD_DIM_ID ) );
+        columns.add( getDimensionalObject( DimensionalObject.DATA_X_DIM_ID ) );
+        rows.add( getDimensionalObject( DimensionalObject.ORGUNIT_DIM_ID ) );
+        
+        if ( !periods.isEmpty() || hasRelativePeriods() )
+        {
+            filters.add( getDimensionalObject( DimensionalObject.PERIOD_DIM_ID ) );
+        }
     }
 
     public List<OrganisationUnit> getAllOrganisationUnits()

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2015-06-26 16:44:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2015-08-04 16:05:37 +0000
@@ -384,17 +384,17 @@
     {
         for ( String column : columnDimensions )
         {
-            columns.addAll( getDimensionalObjectList( column ) );
+            columns.add( getDimensionalObject( column ) );
         }
 
         for ( String row : rowDimensions )
         {
-            rows.addAll( getDimensionalObjectList( row ) );
+            rows.add( getDimensionalObject( row ) );
         }
 
         for ( String filter : filterDimensions )
         {
-            filters.addAll( getDimensionalObjectList( filter ) );
+            filters.add( getDimensionalObject( filter ) );
         }
     }