Search in sources :

Example 1 with DataElementGroup

use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.

the class BaseAnalyticalObjectTest method testGetIdentifier.

@Test
public 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", BaseAnalyticalObject.getIdentifier(column, row));
    assertEquals("b1", BaseAnalyticalObject.getIdentifier(new ArrayList<>(), row));
    assertEquals("b1", BaseAnalyticalObject.getIdentifier(null, row));
}
Also used : DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with DataElementGroup

use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.

the class PreheatServiceTest method testPreheatReferenceConnectAUTO.

@Test
public void testPreheatReferenceConnectAUTO() {
    DataElementGroup dataElementGroup = fromJson("preheat/degAAutoRef.json", DataElementGroup.class);
    defaultSetup();
    PreheatParams params = new PreheatParams();
    params.setPreheatIdentifier(PreheatIdentifier.AUTO);
    params.setPreheatMode(PreheatMode.REFERENCE);
    params.getObjects().put(DataElementGroup.class, Lists.newArrayList(dataElementGroup));
    preheatService.validate(params);
    Preheat preheat = preheatService.preheat(params);
    preheatService.connectReferences(dataElementGroup, preheat, PreheatIdentifier.AUTO);
    List<DataElement> members = new ArrayList<>(dataElementGroup.getMembers());
    assertEquals("DataElementA", members.get(0).getName());
    assertEquals("DataElementCodeA", members.get(0).getCode());
    assertEquals("DataElementB", members.get(1).getName());
    assertEquals("DataElementCodeB", members.get(1).getCode());
    assertEquals("DataElementC", members.get(2).getName());
    assertEquals("DataElementCodeC", members.get(2).getCode());
    assertEquals("FirstNameA", dataElementGroup.getUser().getFirstName());
    assertEquals("SurnameA", dataElementGroup.getUser().getSurname());
    assertEquals("UserCodeA", dataElementGroup.getUser().getCode());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) ArrayList(java.util.ArrayList) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 3 with DataElementGroup

use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.

the class PreheatServiceTest method testPreheatAllMetadataUID.

@Test
public void testPreheatAllMetadataUID() {
    DataElementGroup dataElementGroup = new DataElementGroup("DataElementGroupA");
    dataElementGroup.setAutoFields();
    DataElement de1 = createDataElement('A');
    DataElement de2 = createDataElement('B');
    DataElement de3 = createDataElement('C');
    manager.save(de1);
    manager.save(de2);
    manager.save(de3);
    User user = createUser('A');
    manager.save(user);
    dataElementGroup.addDataElement(de1);
    dataElementGroup.addDataElement(de2);
    dataElementGroup.addDataElement(de3);
    dataElementGroup.setUser(user);
    manager.save(dataElementGroup);
    PreheatParams params = new PreheatParams();
    params.setPreheatMode(PreheatMode.ALL);
    preheatService.validate(params);
    Preheat preheat = preheatService.preheat(params);
    assertFalse(preheat.isEmpty());
    assertFalse(preheat.isEmpty(PreheatIdentifier.UID));
    assertFalse(preheat.isEmpty(PreheatIdentifier.UID, DataElement.class));
    assertFalse(preheat.isEmpty(PreheatIdentifier.UID, DataElementGroup.class));
    assertFalse(preheat.isEmpty(PreheatIdentifier.UID, User.class));
    assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElement.class, de1.getUid()));
    assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElement.class, de2.getUid()));
    assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElement.class, de3.getUid()));
    assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElementGroup.class, dataElementGroup.getUid()));
    assertTrue(preheat.containsKey(PreheatIdentifier.UID, User.class, user.getUid()));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 4 with DataElementGroup

use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.

the class AnalyticalObjectEmbeddedDimensionUpgrader method executeInTransaction.

