Search in sources :

Example 1 with ConfigurablePeriod

use of org.hisp.dhis.period.ConfigurablePeriod in project dhis2-core by dhis2.

the class BaseAnalyticalObject method getDimensionalObject.

/**
 * Assembles a list of DimensionalObjects based on the concrete objects in
 * this BaseAnalyticalObject.
 * <p>
 * Merges fixed and relative periods into the pe dimension, where the
 * RelativePeriods object is represented by enums (e.g. LAST_MONTH). Merges
 * fixed and user organisation units into the ou dimension, where user
 * organisation units properties are represented by enums (e.g.
 * USER_ORG_UNIT).
 * <p>
 * This method is useful when serializing the AnalyticalObject.
 *
 * @param dimension the dimension identifier.
 * @return a list of DimensionalObjects.
 */
protected Optional<DimensionalObject> getDimensionalObject(String dimension) {
    if (DATA_X_DIM_ID.equals(dimension)) {
        return Optional.of(new BaseDimensionalObject(dimension, DimensionType.DATA_X, getDataDimensionNameableObjects()));
    } else if (PERIOD_DIM_ID.equals(dimension)) {
        List<Period> periodList = new ArrayList<>(periods);
        if (hasRelativePeriods()) {
            List<RelativePeriodEnum> list = relatives.getRelativePeriodEnums();
            for (RelativePeriodEnum periodEnum : list) {
                periodList.add(new ConfigurablePeriod(periodEnum.toString()));
            }
        }
        return Optional.of(new BaseDimensionalObject(dimension, DimensionType.PERIOD, periodList));
    } else if (ORGUNIT_DIM_ID.equals(dimension)) {
        List<DimensionalItemObject> ouList = new ArrayList<>();
        ouList.addAll(organisationUnits);
        ouList.addAll(transientOrganisationUnits);
        if (userOrganisationUnit) {
            ouList.add(new BaseDimensionalItemObject(KEY_USER_ORGUNIT));
        }
        if (userOrganisationUnitChildren) {
            ouList.add(new BaseDimensionalItemObject(KEY_USER_ORGUNIT_CHILDREN));
        }
        if (userOrganisationUnitGrandChildren) {
            ouList.add(new BaseDimensionalItemObject(KEY_USER_ORGUNIT_GRANDCHILDREN));
        }
        if (organisationUnitLevels != null && !organisationUnitLevels.isEmpty()) {
            for (Integer level : organisationUnitLevels) {
                String id = KEY_LEVEL + level;
                ouList.add(new BaseDimensionalItemObject(id));
            }
        }
        if (itemOrganisationUnitGroups != null && !itemOrganisationUnitGroups.isEmpty()) {
            for (OrganisationUnitGroup group : itemOrganisationUnitGroups) {
                String id = KEY_ORGUNIT_GROUP + group.getUid();
                ouList.add(new BaseDimensionalItemObject(id));
            }
        }
        return Optional.of(new BaseDimensionalObject(dimension, DimensionType.ORGANISATION_UNIT, ouList));
    } else if (CATEGORYOPTIONCOMBO_DIM_ID.equals(dimension)) {
        return Optional.of(new BaseDimensionalObject(dimension, DimensionType.CATEGORY_OPTION_COMBO, new ArrayList<>()));
    } else if (DATA_COLLAPSED_DIM_ID.equals(dimension)) {
        return Optional.of(new BaseDimensionalObject(dimension, DimensionType.DATA_COLLAPSED, new ArrayList<>()));
    } else if (STATIC_DIMS.contains(dimension)) {
        return Optional.of(new BaseDimensionalObject(dimension, DimensionType.STATIC, new ArrayList<>()));
    } else {
        // Embedded dimensions
        Optional<DimensionalObject> object;
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.DATA_ELEMENT_GROUP_SET, dataElementGroupSetDimensions)).isPresent()) {
            return Optional.of(object.get());
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.ORGANISATION_UNIT_GROUP_SET, organisationUnitGroupSetDimensions)).isPresent()) {
            return Optional.of(object.get());
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.CATEGORY, categoryDimensions)).isPresent()) {
            return Optional.of(object.get());
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.CATEGORY_OPTION_GROUP_SET, categoryOptionGroupSetDimensions)).isPresent()) {
            return Optional.of(object.get());
        }
        final Optional<DimensionalObject> trackedEntityDimension = getTrackedEntityDimension(dimension);
        if (trackedEntityDimension.isPresent()) {
            return trackedEntityDimension;
        }
    }
    return Optional.empty();
}
Also used : Optional(java.util.Optional) ArrayList(java.util.ArrayList) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) ConfigurablePeriod(org.hisp.dhis.period.ConfigurablePeriod) RelativePeriodEnum(org.hisp.dhis.period.RelativePeriodEnum) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)1 ConfigurablePeriod (org.hisp.dhis.period.ConfigurablePeriod)1 RelativePeriodEnum (org.hisp.dhis.period.RelativePeriodEnum)1