use of org.hisp.dhis.analytics.AnalyticsTableUpdateParams in project dhis2-core by dhis2.
the class JdbcEventAnalyticsTableManagerTest method verifyGetAnalyticsTableWithOuLevels.
@Test
void verifyGetAnalyticsTableWithOuLevels() {
List<OrganisationUnitLevel> ouLevels = rnd.objects(OrganisationUnitLevel.class, 2).collect(Collectors.toList());
Program programA = rnd.nextObject(Program.class);
programA.setId(0);
when(idObjectManager.getAllNoAcl(Program.class)).thenReturn(Collections.singletonList(programA));
when(organisationUnitService.getFilledOrganisationUnitLevels()).thenReturn(ouLevels);
when(jdbcTemplate.queryForList("select distinct(extract(year from psi.executiondate)) from programstageinstance psi inner join programinstance pi on psi.programinstanceid = pi.programinstanceid where psi.lastupdated <= '2019-08-01T00:00:00' and pi.programid = 0 and psi.executiondate is not null and psi.executiondate > '1000-01-01' and psi.deleted is false ", Integer.class)).thenReturn(Lists.newArrayList(2018, 2019));
AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withStartTime(START_TIME).build();
List<AnalyticsTable> tables = subject.getAnalyticsTables(params);
assertThat(tables, hasSize(1));
new AnalyticsTableAsserter.Builder(tables.get(0)).withTableName(TABLE_PREFIX + programA.getUid().toLowerCase()).withTableType(AnalyticsTableType.EVENT).withColumnSize(subject.getFixedColumns().size() + PeriodType.getAvailablePeriodTypes().size() + ouLevels.size() + (programA.isRegistration() ? 1 : 0)).addColumns(periodColumns).withDefaultColumns(subject.getFixedColumns()).addColumn(quote("uidlevel" + ouLevels.get(0).getLevel()), col -> match(ouLevels.get(0), col)).addColumn(quote("uidlevel" + ouLevels.get(1).getLevel()), col -> match(ouLevels.get(1), col)).build().verify();
}
use of org.hisp.dhis.analytics.AnalyticsTableUpdateParams in project dhis2-core by dhis2.
the class JdbcEventAnalyticsTableManagerTest method verifyGetLatestAnalyticsTables.
@Test
void verifyGetLatestAnalyticsTables() {
Program prA = createProgram('A');
Program prB = createProgram('B');
Program prC = createProgram('C');
Program prD = createProgram('D');
List<Program> programs = Lists.newArrayList(prA, prB, prC, prD);
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();
Set<String> skipPrograms = new HashSet<>();
skipPrograms.add(prC.getUid());
skipPrograms.add(prD.getUid());
AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withStartTime(startTime).withLatestPartition().withSkipPrograms(skipPrograms).build();
List<Map<String, Object>> queryResp = Lists.newArrayList();
queryResp.add(ImmutableMap.of("dataelementid", 1));
when(systemSettingManager.getDateSetting(SettingKey.LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE)).thenReturn(lastFullTableUpdate);
when(systemSettingManager.getDateSetting(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(1);
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));
}
use of org.hisp.dhis.analytics.AnalyticsTableUpdateParams in project dhis2-core by dhis2.
the class JdbcEventAnalyticsTableManagerTest method verifyGetAnalyticsTableWithOuGroupSet.
@Test
void verifyGetAnalyticsTableWithOuGroupSet() {
List<OrganisationUnitGroupSet> ouGroupSet = rnd.objects(OrganisationUnitGroupSet.class, 2).collect(Collectors.toList());
Program programA = rnd.nextObject(Program.class);
programA.setId(0);
when(idObjectManager.getAllNoAcl(Program.class)).thenReturn(Collections.singletonList(programA));
when(idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class)).thenReturn(ouGroupSet);
AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withStartTime(START_TIME).build();
when(jdbcTemplate.queryForList(getYearQueryForCurrentYear(programA, false), Integer.class)).thenReturn(Lists.newArrayList(2018, 2019));
List<AnalyticsTable> tables = subject.getAnalyticsTables(params);
assertThat(tables, hasSize(1));
new AnalyticsTableAsserter.Builder(tables.get(0)).withTableName(TABLE_PREFIX + programA.getUid().toLowerCase()).withTableType(AnalyticsTableType.EVENT).withColumnSize(subject.getFixedColumns().size() + PeriodType.getAvailablePeriodTypes().size() + ouGroupSet.size() + (programA.isRegistration() ? 1 : 0)).addColumns(periodColumns).withDefaultColumns(subject.getFixedColumns()).addColumn(quote(ouGroupSet.get(0).getUid()), col -> match(ouGroupSet.get(0), col)).addColumn(quote(ouGroupSet.get(1).getUid()), col -> match(ouGroupSet.get(1), col)).build().verify();
}
use of org.hisp.dhis.analytics.AnalyticsTableUpdateParams in project dhis2-core by dhis2.
the class JdbcEnrollmentAnalyticsTableManagerTest method verifyTeiTypeOrgUnitFetchesOuUidWhenPopulatingEventAnalyticsTable.
@Test
void verifyTeiTypeOrgUnitFetchesOuUidWhenPopulatingEventAnalyticsTable() {
ArgumentCaptor<String> sql = ArgumentCaptor.forClass(String.class);
when(databaseInfo.isSpatialSupport()).thenReturn(true);
Program p1 = createProgram('A');
TrackedEntityAttribute tea = createTrackedEntityAttribute('a', ValueType.ORGANISATION_UNIT);
tea.setId(9999);
ProgramTrackedEntityAttribute programTrackedEntityAttribute = createProgramTrackedEntityAttribute(p1, tea);
p1.setProgramAttributes(Lists.newArrayList(programTrackedEntityAttribute));
when(idObjectManager.getAllNoAcl(Program.class)).thenReturn(Lists.newArrayList(p1));
AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withLastYears(2).withStartTime(START_TIME).build();
subject.populateTable(params, PartitionUtils.getTablePartitions(subject.getAnalyticsTables(params)).get(0));
verify(jdbcTemplate).execute(sql.capture());
String ouQuery = "(select ou.%s from organisationunit ou where ou.uid = " + "(select value from trackedentityattributevalue where trackedentityinstanceid=pi.trackedentityinstanceid and " + "trackedentityattributeid=9999)) as \"" + tea.getUid() + "\"";
assertThat(sql.getValue(), containsString(String.format(ouQuery, "uid")));
}
use of org.hisp.dhis.analytics.AnalyticsTableUpdateParams in project dhis2-core by dhis2.
the class JdbcAnalyticsTableManagerTest method testGetRegularAnalyticsTable.
@Test
void testGetRegularAnalyticsTable() {
Date startTime = new DateTime(2019, 3, 1, 10, 0).toDate();
List<Integer> dataYears = Lists.newArrayList(2018, 2019);
AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withStartTime(startTime).build();
when(jdbcTemplate.queryForList(Mockito.anyString(), ArgumentMatchers.<Class<Integer>>any())).thenReturn(dataYears);
List<AnalyticsTable> tables = subject.getAnalyticsTables(params);
assertEquals(1, tables.size());
AnalyticsTable table = tables.get(0);
assertNotNull(table);
assertNotNull(table.getTablePartitions());
assertEquals(2, table.getTablePartitions().size());
AnalyticsTablePartition partitionA = table.getTablePartitions().get(0);
AnalyticsTablePartition partitionB = table.getTablePartitions().get(1);
assertNotNull(partitionA);
assertNotNull(partitionA.getStartDate());
assertNotNull(partitionA.getEndDate());
assertEquals(partitionA.getYear().intValue(), new DateTime(partitionA.getStartDate()).getYear());
assertNotNull(partitionB);
assertNotNull(partitionB.getStartDate());
assertNotNull(partitionB.getEndDate());
assertEquals(partitionB.getYear().intValue(), new DateTime(partitionB.getStartDate()).getYear());
}
Aggregations