use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class ObjectBundleServiceProgramTest method testCreateSimpleProgramNoReg.
@Test
void testCreateSimpleProgramNoReg() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_noreg.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
validate.forEachErrorReport(System.out::println);
assertFalse(validate.hasErrorReports());
objectBundleService.commit(bundle);
List<DataSet> dataSets = manager.getAll(DataSet.class);
List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
List<DataElement> dataElements = manager.getAll(DataElement.class);
List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
List<User> users = manager.getAll(User.class);
List<ValidationRule> validationRules = manager.getAll(ValidationRule.class);
List<Program> programs = manager.getAll(Program.class);
List<ProgramStage> programStages = manager.getAll(ProgramStage.class);
List<ProgramStageDataElement> programStageDataElements = manager.getAll(ProgramStageDataElement.class);
assertFalse(dataSets.isEmpty());
assertFalse(organisationUnits.isEmpty());
assertFalse(dataElements.isEmpty());
assertFalse(users.isEmpty());
assertFalse(userRoles.isEmpty());
assertEquals(1, validationRules.size());
assertEquals(1, programs.size());
assertEquals(1, programStages.size());
assertEquals(3, programStageDataElements.size());
ProgramStage programStage = programStages.get(0);
assertEquals(3, programStage.getProgramStageDataElements().size());
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class ProgramSupplierAclIntegrationTest method verifyUserHasWriteAccessToProgramStageForGroupAccess.
@Test
void verifyUserHasWriteAccessToProgramStageForGroupAccess() {
// Given
final User user = createUser("user1");
final ProgramStage programStage = createProgramStage('A', 1);
programStage.setPublicAccess(AccessStringHelper.DEFAULT);
UserGroup userGroup = new UserGroup("test-group-programstage", singleton(user));
manager.save(userGroup, true);
user.getGroups().add(userGroup);
programStage.getSharing().addUserGroupAccess(new org.hisp.dhis.user.sharing.UserGroupAccess(userGroup, AccessStringHelper.DATA_READ_WRITE));
manager.save(programStage, false);
final Program program = createProgram('A');
program.setProgramStages(singleton(programStage));
program.setPublicAccess(AccessStringHelper.DEFAULT);
manager.save(program, false);
manager.flush();
// When
final Map<String, Program> programs = programSupplier.get(getDefaultImportOptions(), singletonList(event));
// Then
assertThat(programs.keySet(), hasSize(1));
assertTrue(aclService.canDataWrite(user, getProgramStage(programs.get(program.getUid()))));
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class ProgramSupplierAclIntegrationTest method verifyUserHasWriteAccessToProgramStageForUserAccess.
@Test
void verifyUserHasWriteAccessToProgramStageForUserAccess() {
// Given
final User user = createUser("user2");
final ProgramStage programStage = createProgramStage('B', 1);
UserAccess userAccess = new UserAccess(user, AccessStringHelper.DATA_READ_WRITE);
programStage.setUserAccesses(singleton(userAccess));
manager.save(programStage, false);
final Program program = createProgram('A');
program.setProgramStages(singleton(programStage));
program.setPublicAccess(AccessStringHelper.DEFAULT);
manager.save(program, false);
manager.flush();
// When
final Map<String, Program> programs = programSupplier.get(getDefaultImportOptions(), singletonList(event));
// Then
assertThat(programs.keySet(), hasSize(1));
assertTrue(aclService.canDataWrite(user, getProgramStage(programs.get(program.getUid()))));
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class ProgramInstanceRepeatableStageCheckTest method successOnNonRepeatableStageAndExistingEventsOnNewEnrollment.
@Test
void successOnNonRepeatableStageAndExistingEventsOnNewEnrollment() {
// Data preparation
Program program = createProgram('P');
TrackedEntityInstance tei = createTrackedEntityInstance('A', createOrganisationUnit('A'));
event.setProgramStage(CodeGenerator.generateUid());
event.setProgram(program.getUid());
event.setTrackedEntityInstance(tei.getUid());
ProgramStage programStage = createProgramStage('A', program);
programStage.setRepeatable(false);
when(workContext.getProgramStage(programStageIdScheme, event.getProgramStage())).thenReturn(programStage);
Map<String, Program> programMap = new HashMap<>();
programMap.put(program.getUid(), program);
Map<String, ProgramInstance> programInstanceMap = new HashMap<>();
ProgramInstance programInstance = new ProgramInstance();
programInstanceMap.put(event.getUid(), programInstance);
Pair<TrackedEntityInstance, Boolean> teiPair = Pair.of(tei, true);
Map<String, Pair<TrackedEntityInstance, Boolean>> teiMap = new HashMap<>();
teiMap.put(event.getUid(), teiPair);
when(workContext.getTrackedEntityInstanceMap()).thenReturn(teiMap);
when(workContext.getProgramsMap()).thenReturn(programMap);
when(workContext.getProgramInstanceMap()).thenReturn(programInstanceMap);
when(workContext.getServiceDelegator()).thenReturn(serviceDelegator);
when(serviceDelegator.getJdbcTemplate()).thenReturn(jdbcTemplate);
when(jdbcTemplate.queryForObject(anyString(), eq(Boolean.class), eq(programInstance.getId()), eq(programStage.getId()), eq(tei.getId()))).thenReturn(false);
// Method under test
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertNoError(summary);
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method failsOnActiveEventWithDataElementValueNullAndValidationStrategyOnUpdate.
@Test
void failsOnActiveEventWithDataElementValueNullAndValidationStrategyOnUpdate() {
setUpIdentifiers();
DataElement validDataElement = dataElement();
when(context.getDataElement(dataElementUid)).thenReturn(validDataElement);
ProgramStage programStage = programStage(validDataElement, true);
programStage.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
when(context.getProgramStage(programStageUid)).thenReturn(programStage);
ValidationErrorReporter reporter = new ValidationErrorReporter(context);
DataValue validDataValue = dataValue();
validDataValue.setValue(null);
Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.ACTIVE).dataValues(Set.of(validDataValue)).build();
hook.validateEvent(reporter, event);
assertThat(reporter.getReportList(), hasSize(1));
assertEquals(TrackerErrorCode.E1076, reporter.getReportList().get(0).getErrorCode());
}
Aggregations