dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20761
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9642: Analytics, changed syntax for requesting category option combos
------------------------------------------------------------
revno: 9642
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-01-28 17:55:56 +0200
message:
Analytics, changed syntax for requesting category option combos
modified:
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java
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/data/JdbcAnalyticsManager.java
dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java
dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.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/AnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java 2013-01-28 13:31:44 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java 2013-01-28 15:55:56 +0000
@@ -40,5 +40,5 @@
Map<String, Double> getAggregatedDataValueMap( DataQueryParams params, String tableName ) throws Exception;
DataQueryParams getFromUrl( Set<String> dimensionParams, Set<String> filterParams,
- boolean categories, AggregationType aggregationType, String measureCriteria, I18nFormat format );
+ AggregationType aggregationType, String measureCriteria, I18nFormat format );
}
=== 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-28 15:21:17 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2013-01-28 15:55:56 +0000
@@ -73,8 +73,6 @@
private List<Dimension> filters = new ArrayList<Dimension>();
- private boolean categories = false;
-
private AggregationType aggregationType;
private Map<MeasureFilter, Double> measureCriteria = new HashMap<MeasureFilter, Double>();
@@ -103,7 +101,6 @@
{
this.dimensions = new ArrayList<Dimension>( params.getDimensions() );
this.filters = new ArrayList<Dimension>( params.getFilters() );
- this.categories = params.isCategories();
this.aggregationType = params.getAggregationType();
this.measureCriteria = params.getMeasureCriteria();
@@ -118,23 +115,6 @@
// -------------------------------------------------------------------------
/**
- * Creates a list of the names of all dimensions for this query.
- */
- public List<Dimension> getSelectDimensions()
- {
- List<Dimension> list = new ArrayList<Dimension>( dimensions );
-
- list.remove( new Dimension( INDICATOR_DIM_ID ) );
-
- if ( categories )
- {
- list.add( new Dimension( CATEGORYOPTIONCOMBO_DIM_ID, DimensionType.CATEGORY_OPTION_COMBO, new ArrayList<IdentifiableObject>() ) );
- }
-
- return list;
- }
-
- /**
* Creates a list of the names of all dimensions for this query.
*/
public List<Dimension> getQueryDimensions()
@@ -159,7 +139,7 @@
*/
public int getDataElementOrIndicatorDimensionIndex()
{
- List<String> dims = getAllDimensionNamesAsList();
+ List<String> dims = getInputDimensionNamesAsList();
return dims.contains( DATAELEMENT_DIM_ID ) ? dims.indexOf( DATAELEMENT_DIM_ID ) : dims.indexOf( INDICATOR_DIM_ID );
}
@@ -169,7 +149,7 @@
*/
public int getDataElementDimensionIndex()
{
- return getAllDimensionNamesAsList().indexOf( DATAELEMENT_DIM_ID );
+ return getInputDimensionNamesAsList().indexOf( DATAELEMENT_DIM_ID );
}
/**
@@ -177,7 +157,7 @@
*/
public int getCategoryOptionComboDimensionIndex()
{
- return getAllDimensionNamesAsList().indexOf( CATEGORYOPTIONCOMBO_DIM_ID );
+ return getInputDimensionNamesAsList().indexOf( CATEGORYOPTIONCOMBO_DIM_ID );
}
/**
@@ -185,7 +165,7 @@
*/
public int getPeriodDimensionIndex()
{
- return getAllDimensionNamesAsList().indexOf( PERIOD_DIM_ID );
+ return getInputDimensionNamesAsList().indexOf( PERIOD_DIM_ID );
}
/**
@@ -526,19 +506,7 @@
return list;
}
-
- private List<String> getAllDimensionNamesAsList()
- {
- List<String> list = getInputDimensionNamesAsList();
-
- if ( categories )
- {
- list.add( CATEGORYOPTIONCOMBO_DIM_ID );
- }
- return list;
- }
-
// -------------------------------------------------------------------------
// hashCode, equals and toString
// -------------------------------------------------------------------------
@@ -548,7 +516,6 @@
{
final int prime = 31;
int result = 1;
- result = prime * result + ( categories ? 1231 : 1237);
result = prime * result + ( ( dimensions == null ) ? 0 : dimensions.hashCode() );
result = prime * result + ( ( filters == null ) ? 0 : filters.hashCode() );
return result;
@@ -586,11 +553,6 @@
return false;
}
- if ( categories != other.categories )
- {
- return false;
- }
-
if ( filters == null )
{
if ( other.filters != null )
@@ -636,16 +598,6 @@
this.filters = filters;
}
- public boolean isCategories()
- {
- return categories;
- }
-
- public void setCategories( boolean categories )
- {
- this.categories = categories;
- }
-
public AggregationType getAggregationType()
{
return aggregationType;
@@ -795,6 +747,11 @@
setDimensionOptions( dimension.getDimension(), DimensionType.DATAELEMENT_GROUPSET, dataElementGroups );
}
+ public void enableCategoryOptionCombos()
+ {
+ setDimensionOptions( CATEGORYOPTIONCOMBO_DIM_ID, DimensionType.CATEGORY_OPTION_COMBO, new ArrayList<IdentifiableObject>() );
+ }
+
// -------------------------------------------------------------------------
// Get and set helpers for filters
// -------------------------------------------------------------------------
=== 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-28 13:31:44 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2013-01-28 15:55:56 +0000
@@ -30,6 +30,7 @@
import static org.hisp.dhis.analytics.AnalyticsTableManager.ANALYTICS_TABLE_NAME;
import static org.hisp.dhis.analytics.AnalyticsTableManager.COMPLETENESS_TABLE_NAME;
import static org.hisp.dhis.analytics.DataQueryParams.DATAELEMENT_DIM_ID;
+import static org.hisp.dhis.analytics.DataQueryParams.CATEGORYOPTIONCOMBO_DIM_ID;
import static org.hisp.dhis.analytics.DataQueryParams.DATASET_DIM_ID;
import static org.hisp.dhis.analytics.DataQueryParams.DIMENSION_SEP;
import static org.hisp.dhis.analytics.DataQueryParams.INDICATOR_DIM_ID;
@@ -129,7 +130,7 @@
grid.setMetaData( params.getUidNameMap() );
- for ( Dimension col : params.getSelectDimensions() )
+ for ( Dimension col : params.getQueryDimensions() )
{
grid.addHeader( new GridHeader( col.getDimensionName(), col.getDimension(), String.class.getName(), false, true ) );
}
@@ -216,7 +217,7 @@
DataQueryParams dataSourceParams = new DataQueryParams( params );
dataSourceParams.removeDimension( INDICATOR_DIM_ID );
dataSourceParams.removeDimension( DATAELEMENT_DIM_ID );
- dataSourceParams.setCategories( false );
+ dataSourceParams.removeDimension( CATEGORYOPTIONCOMBO_DIM_ID );
dataSourceParams.setAggregationType( AggregationType.COUNT );
Map<String, Double> aggregatedDataMap = getAggregatedDataValueMap( dataSourceParams, COMPLETENESS_TABLE_NAME );
@@ -283,11 +284,10 @@
}
public DataQueryParams getFromUrl( Set<String> dimensionParams, Set<String> filterParams,
- boolean categories, AggregationType aggregationType, String measureCriteria, I18nFormat format )
+ AggregationType aggregationType, String measureCriteria, I18nFormat format )
{
DataQueryParams params = new DataQueryParams();
- params.setCategories( categories );
params.setAggregationType( aggregationType );
if ( dimensionParams != null && !dimensionParams.isEmpty() )
@@ -344,6 +344,10 @@
{
return new Dimension( dimension, DimensionType.DATASET, asList( dataSetService.getDataSetsByUid( options ) ) );
}
+ else if ( CATEGORYOPTIONCOMBO_DIM_ID.equals( dimension ) )
+ {
+ return new Dimension( dimension, DimensionType.CATEGORY_OPTION_COMBO, new ArrayList<IdentifiableObject>() );
+ }
else if ( ORGUNIT_DIM_ID.equals( dimension ) )
{
return new Dimension( dimension, DimensionType.ORGANISATIONUNIT, asList( organisationUnitService.getOrganisationUnitsByUid( options ) ) );
@@ -401,7 +405,7 @@
immutableParams.setDataElements( dataElements );
immutableParams.removeDimension( INDICATOR_DIM_ID );
immutableParams.removeDimension( DATASET_DIM_ID );
- immutableParams.setCategories( true );
+ immutableParams.enableCategoryOptionCombos();
return immutableParams;
}
=== 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 2013-01-28 13:31:44 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java 2013-01-28 15:55:56 +0000
@@ -94,14 +94,13 @@
params.populateDimensionNames();
- List<Dimension> selectDimensions = params.getSelectDimensions();
List<Dimension> queryDimensions = params.getQueryDimensions();
SqlHelper sqlHelper = new SqlHelper();
int days = PeriodType.getPeriodTypeByName( params.getPeriodType() ).getFrequencyOrder();
- String sql = "select " + getCommaDelimitedString( selectDimensions ) + ", ";
+ String sql = "select " + getCommaDelimitedString( queryDimensions ) + ", ";
if ( params.isAggregationType( AVERAGE_INT ) )
{
@@ -138,7 +137,7 @@
}
}
- sql += "group by " + getCommaDelimitedString( selectDimensions );
+ sql += "group by " + getCommaDelimitedString( queryDimensions );
log.info( sql );
@@ -157,7 +156,7 @@
StringBuilder key = new StringBuilder();
- for ( Dimension dim : selectDimensions )
+ for ( Dimension dim : queryDimensions )
{
key.append( rowSet.getString( dim.getDimensionName() ) + DIMENSION_SEP );
}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java 2013-01-28 13:31:44 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java 2013-01-28 15:55:56 +0000
@@ -130,7 +130,7 @@
Set<String> filterParams = new HashSet<String>();
filterParams.add( "ou:" + BASE_UID + "A," + BASE_UID + "B," + BASE_UID + "C," + BASE_UID + "D," + BASE_UID + "E" );
- DataQueryParams params = analyticsService.getFromUrl( dimensionParams, filterParams, false, null, null, null );
+ DataQueryParams params = analyticsService.getFromUrl( dimensionParams, filterParams, null, null, null );
assertEquals( 4, params.getDataElements().size() );
assertEquals( 3, params.getPeriods().size() );
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java 2013-01-22 07:59:25 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java 2013-01-28 15:55:56 +0000
@@ -162,7 +162,7 @@
params.setDataElements( getList( deA, deB ) );
params.setOrganisationUnits( getList( ouA, ouB ) );
params.setPeriods( getList( createPeriod( "2000Q1" ), createPeriod( "2000Q2" ) ) );
- params.setCategories( true );
+ params.enableCategoryOptionCombos();
Map<String, Double> aggregatedDataMap = new HashMap<String, Double>();
aggregatedDataMap.put( deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q1" + DIMENSION_SEP + coc.getUid(), 1d );
@@ -182,7 +182,7 @@
String ouAQ2Key = ouA.getUid() + DIMENSION_SEP + "2000Q2";
String ouBQ1Key = ouB.getUid() + DIMENSION_SEP + "2000Q1";
String ouBQ2Key = ouB.getUid() + DIMENSION_SEP + "2000Q2";
-
+
Map<DataElementOperand, Double> ouAQ1 = permutationMap.get( ouAQ1Key );
Map<DataElementOperand, Double> ouAQ2 = permutationMap.get( ouAQ2Key );
Map<DataElementOperand, Double> ouBQ1 = permutationMap.get( ouBQ1Key );
=== 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-28 13:31:44 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java 2013-01-28 15:55:56 +0000
@@ -71,13 +71,12 @@
public String getJson( // JSON, JSONP
@RequestParam Set<String> dimension,
@RequestParam(required = false) Set<String> filter,
- @RequestParam(required = false) boolean categories,
@RequestParam(required = false) AggregationType aggregationType,
@RequestParam(required = false) String measureCriteria,
Model model,
HttpServletResponse response ) throws Exception
{
- DataQueryParams params = analyticsService.getFromUrl( dimension, filter, categories, aggregationType, measureCriteria, i18nManager.getI18nFormat() );
+ DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, i18nManager.getI18nFormat() );
if ( !valid( params, response ) )
{
@@ -95,13 +94,12 @@
public void getXml(
@RequestParam Set<String> dimension,
@RequestParam(required = false) Set<String> filter,
- @RequestParam(required = false) boolean categories,
@RequestParam(required = false) AggregationType aggregationType,
@RequestParam(required = false) String measureCriteria,
Model model,
HttpServletResponse response ) throws Exception
{
- DataQueryParams params = analyticsService.getFromUrl( dimension, filter, categories, aggregationType, measureCriteria, i18nManager.getI18nFormat() );
+ DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, i18nManager.getI18nFormat() );
if ( !valid( params, response ) )
{
@@ -117,13 +115,12 @@
public void getCsv(
@RequestParam Set<String> dimension,
@RequestParam(required = false) Set<String> filter,
- @RequestParam(required = false) boolean categories,
@RequestParam(required = false) AggregationType aggregationType,
@RequestParam(required = false) String measureCriteria,
Model model,
HttpServletResponse response ) throws Exception
{
- DataQueryParams params = analyticsService.getFromUrl( dimension, filter, categories, aggregationType, measureCriteria, i18nManager.getI18nFormat() );
+ DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, i18nManager.getI18nFormat() );
if ( !valid( params, response ) )
{
@@ -139,13 +136,12 @@
public void getHtml(
@RequestParam Set<String> dimension,
@RequestParam(required = false) Set<String> filter,
- @RequestParam(required = false) boolean categories,
@RequestParam(required = false) AggregationType aggregationType,
@RequestParam(required = false) String measureCriteria,
Model model,
HttpServletResponse response ) throws Exception
{
- DataQueryParams params = analyticsService.getFromUrl( dimension, filter, categories, aggregationType, measureCriteria, i18nManager.getI18nFormat() );
+ DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, i18nManager.getI18nFormat() );
if ( !valid( params, response ) )
{