Search in sources :

Example 41 with GridHeader

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

the class AnalyticsUtilsTest method testGetDataValueSetFromGridEmpty.

@Test
void testGetDataValueSetFromGridEmpty() {
    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(DimensionalObject.CATEGORYOPTIONCOMBO_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ATTRIBUTEOPTIONCOMBO_DIM_ID));
    grid.addHeader(new GridHeader(VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, false, false));
    DataValueSet dvs = AnalyticsUtils.getDataValueSetFromGrid(DataQueryParams.newBuilder().build(), grid);
    assertNotNull(dvs);
    assertNotNull(dvs.getDataValues());
    assertEquals(0, dvs.getDataValues().size());
}
Also used : DataValueSet(org.hisp.dhis.dxf2.datavalueset.DataValueSet) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 42 with GridHeader

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

the class AnalyticsUtilsTest method testGetDataValueSetFromGrid.

@Test
void testGetDataValueSetFromGrid() {
    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(DimensionalObject.CATEGORYOPTIONCOMBO_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ATTRIBUTEOPTIONCOMBO_DIM_ID));
    grid.addHeader(new GridHeader(VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, false, false));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouA", "peA", "coA", "aoA", 1d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouA", "peB", null, null, 2d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouB", "peA", null, null, 3d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouB", "peB", null, null, 4d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxB", "ouA", "peA", "coA", null, 5d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxB", "ouA", "peB", "coA", "aoB", 6d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxC", "ouA", "peA", null, "aoA", 7));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxC", "ouA", "peB", null, null, 8d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxD", "ouA", "peA", "coB", null, 9d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxE", "ouA", "peB", null, null, 10));
    DataValueSet dvs = AnalyticsUtils.getDataValueSetFromGrid(DataQueryParams.newBuilder().build(), grid);
    assertNotNull(dvs);
    assertNotNull(dvs.getDataValues());
    assertEquals(10, dvs.getDataValues().size());
    assertEquals("dxA", dvs.getDataValues().get(1).getDataElement());
    assertEquals("ouA", dvs.getDataValues().get(1).getOrgUnit());
    assertEquals("peB", dvs.getDataValues().get(1).getPeriod());
    assertNull(dvs.getDataValues().get(1).getCategoryOptionCombo());
    assertNull(dvs.getDataValues().get(1).getAttributeOptionCombo());
    assertEquals("2.0", dvs.getDataValues().get(1).getValue());
    assertEquals("dxB", dvs.getDataValues().get(4).getDataElement());
    assertEquals("ouA", dvs.getDataValues().get(4).getOrgUnit());
    assertEquals("peA", dvs.getDataValues().get(4).getPeriod());
    assertEquals("coA", dvs.getDataValues().get(4).getCategoryOptionCombo());
    assertNull(dvs.getDataValues().get(4).getAttributeOptionCombo());
    assertEquals("5.0", dvs.getDataValues().get(4).getValue());
    assertEquals("dxC", dvs.getDataValues().get(6).getDataElement());
    assertEquals("ouA", dvs.getDataValues().get(6).getOrgUnit());
    assertEquals("peA", dvs.getDataValues().get(6).getPeriod());
    assertNull(dvs.getDataValues().get(6).getCategoryOptionCombo());
    assertEquals("aoA", dvs.getDataValues().get(6).getAttributeOptionCombo());
    assertEquals("7", dvs.getDataValues().get(6).getValue());
    assertEquals("dxD", dvs.getDataValues().get(8).getDataElement());
    assertEquals("ouA", dvs.getDataValues().get(8).getOrgUnit());
    assertEquals("peA", dvs.getDataValues().get(8).getPeriod());
    assertEquals("coB", dvs.getDataValues().get(8).getCategoryOptionCombo());
    assertNull(dvs.getDataValues().get(8).getAttributeOptionCombo());
    assertEquals("9.0", dvs.getDataValues().get(8).getValue());
    assertEquals("dxE", dvs.getDataValues().get(9).getDataElement());
    assertEquals("ouA", dvs.getDataValues().get(9).getOrgUnit());
    assertEquals("peB", dvs.getDataValues().get(9).getPeriod());
    assertNull(dvs.getDataValues().get(9).getCategoryOptionCombo());
    assertNull(dvs.getDataValues().get(9).getAttributeOptionCombo());
    assertEquals("10", dvs.getDataValues().get(9).getValue());
}
Also used : DataValueSet(org.hisp.dhis.dxf2.datavalueset.DataValueSet) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 43 with GridHeader

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

the class AnalyticsUtilsTest method testHandleGridForDataValueSetEmpty.

@Test
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, 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());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 44 with GridHeader

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

the class PeriodOffsetUtilsTest method verifyGetPeriodOffsetRow.

