Search in sources :

Example 36 with DimensionalItemObject

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

the class EventQueryParamsTest method testReplacePeriodsWithStartEndDates.

@Test
public void testReplacePeriodsWithStartEndDates() {
    List<DimensionalItemObject> periods = new ArrayList<>();
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 4, 1, 0, 0).toDate()));
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 5, 1, 0, 0).toDate()));
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 6, 1, 0, 0).toDate()));
    EventQueryParams params = new EventQueryParams.Builder().addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, periods)).build();
    assertNull(params.getStartDate());
    assertNull(params.getEndDate());
    params = new EventQueryParams.Builder(params).withStartEndDatesForPeriods().build();
    assertEquals(new DateTime(2014, 4, 1, 0, 0).toDate(), params.getStartDate());
    assertEquals(new DateTime(2014, 6, 30, 0, 0).toDate(), params.getEndDate());
}
Also used : DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 37 with DimensionalItemObject

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

the class PartitionUtilsTest method getGetPartitionsMultiplePeriods.

@Test
public void getGetPartitionsMultiplePeriods() {
    List<DimensionalItemObject> periods = new ArrayList<>();
    periods.add(createPeriod("200011"));
    periods.add(createPeriod("200105"));
    periods.add(createPeriod("200108"));
    assertEquals(new Partitions().add(TBL + "_2000").add(TBL + "_2001"), PartitionUtils.getPartitions(periods, TBL, null, null));
}
Also used : Partitions(org.hisp.dhis.analytics.Partitions) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 38 with DimensionalItemObject

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

the class PartitionUtilsTest method testGetTablePeriodMapA.

@Test
public void testGetTablePeriodMapA() {
    ListMap<Partitions, DimensionalItemObject> map = PartitionUtils.getPartitionPeriodMap(getList(createPeriod("2000S1"), createPeriod("2000S2"), createPeriod("2001S1"), createPeriod("2001S2"), createPeriod("2002S1")), TBL, null, null);
    assertEquals(3, map.size());
    assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2000")));
    assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2001")));
    assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2002")));
    assertEquals(2, map.get(new Partitions().add(TBL + "_2000")).size());
    assertEquals(2, map.get(new Partitions().add(TBL + "_2001")).size());
    assertEquals(1, map.get(new Partitions().add(TBL + "_2002")).size());
}
Also used : Partitions(org.hisp.dhis.analytics.Partitions) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Test(org.junit.Test)

Example 39 with DimensionalItemObject

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

the class PartitionUtilsTest method testGetTablePeriodMapB.

@Test
public void testGetTablePeriodMapB() {
    ListMap<Partitions, DimensionalItemObject> map = PartitionUtils.getPartitionPeriodMap(getList(createPeriod("2000April"), createPeriod("2000"), createPeriod("2001"), createPeriod("2001Oct"), createPeriod("2002Oct")), TBL, null, null);
    assertEquals(5, map.size());
    assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2000")));
    assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2001")));
    assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2000").add(TBL + "_2001")));
    assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2001").add(TBL + "_2002")));
    assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2002").add(TBL + "_2003")));
}
Also used : Partitions(org.hisp.dhis.analytics.Partitions) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Test(org.junit.Test)

Example 40 with DimensionalItemObject

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

the class DefaultValidationService method getDimensionalItemObjects.

/**
     * Gets all required DimensionalItemObjects from their UIDs.
     *
     * @param expressionIdMap UIDs of DimensionalItemObjects to get.
     * @return map of the DimensionalItemObjects.
     */
