← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10157: Analytics, impl support for real column names in excel download

 

------------------------------------------------------------
revno: 10157
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-03-12 18:07:05 +0100
message:
  Analytics, impl support for real column names in excel download
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/Dimension.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.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-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-03-12 15:30:41 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-03-12 17:07:05 +0000
@@ -68,6 +68,11 @@
     public static final String VALUE_ID = "value";    
     public static final String LEVEL_PREFIX = "uidlevel";
     
+    public static final String DISPLAY_NAME_DATA_X = "Data";
+    public static final String DISPLAY_NAME_CATEGORYOPTIONCOMBO = "Category";
+    public static final String DISPLAY_NAME_PERIOD = "Period";
+    public static final String DISPLAY_NAME_ORGUNIT = "Organisation unit";    
+    
     private static final String DIMENSION_NAME_SEP = ":";
     private static final String OPTION_SEP = ";";
     public static final String DIMENSION_SEP = "-";
@@ -76,7 +81,7 @@
     public static final List<String> FIXED_DIMS = Arrays.asList( DATA_X_DIM_ID, INDICATOR_DIM_ID, DATAELEMENT_DIM_ID, DATASET_DIM_ID, PERIOD_DIM_ID, ORGUNIT_DIM_ID );
     
     public static final int MAX_DIM_OPT_PERM = 10000;
-    
+
     private static final List<DimensionType> COMPLETENESS_DIMENSION_TYPES = Arrays.asList( DATASET, ORGANISATIONUNIT, ORGANISATIONUNIT_GROUPSET );
     
     private static final DimensionItem[] DIM_OPT_ARR = new DimensionItem[0];
@@ -220,7 +225,7 @@
         {
             if ( DATA_DIMS.contains( iter.next().getDimension() ) )
             {
-                iter.set( new Dimension( DATA_X_DIM_ID, DimensionType.DATA_X ) );
+                iter.set( new Dimension( DATA_X_DIM_ID, DimensionType.DATA_X, null, DISPLAY_NAME_DATA_X, new ArrayList<IdentifiableObject>() ) );
                 break dimensions;
             }
         }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/Dimension.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/Dimension.java	2013-03-12 15:30:41 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/Dimension.java	2013-03-12 17:07:05 +0000
@@ -40,6 +40,8 @@
 
     private String dimensionName;
 
+    private String displayName;
+    
     private List<IdentifiableObject> items = new ArrayList<IdentifiableObject>();
 
     // -------------------------------------------------------------------------
@@ -72,6 +74,15 @@
         this.items = items;
     }
 
+    public Dimension( String dimension, DimensionType type, String dimensionName, String displayName, List<IdentifiableObject> items )
+    {
+        this.dimension = dimension;
+        this.type = type;
+        this.dimensionName = dimensionName;
+        this.displayName = displayName;
+        this.items = items;
+    }
+
     // -------------------------------------------------------------------------
     // Logic
     // -------------------------------------------------------------------------
@@ -100,7 +111,7 @@
     {
         return dimensionName != null ? dimensionName : dimension;
     }
-
+    
     // -------------------------------------------------------------------------
     // Get and set methods
     // -------------------------------------------------------------------------
@@ -125,6 +136,16 @@
         this.type = type;
     }
 
+    public String getDisplayName()
+    {
+        return displayName;
+    }
+
+    public void setDisplayName( String displayName )
+    {
+        this.displayName = displayName;
+    }
+
     public List<IdentifiableObject> getItems()
     {
         return items;

=== 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	2013-03-10 13:51:37 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-03-12 17:07:05 +0000
@@ -35,6 +35,10 @@
 import static org.hisp.dhis.analytics.DataQueryParams.DATASET_DIM_ID;
 import static org.hisp.dhis.analytics.DataQueryParams.DATA_X_DIM_ID;
 import static org.hisp.dhis.analytics.DataQueryParams.DIMENSION_SEP;
+import static org.hisp.dhis.analytics.DataQueryParams.DISPLAY_NAME_DATA_X;
+import static org.hisp.dhis.analytics.DataQueryParams.DISPLAY_NAME_CATEGORYOPTIONCOMBO;
+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.analytics.DataQueryParams.INDICATOR_DIM_ID;
 import static org.hisp.dhis.analytics.DataQueryParams.ORGUNIT_DIM_ID;
@@ -43,7 +47,8 @@
 import static org.hisp.dhis.analytics.DataQueryParams.getDimensionItemsFromParam;
 import static org.hisp.dhis.common.IdentifiableObjectUtils.asList;
 import static org.hisp.dhis.common.IdentifiableObjectUtils.asTypedList;
-import static org.hisp.dhis.organisationunit.OrganisationUnit.*;
+import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_USER_ORGUNIT;
+import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_USER_ORGUNIT_CHILDREN;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -171,7 +176,7 @@
         
         for ( Dimension col : params.getHeaderDimensions() )
         {
-            grid.addHeader( new GridHeader( col.getDimensionName(), col.getDimension(), String.class.getName(), false, true ) );
+            grid.addHeader( new GridHeader( col.getDimension(), col.getDisplayName(), String.class.getName(), false, true ) );
         }
         
         grid.addHeader( new GridHeader( DataQueryParams.VALUE_ID, VALUE_HEADER_NAME, Double.class.getName(), false, false ) );
@@ -513,7 +518,7 @@
         
         if ( CATEGORYOPTIONCOMBO_DIM_ID.equals( dimension ) )
         {
-            return Arrays.asList( new Dimension( dimension, DimensionType.CATEGORY_OPTION_COMBO, new ArrayList<IdentifiableObject>() ) );
+            return Arrays.asList( new Dimension( dimension, DimensionType.CATEGORY_OPTION_COMBO, null, DISPLAY_NAME_CATEGORYOPTIONCOMBO, new ArrayList<IdentifiableObject>() ) );
         }
         
         if ( ORGUNIT_DIM_ID.equals( dimension ) )
@@ -548,7 +553,7 @@
                 throw new IllegalQueryException( "Dimension ou is present in query without any valid dimension options" );
             }
             
