use of org.hisp.dhis.tracker.report.TrackerValidationReport in project dhis2-core by dhis2.
the class DefaultTrackerValidationServiceTest method needsToRunPreventsHookExecutionOnImportStrategyDeleteByDefault.
@Test
void needsToRunPreventsHookExecutionOnImportStrategyDeleteByDefault() {
Event invalidEvent = event();
TrackerBundle bundle = newBundle().importStrategy(TrackerImportStrategy.DELETE).events(events(invalidEvent)).build();
// StrategyPreProcessor sets the ImportStrategy in the bundle for every
// dto
bundle.setStrategy(invalidEvent, TrackerImportStrategy.DELETE);
ValidationHook hook1 = ValidationHook.builder().validateEvent((reporter, event) -> reporter.addErrorIf(() -> invalidEvent.equals(event), event, TrackerErrorCode.E1032)).build();
service = new DefaultTrackerValidationService(List.of(hook1), Collections.emptyList());
TrackerValidationReport report = service.validate(bundle);
assertFalse(report.hasErrors());
}
use of org.hisp.dhis.tracker.report.TrackerValidationReport in project dhis2-core by dhis2.
the class DefaultTrackerValidationServiceTest method failFastModePreventsFurtherValidationAfterFirstErrorIsAdded.
@Test
void failFastModePreventsFurtherValidationAfterFirstErrorIsAdded() {
Event validEvent = event();
Event invalidEvent = event();
TrackerBundle bundle = newBundle().validationMode(ValidationMode.FAIL_FAST).events(events(invalidEvent, validEvent)).build();
ValidationHook hook1 = ValidationHook.builder().removeOnError(false).validateEvent((reporter, event) -> reporter.addErrorIf(() -> invalidEvent.equals(event), event, TrackerErrorCode.E1032)).build();
TrackerValidationHook hook2 = mock(TrackerValidationHook.class);
service = new DefaultTrackerValidationService(List.of(hook1, hook2), Collections.emptyList());
TrackerValidationReport report = service.validate(bundle);
assertTrue(report.hasErrors());
assertHasError(report, TrackerErrorCode.E1032, invalidEvent);
assertFalse(bundle.getEvents().contains(invalidEvent));
assertTrue(bundle.getEvents().contains(validEvent));
verifyNoInteractions(hook2);
}
use of org.hisp.dhis.tracker.report.TrackerValidationReport in project dhis2-core by dhis2.
the class TrackerImporterServiceTest method setUp.
@BeforeEach
public void setUp() {
subject = new DefaultTrackerImportService(trackerBundleService, trackerValidationService, trackerPreprocessService, trackerUserService, notifier);
final List<Event> events = rnd.objects(Event.class, 3).collect(Collectors.toList());
params = TrackerImportParams.builder().events(events).enrollments(new ArrayList<>()).relationships(new ArrayList<>()).trackedEntities(new ArrayList<>()).userId("123").build();
TrackerBundleReport trackerBundleReport = TrackerBundleReport.builder().build();
when(trackerUserService.getUser(anyString())).thenReturn(getUser());
when(trackerBundleService.commit(any(TrackerBundle.class))).thenReturn(trackerBundleReport);
when(trackerValidationService.validate(any(TrackerBundle.class))).thenReturn(new TrackerValidationReport());
when(trackerValidationService.validateRuleEngine(any(TrackerBundle.class))).thenReturn(new TrackerValidationReport());
when(trackerPreprocessService.preprocess(any(TrackerBundle.class))).thenReturn(ParamsConverter.convert(params));
}
use of org.hisp.dhis.tracker.report.TrackerValidationReport in project dhis2-core by dhis2.
the class DefaultTrackerImportService method validateBundle.
protected TrackerValidationReport validateBundle(TrackerImportParams params, TrackerBundle trackerBundle, TrackerTimingsStats opsTimer) {
TrackerValidationReport validationReport = trackerValidationService.validate(trackerBundle);
notifyOps(params, VALIDATION_OPS, opsTimer);
return validationReport;
}
use of org.hisp.dhis.tracker.report.TrackerValidationReport in project dhis2-core by dhis2.
the class DefaultTrackerImportService method validateRuleEngine.
protected TrackerValidationReport validateRuleEngine(TrackerBundle trackerBundle) {
TrackerValidationReport ruleEngineValidationReport = new TrackerValidationReport();
ruleEngineValidationReport.addValidationReport(trackerValidationService.validateRuleEngine(trackerBundle));
return ruleEngineValidationReport;
}
Aggregations