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());
}
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));
}
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());
}
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")));
}
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;
}
Aggregations