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());
}
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));
});
}
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));
}
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));
}
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;
}
Aggregations