Search in sources :

Example 6 with UniqueArrayList

use of org.hisp.dhis.commons.collection.UniqueArrayList in project dhis2-core by dhis2.

the class JdbcEnrollmentAnalyticsTableManager method getTables.

private List<AnalyticsTable> getTables() {
    List<AnalyticsTable> tables = new UniqueArrayList<>();
    List<Program> programs = idObjectManager.getAllNoAcl(Program.class);
    String baseName = getTableName();
    for (Program program : programs) {
        AnalyticsTable table = new AnalyticsTable(baseName, null, null, program);
        List<AnalyticsTableColumn> dimensionColumns = getDimensionColumns(table);
        table.setDimensionColumns(dimensionColumns);
        tables.add(table);
    }
    return tables;
}
Also used : Program(org.hisp.dhis.program.Program) AnalyticsTable(org.hisp.dhis.analytics.AnalyticsTable) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn)

Example 7 with UniqueArrayList

use of org.hisp.dhis.commons.collection.UniqueArrayList in project dhis2-core by dhis2.

the class AbstractJdbcTableManager method getTables.

/**
     * Generates a list of {@link AnalyticsTable} based on a list of years with data.
     * 
     * @param dataYears the list of years of data.
     */
protected List<AnalyticsTable> getTables(List<Integer> dataYears) {
    List<AnalyticsTable> tables = new UniqueArrayList<>();
    Calendar calendar = PeriodType.getCalendar();
    Collections.sort(dataYears);
    String baseName = getAnalyticsTableType().getTableName();
    for (Integer year : dataYears) {
        Period period = PartitionUtils.getPeriod(calendar, year);
        AnalyticsTable table = new AnalyticsTable(baseName, getDimensionColumns(null), period);
        tables.add(table);
    }
    return tables;
}
Also used : AnalyticsTable(org.hisp.dhis.analytics.AnalyticsTable) Calendar(org.hisp.dhis.calendar.Calendar) Period(org.hisp.dhis.period.Period) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList)

Example 8 with UniqueArrayList

use of org.hisp.dhis.commons.collection.UniqueArrayList in project dhis2-core by dhis2.

the class UniqueArrayListTest method testCollectionConstructor.

