AnalyticsUtils { public static void handleGridForDataValueSet( DataQueryParams params, Grid grid ) { Map<String, DimensionalItemObject> dimItemObjectMap = AnalyticsUtils.getDimensionalItemObjectMap( params ); List<Object> cocCol = Lists.newArrayList(); List<Object> aocCol = Lists.newArrayList(); int dxInx = grid.getIndexOfHeader( DATA_X_DIM_ID ); int vlInx = grid.getHeaderWidth() - 1; Assert.isTrue( dxInx >= 0, "Data dimension index must be greater than or equal to zero" ); Assert.isTrue( vlInx >= 0, "Value index must be greater than or equal to zero" ); for ( List<Object> row : grid.getRows() ) { String dx = String.valueOf( row.get( dxInx ) ); Assert.notNull( dx, "Data dimension item cannot be null" ); DimensionalItemObject item = dimItemObjectMap.get( dx ); Assert.notNull( item, "Dimensional item cannot be null" ); Object value = AnalyticsUtils.getIntegerOrValue( row.get( vlInx ), item ); row.set( vlInx, value ); String coc = null, aoc = null; if ( DataDimensionalItemObject.class.isAssignableFrom( item.getClass() ) ) { DataDimensionalItemObject dataItem = (DataDimensionalItemObject) item; coc = dataItem.getAggregateExportCategoryOptionCombo(); aoc = dataItem.getAggregateExportAttributeOptionCombo(); } else if ( DataElementOperand.class.isAssignableFrom( item.getClass() ) ) { row.set( dxInx, DimensionalObjectUtils.getFirstIdentifer( dx ) ); coc = DimensionalObjectUtils.getSecondIdentifer( dx ); } cocCol.add( coc ); aocCol.add( aoc ); } grid.addHeader( vlInx, new GridHeader( ATTRIBUTEOPTIONCOMBO_DIM_ID, ATTRIBUTEOPTIONCOMBO_DIM_ID, ValueType.TEXT, String.class.getName(), false, true ) ) .addHeader( vlInx, new GridHeader( CATEGORYOPTIONCOMBO_DIM_ID, CATEGORYOPTIONCOMBO_DIM_ID, ValueType.TEXT, String.class.getName(), false, true ) ) .addColumn( vlInx, aocCol ) .addColumn( vlInx, cocCol ); }  static String getDebugDataSql( DataQueryParams params ); static List<DimensionalItemObject> getByDataDimensionItemType( DataDimensionItemType itemType, List<DimensionalItemObject> dataDimensionOptions ); static Number getRoundedValue( DataQueryParams params, Integer decimals, Double value ); static Object getRoundedValueObject( DataQueryParams params, Object value ); static ColumnDataType getColumnType( ValueType valueType, boolean spatialSupport ); static Map<String, T> convertDxToOperand( Map<String, T> valueMap, TotalType totalType ); static Map<String, Double> getDoubleMap( Map<String, Object> map ); static Map<String, Object> getAggregatedDataValueMapping( Grid grid ); static DataValueSet getDataValueSetFromGrid( DataQueryParams params, Grid grid ); static void handleGridForDataValueSet( DataQueryParams params, Grid grid ); static Object getIntegerOrValue( Object value, DimensionalItemObject item ); static Map<String, DimensionalItemObject> getDimensionalItemObjectMap( DataQueryParams params ); static Map<String, String> getDimensionItemNameMap( DataQueryParams params ); static Map<String, MetadataItem> getDimensionMetadataItemMap( DataQueryParams params ); static Map<String, String> getCocNameMap( DataQueryParams params ); static Map<String, String> getUidDisplayPropertyMap( List<QueryItem> queryItems, DisplayProperty displayProperty ); static Map<String, String> getUidDisplayPropertyMap( List<DimensionalObject> dimensions, boolean hierarchyMeta, DisplayProperty displayProperty ); static boolean periodIsOutsideApprovalMaxYears( Integer year, Integer maxYears ); static int getLevelFromOrgUnitDimensionName( String dimensionName ); static boolean isTableLayout( List<String> columns, List<String> rows ); static Double calculateYearlyWeightedAverage( Double year1Value, Double year2Value, Double factor ); static Double getBaseMonth( PeriodType periodType ); static void throwIllegalQueryEx( ErrorCode errorCode, Object... args ); static boolean isPeriodInPeriods( String period, List<DimensionalItemObject> periods ); static List<DimensionalItemObject> findDimensionalItems( String dimensionIdentifier,
        List<DimensionalItemObject> items ); static boolean hasPeriod( List<Object> row, int periodIndex ); static final String ERR_MSG_TABLE_NOT_EXISTING; }
