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)));
}
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")));
}
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;
}
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;
}
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);
}
Aggregations