use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class DimensionalObjectUtilsTest method testGetDataElementOperandIdSchemeCodeMap.
@Test
public void testGetDataElementOperandIdSchemeCodeMap() {
DataElement deA = new DataElement("NameA");
DataElement deB = new DataElement("NameB");
deA.setUid("D123456789A");
deB.setUid("D123456789B");
deA.setCode("DCodeA");
deB.setCode("DCodeB");
DataElementCategoryOptionCombo ocA = new DataElementCategoryOptionCombo();
ocA.setUid("C123456789A");
ocA.setCode("CCodeA");
DataElementOperand opA = new DataElementOperand(deA, ocA);
DataElementOperand opB = new DataElementOperand(deB, ocA);
List<DataElementOperand> operands = Lists.newArrayList(opA, opB);
Map<String, String> map = DimensionalObjectUtils.getDataElementOperandIdSchemeMap(operands, IdScheme.CODE);
assertEquals(3, map.size());
assertEquals("DCodeA", map.get("D123456789A"));
assertEquals("DCodeB", map.get("D123456789B"));
assertEquals("CCodeA", map.get("C123456789A"));
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class AnalyticsUtilsTest method testHandleGridForDataValueSet.
@Test
public void testHandleGridForDataValueSet() {
IndicatorType itA = new IndicatorType();
DataElementCategoryOptionCombo ocA = createCategoryOptionCombo('A');
ocA.setUid("ceabcdefghA");
DataElement dxA = createDataElement('A');
dxA.setUid("deabcdefghA");
dxA.setValueType(ValueType.INTEGER);
DataElement dxB = createDataElement('B');
dxB.setUid("deabcdefghB");
dxB.setValueType(ValueType.NUMBER);
Indicator dxC = createIndicator('C', itA);
dxC.setUid("deabcdefghC");
dxC.setDecimals(0);
dxC.setAggregateExportAttributeOptionCombo("ceabcdefghA");
Indicator dxD = createIndicator('D', itA);
dxD.setUid("deabcdefghD");
dxD.setDecimals(2);
dxD.setAggregateExportCategoryOptionCombo("ceabcdefghB");
DataElementOperand dxE = new DataElementOperand(dxA, ocA);
DataElementOperand dxF = new DataElementOperand(dxB, ocA);
DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(dxA, dxB, dxC, dxD, dxE, dxF))).build();
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(VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, Double.class.getName(), false, false));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghA", "ouA", "peA", 1d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghB", "ouA", "peA", 2d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghC", "ouA", "peA", 3d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghD", "ouA", "peA", 4d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghA.ceabcdefghA", "ouA", "peA", 5d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghB.ceabcdefghA", "ouA", "peA", 6d));
assertEquals(4, grid.getWidth());
assertEquals(6, grid.getHeight());
AnalyticsUtils.handleGridForDataValueSet(params, grid);
assertEquals(6, grid.getWidth());
assertEquals(6, grid.getHeight());
assertEquals("deabcdefghA", grid.getRow(0).get(0));
assertNull(grid.getRow(0).get(3));
assertNull(grid.getRow(0).get(4));
assertEquals(1, grid.getRow(0).get(5));
assertEquals("deabcdefghB", grid.getRow(1).get(0));
assertNull(grid.getRow(1).get(3));
assertNull(grid.getRow(1).get(4));
assertEquals(2d, (Double) grid.getRow(1).get(5), 0.01);
assertEquals("deabcdefghC", grid.getRow(2).get(0));
assertNull(grid.getRow(2).get(3));
assertEquals("ceabcdefghA", grid.getRow(2).get(4));
assertEquals(3, grid.getRow(2).get(5));
assertEquals("deabcdefghD", grid.getRow(3).get(0));
assertEquals("ceabcdefghB", grid.getRow(3).get(3));
assertNull(grid.getRow(3).get(4));
assertEquals(4d, (Double) grid.getRow(3).get(5), 0.01);
assertEquals("deabcdefghA", grid.getRow(4).get(0));
assertEquals("ceabcdefghA", grid.getRow(4).get(3));
assertNull(grid.getRow(4).get(4));
assertEquals(5, grid.getRow(4).get(5));
assertEquals("deabcdefghB", grid.getRow(5).get(0));
assertEquals("ceabcdefghA", grid.getRow(5).get(3));
assertNull(grid.getRow(5).get(4));
assertEquals(6d, (Double) grid.getRow(5).get(5), 0.01);
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class DataSetDeletionHandler method deleteDataElement.
@Override
public void deleteDataElement(DataElement dataElement) {
Iterator<DataSetElement> elements = dataElement.getDataSetElements().iterator();
while (elements.hasNext()) {
DataSetElement element = elements.next();
elements.remove();
dataElement.removeDataSetElement(element);
idObjectManager.updateNoAcl(element.getDataSet());
}
List<DataSet> dataSets = idObjectManager.getAllNoAcl(DataSet.class);
for (DataSet dataSet : dataSets) {
boolean update = false;
Iterator<DataElementOperand> operands = dataSet.getCompulsoryDataElementOperands().iterator();
while (operands.hasNext()) {
DataElementOperand operand = operands.next();
if (operand.getDataElement().equals(dataElement)) {
operands.remove();
update = true;
}
}
if (update) {
idObjectManager.updateNoAcl(dataSet);
}
}
}
Aggregations