private Map<String, DimensionalItemObject> getDimensionalItemObjects(SetMap<Class<? extends DimensionalItemObject>, String> expressionIdMap) {
    // 1. Get ids for all the individual IdentifiableObjects within the DimensionalItemObjects:
    SetMap<Class<? extends IdentifiableObject>, String> idsToGet = new SetMap<>();
    getIdentifiableObjectIds(idsToGet, expressionIdMap, DataElementOperand.class, DataElement.class, DataElementCategoryOptionCombo.class);
    getIdentifiableObjectIds(idsToGet, expressionIdMap, ProgramDataElementDimensionItem.class, Program.class, DataElement.class);
    getIdentifiableObjectIds(idsToGet, expressionIdMap, ProgramTrackedEntityAttributeDimensionItem.class, Program.class, TrackedEntityAttribute.class);
    getIdentifiableObjectIds(idsToGet, expressionIdMap, ProgramIndicator.class, ProgramIndicator.class);
    // 2. Look up all the IdentifiableObjects (each class all together, for best performance):
    MapMap<Class<? extends IdentifiableObject>, String, IdentifiableObject> idMap = new MapMap<>();
    for (Map.Entry<Class<? extends IdentifiableObject>, Set<String>> e : idsToGet.entrySet()) {
        idMap.putEntries(e.getKey(), idObjectManager.get(e.getKey(), e.getValue()).stream().collect(Collectors.toMap(o -> o.getUid(), o -> o)));
    }
    // 3. Build the map of DimensionalItemObjects:
    Map<String, DimensionalItemObject> dimObjects = new HashMap<>();
    for (Map.Entry<Class<? extends DimensionalItemObject>, Set<String>> e : expressionIdMap.entrySet()) {
        for (String id : e.getValue()) {
            if (e.getKey() == DataElementOperand.class) {
                DataElementOperand deo = new DataElementOperand((DataElement) idMap.getValue(DataElement.class, getIdPart(id, 0)), (DataElementCategoryOptionCombo) idMap.getValue(DataElementCategoryOptionCombo.class, getIdPart(id, 1)));
                if (deo.getDataElement() != null && (deo.getCategoryOptionCombo() != null || getIdPart(id, 1) == null)) {
                    dimObjects.put(id, deo);
                }
            } else if (e.getKey() == ProgramDataElementDimensionItem.class) {
                ProgramDataElementDimensionItem pde = new ProgramDataElementDimensionItem((Program) idMap.getValue(Program.class, getIdPart(id, 0)), (DataElement) idMap.getValue(DataElement.class, getIdPart(id, 1)));
                if (pde.getProgram() != null && pde.getDataElement() != null) {
                    dimObjects.put(id, pde);
                }
            } else if (e.getKey() == ProgramTrackedEntityAttributeDimensionItem.class) {
                ProgramTrackedEntityAttributeDimensionItem pa = new ProgramTrackedEntityAttributeDimensionItem((Program) idMap.getValue(Program.class, getIdPart(id, 0)), (TrackedEntityAttribute) idMap.getValue(TrackedEntityAttribute.class, getIdPart(id, 1)));
                if (pa.getProgram() != null && pa.getAttribute() != null) {
                    dimObjects.put(id, pa);
                }
            } else if (e.getKey() == ProgramIndicator.class) {
                ProgramIndicator pi = (ProgramIndicator) idMap.getValue(ProgramIndicator.class, id);
                if (pi != null) {
                    dimObjects.put(id, pi);
                }
            }
        }
    }
    return dimObjects;
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataSet(org.hisp.dhis.dataset.DataSet) ImmutableSet(com.google.common.collect.ImmutableSet) Program(org.hisp.dhis.program.Program) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) MapMap(org.hisp.dhis.common.MapMap) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) SetMap(org.hisp.dhis.common.SetMap) SetMap(org.hisp.dhis.common.SetMap) MapMap(org.hisp.dhis.common.MapMap)

Aggregations

DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)55 ArrayList (java.util.ArrayList)15 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)15 DimensionalObject (org.hisp.dhis.common.DimensionalObject)15 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)14 Test (org.junit.Test)12 Period (org.hisp.dhis.period.Period)11 ListMap (org.hisp.dhis.common.ListMap)10 DataElement (org.hisp.dhis.dataelement.DataElement)10 DhisSpringTest (org.hisp.dhis.DhisSpringTest)7 BaseDimensionalItemObject (org.hisp.dhis.common.BaseDimensionalItemObject)7 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)7 HashMap (java.util.HashMap)6 List (java.util.List)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)6 PeriodType (org.hisp.dhis.period.PeriodType)6 SqlRowSet (org.springframework.jdbc.support.rowset.SqlRowSet)5 Matcher (java.util.regex.Matcher)4 Grid (org.hisp.dhis.common.Grid)4 HashSet (java.util.HashSet)3