Search in sources :

Example 36 with TrackerBundle

use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.

the class EventDateValidationHookTest method setUp.

@BeforeEach
public void setUp() {
    hookToTest = new EventDateValidationHook();
    User user = createUser('A');
    TrackerBundle bundle = TrackerBundle.builder().user(user).build();
    when(validationContext.getBundle()).thenReturn(bundle);
    when(validationContext.getProgram(PROGRAM_WITH_REGISTRATION_ID)).thenReturn(getProgramWithRegistration());
    when(validationContext.getProgram(PROGRAM_WITHOUT_REGISTRATION_ID)).thenReturn(getProgramWithoutRegistration());
}
Also used : User(org.hisp.dhis.user.User) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 37 with TrackerBundle

use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.

the class PreCheckMetaValidationHookTest method setUp.

@BeforeEach
public void setUp() {
    validatorToTest = new PreCheckMetaValidationHook();
    TrackerBundle bundle = TrackerBundle.builder().build();
    when(ctx.getBundle()).thenReturn(bundle);
}
Also used : TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 38 with TrackerBundle

use of org.hisp.dhis.tracker.bundle.TrackerBundle 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));
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Note(org.hisp.dhis.tracker.domain.Note) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 39 with TrackerBundle

use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.

the class TrackedEntityAttributeValidationHookTest method setUp.

@BeforeEach
public void setUp() {
    TrackerBundle bundle = TrackerBundle.builder().build();
    when(validationContext.getBundle()).thenReturn(bundle);
    when(dhisConfigurationProvider.getEncryptionStatus()).thenReturn(EncryptionStatus.OK);
}
Also used : TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 40 with TrackerBundle

use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.

the class DefaultTrackerImportService method importTracker.

@Override
public TrackerImportReport importTracker(TrackerImportParams params) {
    User user = trackerUserService.getUser(params.getUserId());
    params.setUser(user);
    TrackerTimingsStats opsTimer = new TrackerTimingsStats();
    startImport(params);
    TrackerValidationReport validationReport = new TrackerValidationReport();
    TrackerBundleReport bundleReport;
    try {
        TrackerBundle trackerBundle = preHeat(params, opsTimer);
        Map<TrackerType, Integer> bundleSize = calculatePayloadSize(trackerBundle);
        preProcess(opsTimer, trackerBundle);
        if (addToValidationReport(params, opsTimer, validationReport, trackerBundle)) {
            return buildReportAndNotify(params, validationReport, opsTimer, bundleSize);
        }
        bundleReport = commit(params, opsTimer, trackerBundle);
        postCommit(trackerBundle);
        TrackerImportReport trackerImportReport = TrackerImportReport.withImportCompleted(TrackerStatus.OK, bundleReport, validationReport, opsTimer.stopTimer(), bundleSize);
        endImport(params, trackerImportReport);
        return trackerImportReport;
    } catch (Exception e) {
        log.error("Exception thrown during import.", e);
        TrackerImportReport report = TrackerImportReport.withError("Exception:" + e.getMessage(), validationReport, opsTimer.stopTimer());
        endImportWithError(params, report, e);
        return report;
    }
}
Also used : TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) User(org.hisp.dhis.user.User) TrackerTimingsStats(org.hisp.dhis.tracker.report.TrackerTimingsStats) TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerBundleReport(org.hisp.dhis.tracker.report.TrackerBundleReport)

Aggregations

TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)74 Test (org.junit.jupiter.api.Test)43 Event (org.hisp.dhis.tracker.domain.Event)29 User (org.hisp.dhis.user.User)21 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)19 List (java.util.List)17 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)15 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)14 Mockito.mock (org.mockito.Mockito.mock)14 TrackerErrorCode (org.hisp.dhis.tracker.report.TrackerErrorCode)13 TrackerImportStrategy (org.hisp.dhis.tracker.TrackerImportStrategy)12 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)12 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)12 Collections (java.util.Collections)11 ProgramStage (org.hisp.dhis.program.ProgramStage)11 Objects (java.util.Objects)10 Program (org.hisp.dhis.program.Program)10 ValidationMode (org.hisp.dhis.tracker.ValidationMode)10 Relationship (org.hisp.dhis.tracker.domain.Relationship)10