Search in sources :

Example 51 with GridHeader

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

the class ListGrid method addHeaders.

@Override
public Grid addHeaders(SqlRowSet rs) {
    SqlRowSetMetaData rsmd = rs.getMetaData();
    int columnNo = rsmd.getColumnCount();
    for (int i = 1; i <= columnNo; i++) {
        addHeader(new GridHeader(rsmd.getColumnLabel(i), false, false));
    }
    return this;
}
Also used : SqlRowSetMetaData(org.springframework.jdbc.support.rowset.SqlRowSetMetaData) GridHeader(org.hisp.dhis.common.GridHeader)

Example 52 with GridHeader

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

the class ListGrid method addHeaders.

// -------------------------------------------------------------------------
// SQL utility methods
// -------------------------------------------------------------------------
@Override
public Grid addHeaders(ResultSet rs) {
    try {
        ResultSetMetaData rsmd = rs.getMetaData();
        int columnNo = rsmd.getColumnCount();
        for (int i = 1; i <= columnNo; i++) {
            addHeader(new GridHeader(rsmd.getColumnLabel(i), false, false));
        }
    } catch (SQLException ex) {
        throw new RuntimeException(ex);
    }
    return this;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) SQLException(java.sql.SQLException) GridHeader(org.hisp.dhis.common.GridHeader)

Example 53 with GridHeader

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

the class GridTest method testAddHeaderList.

@Test
void testAddHeaderList() {
    Grid grid = new ListGrid();
    GridHeader headerA = new GridHeader("DataElementA", "Data element A");
    GridHeader headerB = new GridHeader("DataElementB", "Data element B");
    GridHeader headerC = new GridHeader("DataElementC", "Data element C");
    GridHeader headerD = new GridHeader("DataElementC", "Data element D");
    GridHeader headerE = new GridHeader("DataElementC", "Data element E");
    grid.addHeader(headerA);
    grid.addHeader(headerB);
    assertEquals(2, grid.getHeaders().size());
    List<GridHeader> headers = Lists.newArrayList(headerC, headerD, headerE);
    grid.addHeaders(1, headers);
    assertEquals(5, grid.getHeaders().size());
    assertEquals(headerA, grid.getHeaders().get(0));
    assertEquals(headerC, grid.getHeaders().get(1));
    assertEquals(headerD, grid.getHeaders().get(2));
    assertEquals(headerE, grid.getHeaders().get(3));
    assertEquals(headerB, grid.getHeaders().get(4));
}
Also used : Grid(org.hisp.dhis.common.Grid) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test)

Example 54 with GridHeader

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

the class GridTest method repositionColumns.

@Test
void repositionColumns() {
    // Given
    final GridHeader headerA = new GridHeader("headerA", "Header A");
    final GridHeader headerB = new GridHeader("headerB", "Header B");
    final GridHeader headerC = new GridHeader("headerC", "Header C");
    final Grid grid = new ListGrid();
    grid.addHeader(headerA);
    grid.addHeader(headerB);
    grid.addHeader(headerC);
    // first
    grid.addRow().addValue(1).addValue("a").addValue("a-1");
    // row +
    // columns
    grid.addRow().addValue(2).addValue("b").addValue("b-1");
    grid.addRow().addValue(3).addValue("c").addValue("c-1");
    final Set<String> headers = new LinkedHashSet<>(List.of("headerC", "headerB", "headerA"));
    final Set<Integer> newColumnIndexes = grid.repositionHeaders(headers);
    // When
    grid.repositionColumns(newColumnIndexes);
    // Then
    assertThat(grid.getHeaderWidth(), is(equalTo(3)));
    // first row + repositioned columns
    assertThat(grid.getRow(0).get(0), is(equalTo("a-1")));
    assertThat(grid.getRow(0).get(1), is(equalTo("a")));
    assertThat(grid.getRow(0).get(2), is(equalTo(1)));
    // second row + repositioned columns
    assertThat(grid.getRow(1).get(0), is(equalTo("b-1")));
    assertThat(grid.getRow(1).get(1), is(equalTo("b")));
    assertThat(grid.getRow(1).get(2), is(equalTo(2)));
    // third row + repositioned columns
    assertThat(grid.getRow(2).get(0), is(equalTo("c-1")));
    assertThat(grid.getRow(2).get(1), is(equalTo("c")));
    assertThat(grid.getRow(2).get(2), is(equalTo(3)));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Grid(org.hisp.dhis.common.Grid) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test)

Example 55 with GridHeader

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

the class GridTest method testKeepOnlyThese.

@Test
void testKeepOnlyThese() {
    // Given
    final GridHeader headerA = new GridHeader("headerA", "Header A");
    final GridHeader headerB = new GridHeader("headerB", "Header B");
    final GridHeader headerC = new GridHeader("headerC", "Header C");
    final Grid grid = new ListGrid();
    grid.addHeader(headerA);
    grid.addHeader(headerB);
    grid.addHeader(headerC);
    grid.addRow().addValue(1).addValue("a").addValue("a-1");
    grid.addRow().addValue(2).addValue("b").addValue("b-1");
    grid.addRow().addValue(3).addValue("c").addValue("c-1");
    final Set<String> headers = new LinkedHashSet<>(List.of("headerA", "headerB"));
    // When
    grid.keepOnlyThese(headers);
    // Then
    assertThat(grid.getHeaderWidth(), is(equalTo(2)));
    assertThat(grid.getHeaders().get(0).getName(), is(equalTo("headerA")));
    assertThat(grid.getHeaders().get(1).getName(), is(equalTo("headerB")));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Grid(org.hisp.dhis.common.Grid) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test)

Aggregations

GridHeader (org.hisp.dhis.common.GridHeader)60 Grid (org.hisp.dhis.common.Grid)39 ListGrid (org.hisp.dhis.system.grid.ListGrid)29 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 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)3 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)3