use of org.hisp.dhis.analytics.Partitions in project dhis2-core by dhis2.
the class PartitionUtilsTest method getGetPartitionsLongPeriodsPrune.
@Test
public void getGetPartitionsLongPeriodsPrune() {
Period period = new Period();
period.setStartDate(new DateTime(2008, 3, 1, 0, 0).toDate());
period.setEndDate(new DateTime(2011, 7, 1, 0, 0).toDate());
Partitions expected = new Partitions().add(TBL + "_2008").add(TBL + "_2009").add(TBL + "_2010").add(TBL + "_2011");
assertEquals(expected, PartitionUtils.getPartitions(period, TBL, null, null));
Set<String> validPartitions = new HashSet<>();
validPartitions.add(TBL + "_2008");
validPartitions.add(TBL + "_2010");
expected = new Partitions().add(TBL + "_2008").add(TBL + "_2010");
assertEquals(expected, PartitionUtils.getPartitions(period, TBL, null, validPartitions));
}
use of org.hisp.dhis.analytics.Partitions 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.analytics.Partitions 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.analytics.Partitions in project dhis2-core by dhis2.
the class EventQueryPlannerTest method testPlanAggregateQueryB.
@Test
public void testPlanAggregateQueryB() {
EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withStartDate(new DateTime(2010, 3, 1, 0, 0).toDate()).withEndDate(new DateTime(2010, 9, 20, 0, 0).toDate()).withOrganisationUnits(Lists.newArrayList(ouA)).build();
List<EventQueryParams> queries = queryPlanner.planAggregateQuery(params);
assertEquals(1, queries.size());
EventQueryParams query = queries.get(0);
assertEquals(new DateTime(2010, 3, 1, 0, 0).toDate(), query.getStartDate());
assertEquals(new DateTime(2010, 9, 20, 0, 0).toDate(), query.getEndDate());
Partitions partitions = query.getPartitions();
assertEquals(1, partitions.getPartitions().size());
assertEquals("analytics_event_2010_programuida", partitions.getSinglePartition());
}
use of org.hisp.dhis.analytics.Partitions in project dhis2-core by dhis2.
the class PartitionUtils method getPartitions.
public static Partitions getPartitions(String tablePrefix, String tableSuffix, Set<String> validPartitions) {
tablePrefix = StringUtils.trimToEmpty(tablePrefix);
tableSuffix = StringUtils.trimToEmpty(tableSuffix);
Partitions partitions = new Partitions();
String name = tablePrefix + tableSuffix;
partitions.add(name.toLowerCase());
return partitions.prunePartitions(validPartitions);
}
Aggregations