Search in sources :

Example 6 with DataElementGroupSet

use of org.hisp.dhis.dataelement.DataElementGroupSet in project dhis2-core by dhis2.

the class AnalyticalObjectEmbeddedDimensionUpgrader method executeInTransaction.

@Override
public void executeInTransaction() {
    BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> dataElementGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
        DataElementGroupSetDimension dimension = new DataElementGroupSetDimension();
        dimension.setDimension((DataElementGroupSet) embeddedDimension.getDimension());
        dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
        analyticalObject.addDataElementGroupSetDimension(dimension);
    };
    BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> orgUnitGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
        OrganisationUnitGroupSetDimension dimension = new OrganisationUnitGroupSetDimension();
        dimension.setDimension((OrganisationUnitGroupSet) embeddedDimension.getDimension());
        dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
        analyticalObject.addOrganisationUnitGroupSetDimension(dimension);
    };
    BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> categoryOptionGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
        CategoryOptionGroupSetDimension dimension = new CategoryOptionGroupSetDimension();
        dimension.setDimension((CategoryOptionGroupSet) embeddedDimension.getDimension());
        dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
        analyticalObject.addCategoryOptionGroupSetDimension(dimension);
    };
    try {
        upgradeGrupSetDimensions("reporttable", "orgunitgroupset", "orgunitgroup", ReportTable.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
        upgradeGrupSetDimensions("reporttable", "dataelementgroupset", "dataelementgroup", ReportTable.class, DataElementGroupSet.class, DataElementGroup.class, dataElementGroupSetConsumer);
        upgradeGrupSetDimensions("reporttable", "categoryoptiongroupset", "categoryoptiongroup", ReportTable.class, CategoryOptionGroupSet.class, CategoryOptionGroup.class, categoryOptionGroupSetConsumer);
        upgradeGrupSetDimensions("chart", "orgunitgroupset", "orgunitgroup", Chart.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
        upgradeGrupSetDimensions("chart", "dataelementgroupset", "dataelementgroup", Chart.class, DataElementGroupSet.class, DataElementGroup.class, dataElementGroupSetConsumer);
        upgradeGrupSetDimensions("chart", "categoryoptiongroupset", "categoryoptiongroup", Chart.class, CategoryOptionGroupSet.class, CategoryOptionGroup.class, categoryOptionGroupSetConsumer);
        upgradeGrupSetDimensions("eventreport", "orgunitgroupset", "orgunitgroup", EventReport.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
        upgradeGrupSetDimensions("eventchart", "orgunitgroupset", "orgunitgroup", EventChart.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
    } catch (Exception ex) {
        log.debug("Error during group set dimensions upgrade of favorite, probably because upgrade was already done", ex);
        return;
    }
}
Also used : AnalyticalObject(org.hisp.dhis.common.AnalyticalObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) OrganisationUnitGroupSetDimension(org.hisp.dhis.organisationunit.OrganisationUnitGroupSetDimension) Autowired(org.springframework.beans.factory.annotation.Autowired) EventReport(org.hisp.dhis.eventreport.EventReport) ArrayList(java.util.ArrayList) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) EventChart(org.hisp.dhis.eventchart.EventChart) ReportTable(org.hisp.dhis.reporttable.ReportTable) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) BiConsumer(java.util.function.BiConsumer) SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) DimensionalObjectUtils(org.hisp.dhis.common.DimensionalObjectUtils) Chart(org.hisp.dhis.chart.Chart) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) CategoryOptionGroup(org.hisp.dhis.dataelement.CategoryOptionGroup) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) TransactionContextStartupRoutine(org.hisp.dhis.system.startup.TransactionContextStartupRoutine) DataElementGroupSetDimension(org.hisp.dhis.dataelement.DataElementGroupSetDimension) List(java.util.List) DimensionalObject(org.hisp.dhis.common.DimensionalObject) CategoryOptionGroupSetDimension(org.hisp.dhis.dataelement.CategoryOptionGroupSetDimension) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) TextUtils(org.hisp.dhis.commons.util.TextUtils) Assert(org.springframework.util.Assert) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) DataElementGroupSetDimension(org.hisp.dhis.dataelement.DataElementGroupSetDimension) OrganisationUnitGroupSetDimension(org.hisp.dhis.organisationunit.OrganisationUnitGroupSetDimension) CategoryOptionGroupSetDimension(org.hisp.dhis.dataelement.CategoryOptionGroupSetDimension) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) AnalyticalObject(org.hisp.dhis.common.AnalyticalObject)

