use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class DeduplicationServiceTest method setUpPrograms.
private void setUpPrograms() {
when(trackedEntityInstanceA.getProgramInstances()).thenReturn(new HashSet<>(Collections.singletonList(programInstanceA)));
when(trackedEntityInstanceB.getProgramInstances()).thenReturn(new HashSet<>(Collections.singletonList(programInstanceB)));
Program programA = new Program();
programA.setUid("progrAUid");
programA.setDescription("programADescr");
programA.setName("programAName");
Program programB = new Program();
programB.setUid("progrBrUid");
programB.setDescription("programBDescr");
programB.setName("programBName");
when(programInstanceA.getProgram()).thenReturn(programA);
when(programInstanceB.getProgram()).thenReturn(programB);
}
use of org.hisp.dhis.program.Program 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.program.Program 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.program.Program 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.program.Program in project dhis2-core by dhis2.
the class AnalyticsUtilsTest method testGetByDataDimensionType.
@Test
void testGetByDataDimensionType() {
Program prA = createProgram('A');
DataElement deA = createDataElement('A', new CategoryCombo());
DataElement deB = createDataElement('B', new CategoryCombo());
ProgramDataElementDimensionItem pdeA = new ProgramDataElementDimensionItem(prA, deA);
ProgramDataElementDimensionItem pdeB = new ProgramDataElementDimensionItem(prA, deB);
ProgramIndicator piA = createProgramIndicator('A', prA, null, null);
List<DimensionalItemObject> list = Lists.newArrayList(deA, deB, pdeA, pdeB, piA);
assertEquals(Lists.newArrayList(deA, deB), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.DATA_ELEMENT, list));
assertEquals(Lists.newArrayList(pdeA, pdeB), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_DATA_ELEMENT, list));
assertEquals(Lists.newArrayList(piA), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_INDICATOR, list));
assertEquals(Lists.newArrayList(), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_ATTRIBUTE, list));
}
Aggregations