Search in sources :

Example 1 with TrackedEntityProgramIndicatorDimension

use of org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension 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 DimensionalObject getDimensionalObject(String dimension) {
    if (DATA_X_DIM_ID.equals(dimension)) {
        return 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()));
            }
        }
        Collections.sort(periodList, new AscendingPeriodComparator());
        return 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 new BaseDimensionalObject(dimension, DimensionType.ORGANISATION_UNIT, ouList);
    } else if (CATEGORYOPTIONCOMBO_DIM_ID.equals(dimension)) {
        return new BaseDimensionalObject(dimension, DimensionType.CATEGORY_OPTION_COMBO, new ArrayList<>());
    } else if (DATA_COLLAPSED_DIM_ID.contains(dimension)) {
        return new BaseDimensionalObject(dimension, DimensionType.DATA_COLLAPSED, new ArrayList<>());
    } else if (STATIC_DIMS.contains(dimension)) {
        return new BaseDimensionalObject(dimension, DimensionType.STATIC, new ArrayList<>());
    } else {
        // Embedded dimensions
        Optional<DimensionalObject> object = Optional.empty();
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.DATA_ELEMENT_GROUP_SET, dataElementGroupSetDimensions)).isPresent()) {
            return object.get();
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.ORGANISATION_UNIT_GROUP_SET, organisationUnitGroupSetDimensions)).isPresent()) {
            return object.get();
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.CATEGORY, categoryDimensions)).isPresent()) {
            return object.get();
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.CATEGORY_OPTION_GROUP_SET, categoryOptionGroupSetDimensions)).isPresent()) {
            return object.get();
        }
        // Tracked entity attribute
        Map<String, TrackedEntityAttributeDimension> attributes = Maps.uniqueIndex(attributeDimensions, TrackedEntityAttributeDimension::getUid);
        if (attributes.containsKey(dimension)) {
            TrackedEntityAttributeDimension tead = attributes.get(dimension);
            return new BaseDimensionalObject(dimension, DimensionType.PROGRAM_ATTRIBUTE, null, tead.getDisplayName(), tead.getLegendSet(), tead.getFilter());
        }
        // Tracked entity data element
        Map<String, TrackedEntityDataElementDimension> dataElements = Maps.uniqueIndex(dataElementDimensions, TrackedEntityDataElementDimension::getUid);
        if (dataElements.containsKey(dimension)) {
            TrackedEntityDataElementDimension tedd = dataElements.get(dimension);
            return new BaseDimensionalObject(dimension, DimensionType.PROGRAM_DATA_ELEMENT, null, tedd.getDisplayName(), tedd.getLegendSet(), tedd.getFilter());
        }
        // Tracked entity program indicator
        Map<String, TrackedEntityProgramIndicatorDimension> programIndicators = Maps.uniqueIndex(programIndicatorDimensions, TrackedEntityProgramIndicatorDimension::getUid);
        if (programIndicators.containsKey(dimension)) {
            TrackedEntityProgramIndicatorDimension teid = programIndicators.get(dimension);
            return new BaseDimensionalObject(dimension, DimensionType.PROGRAM_INDICATOR, null, teid.getDisplayName(), teid.getLegendSet(), teid.getFilter());
        }
    }
    throw new IllegalArgumentException("Not a valid dimension: " + dimension);
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) Optional(java.util.Optional) ArrayList(java.util.ArrayList) TrackedEntityProgramIndicatorDimension(org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension) AscendingPeriodComparator(org.hisp.dhis.period.comparator.AscendingPeriodComparator) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) ConfigurablePeriod(org.hisp.dhis.period.ConfigurablePeriod) RelativePeriodEnum(org.hisp.dhis.period.RelativePeriodEnum) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with TrackedEntityProgramIndicatorDimension

use of org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension in project dhis2-core by dhis2.

the class BaseAnalyticalObject method getDimensionalObject.

