use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class AnalyticsTableTest method testGetTablePartitionName.
@Test
void testGetTablePartitionName() {
Program program = new Program("ProgramA", "DescriptionA");
program.setUid("UIDA");
Period periodA = new YearlyPeriodType().createPeriod(new DateTime(2014, 1, 1, 0, 0).toDate());
Period periodB = new YearlyPeriodType().createPeriod(new DateTime(2015, 1, 1, 0, 0).toDate());
AnalyticsTable tableA = new AnalyticsTable(AnalyticsTableType.EVENT, Lists.newArrayList(), Lists.newArrayList(), program);
tableA.addPartitionTable(2014, periodA.getStartDate(), periodA.getEndDate());
tableA.addPartitionTable(2015, periodB.getStartDate(), periodB.getEndDate());
AnalyticsTablePartition partitionA = tableA.getTablePartitions().get(0);
AnalyticsTablePartition partitionB = tableA.getTablePartitions().get(1);
assertNotNull(partitionA);
assertNotNull(partitionB);
assertEquals("analytics_event_uida_2014", partitionA.getTableName());
assertEquals("analytics_event_uida_2015", partitionB.getTableName());
assertEquals("analytics_event_temp_uida_2014", partitionA.getTempTableName());
assertEquals("analytics_event_temp_uida_2015", partitionB.getTempTableName());
}
use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class AnalyticsTableTest method testGetTableName.
@Test
void testGetTableName() {
Program program = new Program("ProgramA", "DescriptionA");
program.setUid("UIDA");
AnalyticsTable tableA = new AnalyticsTable(AnalyticsTableType.EVENT, Lists.newArrayList(), Lists.newArrayList(), program);
assertEquals("analytics_event_uida", tableA.getTableName());
}
use of org.hisp.dhis.program.Program 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.program.Program in project dhis2-core by dhis2.
the class DefaultProgramStageInstanceFilterService method validate.
// -------------------------------------------------------------------------
// ProgramStageInstanceFilterService implementation
// -------------------------------------------------------------------------
@Override
public List<String> validate(ProgramStageInstanceFilter programStageInstanceFilter) {
List<String> errors = new ArrayList<>();
if (programStageInstanceFilter.getProgram() == null) {
errors.add("Program should be specified for event filters.");
} else {
Program pr = programService.getProgram(programStageInstanceFilter.getProgram());
if (pr == null) {
errors.add("Program is specified but does not exist: " + programStageInstanceFilter.getProgram());
}
}
if (programStageInstanceFilter.getProgramStage() != null) {
ProgramStage ps = programStageService.getProgramStage(programStageInstanceFilter.getProgramStage());
if (ps == null) {
errors.add("Program stage is specified but does not exist: " + programStageInstanceFilter.getProgramStage());
}
}
EventQueryCriteria eventQC = programStageInstanceFilter.getEventQueryCriteria();
if (eventQC != null) {
if (eventQC.getOrganisationUnit() != null) {
OrganisationUnit ou = organisationUnitService.getOrganisationUnit(eventQC.getOrganisationUnit());
if (ou == null) {
errors.add("Org unit is specified but does not exist: " + eventQC.getOrganisationUnit());
}
}
if (eventQC.getAssignedUserMode() != null && eventQC.getAssignedUsers() != null && !eventQC.getAssignedUsers().isEmpty() && !eventQC.getAssignedUserMode().equals(AssignedUserSelectionMode.PROVIDED)) {
errors.add("Assigned User uid(s) cannot be specified if selectionMode is not PROVIDED");
}
if (eventQC.getEvents() != null && !eventQC.getEvents().isEmpty() && eventQC.getDataFilters() != null && !eventQC.getDataFilters().isEmpty()) {
errors.add("Event UIDs and filters can not be specified at the same time");
}
if (eventQC.getDisplayColumnOrder() != null && eventQC.getDisplayColumnOrder().size() > 0 && (new HashSet<String>(eventQC.getDisplayColumnOrder())).size() < eventQC.getDisplayColumnOrder().size()) {
errors.add("Event query criteria can not have duplicate column ordering fields");
}
}
return errors;
}
use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class OrganisationUnitServiceTest method testAddAndDelOrganisationUnitWithPrgUserAndDataSet.
@Test
void testAddAndDelOrganisationUnitWithPrgUserAndDataSet() {
OrganisationUnit organisationUnit1 = createOrganisationUnit('A');
Program program = createProgram('A');
User user = createUser('A');
DataSet dataSet = createDataSet('A');
long id1 = organisationUnitService.addOrganisationUnit(organisationUnit1);
long programId = programService.addProgram(program);
long userId = userService.addUser(user);
long dataSetId = dataSetService.addDataSet(dataSet);
program.getOrganisationUnits().add(organisationUnit1);
organisationUnit1.getPrograms().add(program);
user.addOrganisationUnit(organisationUnit1);
organisationUnit1.addUser(user);
dataSet.addOrganisationUnit(organisationUnit1);
organisationUnit1.addDataSet(dataSet);
organisationUnitService.updateOrganisationUnit(organisationUnit1);
programService.updateProgram(program);
userService.updateUser(user);
dataSetService.updateDataSet(dataSet);
assertNotNull(organisationUnitService.getOrganisationUnit(id1));
organisationUnitService.deleteOrganisationUnit(organisationUnitService.getOrganisationUnit(id1));
assertNull(organisationUnitService.getOrganisationUnit(id1));
assertTrue(programService.getProgram(programId).getOrganisationUnits().isEmpty());
assertTrue(userService.getUser(userId).getOrganisationUnits().isEmpty());
assertTrue(dataSetService.getDataSet(dataSetId).getSources().isEmpty());
}
Aggregations