use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class PreCheckMetaValidationHook method validateRelationship.
@Override
public void validateRelationship(ValidationErrorReporter reporter, Relationship relationship) {
TrackerImportValidationContext context = reporter.getValidationContext();
RelationshipType relationshipType = context.getRelationShipType(relationship.getRelationshipType());
reporter.addErrorIfNull(relationshipType, relationship, E4006, relationship.getRelationshipType());
}
use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class EnrollmentGeoValidationHook method validateEnrollment.
@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
TrackerImportValidationContext context = reporter.getValidationContext();
Program program = context.getProgram(enrollment.getProgram());
checkNotNull(program, TrackerImporterAssertErrors.PROGRAM_CANT_BE_NULL);
if (enrollment.getGeometry() != null) {
ValidationUtils.validateGeometry(reporter, enrollment, enrollment.getGeometry(), program.getFeatureType());
}
}
use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class EventCategoryOptValidationHook method validateEvent.
@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
TrackerImportValidationContext context = reporter.getValidationContext();
Program program = context.getProgram(event.getProgram());
checkNotNull(program, TrackerImporterAssertErrors.PROGRAM_CANT_BE_NULL);
checkNotNull(context.getBundle().getUser(), TrackerImporterAssertErrors.USER_CANT_BE_NULL);
checkNotNull(program, TrackerImporterAssertErrors.PROGRAM_CANT_BE_NULL);
checkNotNull(event, TrackerImporterAssertErrors.EVENT_CANT_BE_NULL);
CategoryOptionCombo categoryOptionCombo = reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getUid());
checkNotNull(categoryOptionCombo, TrackerImporterAssertErrors.CATEGORY_OPTION_COMBO_CANT_BE_NULL);
Date eventDate;
try {
eventDate = DateUtils.fromInstant(ObjectUtils.firstNonNull(event.getOccurredAt(), event.getScheduledAt(), Instant.now()));
} catch (IllegalArgumentException e) {
log.debug("Failed to parse dates, an error should already be reported.");
return;
}
I18nFormat i18nFormat = i18nManager.getI18nFormat();
for (CategoryOption option : categoryOptionCombo.getCategoryOptions()) {
if (option.getStartDate() != null && eventDate.compareTo(option.getStartDate()) < 0) {
reporter.addError(event, E1056, i18nFormat.formatDate(eventDate), i18nFormat.formatDate(option.getStartDate()), option.getName());
}
if (option.getEndDate() != null && eventDate.compareTo(option.getAdjustedEndDate(program)) > 0) {
reporter.addError(event, E1057, i18nFormat.formatDate(eventDate), i18nFormat.formatDate(option.getAdjustedEndDate(program)), option.getName(), program.getName());
}
}
}
use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class EventDateValidationHook method validateEvent.
@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
TrackerImportValidationContext context = reporter.getValidationContext();
Program program = context.getProgram(event.getProgram());
if (event.getOccurredAt() == null && occuredAtDateIsMandatory(event, program)) {
reporter.addError(event, E1031, event);
return;
}
if (event.getScheduledAt() == null && EventStatus.SCHEDULE == event.getStatus()) {
reporter.addError(event, E1050, event);
return;
}
validateExpiryDays(reporter, event, program);
validatePeriodType(reporter, event, program);
}
use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class RepeatedEventsValidationHookTest method testTwoEventInNotRepeatableProgramStageAreNotPassingValidation.
@Test
void testTwoEventInNotRepeatableProgramStageAreNotPassingValidation() {
List<Event> events = Lists.newArrayList(notRepeatableEvent("A"), notRepeatableEvent("B"));
bundle.setEvents(events);
events.forEach(e -> bundle.setStrategy(e, TrackerImportStrategy.CREATE_AND_UPDATE));
ValidationErrorReporter errorReporter = new ValidationErrorReporter(new TrackerImportValidationContext(bundle));
validatorToTest.validate(errorReporter, ctx);
assertEquals(2, errorReporter.getReportList().size());
assertThat(errorReporter.getReportList().get(0).getErrorCode(), is(TrackerErrorCode.E1039));
assertThat(errorReporter.getReportList().get(0).getTrackerType(), is(EVENT));
assertThat(errorReporter.getReportList().get(0).getUid(), is(events.get(0).getUid()));
assertThat(errorReporter.getReportList().get(0).getErrorMessage(), is("ProgramStage: `" + NOT_REPEATABLE_PROGRAM_STAGE_WITH_REGISTRATION + "`, is not repeatable and an event already exists."));
assertThat(errorReporter.getReportList().get(1).getErrorCode(), is(TrackerErrorCode.E1039));
assertThat(errorReporter.getReportList().get(1).getTrackerType(), is(EVENT));
assertThat(errorReporter.getReportList().get(1).getUid(), is(events.get(1).getUid()));
assertThat(errorReporter.getReportList().get(1).getErrorMessage(), is("ProgramStage: `" + NOT_REPEATABLE_PROGRAM_STAGE_WITH_REGISTRATION + "`, is not repeatable and an event already exists."));
}
Aggregations