@Test
public void testCollectionConstructor() {
    List<Period> list = new ArrayList<>();
    PeriodType periodType = new MonthlyPeriodType();
    Period peA = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
    // Duplicate
    Period peB = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
    Period peC = periodType.createPeriod(new DateTime(2000, 2, 1, 0, 0).toDate());
    list.add(peA);
    list.add(peB);
    list.add(peC);
    assertEquals(3, list.size());
    List<Period> uniqueList = new UniqueArrayList<>(list);
    assertEquals(2, uniqueList.size());
    assertTrue(uniqueList.contains(peA));
    assertTrue(uniqueList.contains(peB));
    assertTrue(uniqueList.contains(peC));
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 9 with UniqueArrayList

use of org.hisp.dhis.commons.collection.UniqueArrayList in project dhis2-core by dhis2.

the class DefaultDimensionService method mergeDimensionalObjects.

/**
     * Sets persistent objects for dimensional associations on the given
     * BaseAnalyticalObject based on the given list of transient DimensionalObjects.
     * <p>
     * Relative periods represented by enums are converted into a RelativePeriods
     * object. User organisation units represented by enums are converted and
     * represented by the user organisation unit persisted properties on the
     * BaseAnalyticalObject.
     *
     * @param object     the BaseAnalyticalObject to merge.
     * @param dimensions the list of dimensions.
     */
private void mergeDimensionalObjects(BaseAnalyticalObject object, List<DimensionalObject> dimensions) {
    if (object == null || dimensions == null) {
        return;
    }
    for (DimensionalObject dimension : dimensions) {
        DimensionType type = getDimensionType(dimension.getDimension());
        String dimensionId = dimension.getDimension();
        List<DimensionalItemObject> items = dimension.getItems();
        if (items != null) {
            List<String> uids = getUids(items);
            if (DATA_X.equals(type)) {
                for (String uid : uids) {
                    DimensionalItemObject dimItemObject = getDataDimensionalItemObject(IdScheme.UID, uid);
                    if (dimItemObject != null) {
                        DataDimensionItem item = DataDimensionItem.create(dimItemObject);
                        object.getDataDimensionItems().add(item);
                    }
                }
            } else if (PERIOD.equals(type)) {
                List<RelativePeriodEnum> enums = new ArrayList<>();
                List<Period> periods = new UniqueArrayList<>();
                for (String isoPeriod : uids) {
                    if (RelativePeriodEnum.contains(isoPeriod)) {
                        enums.add(RelativePeriodEnum.valueOf(isoPeriod));
                    } else {
                        Period period = PeriodType.getPeriodFromIsoString(isoPeriod);
                        if (period != null) {
                            periods.add(period);
                        }
                    }
                }
                object.setRelatives(new RelativePeriods().setRelativePeriodsFromEnums(enums));
                object.setPeriods(periodService.reloadPeriods(new ArrayList<>(periods)));
            } else if (ORGANISATION_UNIT.equals(type)) {
                for (String ou : uids) {
                    if (KEY_USER_ORGUNIT.equals(ou)) {
                        object.setUserOrganisationUnit(true);
                    } else if (KEY_USER_ORGUNIT_CHILDREN.equals(ou)) {
                        object.setUserOrganisationUnitChildren(true);
                    } else if (KEY_USER_ORGUNIT_GRANDCHILDREN.equals(ou)) {
                        object.setUserOrganisationUnitGrandChildren(true);
                    } else if (ou != null && ou.startsWith(KEY_LEVEL)) {
                        int level = DimensionalObjectUtils.getLevelFromLevelParam(ou);
                        if (level > 0) {
                            object.getOrganisationUnitLevels().add(level);
                        }
                    } else if (ou != null && ou.startsWith(KEY_ORGUNIT_GROUP)) {
                        String uid = DimensionalObjectUtils.getUidFromGroupParam(ou);
                        OrganisationUnitGroup group = idObjectManager.get(OrganisationUnitGroup.class, uid);
                        if (group != null) {
                            object.getItemOrganisationUnitGroups().add(group);
                        }
                    } else {
                        OrganisationUnit unit = idObjectManager.get(OrganisationUnit.class, ou);
                        if (unit != null) {
                            object.getOrganisationUnits().add(unit);
                        }
                    }
                }
            } else if (DATA_ELEMENT_GROUP_SET.equals(type)) {
                DataElementGroupSetDimension groupSetDimension = new DataElementGroupSetDimension();
                groupSetDimension.setDimension(idObjectManager.get(DataElementGroupSet.class, dimensionId));
                groupSetDimension.getItems().addAll(idObjectManager.getByUidOrdered(DataElementGroup.class, uids));
                object.getDataElementGroupSetDimensions().add(groupSetDimension);
            } else if (ORGANISATION_UNIT_GROUP_SET.equals(type)) {
                OrganisationUnitGroupSetDimension groupSetDimension = new OrganisationUnitGroupSetDimension();
                groupSetDimension.setDimension(idObjectManager.get(OrganisationUnitGroupSet.class, dimensionId));
                groupSetDimension.getItems().addAll(idObjectManager.getByUidOrdered(OrganisationUnitGroup.class, uids));
                object.getOrganisationUnitGroupSetDimensions().add(groupSetDimension);
            } else if (CATEGORY.equals(type)) {
                CategoryDimension categoryDimension = new CategoryDimension();
                categoryDimension.setDimension(idObjectManager.get(DataElementCategory.class, dimensionId));
                categoryDimension.getItems().addAll(idObjectManager.getByUidOrdered(DataElementCategoryOption.class, uids));
                object.getCategoryDimensions().add(categoryDimension);
            } else if (CATEGORY_OPTION_GROUP_SET.equals(type)) {
                CategoryOptionGroupSetDimension groupSetDimension = new CategoryOptionGroupSetDimension();
                groupSetDimension.setDimension(idObjectManager.get(CategoryOptionGroupSet.class, dimensionId));
                groupSetDimension.getItems().addAll(idObjectManager.getByUidOrdered(CategoryOptionGroup.class, uids));
                object.getCategoryOptionGroupSetDimensions().add(groupSetDimension);
            } else if (PROGRAM_ATTRIBUTE.equals(type)) {
                TrackedEntityAttributeDimension attributeDimension = new TrackedEntityAttributeDimension();
                attributeDimension.setAttribute(idObjectManager.get(TrackedEntityAttribute.class, dimensionId));
                attributeDimension.setLegendSet(dimension.hasLegendSet() ? idObjectManager.get(LegendSet.class, dimension.getLegendSet().getUid()) : null);
                attributeDimension.setFilter(dimension.getFilter());
                object.getAttributeDimensions().add(attributeDimension);
            } else if (PROGRAM_DATA_ELEMENT.equals(type)) {
                TrackedEntityDataElementDimension dataElementDimension = new TrackedEntityDataElementDimension();
                dataElementDimension.setDataElement(idObjectManager.get(DataElement.class, dimensionId));
                dataElementDimension.setLegendSet(dimension.hasLegendSet() ? idObjectManager.get(LegendSet.class, dimension.getLegendSet().getUid()) : null);
                dataElementDimension.setFilter(dimension.getFilter());
                object.getDataElementDimensions().add(dataElementDimension);
            } else if (PROGRAM_INDICATOR.equals(type)) {
                TrackedEntityProgramIndicatorDimension programIndicatorDimension = new TrackedEntityProgramIndicatorDimension();
                programIndicatorDimension.setProgramIndicator(idObjectManager.get(ProgramIndicator.class, dimensionId));
                programIndicatorDimension.setLegendSet(dimension.hasLegendSet() ? idObjectManager.get(LegendSet.class, dimension.getLegendSet().getUid()) : null);
                programIndicatorDimension.setFilter(dimension.getFilter());
                object.getProgramIndicatorDimensions().add(programIndicatorDimension);
            }
        }
    }
}
Also used : DimensionType(org.hisp.dhis.common.DimensionType) RelativePeriods(org.hisp.dhis.period.RelativePeriods) DataElementGroupSetDimension(org.hisp.dhis.dataelement.DataElementGroupSetDimension) CategoryDimension(org.hisp.dhis.dataelement.CategoryDimension) CategoryOptionGroupSetDimension(org.hisp.dhis.dataelement.CategoryOptionGroupSetDimension) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension) DimensionalObject(org.hisp.dhis.common.DimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryOptionGroup(org.hisp.dhis.dataelement.CategoryOptionGroup) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DataDimensionItem(org.hisp.dhis.common.DataDimensionItem) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) List(java.util.List) ArrayList(java.util.ArrayList) TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) Period(org.hisp.dhis.period.Period) TrackedEntityProgramIndicatorDimension(org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension) LegendSet(org.hisp.dhis.legend.LegendSet) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) OrganisationUnitGroupSetDimension(org.hisp.dhis.organisationunit.OrganisationUnitGroupSetDimension) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Aggregations

UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)9 Period (org.hisp.dhis.period.Period)8 ArrayList (java.util.ArrayList)4 AnalyticsTable (org.hisp.dhis.analytics.AnalyticsTable)4 PeriodType (org.hisp.dhis.period.PeriodType)4 DateTime (org.joda.time.DateTime)4 Test (org.junit.Test)4 Calendar (org.hisp.dhis.calendar.Calendar)3 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)3 AnalyticsTableColumn (org.hisp.dhis.analytics.AnalyticsTableColumn)2 Program (org.hisp.dhis.program.Program)2 Date (java.util.Date)1 List (java.util.List)1 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)1 DataDimensionItem (org.hisp.dhis.common.DataDimensionItem)1 DimensionType (org.hisp.dhis.common.DimensionType)1 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)1 DimensionalObject (org.hisp.dhis.common.DimensionalObject)1 CategoryDimension (org.hisp.dhis.dataelement.CategoryDimension)1 CategoryOptionGroup (org.hisp.dhis.dataelement.CategoryOptionGroup)1