Search in sources :

Example 21 with CategoryOptionGroupSet

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

the class JdbcEventAnalyticsTableManagerTest method verifyGetAnalyticsTableWithOptionGroupSets.

@Test
void verifyGetAnalyticsTableWithOptionGroupSets() {
    List<CategoryOptionGroupSet> cogs = rnd.objects(CategoryOptionGroupSet.class, 2).collect(Collectors.toList());
    Program programA = rnd.nextObject(Program.class);
    programA.setId(0);
    when(idObjectManager.getAllNoAcl(Program.class)).thenReturn(Collections.singletonList(programA));
    when(categoryService.getAttributeCategoryOptionGroupSetsNoAcl()).thenReturn(cogs);
    when(jdbcTemplate.queryForList(getYearQueryForCurrentYear(programA, false), Integer.class)).thenReturn(Lists.newArrayList(2018, 2019));
    AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withStartTime(START_TIME).build();
    List<AnalyticsTable> tables = subject.getAnalyticsTables(params);
    assertThat(tables, hasSize(1));
    new AnalyticsTableAsserter.Builder(tables.get(0)).withTableName(TABLE_PREFIX + programA.getUid().toLowerCase()).withTableType(AnalyticsTableType.EVENT).withColumnSize(subject.getFixedColumns().size() + PeriodType.getAvailablePeriodTypes().size() + cogs.size() + (programA.isRegistration() ? 1 : 0)).addColumns(periodColumns).withDefaultColumns(subject.getFixedColumns()).addColumn(quote(cogs.get(0).getUid()), col -> match(cogs.get(0), col)).addColumn(quote(cogs.get(1).getUid()), col -> match(cogs.get(1), col)).build().verify();
}
Also used : AnalyticsTableAsserter(org.hisp.dhis.analytics.util.AnalyticsTableAsserter) BeforeEach(org.junit.jupiter.api.BeforeEach) CategoryService(org.hisp.dhis.category.CategoryService) BeanRandomizer(org.hisp.dhis.random.BeanRandomizer) CHARACTER_11(org.hisp.dhis.analytics.ColumnDataType.CHARACTER_11) ResourceTableService(org.hisp.dhis.resourcetable.ResourceTableService) Date(java.util.Date) ValueType(org.hisp.dhis.common.ValueType) AnalyticsTableUpdateParams(org.hisp.dhis.analytics.AnalyticsTableUpdateParams) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) GEOMETRY(org.hisp.dhis.analytics.ColumnDataType.GEOMETRY) GEOMETRY_POINT(org.hisp.dhis.analytics.ColumnDataType.GEOMETRY_POINT) DhisConvenienceTest.createProgramStage(org.hisp.dhis.DhisConvenienceTest.createProgramStage) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) INTEGER(org.hisp.dhis.analytics.ColumnDataType.INTEGER) Map(java.util.Map) AnalyticsTableType(org.hisp.dhis.analytics.AnalyticsTableType) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) IndexType(org.hisp.dhis.analytics.IndexType) Category(org.hisp.dhis.category.Category) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) DhisConvenienceTest.createCategory(org.hisp.dhis.DhisConvenienceTest.createCategory) DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) Matchers.equalTo(org.hamcrest.Matchers.equalTo) LocalDate(java.time.LocalDate) Matchers.is(org.hamcrest.Matchers.is) DhisConvenienceTest.createProgramTrackedEntityAttribute(org.hisp.dhis.DhisConvenienceTest.createProgramTrackedEntityAttribute) CategoryCombo(org.hisp.dhis.category.CategoryCombo) Matchers.containsString(org.hamcrest.Matchers.containsString) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Mockito.mock(org.mockito.Mockito.mock) TIMESTAMP(org.hisp.dhis.analytics.ColumnDataType.TIMESTAMP) DhisConvenienceTest.createTrackedEntityAttribute(org.hisp.dhis.DhisConvenienceTest.createTrackedEntityAttribute) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) DOUBLE(org.hisp.dhis.analytics.ColumnDataType.DOUBLE) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) Mock(org.mockito.Mock) PostgreSQLStatementBuilder(org.hisp.dhis.jdbc.statementbuilder.PostgreSQLStatementBuilder) AnalyticsTable(org.hisp.dhis.analytics.AnalyticsTable) AnalyticsTableHookService(org.hisp.dhis.analytics.AnalyticsTableHookService) PartitionManager(org.hisp.dhis.analytics.partition.PartitionManager) Program(org.hisp.dhis.program.Program) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) HashSet(java.util.HashSet) DataElement(org.hisp.dhis.dataelement.DataElement) DatabaseInfo(org.hisp.dhis.system.database.DatabaseInfo) ArgumentCaptor(org.mockito.ArgumentCaptor) Lists(com.google.common.collect.Lists) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) BIGINT(org.hisp.dhis.analytics.ColumnDataType.BIGINT) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) ColumnNotNullConstraint(org.hisp.dhis.analytics.ColumnNotNullConstraint) DhisConvenienceTest.createCategoryCombo(org.hisp.dhis.DhisConvenienceTest.createCategoryCombo) DataApprovalLevelService(org.hisp.dhis.dataapproval.DataApprovalLevelService) AnalyticsTablePartition(org.hisp.dhis.analytics.AnalyticsTablePartition) DateTime(org.joda.time.DateTime) TEXT(org.hisp.dhis.analytics.ColumnDataType.TEXT) AggregationType(org.hisp.dhis.analytics.AggregationType) Mockito.when(org.mockito.Mockito.when) StatementBuilder(org.hisp.dhis.jdbc.StatementBuilder) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) ProgramStage(org.hisp.dhis.program.ProgramStage) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) PeriodType(org.hisp.dhis.period.PeriodType) DhisConvenienceTest.getDate(org.hisp.dhis.DhisConvenienceTest.getDate) SettingKey(org.hisp.dhis.setting.SettingKey) Collections(java.util.Collections) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) Program(org.hisp.dhis.program.Program) AnalyticsTableAsserter(org.hisp.dhis.analytics.util.AnalyticsTableAsserter) AnalyticsTable(org.hisp.dhis.analytics.AnalyticsTable) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) AnalyticsTableUpdateParams(org.hisp.dhis.analytics.AnalyticsTableUpdateParams) Test(org.junit.jupiter.api.Test)