-            return Arrays.asList( new Dimension( dimension, DimensionType.ORGANISATIONUNIT, ous ) );
+            return Arrays.asList( new Dimension( dimension, DimensionType.ORGANISATIONUNIT, null, DISPLAY_NAME_ORGUNIT, ous ) );
         }
         
         if ( PERIOD_DIM_ID.equals( dimension ) )
@@ -582,30 +587,30 @@
             List<Period> periodList = new ArrayList<Period>( periods );
             Collections.sort( periodList, PeriodComparator.INSTANCE );
             
-            return Arrays.asList( new Dimension( dimension, DimensionType.PERIOD, asList( periodList ) ) );
+            return Arrays.asList( new Dimension( dimension, DimensionType.PERIOD, null, DISPLAY_NAME_PERIOD, asList( periodList ) ) );
         }
         
-        OrganisationUnitGroupSet orgUnitGroupSet = organisationUnitGroupService.getOrganisationUnitGroupSet( dimension );
+        OrganisationUnitGroupSet ougs = organisationUnitGroupService.getOrganisationUnitGroupSet( dimension );
             
-        if ( orgUnitGroupSet != null )
+        if ( ougs != null )
         {
             List<IdentifiableObject> ous = asList( organisationUnitGroupService.getOrganisationUnitGroupsByUid( options ) );
             
-            return Arrays.asList( new Dimension( dimension, DimensionType.ORGANISATIONUNIT_GROUPSET, ous ) );
+            return Arrays.asList( new Dimension( dimension, DimensionType.ORGANISATIONUNIT_GROUPSET, null, ougs.getDisplayName(), ous ) );
         }
         
-        DataElementGroupSet dataElementGroupSet = dataElementService.getDataElementGroupSet( dimension );
+        DataElementGroupSet degs = dataElementService.getDataElementGroupSet( dimension );
         
-        if ( dataElementGroupSet != null )
+        if ( degs != null )
         {
             List<IdentifiableObject> des = asList( dataElementService.getDataElementGroupsByUid( options ) );
             
-            return Arrays.asList( new Dimension( dimension, DimensionType.DATAELEMENT_GROUPSET, des ) );
+            return Arrays.asList( new Dimension( dimension, DimensionType.DATAELEMENT_GROUPSET, null, degs.getDisplayName(), des ) );
         }
         
         throw new IllegalQueryException( "Dimension identifier does not reference any dimension: " + dimension );
     }
-    
+        
     private DataQueryParams replaceIndicatorsWithDataElements( DataQueryParams params, int indicatorIndex )
     {
         List<Indicator> indicators = asTypedList( params.getIndicators() );        
@@ -621,7 +626,9 @@
     {
         Map<Object, String> map = new HashMap<Object, String>();
         map.putAll( getUidNameMap( params.getDimensions() ) );
-        map.putAll( getUidNameMap( params.getFilters() ) );        
+        map.putAll( getUidNameMap( params.getFilters() ) );
+        map.put( DATA_X_DIM_ID, DISPLAY_NAME_DATA_X );
+        
         return map;
     }
     
@@ -657,6 +664,11 @@
             {
                 map.put( idObject.getUid(), idObject.getDisplayName() );
             }
+            
+            if ( dimension.getDisplayName() != null )
+            {
+                map.put( dimension.getDimension(), dimension.getDisplayName() );
+            }
         }
         
         return map;

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java	2013-03-04 10:30:59 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java	2013-03-12 17:07:05 +0000
@@ -540,8 +540,21 @@
         
         for ( int colIndex = 0; colIndex < headers.size(); colIndex++ )
         {
-            if ( headers.get( colIndex ).isMeta() )
+            GridHeader header = headers.get( colIndex );
+            
+            if ( header.isMeta() )
             {
+                // Header
+                
+                String headerMetaName = metaData.get( header.getName() );
+                
+                if ( headerMetaName != null )
+                {
+                    header.setName( headerMetaName );
+                }
+                
+                // Column cells
+                
                 List<Object> col = getColumn( colIndex );
                 
                 for ( int rowIndex = 0; rowIndex < col.size(); rowIndex++ )