Search in sources :

Example 41 with Category

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

the class TypedIndexedObjectContainerTest method getContainerExisting.

@Test
void getContainerExisting() {
    final Attribute attribute1 = new Attribute();
    final Category category1 = new Category();
    container.mergeObjectIndex(new Attribute());
    container.mergeObjectIndex(new Category());
    container.mergeObjectIndex(attribute1);
    container.mergeObjectIndex(category1);
    IndexedObjectContainer container1 = container.getTypedContainer(Attribute.class);
    Assertions.assertSame(1, container1.mergeObjectIndex(attribute1));
    IndexedObjectContainer container2 = container.getTypedContainer(Category.class);
    Assertions.assertSame(1, container2.mergeObjectIndex(category1));
}
Also used : Category(org.hisp.dhis.category.Category) Attribute(org.hisp.dhis.attribute.Attribute) Test(org.junit.jupiter.api.Test)

Example 42 with Category

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

the class TypedIndexedObjectContainerTest method add.

@Test
void add() {
    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();
    container.add(attribute1);
    container.add(attribute2);
    container.add(attribute3);
    container.add(category1);
    container.add(category2);
    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 43 with Category

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

the class JdbcEventAnalyticsTableManager method getDimensionColumns.

/**
 * Returns dimensional analytics table columns.
 *
 * @param program the program.
 * @return a list of {@link AnalyticsTableColumn}.
 */
private List<AnalyticsTableColumn> getDimensionColumns(Program program) {
    List<AnalyticsTableColumn> columns = new ArrayList<>();
    if (program.hasNonDefaultCategoryCombo()) {
        List<Category> categories = program.getCategoryCombo().getCategories();
        for (Category category : categories) {
            if (category.isDataDimension()) {
                columns.add(new AnalyticsTableColumn(quote(category.getUid()), CHARACTER_11, "acs." + quote(category.getUid())).withCreated(category.getCreated()));
            }
        }
    }
    columns.addAll(addOrganisationUnitLevels());
    columns.addAll(addOrganisationUnitGroupSets());
    columns.addAll(categoryService.getAttributeCategoryOptionGroupSetsNoAcl().stream().map(l -> toCharColumn(quote(l.getUid()), "acs", l.getCreated())).collect(Collectors.toList()));
    columns.addAll(addPeriodTypeColumns("dps"));
    columns.addAll(program.getAnalyticsDataElements().stream().map(de -> getColumnFromDataElement(de, false)).flatMap(Collection::stream).collect(Collectors.toList()));
    columns.addAll(program.getAnalyticsDataElementsWithLegendSet().stream().map(de -> getColumnFromDataElement(de, true)).flatMap(Collection::stream).collect(Collectors.toList()));
    columns.addAll(program.getNonConfidentialTrackedEntityAttributes().stream().map(tea -> getColumnFromTrackedEntityAttribute(tea, getNumericClause(), getDateClause(), false)).flatMap(Collection::stream).collect(Collectors.toList()));
    columns.addAll(program.getNonConfidentialTrackedEntityAttributesWithLegendSet().stream().map(tea -> getColumnFromTrackedEntityAttribute(tea, getNumericClause(), getDateClause(), true)).flatMap(Collection::stream).collect(Collectors.toList()));
    columns.addAll(getFixedColumns());
    if (program.isRegistration()) {
        columns.add(new AnalyticsTableColumn(quote("tei"), CHARACTER_11, "tei.uid"));
    }
    return filterDimensionColumns(columns);
}
Also used : CategoryService(org.hisp.dhis.category.CategoryService) 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) AnalyticsSqlUtils.quote(org.hisp.dhis.analytics.util.AnalyticsSqlUtils.quote) AnalyticsTableUpdateParams(org.hisp.dhis.analytics.AnalyticsTableUpdateParams) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) GEOMETRY(org.hisp.dhis.analytics.ColumnDataType.GEOMETRY) AnalyticsUtils.getColumnType(org.hisp.dhis.analytics.util.AnalyticsUtils.getColumnType) Calendar(org.hisp.dhis.calendar.Calendar) INTEGER(org.hisp.dhis.analytics.ColumnDataType.INTEGER) NOT_NULL(org.hisp.dhis.analytics.ColumnNotNullConstraint.NOT_NULL) AnalyticsTableType(org.hisp.dhis.analytics.AnalyticsTableType) Collection(java.util.Collection) IndexType(org.hisp.dhis.analytics.IndexType) Category(org.hisp.dhis.category.Category) Collectors(java.util.stream.Collectors) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) VARCHAR_255(org.hisp.dhis.analytics.ColumnDataType.VARCHAR_255) DateUtils.getLongDateString(org.hisp.dhis.util.DateUtils.getLongDateString) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) NUMERIC_LENIENT_REGEXP(org.hisp.dhis.system.util.MathUtils.NUMERIC_LENIENT_REGEXP) TIMESTAMP(org.hisp.dhis.analytics.ColumnDataType.TIMESTAMP) DOUBLE(org.hisp.dhis.analytics.ColumnDataType.DOUBLE) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) 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) ArrayList(java.util.ArrayList) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DataElement(org.hisp.dhis.dataelement.DataElement) DatabaseInfo(org.hisp.dhis.system.database.DatabaseInfo) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) Service(org.springframework.stereotype.Service) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) DataApprovalLevelService(org.hisp.dhis.dataapproval.DataApprovalLevelService) AnalyticsSqlUtils.getClosingParentheses(org.hisp.dhis.analytics.util.AnalyticsSqlUtils.getClosingParentheses) AnalyticsTablePartition(org.hisp.dhis.analytics.AnalyticsTablePartition) TEXT(org.hisp.dhis.analytics.ColumnDataType.TEXT) StatementBuilder(org.hisp.dhis.jdbc.StatementBuilder) ColumnDataType(org.hisp.dhis.analytics.ColumnDataType) VARCHAR_50(org.hisp.dhis.analytics.ColumnDataType.VARCHAR_50) PeriodType(org.hisp.dhis.period.PeriodType) SettingKey(org.hisp.dhis.setting.SettingKey) Collections(java.util.Collections) DateUtils(org.hisp.dhis.util.DateUtils) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) Category(org.hisp.dhis.category.Category) ArrayList(java.util.ArrayList) Collection(java.util.Collection) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn)

