PartitionUtils { public static Partitions getPartitions( List<DimensionalItemObject> periods ) { final Set<Integer> years = new HashSet<>(); periods.forEach( p -> { Period period = (Period) p; years.addAll( getYears( period ) ); } ); return new Partitions( years ); }  static Date getStartDate( Calendar calendar, Integer year ); static Date getEndDate( Calendar calendar, Integer year ); static String getTableName( String baseName, Program program ); static Partitions getPartitions( List<DimensionalItemObject> periods ); static Partitions getPartitions( Period period ); static Partitions getPartitions( Date startDate, Date endDate ); static Partitions getPartitions( DataQueryParams params, AnalyticsTableType tableType ); static ListMap<String, DimensionalItemObject> getPeriodTypePeriodMap( Collection<DimensionalItemObject> periods ); static List<AnalyticsTablePartition> getTablePartitions( List<AnalyticsTable> tables ); static AnalyticsTablePartition getLatestTablePartition( List<AnalyticsTable> tables ); static String getPartitionName( String tableName, Integer partition ); static final String SEP; }
@Test public void testGetPartitions() { assertEquals( new Partitions( Sets.newHashSet( 2000 ) ), PartitionUtils.getPartitions( createPeriod( "200001" ) ) ); assertEquals( new Partitions( Sets.newHashSet( 2001 ) ), PartitionUtils.getPartitions( createPeriod( "200110" ) ) ); assertEquals( new Partitions( Sets.newHashSet( 2002 ) ), PartitionUtils.getPartitions( createPeriod( "2002Q2" ) ) ); assertEquals( new Partitions( Sets.newHashSet( 2003 ) ), PartitionUtils.getPartitions( createPeriod( "2003S2" ) ) ); assertEquals( new Partitions( Sets.newHashSet( 2000, 2001 ) ), PartitionUtils.getPartitions( createPeriod( "2000July" ) ) ); assertEquals( new Partitions( Sets.newHashSet( 2001, 2002 ) ), PartitionUtils.getPartitions( createPeriod( "2001April" ) ) ); }
@Test public void getGetPartitionsLongPeriods() { 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( Sets.newHashSet( 2008, 2009, 2010, 2011 ) ); assertEquals( expected, PartitionUtils.getPartitions( period ) ); period = new Period(); period.setStartDate( new DateTime( 2009, 8, 1, 0, 0 ).toDate() ); period.setEndDate( new DateTime( 2010, 2, 1, 0, 0 ).toDate() ); expected = new Partitions( Sets.newHashSet( 2009, 2010 ) ); assertEquals( expected, PartitionUtils.getPartitions( period ) ); }
@Test public void testGetTablePartitionsFromQuery() { DataQueryParams params = DataQueryParams.newBuilder() .withPeriods( Lists.newArrayList( q1, q2, q3 ) ) .build(); Partitions partitions = PartitionUtils.getPartitions( params, AnalyticsTableType.DATA_VALUE ); assertEquals( 3, partitions.getPartitions().size() ); assertTrue( partitions.getPartitions().contains( 2018 ) ); assertTrue( partitions.getPartitions().contains( 2019 ) ); assertTrue( partitions.getPartitions().contains( 0 ) ); params = DataQueryParams.newBuilder() .withPeriods( Lists.newArrayList( q1 ) ) .build(); partitions = PartitionUtils.getPartitions( params, AnalyticsTableType.ORG_UNIT_TARGET ); assertEquals( 1, partitions.getPartitions().size() ); assertTrue( partitions.getPartitions().contains( 2018 ) ); }