Search in sources :

Example 1 with DataDimensionItem

use of org.hisp.dhis.common.DataDimensionItem in project dhis2-core by dhis2.

the class FavoriteDataItemUpgrader method upgradeFavorites.

private void upgradeFavorites(Class<? extends BaseAnalyticalObject> favoriteClass, String favoriteTablename, Class<? extends IdentifiableObject> objectClass, String objectTablename) {
    String linkTablename = favoriteTablename + "_" + objectTablename + "s";
    String selectSql = "select " + favoriteTablename + "id, " + objectTablename + "id from " + linkTablename + " " + "order by " + favoriteTablename + "id, sort_order";
    SqlRowSet rs = jdbcTemplate.queryForRowSet(selectSql);
    while (rs.next()) {
        int rtId = rs.getInt(1);
        int obId = rs.getInt(2);
        BaseAnalyticalObject favorite = idObjectManager.get(favoriteClass, rtId);
        DimensionalItemObject object = (DimensionalItemObject) idObjectManager.get(objectClass, obId);
        DataDimensionItem item = DataDimensionItem.create(object);
        favorite.getDataDimensionItems().add(item);
        idObjectManager.update(favorite);
        log.debug("Upgraded " + favoriteTablename + " " + favorite.getUid() + " for " + objectTablename + " " + object.getUid());
    }
    String dropSql = "drop table " + linkTablename;
    jdbcTemplate.update(dropSql);
    log.info("Update done, dropped table " + linkTablename);
}
Also used : SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseAnalyticalObject(org.hisp.dhis.common.BaseAnalyticalObject) DataDimensionItem(org.hisp.dhis.common.DataDimensionItem)

Example 2 with DataDimensionItem

use of org.hisp.dhis.common.DataDimensionItem in project dhis2-core by dhis2.

the class DefaultPreheatService method collectAnalyticalObjectReferences.

/**
 * Collect references for {@link AnalyticalObject}.
 *
 * @param map the mapping between {@link PreheatIdentifier} and object
 *        identifiers.
 * @param object the object.
 */
private void collectAnalyticalObjectReferences(Map<PreheatIdentifier, Map<Class<? extends IdentifiableObject>, Set<String>>> map, Object object) {
    if (object instanceof AnalyticalObject) {
        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());
            }
            if (dataDimensionItem.getProgramDataElement() != null) {
                addIdentifiers(map, dataDimensionItem.getProgramDataElement().getDataElement());
                addIdentifiers(map, dataDimensionItem.getProgramDataElement().getProgram());
            }
            if (dataDimensionItem.getProgramAttribute() != null) {
                addIdentifiers(map, dataDimensionItem.getProgramAttribute().getAttribute());
                addIdentifiers(map, dataDimensionItem.getProgramAttribute().getProgram());
            }
        });
        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());
            addIdentifiers(map, trackedEntityDataElementDimension.getProgramStage());
        });
        CollectionUtils.nullSafeForEach(attributeDimensions, trackedEntityAttributeDimension -> {
            addIdentifiers(map, trackedEntityAttributeDimension.getAttribute());
            addIdentifiers(map, trackedEntityAttributeDimension.getLegendSet());
        });
        CollectionUtils.nullSafeForEach(programIndicatorDimensions, programIndicatorDimension -> {
            addIdentifiers(map, programIndicatorDimension.getProgramIndicator());
            addIdentifiers(map, programIndicatorDimension.getLegendSet());
        });
    }
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) BaseAnalyticalObject(org.hisp.dhis.common.BaseAnalyticalObject) CategoryDimension(org.hisp.dhis.category.CategoryDimension) TrackedEntityProgramIndicatorDimension(org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension) DataDimensionItem(org.hisp.dhis.common.DataDimensionItem) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension) BaseAnalyticalObject(org.hisp.dhis.common.BaseAnalyticalObject) AnalyticalObject(org.hisp.dhis.common.AnalyticalObject)

Example 3 with DataDimensionItem

use of org.hisp.dhis.common.DataDimensionItem in project dhis2-core by dhis2.

the class AnalyticalObjectObjectBundleHook method handleDataDimensionItems.

private void handleDataDimensionItems(Session session, Schema schema, BaseAnalyticalObject analyticalObject, ObjectBundle bundle) {
    if (!schema.havePersistedProperty("dataDimensionItems"))
        return;
    for (DataDimensionItem dataDimensionItem : analyticalObject.getDataDimensionItems()) {
        if (dataDimensionItem == null) {
            continue;
        }
        dataDimensionItem.setDataElement(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataDimensionItem.getDataElement()));
        dataDimensionItem.setIndicator(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataDimensionItem.getIndicator()));
        dataDimensionItem.setProgramIndicator(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataDimensionItem.getProgramIndicator()));
        dataDimensionItem.setProgramAttribute(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataDimensionItem.getProgramAttribute()));
        dataDimensionItem.setProgramDataElement(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataDimensionItem.getProgramDataElement()));
        if (dataDimensionItem.getDataElementOperand() != null) {
            preheatService.connectReferences(dataDimensionItem.getDataElementOperand(), bundle.getPreheat(), bundle.getPreheatIdentifier());
            session.save(dataDimensionItem.getDataElementOperand());
        }
        if (dataDimensionItem.getReportingRate() != null) {
            dataDimensionItem.getReportingRate().setDataSet(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataDimensionItem.getReportingRate().getDataSet()));
        }
        preheatService.connectReferences(dataDimensionItem, bundle.getPreheat(), bundle.getPreheatIdentifier());
        session.save(dataDimensionItem);
    }
}
Also used : DataDimensionItem(org.hisp.dhis.common.DataDimensionItem)

