← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11141: Fixed bug when saving pivots/charts with multiple dx dimensions

 

------------------------------------------------------------
revno: 11141
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-06-05 14:45:22 +0200
message:
  Fixed bug when saving pivots/charts with multiple dx dimensions
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObjectUtils.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.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/DimensionalObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObjectUtils.java	2013-05-24 11:48:35 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObjectUtils.java	2013-06-05 12:45:22 +0000
@@ -55,6 +55,33 @@
         
         return identifier;
     }
+    
+    /**
+     * Creates a unique list of dimension identifiers based on the given list
+     * of DimensionalObjects.
+     * 
+     * @param dimensions the list of DimensionalObjects.
+     * @return list of dimension identifiers.
+     */
+    public static List<String> getUniqueDimensions( List<DimensionalObject> dimensions )
+    {
+        List<String> dims = new ArrayList<String>();
+        
+        if ( dimensions != null )
+        {
+            for ( DimensionalObject dimension : dimensions )
+            {
+                String dim = toDimension( dimension.getDimension() );
+                
+                if ( dim != null && !dims.contains( dim ) )
+                {
+                    dims.add( dim );
+                }
+            }
+        }
+        
+        return dims;
+    }
 
     /**
      * Creates a two-dimensional array of dimension items based on the list of

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java	2013-05-27 16:40:21 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java	2013-06-05 12:45:22 +0000
@@ -27,6 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.common.DimensionalObjectUtils.getUniqueDimensions;
 import static org.hisp.dhis.common.DimensionalObjectUtils.toDimension;
 
 import java.io.IOException;
@@ -41,7 +42,6 @@
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.chart.ChartService;
 import org.hisp.dhis.common.DimensionService;
-import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.i18n.I18nManager;
@@ -246,12 +246,6 @@
             chart.setCategory( toDimension( chart.getRows().get( 0 ).getDimension() ) );
         }
         
-        if ( chart.getFilters() != null )
-        {
-            for ( DimensionalObject dimension : chart.getFilters() )
-            {
-                chart.getFilterDimensions().add( toDimension( dimension.getDimension() ) );
-            }
-        }
+        chart.getFilterDimensions().addAll( getUniqueDimensions( chart.getFilters() ) );
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java	2013-05-25 12:22:29 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java	2013-06-05 12:45:22 +0000
@@ -27,7 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.common.DimensionalObjectUtils.toDimension;
+import static org.hisp.dhis.common.DimensionalObjectUtils.getUniqueDimensions;
 import static org.hisp.dhis.system.util.CodecUtils.filenameEncode;
 
 import java.io.InputStream;
@@ -40,7 +40,6 @@
 import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
 import org.hisp.dhis.common.DimensionService;
-import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.dataset.DataSetService;
@@ -302,28 +301,8 @@
         reportTable.getRowDimensions().clear();
         reportTable.getFilterDimensions().clear();
         
-        if ( reportTable.getColumns() != null )
-        {
-            for ( DimensionalObject column : reportTable.getColumns() )
-            {
-                reportTable.getColumnDimensions().add( toDimension( column.getDimension() ) );
-            }
-        }
-        
-        if ( reportTable.getRows() != null )
-        {
-            for ( DimensionalObject row : reportTable.getRows() )
-            {
-                reportTable.getRowDimensions().add( toDimension( row.getDimension() ) );
-            }
-        }
-        
-        if ( reportTable.getFilters() != null )
-        {
-            for ( DimensionalObject filter : reportTable.getFilters() )
-            {
-                reportTable.getFilterDimensions().add( toDimension( filter.getDimension() ) );
-            }
-        }
+        reportTable.getColumnDimensions().addAll( getUniqueDimensions( reportTable.getColumns() ) );
+        reportTable.getRowDimensions().addAll( getUniqueDimensions( reportTable.getRows() ) );
+        reportTable.getFilterDimensions().addAll( getUniqueDimensions( reportTable.getFilters() ) );        
     }
 }