Search in sources :

Example 36 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)

Example 37 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 38 with GridHeader

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

the class GridTest method testRepositionHeadersUsingInvalidHeader.

@Test
void testRepositionHeadersUsingInvalidHeader() {
    // 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("invalidHeader", "headerB", "headerA"));
    // When
    final IllegalQueryException expectedException = assertThrows(IllegalQueryException.class, () -> grid.repositionHeaders(headers));
    // Then
    assertThat(expectedException.getMessage(), is(equalTo("Header param `invalidHeader` does not exist")));
    assertThat(expectedException.getErrorCode(), is(equalTo(E7230)));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Grid(org.hisp.dhis.common.Grid) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test)

Example 39 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 40 with GridHeader

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

the class GridTest method testRepositionHeaders.

@Test
void testRepositionHeaders() {
    // 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("headerC", "headerB", "headerA"));
    // When
    grid.repositionHeaders(headers);
    // Then
    assertThat(grid.getHeaderWidth(), is(equalTo(3)));
    assertThat(grid.getHeaders().get(0).getName(), is(equalTo("headerC")));
    assertThat(grid.getHeaders().get(1).getName(), is(equalTo("headerB")));
    assertThat(grid.getHeaders().get(2).getName(), is(equalTo("headerA")));
}
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)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