/**
     * Assembles a DimensionalObject based on the persisted properties of this
     * AnalyticalObject. Collapses indicators, data elements, data element
     * operands and data sets into the dx dimension.
     * <p>
     * Collapses fixed and relative periods into the pe dimension. Collapses
     * fixed and user organisation units into the ou dimension.
     *
     * @param dimension    the dimension identifier.
     * @param date         the date used for generating relative periods.
     * @param user         the current user.
     * @param dynamicNames whether to use dynamic or static names.
     * @param format       the I18nFormat.
     * @return a DimensionalObject.
     */
protected DimensionalObject getDimensionalObject(String dimension, Date date, User user, boolean dynamicNames, List<OrganisationUnit> organisationUnitsAtLevel, List<OrganisationUnit> organisationUnitsInGroups, I18nFormat format) {
    List<DimensionalItemObject> items = new ArrayList<>();
    DimensionType type = null;
    if (DATA_X_DIM_ID.equals(dimension)) {
        items.addAll(getDataDimensionNameableObjects());
        type = DimensionType.DATA_X;
    } else if (PERIOD_DIM_ID.equals(dimension)) {
        setPeriodNames(periods, dynamicNames, format);
        items.addAll(periods);
        if (hasRelativePeriods()) {
            items.addAll(relatives.getRelativePeriods(date, format, dynamicNames));
        }
        type = DimensionType.PERIOD;
    } else if (ORGUNIT_DIM_ID.equals(dimension)) {
        items.addAll(organisationUnits);
        items.addAll(transientOrganisationUnits);
        if (userOrganisationUnit && user != null && user.hasOrganisationUnit()) {
            items.addAll(user.getOrganisationUnits());
        }
        if (userOrganisationUnitChildren && user != null && user.hasOrganisationUnit()) {
            user.getOrganisationUnits().forEach(ou -> items.addAll(ou.getSortedChildren()));
        }
        if (userOrganisationUnitGrandChildren && user != null && user.hasOrganisationUnit()) {
            user.getOrganisationUnits().forEach(ou -> items.addAll(ou.getSortedGrandChildren()));
        }
        if (organisationUnitLevels != null && !organisationUnitLevels.isEmpty() && organisationUnitsAtLevel != null) {
            // Must be set externally
            items.addAll(organisationUnitsAtLevel);
        }
        if (itemOrganisationUnitGroups != null && !itemOrganisationUnitGroups.isEmpty() && organisationUnitsInGroups != null) {
            // Must be set externally
            items.addAll(organisationUnitsInGroups);
        }
        type = DimensionType.ORGANISATION_UNIT;
    } else if (CATEGORYOPTIONCOMBO_DIM_ID.equals(dimension)) {
        items.addAll(transientCategoryOptionCombos);
        type = DimensionType.CATEGORY_OPTION_COMBO;
    } else if (STATIC_DIMS.contains(dimension)) {
        type = DimensionType.STATIC;
    } else {
        // Embedded dimensions
        Optional<DimensionalObject> object = Optional.empty();
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.DATA_ELEMENT_GROUP_SET, dataElementGroupSetDimensions)).isPresent()) {
            items.addAll(object.get().getItems());
            type = DimensionType.DATA_ELEMENT_GROUP_SET;
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.ORGANISATION_UNIT_GROUP_SET, organisationUnitGroupSetDimensions)).isPresent()) {
            items.addAll(object.get().getItems());
            type = DimensionType.ORGANISATION_UNIT_GROUP_SET;
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.CATEGORY, categoryDimensions)).isPresent()) {
            items.addAll(object.get().getItems());
            type = DimensionType.CATEGORY;
        }
        if ((object = getDimensionFromEmbeddedObjects(dimension, DimensionType.CATEGORY_OPTION_GROUP_SET, categoryOptionGroupSetDimensions)).isPresent()) {
            items.addAll(object.get().getItems());
            type = DimensionType.CATEGORY_OPTION_GROUP_SET;
        }
        // Tracked entity attribute
        Map<String, TrackedEntityAttributeDimension> attributes = Maps.uniqueIndex(attributeDimensions, TrackedEntityAttributeDimension::getUid);
        if (attributes.containsKey(dimension)) {
            TrackedEntityAttributeDimension tead = attributes.get(dimension);
            return new BaseDimensionalObject(dimension, DimensionType.PROGRAM_ATTRIBUTE, null, tead.getDisplayName(), tead.getLegendSet(), tead.getFilter());
        }
        // Tracked entity data element
        Map<String, TrackedEntityDataElementDimension> dataElements = Maps.uniqueIndex(dataElementDimensions, TrackedEntityDataElementDimension::getUid);
        if (dataElements.containsKey(dimension)) {
            TrackedEntityDataElementDimension tedd = dataElements.get(dimension);
            return new BaseDimensionalObject(dimension, DimensionType.PROGRAM_DATA_ELEMENT, null, tedd.getDisplayName(), tedd.getLegendSet(), tedd.getFilter());
        }
        // Tracked entity program indicator
        Map<String, TrackedEntityProgramIndicatorDimension> programIndicators = Maps.uniqueIndex(programIndicatorDimensions, TrackedEntityProgramIndicatorDimension::getUid);
        if (programIndicators.containsKey(dimension)) {
            TrackedEntityProgramIndicatorDimension teid = programIndicators.get(dimension);
            return new BaseDimensionalObject(dimension, DimensionType.PROGRAM_INDICATOR, null, teid.getDisplayName(), teid.getLegendSet(), teid.getFilter());
        }
    }
    IdentifiableObjectUtils.removeDuplicates(items);
    return new BaseDimensionalObject(dimension, type, items);
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) ArrayList(java.util.ArrayList) TrackedEntityProgramIndicatorDimension(org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 3 with TrackedEntityProgramIndicatorDimension

use of org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension 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)

