Search in sources :

Example 56 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 57 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)

Example 58 with GridHeader

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

the class DataAnalysisController method generateAnalysisReportGridFromResults.

private Grid generateAnalysisReportGridFromResults(List<DeflatedDataValue> results, OrganisationUnit orgUnit) {
    Grid grid = new ListGrid();
    if (results != null) {
        I18nFormat format = i18nManager.getI18nFormat();
        I18n i18n = i18nManager.getI18n();
        grid.setTitle(i18n.getString("data_analysis_report"));
        if (orgUnit != null) {
            grid.setSubtitle(orgUnit.getName());
        }
        grid.addHeader(new GridHeader(i18n.getString("dataelement"), false, true));
        grid.addHeader(new GridHeader(i18n.getString("source"), false, true));
        grid.addHeader(new GridHeader(i18n.getString("period"), false, true));
        grid.addHeader(new GridHeader(i18n.getString("min"), false, false));
        grid.addHeader(new GridHeader(i18n.getString("value"), false, false));
        grid.addHeader(new GridHeader(i18n.getString("max"), false, false));
        for (DeflatedDataValue dataValue : results) {
            Period period = dataValue.getPeriod();
            grid.addRow();
            grid.addValue(dataValue.getDataElementName());
            grid.addValue(dataValue.getSourceName());
            grid.addValue(format.formatPeriod(period));
            grid.addValue(dataValue.getMin());
            grid.addValue(dataValue.getValue());
            grid.addValue(dataValue.getMax());
        }
    }
    return grid;
}
Also used : DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) Period(org.hisp.dhis.period.Period) I18nFormat(org.hisp.dhis.i18n.I18nFormat) ListGrid(org.hisp.dhis.system.grid.ListGrid) I18n(org.hisp.dhis.i18n.I18n) GridHeader(org.hisp.dhis.common.GridHeader)

Example 59 with GridHeader

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

the class DataAnalysisController method generateValidationRulesReportGridFromResults.

private Grid generateValidationRulesReportGridFromResults(List<ValidationResult> results, OrganisationUnit orgUnit) {
    Grid grid = new ListGrid();
    if (results != null) {
        I18nFormat format = i18nManager.getI18nFormat();
        I18n i18n = i18nManager.getI18n();
        grid.setTitle(i18n.getString("data_quality_report"));
        if (orgUnit != null) {
            grid.setSubtitle(orgUnit.getName());
        }
        grid.addHeader(new GridHeader(i18n.getString("source"), false, true));
        grid.addHeader(new GridHeader(i18n.getString("period"), false, true));
        grid.addHeader(new GridHeader(i18n.getString("validation_rule"), false, true));
        grid.addHeader(new GridHeader(i18n.getString("importance"), false, true));
        grid.addHeader(new GridHeader(i18n.getString("left_side_description"), false, true));
        grid.addHeader(new GridHeader(i18n.getString("value"), false, false));
        grid.addHeader(new GridHeader(i18n.getString("operator"), false, false));
        grid.addHeader(new GridHeader(i18n.getString("value"), false, false));
        grid.addHeader(new GridHeader(i18n.getString("right_side_description"), false, true));
        for (ValidationResult validationResult : results) {
            OrganisationUnit unit = validationResult.getOrganisationUnit();
            Period period = validationResult.getPeriod();
            Importance importance = validationResult.getValidationRule().getImportance();
            Operator operator = validationResult.getValidationRule().getOperator();
            grid.addRow();
            grid.addValue(unit.getName());
            grid.addValue(format.formatPeriod(period));
            grid.addValue(validationResult.getValidationRule().getName());
            grid.addValue(i18n.getString(importance.toString().toLowerCase()));
            grid.addValue(validationResult.getValidationRule().getLeftSide().getDescription());
            grid.addValue(String.valueOf(validationResult.getLeftsideValue()));
            grid.addValue(i18n.getString(operator.toString()));
            grid.addValue(String.valueOf(validationResult.getRightsideValue()));
            grid.addValue(validationResult.getValidationRule().getRightSide().getDescription());
        }
    }
    return grid;
}
Also used : Importance(org.hisp.dhis.validation.Importance) Operator(org.hisp.dhis.expression.Operator) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) Period(org.hisp.dhis.period.Period) I18nFormat(org.hisp.dhis.i18n.I18nFormat) ValidationResult(org.hisp.dhis.validation.ValidationResult) ListGrid(org.hisp.dhis.system.grid.ListGrid) I18n(org.hisp.dhis.i18n.I18n) GridHeader(org.hisp.dhis.common.GridHeader)

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