Search in sources :

Example 21 with DataElementGroup

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()));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 22 with DataElementGroup

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));
}
Also used : DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) Test(org.junit.jupiter.api.Test)

Example 23 with DataElementGroup

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));
}
Also used : DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 24 with DataElementGroup

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);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 25 with DataElementGroup

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());
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Pager(org.hisp.dhis.common.Pager) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

DataElementGroup (org.hisp.dhis.dataelement.DataElementGroup)55 DataElement (org.hisp.dhis.dataelement.DataElement)31 Test (org.junit.jupiter.api.Test)29 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)17 ArrayList (java.util.ArrayList)15 User (org.hisp.dhis.user.User)15 DataSet (org.hisp.dhis.dataset.DataSet)9 List (java.util.List)8 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)8 Set (java.util.Set)7 DhisSpringTest (org.hisp.dhis.DhisSpringTest)7 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)6 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)6 DataElementGroupSet (org.hisp.dhis.dataelement.DataElementGroupSet)6 DimensionalObject (org.hisp.dhis.common.DimensionalObject)5 LegendSet (org.hisp.dhis.legend.LegendSet)5 OptionSet (org.hisp.dhis.option.OptionSet)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 PeriodType (org.hisp.dhis.period.PeriodType)5 DimensionItemKeywords (org.hisp.dhis.common.DimensionItemKeywords)4