Example 4 with TrackedEntityProgramIndicatorDimension

use of org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension in project dhis2-core by dhis2.

the class AnalyticalObjectObjectBundleHook method handleProgramIndicatorDimensions.

private void handleProgramIndicatorDimensions(Session session, Schema schema, BaseAnalyticalObject analyticalObject, ObjectBundle bundle) {
    if (!schema.havePersistedProperty("programIndicatorDimensions"))
        return;
    for (TrackedEntityProgramIndicatorDimension programIndicatorDimension : analyticalObject.getProgramIndicatorDimensions()) {
        if (programIndicatorDimension == null) {
            continue;
        }
        programIndicatorDimension.setProgramIndicator(bundle.getPreheat().get(bundle.getPreheatIdentifier(), programIndicatorDimension.getProgramIndicator()));
        programIndicatorDimension.setLegendSet(bundle.getPreheat().get(bundle.getPreheatIdentifier(), programIndicatorDimension.getLegendSet()));
        preheatService.connectReferences(programIndicatorDimension, bundle.getPreheat(), bundle.getPreheatIdentifier());
        session.save(programIndicatorDimension);
    }
}
Also used : TrackedEntityProgramIndicatorDimension(org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension)

Example 5 with TrackedEntityProgramIndicatorDimension

use of org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension in project dhis2-core by dhis2.

the class DefaultPreheatService method collectReferences.

