Search in sources :

Example 1 with DisplayProperty

use of org.hisp.dhis.common.DisplayProperty in project dhis2-core by dhis2.

the class ReportTableTest method testGetGridShowHierarchy.

@Test
public void testGetGridShowHierarchy() {
    ReportTable reportTable = new ReportTable("Grid table", dataElements, new ArrayList<>(), new ArrayList<>(), periods, Lists.newArrayList(unitB, unitC), true, true, false, null, null, null);
    reportTable.setShowHierarchy(true);
    reportTable.init(null, null, null, null, null, i18nFormat);
    Map<Object, List<?>> ancestorMap = new HashMap<>();
    ancestorMap.put(unitB.getUid(), unitB.getAncestorNames(null, true));
    ancestorMap.put(unitC.getUid(), unitC.getAncestorNames(null, true));
    Map<String, Object> metaData = new HashMap<>();
    Map<String, Object> internalMetaData = new HashMap<>();
    internalMetaData.put(AnalyticsMetaDataKey.ORG_UNIT_ANCESTORS.getKey(), ancestorMap);
    Map<String, Object> valueMap = new HashMap<>();
    valueMap.put(dataElementA.getDimensionItem() + DIMENSION_SEP + periodA.getDimensionItem() + DIMENSION_SEP + unitB.getDimensionItem(), 11);
    valueMap.put(dataElementA.getDimensionItem() + DIMENSION_SEP + periodA.getDimensionItem() + DIMENSION_SEP + unitC.getDimensionItem(), 21);
    valueMap.put(dataElementA.getDimensionItem() + DIMENSION_SEP + periodB.getDimensionItem() + DIMENSION_SEP + unitB.getDimensionItem(), 12);
    valueMap.put(dataElementA.getDimensionItem() + DIMENSION_SEP + periodB.getDimensionItem() + DIMENSION_SEP + unitC.getDimensionItem(), 22);
    valueMap.put(dataElementB.getDimensionItem() + DIMENSION_SEP + periodA.getDimensionItem() + DIMENSION_SEP + unitB.getDimensionItem(), 13);
    valueMap.put(dataElementB.getDimensionItem() + DIMENSION_SEP + periodA.getDimensionItem() + DIMENSION_SEP + unitC.getDimensionItem(), 23);
    valueMap.put(dataElementB.getDimensionItem() + DIMENSION_SEP + periodB.getDimensionItem() + DIMENSION_SEP + unitB.getDimensionItem(), 14);
    valueMap.put(dataElementB.getDimensionItem() + DIMENSION_SEP + periodB.getDimensionItem() + DIMENSION_SEP + unitC.getDimensionItem(), 24);
    DisplayProperty property = DisplayProperty.NAME;
    Grid grid = reportTable.getGrid(new ListGrid(metaData, internalMetaData), valueMap, property, false);
    assertEquals(10, grid.getWidth());
    assertEquals(10, grid.getHeaders().size());
    assertEquals(2, grid.getHeight());
    assertEquals(unitA.getDisplayName(), grid.getValue(0, 0));
    assertEquals(unitB.getDisplayName(), grid.getValue(0, 1));
    assertEquals(unitB.getUid(), grid.getValue(0, 2));
    assertEquals(unitB.getDisplayProperty(property), grid.getValue(0, 3));
    assertEquals(unitB.getCode(), grid.getValue(0, 4));
    assertEquals(unitA.getDisplayName(), grid.getValue(1, 0));
    assertEquals(unitC.getDisplayName(), grid.getValue(1, 1));
    assertEquals(unitC.getUid(), grid.getValue(1, 2));
    assertEquals(unitC.getDisplayProperty(property), grid.getValue(1, 3));
    assertEquals(unitC.getCode(), grid.getValue(1, 4));
}
Also used : DisplayProperty(org.hisp.dhis.common.DisplayProperty) HashMap(java.util.HashMap) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) ArrayList(java.util.ArrayList) List(java.util.List) ListGrid(org.hisp.dhis.system.grid.ListGrid) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 2 with DisplayProperty

use of org.hisp.dhis.common.DisplayProperty in project dhis2-core by dhis2.

the class ReportTableTest method testGetGrid.

