use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method setUp.
@BeforeEach
void setUp() {
hook = new PreCheckDataRelationsValidationHook(categoryService);
bundle = TrackerBundle.builder().preheat(preheat).build();
ctx = new TrackerImportValidationContext(bundle);
reporter = new ValidationErrorReporter(ctx);
}
use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class EnrollmentNoteValidationHookTest method testNoteWithExistingUidWarnings.
@Test
void testNoteWithExistingUidWarnings() {
// Given
final Note note = rnd.nextObject(Note.class);
TrackerBundle trackerBundle = mock(TrackerBundle.class);
TrackerImportValidationContext ctx = mock(TrackerImportValidationContext.class);
TrackerPreheat preheat = mock(TrackerPreheat.class);
when(ctx.getBundle()).thenReturn(trackerBundle);
when(trackerBundle.getValidationMode()).thenReturn(ValidationMode.FULL);
when(trackerBundle.getPreheat()).thenReturn(preheat);
when(ctx.getNote(note.getNote())).thenReturn(Optional.of(new TrackedEntityComment()));
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
enrollment.setNotes(Collections.singletonList(note));
// When
this.hook.validateEnrollment(reporter, enrollment);
// Then
assertTrue(reporter.hasWarnings());
assertTrue(reporter.hasWarningReport(warn -> E1119.equals(warn.getWarningCode()) && ENROLLMENT.equals(warn.getTrackerType()) && enrollment.getUid().equals(warn.getUid())));
assertThat(enrollment.getNotes(), hasSize(0));
}
use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class EnrollmentNoteValidationHookTest method testNotesAreValidWhenUidDoesNotExist.
@Test
void testNotesAreValidWhenUidDoesNotExist() {
// Given
final List<Note> notes = rnd.objects(Note.class, 5).collect(Collectors.toList());
TrackerBundle trackerBundle = mock(TrackerBundle.class);
TrackerImportValidationContext ctx = mock(TrackerImportValidationContext.class);
when(ctx.getBundle()).thenReturn(trackerBundle);
when(trackerBundle.getValidationMode()).thenReturn(ValidationMode.FULL);
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
enrollment.setNotes(notes);
// When
this.hook.validateEnrollment(reporter, enrollment);
// Then
assertFalse(reporter.hasErrors());
assertThat(enrollment.getNotes(), hasSize(5));
}
use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class PreCheckMetaValidationHook method validateEvent.
@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
TrackerImportValidationContext context = reporter.getValidationContext();
OrganisationUnit organisationUnit = context.getOrganisationUnit(event.getOrgUnit());
reporter.addErrorIfNull(organisationUnit, event, E1011, event.getOrgUnit());
Program program = context.getProgram(event.getProgram());
reporter.addErrorIfNull(program, event, E1010, event.getProgram());
ProgramStage programStage = context.getProgramStage(event.getProgramStage());
reporter.addErrorIfNull(programStage, event, E1013, event.getProgramStage());
}
use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHook method validateEvent.
@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
TrackerImportValidationContext context = reporter.getValidationContext();
TrackerImportStrategy strategy = context.getStrategy(event);
TrackerBundle bundle = context.getBundle();
User user = bundle.getUser();
checkNotNull(user, USER_CANT_BE_NULL);
checkNotNull(event, EVENT_CANT_BE_NULL);
checkNotNull(event.getOrgUnit(), ORGANISATION_UNIT_CANT_BE_NULL);
OrganisationUnit organisationUnit = context.getOrganisationUnit(event.getOrgUnit());
ProgramStage programStage = context.getProgramStage(event.getProgramStage());
Program program = context.getProgram(event.getProgram());
// has to be checked
if (program.isWithoutRegistration() || strategy.isCreate() || strategy.isDelete()) {
checkOrgUnitInCaptureScope(reporter, event, organisationUnit);
}
String teiUid = getTeiUidFromEvent(context, event, program);
CategoryOptionCombo categoryOptionCombo = bundle.getPreheat().getCategoryOptionCombo(event.getAttributeOptionCombo());
OrganisationUnit ownerOrgUnit = context.getOwnerOrganisationUnit(teiUid, program.getUid());
// Check acting user is allowed to change existing/write event
if (strategy.isUpdateOrDelete()) {
ProgramStageInstance programStageInstance = context.getProgramStageInstance(event.getEvent());
TrackedEntityInstance entityInstance = programStageInstance.getProgramInstance().getEntityInstance();
validateUpdateAndDeleteEvent(reporter, event, programStageInstance, entityInstance == null ? null : entityInstance.getUid(), ownerOrgUnit);
} else {
validateCreateEvent(reporter, event, user, categoryOptionCombo, programStage, teiUid, organisationUnit, ownerOrgUnit, program, event.isCreatableInSearchScope());
}
}
Aggregations