use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class EventNoteValidationHookTest method testNoteWithExistingUidAndNoTextIsIgnored.
@Test
void testNoteWithExistingUidAndNoTextIsIgnored() {
// Given
final Note note = rnd.nextObject(Note.class);
note.setValue(null);
TrackerBundle trackerBundle = mock(TrackerBundle.class);
TrackerImportValidationContext ctx = mock(TrackerImportValidationContext.class);
when(ctx.getBundle()).thenReturn(trackerBundle);
when(trackerBundle.getValidationMode()).thenReturn(ValidationMode.FULL);
when(ctx.getNote(note.getNote())).thenReturn(Optional.of(new TrackedEntityComment()));
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
event.setNotes(Collections.singletonList(note));
// When
this.hook.validateEvent(reporter, event);
// Then
assertFalse(reporter.hasErrors());
assertThat(event.getNotes(), hasSize(0));
}
use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class EnrollmentRuleValidationHook method validateEnrollment.
@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
TrackerImportValidationContext context = reporter.getValidationContext();
List<ProgramRuleIssue> programRuleIssues = validators.stream().flatMap(v -> v.validateEnrollments(context.getBundle()).getOrDefault(enrollment.getEnrollment(), Lists.newArrayList()).stream()).collect(Collectors.toList());
addIssuesToReporter(reporter, enrollment, programRuleIssues);
}
use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class EventDataValuesValidationHook method validateEvent.
@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
TrackerImportValidationContext context = reporter.getValidationContext();
ProgramStage programStage = context.getProgramStage(event.getProgramStage());
checkNotNull(programStage, TrackerImporterAssertErrors.PROGRAM_STAGE_CANT_BE_NULL);
for (DataValue dataValue : event.getDataValues()) {
// event dates (createdAt, updatedAt) are ignored and set by the
// system
DataElement dataElement = context.getDataElement(dataValue.getDataElement());
if (dataElement == null) {
reporter.addError(event, TrackerErrorCode.E1304, dataValue.getDataElement());
continue;
}
validateDataElement(reporter, dataElement, dataValue, programStage, event);
if (dataValue.getValue() != null) {
validateOptionSet(reporter, event, dataElement, dataValue.getValue());
}
}
validateMandatoryDataValues(event, context, reporter);
validateDataValueDataElementIsConnectedToProgramStage(reporter, event, programStage);
}
use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class PreCheckExistenceValidationHook method validateEnrollment.
@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
TrackerImportValidationContext context = reporter.getValidationContext();
TrackerImportStrategy importStrategy = context.getStrategy(enrollment);
ProgramInstance existingPi = context.getProgramInstance(enrollment.getEnrollment());
// If the tracked entity is soft-deleted no operation is allowed
if (existingPi != null && existingPi.isDeleted()) {
reporter.addError(enrollment, E1113, enrollment.getEnrollment());
return;
}
if (existingPi != null && importStrategy.isCreate()) {
reporter.addError(enrollment, E1080, enrollment.getEnrollment());
} else if (existingPi == null && importStrategy.isUpdateOrDelete()) {
reporter.addError(enrollment, E1081, enrollment.getEnrollment());
}
}
use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class PreCheckExistenceValidationHook method validateEvent.
@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
TrackerImportValidationContext context = reporter.getValidationContext();
TrackerImportStrategy importStrategy = context.getStrategy(event);
ProgramStageInstance existingPsi = context.getProgramStageInstance(event.getEvent());
// If the event is soft-deleted no operation is allowed
if (existingPsi != null && existingPsi.isDeleted()) {
reporter.addError(event, E1082, event.getEvent());
return;
}
if (existingPsi != null && importStrategy.isCreate()) {
reporter.addError(event, E1030, event.getEvent());
} else if (existingPsi == null && importStrategy.isUpdateOrDelete()) {
reporter.addError(event, E1032, event.getEvent());
}
}
Aggregations