@Test
public void testGetGrid() {
    ReportTable reportTable = new ReportTable("Grid table", dataElements, new ArrayList<>(), new ArrayList<>(), periods, Lists.newArrayList(unitB, unitC), true, true, false, null, null, null);
    reportTable.init(null, null, null, null, null, i18nFormat);
    List<String> columnDims = reportTable.getColumnDimensions();
    List<String> rowDims = reportTable.getRowDimensions();
    assertEquals(2, columnDims.size());
    assertEquals(1, rowDims.size());
    assertTrue(columnDims.contains(DimensionalObject.DATA_X_DIM_ID));
    assertTrue(columnDims.contains(DimensionalObject.PERIOD_DIM_ID));
    assertTrue(rowDims.contains(DimensionalObject.ORGUNIT_DIM_ID));
    Map<String, Object> valueMap = new HashMap<>();
    valueMap.put(dataElementA.getDimensionItem() + DIMENSION_SEP + periodA.getDimensionItem() + DIMENSION_SEP + unitB.getDimensionItem(), 11);
    valueMap.put(dataElementA.getDimensionItem() + DIMENSION_SEP + periodA.getDimensionItem() + DIMENSION_SEP + unitC.getDimensionItem(), 21);
    valueMap.put(dataElementA.getDimensionItem() + DIMENSION_SEP + periodB.getDimensionItem() + DIMENSION_SEP + unitB.getDimensionItem(), 12);
    valueMap.put(dataElementA.getDimensionItem() + DIMENSION_SEP + periodB.getDimensionItem() + DIMENSION_SEP + unitC.getDimensionItem(), 22);
    valueMap.put(dataElementB.getDimensionItem() + DIMENSION_SEP + periodA.getDimensionItem() + DIMENSION_SEP + unitB.getDimensionItem(), 13);
    valueMap.put(dataElementB.getDimensionItem() + DIMENSION_SEP + periodA.getDimensionItem() + DIMENSION_SEP + unitC.getDimensionItem(), 23);
    valueMap.put(dataElementB.getDimensionItem() + DIMENSION_SEP + periodB.getDimensionItem() + DIMENSION_SEP + unitB.getDimensionItem(), 14);
    valueMap.put(dataElementB.getDimensionItem() + DIMENSION_SEP + periodB.getDimensionItem() + DIMENSION_SEP + unitC.getDimensionItem(), 24);
    DisplayProperty property = DisplayProperty.NAME;
    Grid grid = reportTable.getGrid(new ListGrid(), valueMap, property, false);
    assertEquals(8, grid.getWidth());
    assertEquals(8, grid.getHeaders().size());
    assertEquals(2, grid.getHeight());
    assertEquals(unitB.getUid(), grid.getValue(0, 0));
    assertEquals(unitB.getDisplayProperty(property), grid.getValue(0, 1));
    assertEquals(unitB.getCode(), grid.getValue(0, 2));
    assertEquals(unitB.getDescription(), grid.getValue(0, 3));
    assertEquals(11, grid.getValue(0, 4));
    assertEquals(12, grid.getValue(0, 5));
    assertEquals(13, grid.getValue(0, 6));
    assertEquals(14, grid.getValue(0, 7));
    assertEquals(unitC.getUid(), grid.getValue(1, 0));
    assertEquals(unitC.getDisplayProperty(property), grid.getValue(1, 1));
    assertEquals(unitC.getCode(), grid.getValue(1, 2));
    assertEquals(unitC.getDescription(), grid.getValue(1, 3));
    assertEquals(21, grid.getValue(1, 4));
    assertEquals(22, grid.getValue(1, 5));
    assertEquals(23, grid.getValue(1, 6));
    assertEquals(24, grid.getValue(1, 7));
}
Also used : DisplayProperty(org.hisp.dhis.common.DisplayProperty) HashMap(java.util.HashMap) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

HashMap (java.util.HashMap)2 DhisSpringTest (org.hisp.dhis.DhisSpringTest)2 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 DimensionalObject (org.hisp.dhis.common.DimensionalObject)2 DisplayProperty (org.hisp.dhis.common.DisplayProperty)2 Grid (org.hisp.dhis.common.Grid)2 ListGrid (org.hisp.dhis.system.grid.ListGrid)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1