Search in sources :

Example 46 with DataElementGroup

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

the class MetadataExportServiceTest method testMetadataExportWithCustomClasses.

@Test
void testMetadataExportWithCustomClasses() {
    DataElementGroup deg1 = createDataElementGroup('A');
    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);
    deg1.addDataElement(de1);
    deg1.addDataElement(de2);
    deg1.addDataElement(de3);
    deg1.setCreatedBy(user);
    manager.save(deg1);
    MetadataExportParams params = new MetadataExportParams();
    params.addClass(DataElement.class);
    Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> metadata = metadataExportService.getMetadata(params);
    assertFalse(metadata.containsKey(User.class));
    assertFalse(metadata.containsKey(DataElementGroup.class));
    assertTrue(metadata.containsKey(DataElement.class));
    assertEquals(3, metadata.get(DataElement.class).size());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) List(java.util.List) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 47 with DataElementGroup

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

the class DefaultCascadeSharingService method handleDataElementGroupSetDimensions.

/**
 * Check if can merge sharing from given source to given analyticalObject's
 * {@link DataElementGroupSetDimension} and all related objects that has
 * Sharing enabled.
 *
 * @param sourceSharing {@link Sharing}
 * @param analyticalObject any object extends {@link BaseAnalyticalObject}
 * @param listUpdateObjects Set of objects need to be updated
 * @param parameters {@link CascadeSharingParameters}
 */
private void handleDataElementGroupSetDimensions(final Sharing sourceSharing, BaseAnalyticalObject analyticalObject, Set<IdentifiableObject> listUpdateObjects, CascadeSharingParameters parameters) {
    List<DataElementGroupSetDimension> deGroupSetDimensions = analyticalObject.getDataElementGroupSetDimensions();
    if (CollectionUtils.isEmpty(deGroupSetDimensions)) {
        return;
    }
    deGroupSetDimensions.forEach(deGroupSetDimension -> {
        DataElementGroupSet deGroupSet = deGroupSetDimension.getDimension();
        handleIdentifiableObject(sourceSharing, DataElementGroupSet.class, deGroupSet, listUpdateObjects, parameters);
        List<DataElementGroup> deGroups = deGroupSetDimension.getItems();
        if (CollectionUtils.isEmpty(deGroups)) {
            return;
        }
        deGroups.forEach(deGroup -> handleIdentifiableObject(sourceSharing, DataElementGroup.class, deGroup, listUpdateObjects, parameters));
    });
}
Also used : DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) DataElementGroupSetDimension(org.hisp.dhis.dataelement.DataElementGroupSetDimension) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup)

Example 48 with DataElementGroup

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

the class ListMapTest method testGetListMapValueMapper.

@Test
void testGetListMapValueMapper() {
    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, DataElementGroup> map = ListMap.getListMap(groups, group -> group.getGroupSets().iterator().next());
    assertEquals(Lists.newArrayList(groupA, groupD, groupF), map.get(groupSetA));
    assertEquals(Lists.newArrayList(groupB, groupE), map.get(groupSetB));
    assertEquals(Lists.newArrayList(groupC), 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 49 with DataElementGroup

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

the class SetMapTest method testGetListMapValueMapper.

@Test
void testGetListMapValueMapper() {
    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);
    Set<DataElementGroup> groups = Sets.newHashSet(groupA, groupB, groupC, groupD, groupE, groupF);
    SetMap<DataElementGroupSet, DataElementGroup> map = SetMap.getSetMap(groups, group -> group.getGroupSets().iterator().next());
    assertEquals(Sets.newHashSet(groupA, groupD, groupF), map.get(groupSetA));
    assertEquals(Sets.newHashSet(groupB, groupE), map.get(groupSetB));
    assertEquals(Sets.newHashSet(groupC), 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 50 with DataElementGroup

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

the class DefaultQueryPlanner method groupByDataPeriodType.

/**
 * Groups the given query in sub queries based on the period type of its
 * data elements. Sets the data period type on each query. This only applies
 * if the aggregation type of the query involves disaggregation.
 *
 * @param params the {@link DataQueryParams}.
 * @return a list of {@link DataQueryParams}.
 */
private List<DataQueryParams> groupByDataPeriodType(DataQueryParams params) {
    List<DataQueryParams> queries = new ArrayList<>();
    if (params.isDisaggregation() && !params.getDataElements().isEmpty()) {
        ListMap<PeriodType, DimensionalItemObject> periodTypeDataElementMap = QueryPlannerUtils.getPeriodTypeDataElementMap(params.getDataElements());
        for (PeriodType periodType : periodTypeDataElementMap.keySet()) {
            DataQueryParams query = DataQueryParams.newBuilder(params).withDataElements(periodTypeDataElementMap.get(periodType)).withDataPeriodType(periodType).build();
            queries.add(query);
        }
    } else if (params.isDisaggregation() && !params.getDataElementGroupSets().isEmpty()) {
        DataElementGroup deg = params.getFirstDataElementGroup();
        PeriodType periodType = deg != null ? deg.getPeriodType() : null;
        queries.add(DataQueryParams.newBuilder(params).withDataPeriodType(periodType).build());
    } else {
        queries.add(DataQueryParams.newBuilder(params).build());
    }
    logQuerySplit(queries, "data period type");
    return queries;
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) PeriodType(org.hisp.dhis.period.PeriodType) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ArrayList(java.util.ArrayList) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup)

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