@Override
public void executeInTransaction() {
    BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> dataElementGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
        DataElementGroupSetDimension dimension = new DataElementGroupSetDimension();
        dimension.setDimension((DataElementGroupSet) embeddedDimension.getDimension());
        dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
        analyticalObject.addDataElementGroupSetDimension(dimension);
    };
    BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> orgUnitGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
        OrganisationUnitGroupSetDimension dimension = new OrganisationUnitGroupSetDimension();
        dimension.setDimension((OrganisationUnitGroupSet) embeddedDimension.getDimension());
        dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
        analyticalObject.addOrganisationUnitGroupSetDimension(dimension);
    };
    BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> categoryOptionGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
        CategoryOptionGroupSetDimension dimension = new CategoryOptionGroupSetDimension();
        dimension.setDimension((CategoryOptionGroupSet) embeddedDimension.getDimension());
        dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
        analyticalObject.addCategoryOptionGroupSetDimension(dimension);
    };
    try {
        upgradeGrupSetDimensions("reporttable", "orgunitgroupset", "orgunitgroup", ReportTable.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
        upgradeGrupSetDimensions("reporttable", "dataelementgroupset", "dataelementgroup", ReportTable.class, DataElementGroupSet.class, DataElementGroup.class, dataElementGroupSetConsumer);
        upgradeGrupSetDimensions("reporttable", "categoryoptiongroupset", "categoryoptiongroup", ReportTable.class, CategoryOptionGroupSet.class, CategoryOptionGroup.class, categoryOptionGroupSetConsumer);
        upgradeGrupSetDimensions("chart", "orgunitgroupset", "orgunitgroup", Chart.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
        upgradeGrupSetDimensions("chart", "dataelementgroupset", "dataelementgroup", Chart.class, DataElementGroupSet.class, DataElementGroup.class, dataElementGroupSetConsumer);
        upgradeGrupSetDimensions("chart", "categoryoptiongroupset", "categoryoptiongroup", Chart.class, CategoryOptionGroupSet.class, CategoryOptionGroup.class, categoryOptionGroupSetConsumer);
        upgradeGrupSetDimensions("eventreport", "orgunitgroupset", "orgunitgroup", EventReport.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
        upgradeGrupSetDimensions("eventchart", "orgunitgroupset", "orgunitgroup", EventChart.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
    } catch (Exception ex) {
        log.debug("Error during group set dimensions upgrade of favorite, probably because upgrade was already done", ex);
        return;
    }
}
Also used : AnalyticalObject(org.hisp.dhis.common.AnalyticalObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) OrganisationUnitGroupSetDimension(org.hisp.dhis.organisationunit.OrganisationUnitGroupSetDimension) Autowired(org.springframework.beans.factory.annotation.Autowired) EventReport(org.hisp.dhis.eventreport.EventReport) ArrayList(java.util.ArrayList) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) EventChart(org.hisp.dhis.eventchart.EventChart) ReportTable(org.hisp.dhis.reporttable.ReportTable) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) BiConsumer(java.util.function.BiConsumer) SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) DimensionalObjectUtils(org.hisp.dhis.common.DimensionalObjectUtils) Chart(org.hisp.dhis.chart.Chart) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) CategoryOptionGroup(org.hisp.dhis.dataelement.CategoryOptionGroup) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) TransactionContextStartupRoutine(org.hisp.dhis.system.startup.TransactionContextStartupRoutine) DataElementGroupSetDimension(org.hisp.dhis.dataelement.DataElementGroupSetDimension) List(java.util.List) DimensionalObject(org.hisp.dhis.common.DimensionalObject) CategoryOptionGroupSetDimension(org.hisp.dhis.dataelement.CategoryOptionGroupSetDimension) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) TextUtils(org.hisp.dhis.commons.util.TextUtils) Assert(org.springframework.util.Assert) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) DataElementGroupSetDimension(org.hisp.dhis.dataelement.DataElementGroupSetDimension) OrganisationUnitGroupSetDimension(org.hisp.dhis.organisationunit.OrganisationUnitGroupSetDimension) CategoryOptionGroupSetDimension(org.hisp.dhis.dataelement.CategoryOptionGroupSetDimension) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) AnalyticalObject(org.hisp.dhis.common.AnalyticalObject)

Example 5 with DataElementGroup

use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.

the class DataElementOperandController method getObjectList.

@GetMapping
@SuppressWarnings("unchecked")
@ResponseBody
public RootNode getObjectList(@RequestParam Map<String, String> rpParameters, OrderParams orderParams) throws QueryParserException {
    Schema schema = schemaService.getDynamicSchema(DataElementOperand.class);
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    List<Order> orders = orderParams.getOrders(schema);
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    WebOptions options = new WebOptions(rpParameters);
    WebMetadata metadata = new WebMetadata();
    List<DataElementOperand> dataElementOperands;
    if (options.isTrue("persisted")) {
        dataElementOperands = Lists.newArrayList(manager.getAll(DataElementOperand.class));
    } else {
        boolean totals = options.isTrue("totals");
        String deg = CollectionUtils.popStartsWith(filters, "dataElement.dataElementGroups.id:eq:");
        deg = deg != null ? deg.substring("dataElement.dataElementGroups.id:eq:".length()) : null;
        String ds = options.get("dataSet");
        if (deg != null) {
            DataElementGroup dataElementGroup = manager.get(DataElementGroup.class, deg);
            dataElementOperands = dataElementCategoryService.getOperands(dataElementGroup.getMembers(), totals);
        } else if (ds != null) {
            DataSet dataSet = manager.get(DataSet.class, ds);
            dataElementOperands = dataElementCategoryService.getOperands(dataSet, totals);
        } else {
            List<DataElement> dataElements = new ArrayList<>(manager.getAllSorted(DataElement.class));
            dataElementOperands = dataElementCategoryService.getOperands(dataElements, totals);
        }
    }
    Query query = queryService.getQueryFromUrl(DataElementOperand.class, filters, orders, options.getRootJunction());
    query.setDefaultOrder();
    query.setObjects(dataElementOperands);
    dataElementOperands = (List<DataElementOperand>) queryService.query(query);
    Pager pager = metadata.getPager();
    if (options.hasPaging() && pager == null) {
        pager = new Pager(options.getPage(), dataElementOperands.size(), options.getPageSize());
        linkService.generatePagerLinks(pager, DataElementOperand.class);
        dataElementOperands = PagerUtils.pageCollection(dataElementOperands, pager);
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    rootNode.addChild(fieldFilterService.filter(DataElementOperand.class, dataElementOperands, fields));
    return rootNode;
}
Also used : Order(org.hisp.dhis.query.Order) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) RootNode(org.hisp.dhis.node.types.RootNode) Query(org.hisp.dhis.query.Query) DataSet(org.hisp.dhis.dataset.DataSet) Schema(org.hisp.dhis.schema.Schema) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) Pager(org.hisp.dhis.common.Pager) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) ArrayList(java.util.ArrayList) List(java.util.List) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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