use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.
the class User method getDimensionConstraints.
/**
* Returns the dimensions to use as constrains (filters) in data analytics
* aggregation.
*/
public Set<DimensionalObject> getDimensionConstraints() {
Set<DimensionalObject> constraints = new HashSet<>();
for (CategoryOptionGroupSet cogs : cogsDimensionConstraints) {
cogs.setDimensionType(DimensionType.CATEGORY_OPTION_GROUP_SET);
constraints.add(cogs);
}
for (Category cat : catDimensionConstraints) {
cat.setDimensionType(DimensionType.CATEGORY);
constraints.add(cat);
}
return constraints;
}
use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.
the class DefaultAnalyticsDimensionService method getRecommendedDimensions.
@Override
public List<DimensionalObject> getRecommendedDimensions(DataQueryParams params) {
User user = currentUserService.getCurrentUser();
Set<DimensionalObject> dimensions = new HashSet<>();
if (!params.getDataElements().isEmpty()) {
dimensions.addAll(params.getDataElements().stream().map(de -> ((DataElement) de).getCategoryCombos()).flatMap(cc -> cc.stream()).map(cc -> cc.getCategories()).flatMap(c -> c.stream()).filter(Category::isDataDimension).collect(Collectors.toSet()));
dimensions.addAll(params.getDataElements().stream().map(de -> ((DataElement) de).getDataSets()).flatMap(ds -> ds.stream()).map(ds -> ds.getCategoryCombo().getCategories()).flatMap(c -> c.stream()).filter(Category::isDataDimension).collect(Collectors.toSet()));
}
dimensions.addAll(idObjectManager.getDataDimensions(OrganisationUnitGroupSet.class));
return dimensions.stream().filter(d -> aclService.canDataOrMetadataRead(user, d)).sorted().collect(Collectors.toList());
}
use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.
the class AnalyticsDimensionServiceTest method testGetRecommendedDimensions.
@Test
void testGetRecommendedDimensions() {
CategoryOption coA = createCategoryOption('A');
CategoryOption coB = createCategoryOption('B');
CategoryOption coC = createCategoryOption('C');
CategoryOption coD = createCategoryOption('D');
Category caA = createCategory('A', coA);
Category caB = createCategory('B', coB);
Category caC = createCategory('C', coC);
Category caD = createCategory('D', coD);
caD.setDataDimension(false);
CategoryCombo ccA = createCategoryCombo('A', caA, caB);
CategoryCombo ccB = createCategoryCombo('A', caC, caD);
DataSet dsA = createDataSet('A');
dsA.setCategoryCombo(ccB);
DataElement deA = createDataElement('A', ccA);
DataElement deB = createDataElement('B', ccA);
dsA.addDataSetElement(deB);
DataQueryParams params = DataQueryParams.newBuilder().withDataElements(Lists.newArrayList(deA, deB)).build();
List<DimensionalObject> dimensons = dimensionService.getRecommendedDimensions(params);
assertEquals(3, dimensons.size());
assertTrue(dimensons.contains(caA));
assertTrue(dimensons.contains(caB));
assertTrue(dimensons.contains(caC));
params = DataQueryParams.newBuilder().withDataElements(Lists.newArrayList(deA)).build();
dimensons = dimensionService.getRecommendedDimensions(params);
assertEquals(2, dimensons.size());
assertTrue(dimensons.contains(caA));
assertTrue(dimensons.contains(caB));
}
use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.
the class DefaultDimensionService method getDimensionType.
@Override
public DimensionType getDimensionType(String uid) {
Category cat = idObjectManager.get(Category.class, uid);
if (cat != null) {
return DimensionType.CATEGORY;
}
DataElementGroupSet degs = idObjectManager.get(DataElementGroupSet.class, uid);
if (degs != null) {
return DimensionType.DATA_ELEMENT_GROUP_SET;
}
OrganisationUnitGroupSet ougs = idObjectManager.get(OrganisationUnitGroupSet.class, uid);
if (ougs != null) {
return DimensionType.ORGANISATION_UNIT_GROUP_SET;
}
CategoryOptionGroupSet cogs = idObjectManager.get(CategoryOptionGroupSet.class, uid);
if (cogs != null) {
return DimensionType.CATEGORY_OPTION_GROUP_SET;
}
TrackedEntityAttribute tea = idObjectManager.get(TrackedEntityAttribute.class, uid);
if (tea != null) {
return DimensionType.PROGRAM_ATTRIBUTE;
}
DataElement pde = idObjectManager.get(DataElement.class, uid);
if (pde != null && DataElementDomain.TRACKER.equals(pde.getDomainType())) {
return DimensionType.PROGRAM_DATA_ELEMENT;
}
ProgramIndicator pin = idObjectManager.get(ProgramIndicator.class, uid);
if (pin != null) {
return DimensionType.PROGRAM_INDICATOR;
}
final Map<String, DimensionType> dimObjectTypeMap = new HashMap<>();
dimObjectTypeMap.put(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X);
dimObjectTypeMap.put(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD);
dimObjectTypeMap.put(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT);
return dimObjectTypeMap.get(uid);
}
use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.
the class DefaultDimensionService method getAllDimensions.
@Override
public List<DimensionalObject> getAllDimensions() {
Collection<Category> dcs = idObjectManager.getDataDimensions(Category.class);
Collection<CategoryOptionGroupSet> cogs = idObjectManager.getDataDimensions(CategoryOptionGroupSet.class);
Collection<DataElementGroupSet> degs = idObjectManager.getDataDimensions(DataElementGroupSet.class);
Collection<OrganisationUnitGroupSet> ougs = idObjectManager.getDataDimensions(OrganisationUnitGroupSet.class);
final List<DimensionalObject> dimensions = new ArrayList<>();
dimensions.addAll(dcs);
dimensions.addAll(cogs);
dimensions.addAll(degs);
dimensions.addAll(ougs);
User user = currentUserService.getCurrentUser();
return getCanReadObjects(user, dimensions);
}
Aggregations