Search in sources :

Example 16 with Category

use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.

the class TypedIndexedObjectContainerTest method merge.

@Test
void merge() {
    final Attribute attribute1 = new Attribute();
    final Attribute attribute2 = new Attribute();
    final Attribute attribute3 = new Attribute();
    final Category category1 = new Category();
    final Category category2 = new Category();
    Assertions.assertEquals((Integer) 0, container.mergeObjectIndex(attribute1));
    Assertions.assertEquals((Integer) 1, container.mergeObjectIndex(attribute2));
    Assertions.assertEquals((Integer) 2, container.mergeObjectIndex(attribute3));
    Assertions.assertEquals((Integer) 0, container.mergeObjectIndex(category1));
    Assertions.assertEquals((Integer) 1, container.mergeObjectIndex(category2));
}
Also used : Category(org.hisp.dhis.category.Category) Attribute(org.hisp.dhis.attribute.Attribute) Test(org.junit.jupiter.api.Test)

Example 17 with Category

use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.

the class EventAnalyticsServiceTest method testDimensionRestrictionSuccessfully.

@Test
void testDimensionRestrictionSuccessfully() {
    // Given
    // A program
    Program aProgram = createProgram('B', null, null, Sets.newHashSet(ouA, ouB), null);
    aProgram.setUid("aProgram123");
    idObjectManager.save(aProgram);
    // The category options
    CategoryOption coA = createCategoryOption('A');
    CategoryOption coB = createCategoryOption('B');
    categoryService.addCategoryOption(coA);
    categoryService.addCategoryOption(coB);
    // The categories
    Category caA = createCategory('A', coA);
    Category caB = createCategory('B', coB);
    categoryService.addCategory(caA);
    categoryService.addCategory(caB);
    // The constraints
    Set<Category> catDimensionConstraints = Sets.newHashSet(caA, caB);
    // The user
    User user = createUser("A", "F_VIEW_EVENT_ANALYTICS");
    user.setCatDimensionConstraints(catDimensionConstraints);
    userService.addUser(user);
    enableDataSharing(user, aProgram, AccessStringHelper.DATA_READ_WRITE);
    idObjectManager.update(user);
    injectSecurityContext(user);
    // All events in program B - 2017
    EventQueryParams events_2017_params = new EventQueryParams.Builder().withOrganisationUnits(Lists.newArrayList(ouA)).withStartDate(getDate(2017, 1, 1)).withEndDate(getDate(2017, 12, 31)).withProgram(aProgram).build();
    // When
    Grid aggregatedDataValueGrid = eventAnalyticsService.getAggregatedEventData(events_2017_params);
    // Then
    boolean noCategoryRestrictionExceptionIsThrown = true;
    assertThat(aggregatedDataValueGrid, is(notNullValue()));
    assert (noCategoryRestrictionExceptionIsThrown);
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) Program(org.hisp.dhis.program.Program) Category(org.hisp.dhis.category.Category) User(org.hisp.dhis.user.User) Grid(org.hisp.dhis.common.Grid) CategoryOption(org.hisp.dhis.category.CategoryOption) Test(org.junit.jupiter.api.Test)

Example 18 with Category

use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.

