← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9616: Analytics, validation

 

------------------------------------------------------------
revno: 9616
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2013-01-26 10:20:27 +0200
message:
  Analytics, validation
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/data/DefaultAnalyticsService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.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-01-22 07:59:25 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-01-26 08:20:27 +0000
@@ -234,6 +234,30 @@
     }
     
     /**
+     * Returns the first dimension which has no dimension options. 
+     */
+    public Dimension getEmptyDimension()
+    {
+        for ( Dimension dim : dimensions )
+        {
+            if ( dim.getOptions() == null || dim.getOptions().isEmpty() )
+            {
+                return dim;
+            }
+        }
+        
+        for ( Dimension filter : filters )
+        {
+            if ( filter == null ||  filter.getOptions().isEmpty() )
+            {
+                return filter;
+            }
+        }
+        
+        return null;
+    }
+    
+    /**
      * Indicates whether periods are present as a dimension or as a filter. If
      * not this object is in an illegal state.
      */

=== 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-01-25 10:33:17 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-01-26 08:20:27 +0000
@@ -136,11 +136,13 @@
         
         grid.addHeader( new GridHeader( DataQueryParams.VALUE_ID, VALUE_HEADER_NAME, Double.class.getName(), false, false ) );
 
+        //TODO how to handle group sets?
+        
         // ---------------------------------------------------------------------
         // Indicators
         // ---------------------------------------------------------------------
 
-        if ( params.getIndicators() != null && !params.getIndicators().isEmpty() )
+        if ( params.getIndicators() != null )
         {         
             int indicatorIndex = params.getDataElementOrIndicatorDimensionIndex();
 
@@ -191,7 +193,7 @@
         // Data elements
         // ---------------------------------------------------------------------
 
-        if ( params.getDataElements() != null && !params.getDataElements().isEmpty() )
+        if ( params.getDataElements() != null )
         {
             DataQueryParams dataSourceParams = new DataQueryParams( params );
             dataSourceParams.removeDimension( INDICATOR_DIM_ID );
@@ -211,7 +213,7 @@
         // Data sets / completeness
         // ---------------------------------------------------------------------
 
-        if ( params.getDataSets() != null && !params.getDataSets().isEmpty() )
+        if ( params.getDataSets() != null )
         {
             DataQueryParams dataSourceParams = new DataQueryParams( params );
             dataSourceParams.removeDimension( INDICATOR_DIM_ID );
@@ -228,6 +230,22 @@
                 grid.addValue( entry.getValue() );
             }
         }
+
+        // ---------------------------------------------------------------------
+        // Other dimensions
+        // ---------------------------------------------------------------------
+
+        if ( params.getIndicators() == null && params.getDataElements() == null && params.getDataSets() == null )
+        {
+            Map<String, Double> aggregatedDataMap = getAggregatedDataValueMap( new DataQueryParams( params ), ANALYTICS_TABLE_NAME );
+            
+            for ( Map.Entry<String, Double> entry : aggregatedDataMap.entrySet() )
+            {
+                grid.addRow();
+                grid.addValues( entry.getKey().split( DIMENSION_SEP ) );
+                grid.addValue( entry.getValue() );
+            }
+        }        
         
         return grid;
     }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2013-01-17 17:49:13 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2013-01-26 08:20:27 +0000
@@ -152,7 +152,7 @@
     {
         final String sql = statementBuilder.getVacuum( tableName );
         
-        log.info( "Vacuum SQL:" + sql );
+        log.info( "Vacuum SQL: " + sql );
         
         jdbcTemplate.execute( sql );
         

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java	2013-01-25 10:33:17 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java	2013-01-26 08:20:27 +0000
@@ -178,6 +178,12 @@
             return false;
         }
         
+        if ( params.getEmptyDimension() != null )
+        {
+            ContextUtils.conflictResponse( response, "Dimensions or filters must have at least one option: " + params.getEmptyDimension() );
+            return false;
+        }
+        
         return true;        
     }
 }