Example 7 with DataElementGroupSet

use of org.hisp.dhis.dataelement.DataElementGroupSet in project dhis2-core by dhis2.

the class ListMapTest method testGetListMapValueMapper.

@Test
public void testGetListMapValueMapper() {
    DataElementGroupSet groupSetA = new DataElementGroupSet("GroupSetA");
    DataElementGroupSet groupSetB = new DataElementGroupSet("GroupSetB");
    DataElementGroupSet groupSetC = new DataElementGroupSet("GroupSetC");
    DataElementGroupSet groupSetZ = new DataElementGroupSet("GroupSetZ");
    DataElementGroup groupA = new DataElementGroup("GroupA");
    DataElementGroup groupB = new DataElementGroup("GroupB");
    DataElementGroup groupC = new DataElementGroup("GroupC");
    DataElementGroup groupD = new DataElementGroup("GroupD");
    DataElementGroup groupE = new DataElementGroup("GroupE");
    DataElementGroup groupF = new DataElementGroup("GroupF");
    groupA.getGroupSets().add(groupSetA);
    groupB.getGroupSets().add(groupSetB);
    groupC.getGroupSets().add(groupSetC);
    groupD.getGroupSets().add(groupSetA);
    groupE.getGroupSets().add(groupSetB);
    groupF.getGroupSets().add(groupSetA);
    List<DataElementGroup> groups = Lists.newArrayList(groupA, groupB, groupC, groupD, groupE, groupF);
    ListMap<DataElementGroupSet, DataElementGroup> map = ListMap.getListMap(groups, group -> group.getGroupSets().iterator().next());
    assertEquals(Lists.newArrayList(groupA, groupD, groupF), map.get(groupSetA));
    assertEquals(Lists.newArrayList(groupB, groupE), map.get(groupSetB));
    assertEquals(Lists.newArrayList(groupC), map.get(groupSetC));
    assertNull(map.get(groupSetZ));
}
Also used : DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) Test(org.junit.Test)

Example 8 with DataElementGroupSet

use of org.hisp.dhis.dataelement.DataElementGroupSet in project dhis2-core by dhis2.

the class SetMapTest method testGetListMapValueMapper.

@Test
public void testGetListMapValueMapper() {
    DataElementGroupSet groupSetA = new DataElementGroupSet("GroupSetA");
    DataElementGroupSet groupSetB = new DataElementGroupSet("GroupSetB");
    DataElementGroupSet groupSetC = new DataElementGroupSet("GroupSetC");
    DataElementGroupSet groupSetZ = new DataElementGroupSet("GroupSetZ");
    DataElementGroup groupA = new DataElementGroup("GroupA");
    DataElementGroup groupB = new DataElementGroup("GroupB");
    DataElementGroup groupC = new DataElementGroup("GroupC");
    DataElementGroup groupD = new DataElementGroup("GroupD");
    DataElementGroup groupE = new DataElementGroup("GroupE");
    DataElementGroup groupF = new DataElementGroup("GroupF");
    groupA.getGroupSets().add(groupSetA);
    groupB.getGroupSets().add(groupSetB);
    groupC.getGroupSets().add(groupSetC);
    groupD.getGroupSets().add(groupSetA);
    groupE.getGroupSets().add(groupSetB);
    groupF.getGroupSets().add(groupSetA);
    Set<DataElementGroup> groups = Sets.newHashSet(groupA, groupB, groupC, groupD, groupE, groupF);
    SetMap<DataElementGroupSet, DataElementGroup> map = SetMap.getSetMap(groups, group -> group.getGroupSets().iterator().next());
    assertEquals(Sets.newHashSet(groupA, groupD, groupF), map.get(groupSetA));
    assertEquals(Sets.newHashSet(groupB, groupE), map.get(groupSetB));
    assertEquals(Sets.newHashSet(groupC), map.get(groupSetC));
    assertNull(map.get(groupSetZ));
}
Also used : DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) Test(org.junit.Test)