Example 4 with DataDimensionItem

use of org.hisp.dhis.common.DataDimensionItem in project dhis2-core by dhis2.

the class DefaultAnalyticalObjectImportHandler method handleDataDimensionItems.

private void handleDataDimensionItems(Session session, Schema schema, BaseAnalyticalObject analyticalObject, ObjectBundle bundle) {
    if (!schema.havePersistedProperty("dataDimensionItems"))
        return;
    for (DataDimensionItem dataDimensionItem : analyticalObject.getDataDimensionItems()) {
        if (dataDimensionItem == null) {
            continue;
        }
        dataDimensionItem.setDataElement(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataDimensionItem.getDataElement()));
        dataDimensionItem.setIndicator(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataDimensionItem.getIndicator()));
        dataDimensionItem.setProgramIndicator(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataDimensionItem.getProgramIndicator()));
        if (dataDimensionItem.getDataElementOperand() != null) {
            preheatService.connectReferences(dataDimensionItem.getDataElementOperand(), bundle.getPreheat(), bundle.getPreheatIdentifier());
        }
        if (dataDimensionItem.getReportingRate() != null) {
            dataDimensionItem.getReportingRate().setDataSet(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataDimensionItem.getReportingRate().getDataSet()));
        }
        if (dataDimensionItem.getProgramDataElement() != null) {
            dataDimensionItem.getProgramDataElement().setProgram(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataDimensionItem.getProgramDataElement().getProgram()));
            dataDimensionItem.getProgramDataElement().setDataElement(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataDimensionItem.getProgramDataElement().getDataElement()));
        }
        if (dataDimensionItem.getProgramAttribute() != null) {
            dataDimensionItem.getProgramAttribute().setProgram(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataDimensionItem.getProgramAttribute().getProgram()));
            dataDimensionItem.getProgramAttribute().setAttribute(bundle.getPreheat().get(bundle.getPreheatIdentifier(), dataDimensionItem.getProgramAttribute().getAttribute()));
        }
        preheatService.connectReferences(dataDimensionItem, bundle.getPreheat(), bundle.getPreheatIdentifier());
        session.save(dataDimensionItem);
    }
}
Also used : DataDimensionItem(org.hisp.dhis.common.DataDimensionItem)

Example 5 with DataDimensionItem

use of org.hisp.dhis.common.DataDimensionItem 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)) {
                        String level = DimensionalObjectUtils.getValueFromKeywordParam(ou);
                        Integer orgUnitLevel = organisationUnitService.getOrganisationUnitLevelByLevelOrUid(level);
                        if (orgUnitLevel != null) {
                            object.getOrganisationUnitLevels().add(orgUnitLevel);
                        }
                    } 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(Category.class, dimensionId));
                categoryDimension.getItems().addAll(idObjectManager.getByUidOrdered(CategoryOption.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.setProgramStage(dimension.hasProgramStage() ? idObjectManager.get(ProgramStage.class, dimension.getProgramStage().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.category.CategoryDimension) CategoryOptionGroupSetDimension(org.hisp.dhis.category.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.category.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.category.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

DataDimensionItem (org.hisp.dhis.common.DataDimensionItem)5 CategoryDimension (org.hisp.dhis.category.CategoryDimension)2 BaseAnalyticalObject (org.hisp.dhis.common.BaseAnalyticalObject)2 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 TrackedEntityAttributeDimension (org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension)2 TrackedEntityDataElementDimension (org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension)2 TrackedEntityProgramIndicatorDimension (org.hisp.dhis.trackedentity.TrackedEntityProgramIndicatorDimension)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CategoryOptionGroup (org.hisp.dhis.category.CategoryOptionGroup)1 CategoryOptionGroupSet (org.hisp.dhis.category.CategoryOptionGroupSet)1 CategoryOptionGroupSetDimension (org.hisp.dhis.category.CategoryOptionGroupSetDimension)1 AnalyticalObject (org.hisp.dhis.common.AnalyticalObject)1 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)1 DimensionType (org.hisp.dhis.common.DimensionType)1 DimensionalObject (org.hisp.dhis.common.DimensionalObject)1 UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 DataElementGroupSetDimension (org.hisp.dhis.dataelement.DataElementGroupSetDimension)1 LegendSet (org.hisp.dhis.legend.LegendSet)1