Example 22 with CategoryOptionGroupSet

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

the class DefaultCategoryService method getCogDimensionConstraints.

@Override
@Transactional(readOnly = true)
public Set<CategoryOptionGroup> getCogDimensionConstraints(User user) {
    Set<CategoryOptionGroup> groups = null;
    Set<CategoryOptionGroupSet> cogsConstraints = user.getCogsDimensionConstraints();
    if (cogsConstraints != null && !cogsConstraints.isEmpty()) {
        groups = new HashSet<>();
        for (CategoryOptionGroupSet cogs : cogsConstraints) {
            groups.addAll(getCategoryOptionGroups(cogs));
        }
    }
    return groups;
}
Also used : CategoryOptionGroup(org.hisp.dhis.category.CategoryOptionGroup) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with CategoryOptionGroupSet

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

the class DefaultDataApprovalAuditService method retainFromDimensionConstraints.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
 * Retain the DataApprovalAudits that the user can read despite any
 * dimension constraints that the user my have.
 *
 * @param audits the list of audit records.
 */
private void retainFromDimensionConstraints(List<DataApprovalAudit> audits) {
    User user = currentUserService.getCurrentUser();
    Set<CategoryOptionGroupSet> cogDimensionConstraints = user.getCogsDimensionConstraints();
    Set<Category> catDimensionConstraints = user.getCatDimensionConstraints();
    if (currentUserService.currentUserIsSuper() || (CollectionUtils.isEmpty(cogDimensionConstraints) && CollectionUtils.isEmpty(catDimensionConstraints))) {
        return;
    }
    // Local
    Map<CategoryOptionCombo, Boolean> readableOptionCombos = new HashMap<>();
    for (Iterator<DataApprovalAudit> i = audits.iterator(); i.hasNext(); ) {
        CategoryOptionCombo optionCombo = i.next().getAttributeOptionCombo();
        Boolean canRead = readableOptionCombos.get(optionCombo);
        if (canRead == null) {
            canRead = canReadOptionCombo(user, optionCombo, cogDimensionConstraints, catDimensionConstraints);
            readableOptionCombos.put(optionCombo, canRead);
        }
        if (!canRead) {
            i.remove();
        }
    }
}
Also used : User(org.hisp.dhis.user.User) Category(org.hisp.dhis.category.Category) HashMap(java.util.HashMap) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 24 with CategoryOptionGroupSet

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

the class ValidationResultStoreHqlTest method queryWithUserWithCategoryAndCategoryOptionGroupSet.

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

Example 25 with CategoryOptionGroupSet

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

the class ValidationResultStoreHqlTest method setUpUser.

private void setUpUser(String orgUnitUid, Category category, CategoryOptionGroupSet groupSet) {
    User user = new User();
    when(currentUserService.getCurrentUser()).thenReturn(user);
    user.setGroups(emptySet());
    OrganisationUnit unit = new OrganisationUnit();
    unit.setUid(orgUnitUid);
    user.setDataViewOrganisationUnits(singleton(unit));
    // categories
    Set<Category> categories = category == null ? emptySet() : singleton(category);
    user.setCatDimensionConstraints(categories);
    // option groups
    Set<CategoryOptionGroupSet> options = groupSet == null ? emptySet() : singleton(groupSet);
    user.setCogsDimensionConstraints(options);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Category(org.hisp.dhis.category.Category) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet)

Aggregations

CategoryOptionGroupSet (org.hisp.dhis.category.CategoryOptionGroupSet)26 Category (org.hisp.dhis.category.Category)14 CategoryOption (org.hisp.dhis.category.CategoryOption)7 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)7 ArrayList (java.util.ArrayList)6 User (org.hisp.dhis.user.User)5 AnalyticsTableColumn (org.hisp.dhis.analytics.AnalyticsTableColumn)4 CategoryOptionGroup (org.hisp.dhis.category.CategoryOptionGroup)4 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)4 PeriodType (org.hisp.dhis.period.PeriodType)4 Test (org.junit.jupiter.api.Test)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 DataElement (org.hisp.dhis.dataelement.DataElement)3 DataElementGroupSet (org.hisp.dhis.dataelement.DataElementGroupSet)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 HashSet (java.util.HashSet)2 DimensionalObject (org.hisp.dhis.common.DimensionalObject)2 Expression (org.hisp.dhis.expression.Expression)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2