use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class IdentifiableObjectManagerTest method testGetObject.
@Test
void testGetObject() {
DataElement dataElementA = createDataElement('A');
DataElement dataElementB = createDataElement('B');
dataElementService.addDataElement(dataElementA);
long dataElementIdA = dataElementA.getId();
dataElementService.addDataElement(dataElementB);
long dataElementIdB = dataElementB.getId();
DataElementGroup dataElementGroupA = createDataElementGroup('A');
DataElementGroup dataElementGroupB = createDataElementGroup('B');
dataElementService.addDataElementGroup(dataElementGroupA);
long dataElementGroupIdA = dataElementGroupA.getId();
dataElementService.addDataElementGroup(dataElementGroupB);
long dataElementGroupIdB = dataElementGroupB.getId();
assertEquals(dataElementA, identifiableObjectManager.getObject(dataElementIdA, DataElement.class.getSimpleName()));
assertEquals(dataElementB, identifiableObjectManager.getObject(dataElementIdB, DataElement.class.getSimpleName()));
assertEquals(dataElementGroupA, identifiableObjectManager.getObject(dataElementGroupIdA, DataElementGroup.class.getSimpleName()));
assertEquals(dataElementGroupB, identifiableObjectManager.getObject(dataElementGroupIdB, DataElementGroup.class.getSimpleName()));
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class ListMapTest method testGetListMapKeyValueMapper.
@Test
void testGetListMapKeyValueMapper() {
DataElementGroupSet groupSetA = new DataElementGroupSet("GroupSetA");
DataElementGroupSet groupSetB = new DataElementGroupSet("GroupSetB");
DataElementGroupSet groupSetC = new DataElementGroupSet("GroupSetC");
DataElementGroupSet groupSetZ = new DataElementGroupSet("GroupSetZ");
DataElementGroup groupA = new DataElementGroup("GroupA");
DataElementGroup groupB = new DataElementGroup("GroupB");
DataElementGroup groupC = new DataElementGroup("GroupC");
DataElementGroup groupD = new DataElementGroup("GroupD");
DataElementGroup groupE = new DataElementGroup("GroupE");
DataElementGroup groupF = new DataElementGroup("GroupF");
groupA.getGroupSets().add(groupSetA);
groupB.getGroupSets().add(groupSetB);
groupC.getGroupSets().add(groupSetC);
groupD.getGroupSets().add(groupSetA);
groupE.getGroupSets().add(groupSetB);
groupF.getGroupSets().add(groupSetA);
List<DataElementGroup> groups = Lists.newArrayList(groupA, groupB, groupC, groupD, groupE, groupF);
ListMap<DataElementGroupSet, Long> map = ListMap.getListMap(groups, group -> group.getGroupSets().iterator().next(), group -> group.getId());
assertEquals(Lists.newArrayList(groupA.getId(), groupD.getId(), groupF.getId()), map.get(groupSetA));
assertEquals(Lists.newArrayList(groupB.getId(), groupE.getId()), map.get(groupSetB));
assertEquals(Lists.newArrayList(groupC.getId()), map.get(groupSetC));
assertNull(map.get(groupSetZ));
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class DimensionalObjectUtilsTest method testGetIdentifier.
@Test
void testGetIdentifier() {
DataElementGroup oA = new DataElementGroup();
DataElementGroup oB = new DataElementGroup();
DataElementGroup oC = new DataElementGroup();
oA.setUid("a1");
oB.setUid("b1");
oC.setUid("c1");
List<DimensionalItemObject> column = new ArrayList<>();
column.add(oC);
column.add(oA);
List<DimensionalItemObject> row = new ArrayList<>();
row.add(oB);
assertEquals("a1-b1-c1", DimensionalObjectUtils.getKey(column, row));
assertEquals("b1", DimensionalObjectUtils.getKey(new ArrayList<>(), row));
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class QueryServiceTest method createDataElements.
@BeforeEach
void createDataElements() {
DataElement dataElementA = createDataElement('A');
dataElementA.setValueType(ValueType.NUMBER);
DataElement dataElementB = createDataElement('B');
dataElementB.setValueType(ValueType.BOOLEAN);
DataElement dataElementC = createDataElement('C');
dataElementC.setValueType(ValueType.INTEGER);
DataElement dataElementD = createDataElement('D');
dataElementD.setValueType(ValueType.NUMBER);
DataElement dataElementE = createDataElement('E');
dataElementE.setValueType(ValueType.BOOLEAN);
DataElement dataElementF = createDataElement('F');
dataElementF.setValueType(ValueType.INTEGER);
dataElementA.setCreated(Year.parseYear("2001").getStart());
dataElementB.setCreated(Year.parseYear("2002").getStart());
dataElementC.setCreated(Year.parseYear("2003").getStart());
dataElementD.setCreated(Year.parseYear("2004").getStart());
dataElementE.setCreated(Year.parseYear("2005").getStart());
dataElementF.setCreated(Year.parseYear("2006").getStart());
identifiableObjectManager.save(dataElementB);
identifiableObjectManager.save(dataElementE);
identifiableObjectManager.save(dataElementA);
identifiableObjectManager.save(dataElementC);
identifiableObjectManager.save(dataElementF);
identifiableObjectManager.save(dataElementD);
DataElementGroup dataElementGroupA = createDataElementGroup('A');
dataElementGroupA.getMembers().addAll(Lists.newArrayList(dataElementA, dataElementB, dataElementC));
DataElementGroup dataElementGroupB = createDataElementGroup('B');
dataElementGroupB.getMembers().addAll(Lists.newArrayList(dataElementD, dataElementE, dataElementF));
identifiableObjectManager.save(dataElementGroupA);
identifiableObjectManager.save(dataElementGroupB);
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class DataElementGroupController method getOperands.
@GetMapping("/{uid}/operands")
public String getOperands(@PathVariable("uid") String uid, @RequestParam Map<String, String> parameters, Model model, TranslateParams translateParams, HttpServletRequest request, HttpServletResponse response) throws Exception {
WebOptions options = new WebOptions(parameters);
setUserContext(translateParams);
List<DataElementGroup> dataElementGroups = getEntity(uid, NO_WEB_OPTIONS);
if (dataElementGroups.isEmpty()) {
throw new WebMessageException(notFound("DataElementGroup not found for uid: " + uid));
}
WebMetadata metadata = new WebMetadata();
List<DataElementOperand> dataElementOperands = Lists.newArrayList(dataElementCategoryService.getOperands(dataElementGroups.get(0).getMembers()));
Collections.sort(dataElementOperands);
metadata.setDataElementOperands(dataElementOperands);
if (options.hasPaging()) {
Pager pager = new Pager(options.getPage(), dataElementOperands.size(), options.getPageSize());
metadata.setPager(pager);
dataElementOperands = PagerUtils.pageCollection(dataElementOperands, pager);
}
metadata.setDataElementOperands(dataElementOperands);
linkService.generateLinks(metadata, false);
model.addAttribute("model", metadata);
model.addAttribute("viewClass", options.getViewClass("basic"));
return StringUtils.uncapitalize(getEntitySimpleName());
}
Aggregations