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