the class GetMetaDataAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
    User user = currentUserService.getCurrentUser();
    Date lastUpdated = DateUtils.max(Sets.newHashSet(identifiableObjectManager.getLastUpdated(DataElement.class), identifiableObjectManager.getLastUpdated(OptionSet.class), identifiableObjectManager.getLastUpdated(Indicator.class), identifiableObjectManager.getLastUpdated(DataSet.class), identifiableObjectManager.getLastUpdated(CategoryCombo.class), identifiableObjectManager.getLastUpdated(Category.class), identifiableObjectManager.getLastUpdated(CategoryOption.class)));
    String tag = lastUpdated != null && user != null ? (DateUtils.getLongDateString(lastUpdated) + SEP + user.getUid()) : null;
    if (ContextUtils.isNotModified(ServletActionContext.getRequest(), ServletActionContext.getResponse(), tag)) {
        return SUCCESS;
    }
    if (user != null && user.getOrganisationUnits().isEmpty()) {
        emptyOrganisationUnits = true;
        return SUCCESS;
    }
    significantZeros = dataElementService.getDataElementsByZeroIsSignificant(true);
    dataElements = dataElementService.getDataElementsWithDataSets();
    for (DataElement dataElement : dataElements) {
        if (dataElement != null && dataElement.getOptionSet() != null) {
            dataElementsWithOptionSet.add(dataElement);
        }
    }
    indicators = indicatorService.getIndicatorsWithDataSets();
    expressionService.substituteIndicatorExpressions(indicators);
    dataSets = dataSetService.getUserDataWrite(user);
    Set<CategoryCombo> categoryComboSet = new HashSet<>();
    Set<Category> categorySet = new HashSet<>();
    for (DataSet dataSet : dataSets) {
        if (dataSet.getCategoryCombo() != null) {
            categoryComboSet.add(dataSet.getCategoryCombo());
        }
    }
    for (CategoryCombo categoryCombo : categoryComboSet) {
        if (categoryCombo.getCategories() != null) {
            categorySet.addAll(categoryCombo.getCategories());
        }
    }
    categoryCombos = new ArrayList<>(categoryComboSet);
    categories = new ArrayList<>(categorySet);
    for (Category category : categories) {
        List<CategoryOption> categoryOptions = new ArrayList<>(categoryService.getDataWriteCategoryOptions(category, user));
        Collections.sort(categoryOptions);
        categoryOptionMap.put(category.getUid(), categoryOptions);
    }
    Set<String> nonAccessibleDataSetIds = new HashSet<>();
    for (DataSet dataSet : dataSets) {
        CategoryCombo categoryCombo = dataSet.getCategoryCombo();
        if (categoryCombo != null && categoryCombo.getCategories() != null) {
            for (Category category : categoryCombo.getCategories()) {
                if (!categoryOptionMap.containsKey(category.getUid()) || categoryOptionMap.get(category.getUid()).isEmpty()) {
                    nonAccessibleDataSetIds.add(dataSet.getUid());
                    break;
                }
            }
        }
    }
    dataSets = dataSets.stream().filter(dataSet -> !nonAccessibleDataSetIds.contains(dataSet.getUid())).collect(Collectors.toList());
    lockExceptions = dataSetService.getAllLockExceptions();
    Collections.sort(dataSets);
    Collections.sort(categoryCombos);
    Collections.sort(categories);
    defaultCategoryCombo = categoryService.getDefaultCategoryCombo();
    return SUCCESS;
}
Also used : User(org.hisp.dhis.user.User) Category(org.hisp.dhis.category.Category) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) Date(java.util.Date) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) HashSet(java.util.HashSet)

Example 19 with Category

use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.

the class DefaultCascadeSharingService method handleCategoryDimension.

/**
 * Check if can merge sharing from given source to given analyticalObject's
 * {@link CategoryDimension} 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 handleCategoryDimension(final Sharing sourceSharing, BaseAnalyticalObject analyticalObject, Set<IdentifiableObject> listUpdateObjects, CascadeSharingParameters parameters) {
    List<CategoryDimension> catDimensions = analyticalObject.getCategoryDimensions();
    if (CollectionUtils.isEmpty(catDimensions)) {
        return;
    }
    catDimensions.forEach(catDimension -> {
        Category category = catDimension.getDimension();
        handleIdentifiableObject(sourceSharing, Category.class, category, listUpdateObjects, parameters);
        List<CategoryOption> catOptions = catDimension.getItems();
        if (CollectionUtils.isEmpty(catOptions)) {
            return;
        }
        catOptions.forEach(catOption -> handleIdentifiableObject(sourceSharing, CategoryOption.class, catOption, listUpdateObjects, parameters));
    });
}
Also used : Category(org.hisp.dhis.category.Category) CategoryDimension(org.hisp.dhis.category.CategoryDimension) CategoryOption(org.hisp.dhis.category.CategoryOption)

Example 20 with Category

use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.

the class ValidationResultStoreHqlTest method queryWithUserWithCategory.

@Test
void queryWithUserWithCategory() {
    Category category = new Category();
    category.setId(42L);
    setUpUser("orgUid", category, null);
    store.query(new ValidationResultQuery());
    assertHQLMatches("from ValidationResult vr where (locate('orgUid',vr.organisationUnit.path) <> 0) and 1 = ...", 523);
}
Also used : Category(org.hisp.dhis.category.Category) ValidationResultQuery(org.hisp.dhis.validation.comparator.ValidationResultQuery) Test(org.junit.jupiter.api.Test)

Aggregations

Category (org.hisp.dhis.category.Category)61 CategoryOption (org.hisp.dhis.category.CategoryOption)25 CategoryCombo (org.hisp.dhis.category.CategoryCombo)22 Test (org.junit.jupiter.api.Test)21 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)13 CategoryOptionGroupSet (org.hisp.dhis.category.CategoryOptionGroupSet)13 ArrayList (java.util.ArrayList)12 User (org.hisp.dhis.user.User)12 DataElement (org.hisp.dhis.dataelement.DataElement)11 HashSet (java.util.HashSet)8 DataSet (org.hisp.dhis.dataset.DataSet)8 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)8 HashMap (java.util.HashMap)7 Date (java.util.Date)5 AnalyticsTableColumn (org.hisp.dhis.analytics.AnalyticsTableColumn)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)5 List (java.util.List)4 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 Attribute (org.hisp.dhis.attribute.Attribute)4