AbstractAnalyticsService { protected Grid getGrid( EventQueryParams params ) { securityManager.decideAccessEventQuery( params ); params = securityManager.withUserConstraints( params ); queryValidator.validate( params ); params = new EventQueryParams.Builder( params ) .withStartEndDatesForPeriods() .build(); Grid grid = createGridWithHeaders( params ); for ( DimensionalObject dimension : params.getDimensions() ) { grid.addHeader( new GridHeader( dimension.getDimension(), dimension.getDimensionDisplayName(), ValueType.TEXT, String.class.getName(), false, true ) ); } for ( QueryItem item : params.getItems() ) { if ( item.getValueType() == ValueType.ORGANISATION_UNIT && params.getCoordinateField().equals( item.getItem().getUid() ) ) { grid.addHeader( new GridHeader( item.getItem().getUid(), item.getItem().getDisplayProperty( params.getDisplayProperty() ), COORDINATE, Point.class.getName(), false, true, item.getOptionSet(), item.getLegendSet() ) ); } else { grid.addHeader( new GridHeader( item.getItem().getUid(), item.getItem().getDisplayProperty( params.getDisplayProperty() ), item.getValueType(), item.getTypeAsString(), false, true, item.getOptionSet(), item.getLegendSet() ) ); } } long count = addEventData( grid, params ); addMetadata( params, grid ); if ( params.hasDataIdScheme() ) { substituteData( grid ); } if ( params.isPaging() ) { Pager pager = new Pager( params.getPageWithDefault(), count, params.getPageSizeWithDefault() ); grid.getMetaData().put( PAGER.getKey(), pager ); } return grid; } AbstractAnalyticsService( AnalyticsSecurityManager securityManager, EventQueryValidator queryValidator );   }
@Test public void verifyHeaderCreationBasedOnQueryItemsAndDimensions() { DimensionalObject periods = new BaseDimensionalObject( DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList( peA ) ); DimensionalObject orgUnits = new BaseDimensionalObject( DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, "ouA", Lists.newArrayList( ouA ) ); QueryItem qiA = new QueryItem( deA, null, deA.getValueType(), deA.getAggregationType(), null ); QueryItem qiB = new QueryItem( deB, null, deB.getValueType(), deB.getAggregationType(), null ); QueryItem qiC = new QueryItem( deC, null, deC.getValueType(), deC.getAggregationType(), null ); EventQueryParams params = new EventQueryParams.Builder() .addDimension( periods ) .addDimension( orgUnits ) .addItem( qiA ).addItem( qiB ).addItem( qiC ) .withCoordinateField( deB.getUid() ) .withSkipData( true ) .withSkipMeta( false ) .withApiVersion( DhisApiVersion.V33 ) .build(); when( securityManager.withUserConstraints( any( EventQueryParams.class ) ) ).thenReturn( params ); Grid grid = dummyAnalyticsService.getGrid( params ); final List<GridHeader> headers = grid.getHeaders(); assertThat( headers, is( notNullValue() ) ); assertThat( headers, hasSize( 4 ) ); assertHeader( headers.get( 0 ), "ou", "ouA", ValueType.TEXT, String.class.getName() ); assertHeader( headers.get( 1 ), deA.getUid(), deA.getName(), ValueType.TEXT, String.class.getName() ); assertHeader( headers.get( 2 ), deB.getUid(), deB.getName(), ValueType.COORDINATE, Point.class.getName() ); assertHeader( headers.get( 3 ), deC.getUid(), deC.getName(), ValueType.NUMBER, Double.class.getName() ); }