@SuppressWarnings("unchecked")
private Map<PreheatIdentifier, Map<Class<? extends IdentifiableObject>, Set<String>>> collectReferences(Map<Class<?>, List<?>> objects) {
    Map<PreheatIdentifier, Map<Class<? extends IdentifiableObject>, Set<String>>> map = new HashMap<>();
    map.put(PreheatIdentifier.UID, new HashMap<>());
    map.put(PreheatIdentifier.CODE, new HashMap<>());
    Map<Class<? extends IdentifiableObject>, Set<String>> uidMap = map.get(PreheatIdentifier.UID);
    Map<Class<? extends IdentifiableObject>, Set<String>> codeMap = map.get(PreheatIdentifier.CODE);
    if (objects.isEmpty()) {
        return map;
    }
    Map<Class<?>, List<?>> targets = new HashMap<>();
    // clone objects list, we don't want to modify it
    targets.putAll(objects);
    collectScanTargets(targets);
    for (Class<?> klass : targets.keySet()) {
        Schema schema = schemaService.getDynamicSchema(klass);
        List<Property> referenceProperties = schema.getProperties().stream().filter(p -> p.isPersisted() && p.isOwner() && (PropertyType.REFERENCE == p.getPropertyType() || PropertyType.REFERENCE == p.getItemPropertyType())).collect(Collectors.toList());
        for (Object object : targets.get(klass)) {
            if (schema.isIdentifiableObject()) {
                IdentifiableObject identifiableObject = (IdentifiableObject) object;
                identifiableObject.getAttributeValues().forEach(av -> addIdentifiers(map, av.getAttribute()));
                identifiableObject.getUserGroupAccesses().forEach(uga -> addIdentifiers(map, uga.getUserGroup()));
                identifiableObject.getUserAccesses().forEach(ua -> addIdentifiers(map, ua.getUser()));
                addIdentifiers(map, identifiableObject);
            }
            referenceProperties.forEach(p -> {
                if (!p.isCollection()) {
                    Class<? extends IdentifiableObject> itemKlass = (Class<? extends IdentifiableObject>) p.getKlass();
                    if (!uidMap.containsKey(itemKlass))
                        uidMap.put(itemKlass, new HashSet<>());
                    if (!codeMap.containsKey(itemKlass))
                        codeMap.put(itemKlass, new HashSet<>());
                    Object reference = ReflectionUtils.invokeMethod(object, p.getGetterMethod());
                    if (reference != null) {
                        IdentifiableObject identifiableObject = (IdentifiableObject) reference;
                        addIdentifiers(map, identifiableObject);
                    }
                } else {
                    Collection<IdentifiableObject> reference = ReflectionUtils.invokeMethod(object, p.getGetterMethod());
                    reference.forEach(identifiableObject -> addIdentifiers(map, identifiableObject));
                    if (DataElementOperand.class.isAssignableFrom(p.getItemKlass())) {
                        CollectionUtils.nullSafeForEach(reference, identifiableObject -> {
                            DataElementOperand dataElementOperand = (DataElementOperand) identifiableObject;
                            addIdentifiers(map, dataElementOperand.getDataElement());
                            addIdentifiers(map, dataElementOperand.getCategoryOptionCombo());
                        });
                    }
                }
            });
            if (AnalyticalObject.class.isInstance(object)) {
                BaseAnalyticalObject analyticalObject = (BaseAnalyticalObject) object;
                List<DataDimensionItem> dataDimensionItems = analyticalObject.getDataDimensionItems();
                List<CategoryDimension> categoryDimensions = analyticalObject.getCategoryDimensions();
                List<TrackedEntityDataElementDimension> trackedEntityDataElementDimensions = analyticalObject.getDataElementDimensions();
                List<TrackedEntityAttributeDimension> attributeDimensions = analyticalObject.getAttributeDimensions();
                List<TrackedEntityProgramIndicatorDimension> programIndicatorDimensions = analyticalObject.getProgramIndicatorDimensions();
                CollectionUtils.nullSafeForEach(dataDimensionItems, dataDimensionItem -> {
                    addIdentifiers(map, dataDimensionItem.getDimensionalItemObject());
                    if (dataDimensionItem.getDataElementOperand() != null) {
                        addIdentifiers(map, dataDimensionItem.getDataElementOperand().getDataElement());
                        addIdentifiers(map, dataDimensionItem.getDataElementOperand().getCategoryOptionCombo());
                    }
                    if (dataDimensionItem.getReportingRate() != null) {
                        addIdentifiers(map, dataDimensionItem.getReportingRate().getDataSet());
                    }
                });
                CollectionUtils.nullSafeForEach(categoryDimensions, categoryDimension -> {
                    addIdentifiers(map, categoryDimension.getDimension());
                    categoryDimension.getItems().forEach(item -> addIdentifiers(map, item));
                });
                CollectionUtils.nullSafeForEach(trackedEntityDataElementDimensions, trackedEntityDataElementDimension -> {
                    addIdentifiers(map, trackedEntityDataElementDimension.getDataElement());
                    addIdentifiers(map, trackedEntityDataElementDimension.getLegendSet());
                });
                CollectionUtils.nullSafeForEach(attributeDimensions, trackedEntityAttributeDimension -> {
                    addIdentifiers(map, trackedEntityAttributeDimension.getAttribute());
                    addIdentifiers(map, trackedEntityAttributeDimension.getLegendSet());
                });
                CollectionUtils.nullSafeForEach(programIndicatorDimensions, programIndicatorDimension -> {
                    addIdentifiers(map, programIndicatorDimension.getProgramIndicator());
                    addIdentifiers(map, programIndicatorDimension.getLegendSet());
                });
            }
        }
    }
    cleanEmptyEntries(uidMap);
    cleanEmptyEntries(codeMap);
    return map;
}
Also used : ReflectionUtils(org.hisp.dhis.system.util.ReflectionUtils) BaseAnalyticalObject(org.hisp.dhis.common.BaseAnalyticalObject) Restrictions(org.hisp.dhis.query.Restrictions) PeriodService(org.hisp.dhis.period.PeriodService) MergeService(org.hisp.dhis.schema.MergeService) Autowired(org.springframework.beans.factory.annotation.Autowired) TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) StringUtils(org.apache.commons.lang3.StringUtils) MergeParams(org.hisp.dhis.schema.MergeParams) EmbeddedObject(org.hisp.dhis.common.EmbeddedObject) CategoryDimension(org.hisp.dhis.dataelement.CategoryDimension) UserCredentials(org.hisp.dhis.user.UserCredentials) Map(java.util.Map) Period(org.hisp.dhis.period.Period) Query(org.hisp.dhis.query.Query) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) UserGroup(org.hisp.dhis.user.UserGroup) Collection(java.util.Collection) Set(java.util.Set) SchemaService(org.hisp.dhis.schema.SchemaService) QueryService(org.hisp.dhis.query.QueryService) Property(org.hisp.dhis.schema.Property) Collectors(java.util.stream.Collectors) DataDimensionItem(org.hisp.dhis.common.DataDimensionItem) List(java.util.List) AttributeService(org.hisp.dhis.attribute.AttributeService) Schema(org.hisp.dhis.schema.Schema) LogFactory(org.apache.commons.logging.LogFactory) AnalyticalObject(org.hisp.dhis.common.AnalyticalObject) PropertyType(org.hisp.dhis.schema.PropertyType) DataSetElement(org.hisp.dhis.dataset.DataSetElement) HashMap(java.util.HashMap) Attribute(org.hisp.dhis.attribute.Attribute) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) User(org.hisp.dhis.user.User) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) SystemTimer(org.hisp.dhis.commons.timer.SystemTimer) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) TrackedEntityProgramIndicatorDimension(org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension) Timer(org.hisp.dhis.commons.timer.Timer) CollectionUtils(org.hisp.dhis.commons.collection.CollectionUtils) CurrentUserService(org.hisp.dhis.user.CurrentUserService) PeriodStore(org.hisp.dhis.period.PeriodStore) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension) Log(org.apache.commons.logging.Log) CodeGenerator(org.hisp.dhis.common.CodeGenerator) Transactional(org.springframework.transaction.annotation.Transactional) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Schema(org.hisp.dhis.schema.Schema) CategoryDimension(org.hisp.dhis.dataelement.CategoryDimension) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) BaseAnalyticalObject(org.hisp.dhis.common.BaseAnalyticalObject) List(java.util.List) ArrayList(java.util.ArrayList) DataDimensionItem(org.hisp.dhis.common.DataDimensionItem) Property(org.hisp.dhis.schema.Property) HashSet(java.util.HashSet) TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) TrackedEntityProgramIndicatorDimension(org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension) BaseAnalyticalObject(org.hisp.dhis.common.BaseAnalyticalObject) EmbeddedObject(org.hisp.dhis.common.EmbeddedObject) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) AnalyticalObject(org.hisp.dhis.common.AnalyticalObject) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

TrackedEntityProgramIndicatorDimension (org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension)5 ArrayList (java.util.ArrayList)4 TrackedEntityAttributeDimension (org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension)4 TrackedEntityDataElementDimension (org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension)4 List (java.util.List)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DataDimensionItem (org.hisp.dhis.common.DataDimensionItem)2 DimensionalObject (org.hisp.dhis.common.DimensionalObject)2 CategoryDimension (org.hisp.dhis.dataelement.CategoryDimension)2 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)2 Period (org.hisp.dhis.period.Period)2 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1