Example 44 with Category

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

the class JdbcValidationResultTableManager method getDimensionColumns.

private List<AnalyticsTableColumn> getDimensionColumns() {
    List<AnalyticsTableColumn> columns = new ArrayList<>();
    List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
    List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
    List<Category> attributeCategories = categoryService.getAttributeDataDimensionCategoriesNoAcl();
    for (OrganisationUnitGroupSet groupSet : orgUnitGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), CHARACTER_11, "ougs." + quote(groupSet.getUid())).withCreated(groupSet.getCreated()));
    }
    for (OrganisationUnitLevel level : levels) {
        String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
        columns.add(new AnalyticsTableColumn(column, CHARACTER_11, "ous." + column).withCreated(level.getCreated()));
    }
    for (Category category : attributeCategories) {
        columns.add(new AnalyticsTableColumn(quote(category.getUid()), CHARACTER_11, "acs." + quote(category.getUid())).withCreated(category.getCreated()));
    }
    for (PeriodType periodType : PeriodType.getAvailablePeriodTypes()) {
        String column = quote(periodType.getName().toLowerCase());
        columns.add(new AnalyticsTableColumn(column, TEXT, "ps." + column));
    }
    columns.addAll(getFixedColumns());
    return filterDimensionColumns(columns);
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Category(org.hisp.dhis.category.Category) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) ArrayList(java.util.ArrayList) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) DateUtils.getLongDateString(org.hisp.dhis.util.DateUtils.getLongDateString) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 45 with Category

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

the class JdbcCompletenessTargetTableManager method getDimensionColumns.

private List<AnalyticsTableColumn> getDimensionColumns() {
    List<AnalyticsTableColumn> columns = new ArrayList<>();
    List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
    List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
    List<CategoryOptionGroupSet> attributeCategoryOptionGroupSets = categoryService.getAttributeCategoryOptionGroupSetsNoAcl();
    List<Category> attributeCategories = categoryService.getAttributeDataDimensionCategoriesNoAcl();
    for (OrganisationUnitGroupSet groupSet : orgUnitGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), CHARACTER_11, "ougs." + quote(groupSet.getUid())).withCreated(groupSet.getCreated()));
    }
    for (OrganisationUnitLevel level : levels) {
        String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
        columns.add(new AnalyticsTableColumn(column, CHARACTER_11, "ous." + column).withCreated(level.getCreated()));
    }
    for (CategoryOptionGroupSet groupSet : attributeCategoryOptionGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), CHARACTER_11, "acs." + quote(groupSet.getUid())).withCreated(groupSet.getCreated()));
    }
    for (Category category : attributeCategories) {
        columns.add(new AnalyticsTableColumn(quote(category.getUid()), CHARACTER_11, "acs." + quote(category.getUid())).withCreated(category.getCreated()));
    }
    columns.addAll(getFixedColumns());
    return filterDimensionColumns(columns);
}
Also used : Category(org.hisp.dhis.category.Category) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) ArrayList(java.util.ArrayList) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

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