JdbcEventAnalyticsTableManager extends AbstractEventJdbcTableManager { @Override @Transactional public List<AnalyticsTable> getAnalyticsTables( AnalyticsTableUpdateParams params ) { log.info( String.format( "Get tables using earliest: %s, spatial support: %b", params.getFromDate(), databaseInfo.isSpatialSupport() ) ); return params.isLatestUpdate() ? getLatestAnalyticsTables( params ) : getRegularAnalyticsTables( params ); } JdbcEventAnalyticsTableManager( IdentifiableObjectManager idObjectManager,
        OrganisationUnitService organisationUnitService, CategoryService categoryService,
        SystemSettingManager systemSettingManager, DataApprovalLevelService dataApprovalLevelService,
        ResourceTableService resourceTableService, AnalyticsTableHookService tableHookService,
        StatementBuilder statementBuilder, PartitionManager partitionManager, DatabaseInfo databaseInfo,
        JdbcTemplate jdbcTemplate ); @Override AnalyticsTableType getAnalyticsTableType(); @Override @Transactional List<AnalyticsTable> getAnalyticsTables( AnalyticsTableUpdateParams params ); @Override void removeUpdatedData( AnalyticsTableUpdateParams params, List<AnalyticsTable> tables ); @Override List<AnalyticsTableColumn> getFixedColumns(); static final String OU_NAME_COL_SUFFIX; static final String OU_GEOMETRY_COL_SUFFIX; }
@Test public void verifyGetLatestAnalyticsTables() { Program prA = createProgram( 'A' ); Program prB = createProgram( 'B' ); List<Program> programs = Lists.newArrayList( prA, prB ); Date lastFullTableUpdate = new DateTime( 2019, 3, 1, 2, 0 ).toDate(); Date lastLatestPartitionUpdate = new DateTime( 2019, 3, 1, 9, 0 ).toDate(); Date startTime = new DateTime( 2019, 3, 1, 10, 0 ).toDate(); AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withStartTime( startTime ) .withLatestPartition().build(); List<Map<String, Object>> queryResp = Lists.newArrayList(); queryResp.add( ImmutableMap.of( "dataelementid", 1 ) ); when( systemSettingManager.getSystemSetting( SettingKey.LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE ) ) .thenReturn( lastFullTableUpdate ); when( systemSettingManager.getSystemSetting( SettingKey.LAST_SUCCESSFUL_LATEST_ANALYTICS_PARTITION_UPDATE ) ) .thenReturn( lastLatestPartitionUpdate ); when( jdbcTemplate.queryForList( Mockito.anyString() ) ).thenReturn( queryResp ); when( idObjectManager.getAllNoAcl( Program.class ) ).thenReturn( programs ); List<AnalyticsTable> tables = subject.getAnalyticsTables( params ); assertThat( tables, hasSize( 2 ) ); AnalyticsTable tableA = tables.get( 0 ); AnalyticsTable tableB = tables.get( 0 ); assertThat( tableA, notNullValue() ); assertThat( tableB, notNullValue() ); AnalyticsTablePartition partitionA = tableA.getLatestPartition(); AnalyticsTablePartition partitionB = tableA.getLatestPartition(); assertThat( partitionA, notNullValue() ); assertThat( partitionA.isLatestPartition(), equalTo( true ) ); assertThat( partitionA.getStartDate(), equalTo( lastFullTableUpdate ) ); assertThat( partitionA.getEndDate(), equalTo( startTime ) ); assertThat( partitionB, notNullValue() ); assertThat( partitionB.isLatestPartition(), equalTo( true ) ); assertThat( partitionB.getStartDate(), equalTo( lastFullTableUpdate ) ); assertThat( partitionB.getEndDate(), equalTo( startTime ) ); }