@Test public void testHandleGridForDataValueSetEmpty() { Grid grid = new ListGrid(); DataQueryParams params = DataQueryParams.newBuilder(). addDimension( new BaseDimensionalObject( DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList() ) ) .build(); grid.addHeader( new GridHeader( DimensionalObject.DATA_X_DIM_ID ) ); grid.addHeader( new GridHeader( DimensionalObject.ORGUNIT_DIM_ID ) ); grid.addHeader( new GridHeader( DimensionalObject.PERIOD_DIM_ID ) ); grid.addHeader( new GridHeader( VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, Double.class.getName(), false, false ) ); assertEquals( 4, grid.getHeaders().size() ); assertEquals( 0, grid.getWidth() ); assertEquals( 0, grid.getHeight() ); AnalyticsUtils.handleGridForDataValueSet( params, grid ); assertEquals( 6, grid.getHeaders().size() ); assertEquals( 0, grid.getWidth() ); assertEquals( 0, grid.getHeight() ); }
@Test public void testHandleGridForDataValueSet() { IndicatorType itA = new IndicatorType(); CategoryOptionCombo ocA = createCategoryOptionCombo( 'A' ); ocA.setUid( "ceabcdefghA" ); DataElement dxA = createDataElement( 'A' ); dxA.setUid( "deabcdefghA" ); dxA.setValueType( ValueType.INTEGER ); DataElement dxB = createDataElement( 'B' ); dxB.setUid( "deabcdefghB" ); dxB.setValueType( ValueType.NUMBER ); Indicator dxC = createIndicator( 'C', itA ); dxC.setUid( "deabcdefghC" ); dxC.setDecimals( 0 ); dxC.setAggregateExportAttributeOptionCombo( "ceabcdefghA" ); Indicator dxD = createIndicator( 'D', itA ); dxD.setUid( "deabcdefghD" ); dxD.setDecimals( 2 ); dxD.setAggregateExportCategoryOptionCombo( "ceabcdefghB" ); DataElementOperand dxE = new DataElementOperand( dxA, ocA ); DataElementOperand dxF = new DataElementOperand( dxB, ocA ); DataQueryParams params = DataQueryParams.newBuilder() .addDimension( new BaseDimensionalObject( DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList( dxA, dxB, dxC, dxD, dxE, dxF ) ) ) .build(); Grid grid = new ListGrid(); grid.addHeader( new GridHeader( DimensionalObject.DATA_X_DIM_ID ) ); grid.addHeader( new GridHeader( DimensionalObject.ORGUNIT_DIM_ID ) ); grid.addHeader( new GridHeader( DimensionalObject.PERIOD_DIM_ID ) ); grid.addHeader( new GridHeader( VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, Double.class.getName(), false, false ) ); grid.addRow().addValuesAsList( Lists.newArrayList( "deabcdefghA", "ouA", "peA", 1d ) ); grid.addRow().addValuesAsList( Lists.newArrayList( "deabcdefghB", "ouA", "peA", 2d ) ); grid.addRow().addValuesAsList( Lists.newArrayList( "deabcdefghC", "ouA", "peA", 3d ) ); grid.addRow().addValuesAsList( Lists.newArrayList( "deabcdefghD", "ouA", "peA", 4d ) ); grid.addRow().addValuesAsList( Lists.newArrayList( "deabcdefghA.ceabcdefghA", "ouA", "peA", 5d ) ); grid.addRow().addValuesAsList( Lists.newArrayList( "deabcdefghB.ceabcdefghA", "ouA", "peA", 6d ) ); assertEquals( 4, grid.getWidth() ); assertEquals( 6, grid.getHeight() ); AnalyticsUtils.handleGridForDataValueSet( params, grid ); assertEquals( 6, grid.getWidth() ); assertEquals( 6, grid.getHeight() ); assertEquals( "deabcdefghA", grid.getRow( 0 ).get( 0 ) ); assertNull( grid.getRow( 0 ).get( 3 ) ); assertNull( grid.getRow( 0 ).get( 4 ) ); assertEquals( 1, grid.getRow( 0 ).get( 5 ) ); assertEquals( "deabcdefghB", grid.getRow( 1 ).get( 0 ) ); assertNull( grid.getRow( 1 ).get( 3 ) ); assertNull( grid.getRow( 1 ).get( 4 ) ); assertEquals( 2d, (Double) grid.getRow( 1 ).get( 5 ), 0.01 ); assertEquals( "deabcdefghC", grid.getRow( 2 ).get( 0 ) ); assertNull( grid.getRow( 2 ).get( 3 ) ); assertEquals( "ceabcdefghA", grid.getRow( 2 ).get( 4 ) ); assertEquals( 3, grid.getRow( 2 ).get( 5 ) ); assertEquals( "deabcdefghD", grid.getRow( 3 ).get( 0 ) ); assertEquals( "ceabcdefghB", grid.getRow( 3 ).get( 3 ) ); assertNull( grid.getRow( 3 ).get( 4 ) ); assertEquals( 4d, (Double) grid.getRow( 3 ).get( 5 ), 0.01 ); assertEquals( "deabcdefghA", grid.getRow( 4 ).get( 0 ) ); assertEquals( "ceabcdefghA", grid.getRow( 4 ).get( 3 ) ); assertNull( grid.getRow( 4 ).get( 4 ) ); assertEquals( 5, grid.getRow( 4 ).get( 5 ) ); assertEquals( "deabcdefghB", grid.getRow( 5 ).get( 0 ) ); assertEquals( "ceabcdefghA", grid.getRow( 5 ).get( 3 ) ); assertNull( grid.getRow( 5 ).get( 4 ) ); assertEquals( 6d, (Double) grid.getRow( 5 ).get( 5 ), 0.01 ); }