@Test
void verifyGetPeriodOffsetRow() {
    // Given
    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));
    int periodIndex = 2;
    grid.addRow();
    grid.addValue("de1");
    grid.addValue("ou2");
    grid.addValue("202001");
    grid.addValue(3);
    grid.addRow();
    grid.addValue("de1");
    grid.addValue("ou3");
    grid.addValue("202002");
    grid.addValue(5);
    DataElement dataElement = createDataElement(0);
    dataElement.setUid("de1");
    // When
    final List<Object> row1 = PeriodOffsetUtils.getPeriodOffsetRow(grid.getRow(0), periodIndex, 1);
    // Then
    assertThat(row1, is(notNullValue()));
    assertThat(row1, hasSize(4));
    assertThat(row1.get(periodIndex), is("201912"));
    // When
    final List<Object> row2 = PeriodOffsetUtils.getPeriodOffsetRow(grid.getRow(1), periodIndex, -1);
    // Then
    assertThat(row2, is(notNullValue()));
    assertThat(row2, hasSize(4));
    assertThat(row2.get(periodIndex), is("202003"));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) 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) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 45 with GridHeader

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

the class AbstractGridView method renderMergedOutputModel.

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    Object object = model.get("model");
    List<Grid> grids = new ArrayList<>();
    if (WebMetadata.class.isAssignableFrom(object.getClass())) {
        WebMetadata metadata = (WebMetadata) object;
        Collection<Field> fields = ReflectionUtils.collectFields(WebMetadata.class, PredicateUtils.idObjectCollections);
        for (Field field : fields) {
            List<IdentifiableObject> identifiableObjects = ReflectionUtils.invokeGetterMethod(field.getName(), metadata);
            if (identifiableObjects == null || identifiableObjects.isEmpty()) {
                continue;
            }
            Grid grid = new ListGrid();
            grid.setTitle(HibernateProxyUtils.getRealClass(identifiableObjects.get(0)).getSimpleName() + "s");
            boolean nameable = false;
            grid.addHeader(new GridHeader("UID", false, false));
            grid.addHeader(new GridHeader("Name", false, false));
            if (NameableObject.class.isAssignableFrom(HibernateProxyUtils.getRealClass(HibernateProxyUtils.getRealClass(object)))) {
                grid.addHeader(new GridHeader("ShortName", false, false));
                nameable = true;
            }
            grid.addHeader(new GridHeader("Code", false, false));
            for (IdentifiableObject identifiableObject : identifiableObjects) {
                grid.addRow();
                grid.addValue(identifiableObject.getUid());
                grid.addValue(identifiableObject.getName());
                if (nameable) {
                    grid.addValue(((NameableObject) identifiableObject).getShortName());
                }
                grid.addValue(identifiableObject.getCode());
            }
            grids.add(grid);
        }
    } else {
        IdentifiableObject identifiableObject = (IdentifiableObject) object;
        Grid grid = new ListGrid();
        grid.setTitle(HibernateProxyUtils.getRealClass(identifiableObject).getSimpleName());
        grid.addEmptyHeaders(2);
        grid.addRow().addValue("UID").addValue(identifiableObject.getUid());
        grid.addRow().addValue("Name").addValue(identifiableObject.getName());
        if (NameableObject.class.isAssignableFrom(HibernateProxyUtils.getRealClass(identifiableObject))) {
            grid.addRow().addValue("ShortName").addValue(((NameableObject) identifiableObject).getShortName());
            grid.addRow().addValue("Description").addValue(((NameableObject) identifiableObject).getDescription());
        }
        grid.addRow().addValue("Code").addValue(identifiableObject.getCode());
        grids.add(grid);
    }
    renderGrids(grids, response);
}
Also used : Field(java.lang.reflect.Field) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) NameableObject(org.hisp.dhis.common.NameableObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) GridHeader(org.hisp.dhis.common.GridHeader)

Aggregations

GridHeader (org.hisp.dhis.common.GridHeader)63 Grid (org.hisp.dhis.common.Grid)41 ListGrid (org.hisp.dhis.system.grid.ListGrid)31 Test (org.junit.jupiter.api.Test)17 ArrayList (java.util.ArrayList)15 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)15 DimensionalObject (org.hisp.dhis.common.DimensionalObject)13 HashMap (java.util.HashMap)9 List (java.util.List)8 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)7 Map (java.util.Map)6 QueryItem (org.hisp.dhis.common.QueryItem)6 LinkedHashSet (java.util.LinkedHashSet)5 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)5 DataElement (org.hisp.dhis.dataelement.DataElement)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 RepeatableStageParams (org.hisp.dhis.common.RepeatableStageParams)4 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)3