Example 9 with DataElementGroupSet

use of org.hisp.dhis.dataelement.DataElementGroupSet in project dhis2-core by dhis2.

the class DefaultDataIntegrityService method getDataElementsViolatingExclusiveGroupSets.

@Override
public SortedMap<DataElement, Collection<DataElementGroup>> getDataElementsViolatingExclusiveGroupSets() {
    Collection<DataElementGroupSet> groupSets = dataElementService.getAllDataElementGroupSets();
    SortedMap<DataElement, Collection<DataElementGroup>> targets = new TreeMap<>();
    for (DataElementGroupSet groupSet : groupSets) {
        Collection<DataElement> duplicates = getDuplicates(new ArrayList<>(groupSet.getDataElements()));
        for (DataElement duplicate : duplicates) {
            targets.put(duplicate, duplicate.getGroups());
        }
    }
    return targets;
}
Also used : DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) DataElement(org.hisp.dhis.dataelement.DataElement) Collection(java.util.Collection) TreeMap(java.util.TreeMap)

Example 10 with DataElementGroupSet

use of org.hisp.dhis.dataelement.DataElementGroupSet in project dhis2-core by dhis2.

the class DefaultDimensionService method getDimensionType.

@Override
public DimensionType getDimensionType(String uid) {
    DataElementCategory cat = idObjectManager.get(DataElementCategory.class, uid);
    if (cat != null) {
        return DimensionType.CATEGORY;
    }
    DataElementGroupSet degs = idObjectManager.get(DataElementGroupSet.class, uid);
    if (degs != null) {
        return DimensionType.DATA_ELEMENT_GROUP_SET;
    }
    OrganisationUnitGroupSet ougs = idObjectManager.get(OrganisationUnitGroupSet.class, uid);
    if (ougs != null) {
        return DimensionType.ORGANISATION_UNIT_GROUP_SET;
    }
    CategoryOptionGroupSet cogs = idObjectManager.get(CategoryOptionGroupSet.class, uid);
    if (cogs != null) {
        return DimensionType.CATEGORY_OPTION_GROUP_SET;
    }
    TrackedEntityAttribute tea = idObjectManager.get(TrackedEntityAttribute.class, uid);
    if (tea != null) {
        return DimensionType.PROGRAM_ATTRIBUTE;
    }
    DataElement pde = idObjectManager.get(DataElement.class, uid);
    if (pde != null && DataElementDomain.TRACKER.equals(pde.getDomainType())) {
        return DimensionType.PROGRAM_DATA_ELEMENT;
    }
    ProgramIndicator pin = idObjectManager.get(ProgramIndicator.class, uid);
    if (pin != null) {
        return DimensionType.PROGRAM_INDICATOR;
    }
    final Map<String, DimensionType> dimObjectTypeMap = new HashMap<>();
    dimObjectTypeMap.put(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X);
    dimObjectTypeMap.put(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD);
    dimObjectTypeMap.put(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT);
    return dimObjectTypeMap.get(uid);
}
Also used : DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) DataElement(org.hisp.dhis.dataelement.DataElement) DimensionType(org.hisp.dhis.common.DimensionType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) HashMap(java.util.HashMap) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Aggregations

DataElementGroupSet (org.hisp.dhis.dataelement.DataElementGroupSet)12 DataElementGroup (org.hisp.dhis.dataelement.DataElementGroup)5 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)4 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)4 DataElement (org.hisp.dhis.dataelement.DataElement)3 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 DimensionalObject (org.hisp.dhis.common.DimensionalObject)2 PeriodType (org.hisp.dhis.period.PeriodType)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 BiConsumer (java.util.function.BiConsumer)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 Chart (org.hisp.dhis.chart.Chart)1 AnalyticalObject (org.hisp.dhis.common.AnalyticalObject)1 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)1