Search in sources :

Example 56 with TrackerImportParams

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

the class TrackedEntityProgramAttributeTest method testTrackedEntityProgramAttributeValueUpdateAndDelete.

@Test
void testTrackedEntityProgramAttributeValueUpdateAndDelete() throws IOException {
    TrackerImportParams trackerImportParams = fromJson("tracker/te_program_with_tea_data.json");
    TrackerBundle trackerBundle = trackerBundleService.create(trackerImportParams);
    trackerBundleService.commit(trackerBundle);
    List<TrackedEntityInstance> trackedEntityInstances = manager.getAll(TrackedEntityInstance.class);
    assertEquals(1, trackedEntityInstances.size());
    TrackedEntityInstance trackedEntityInstance = trackedEntityInstances.get(0);
    List<TrackedEntityAttributeValue> attributeValues = trackedEntityAttributeValueService.getTrackedEntityAttributeValues(trackedEntityInstance);
    assertEquals(4, attributeValues.size());
    manager.clear();
    // update
    trackerImportParams = fromJson("tracker/te_program_with_tea_update_data.json");
    trackerBundle = trackerBundleService.create(trackerImportParams);
    trackerBundleService.commit(trackerBundle);
    trackedEntityInstances = manager.getAll(TrackedEntityInstance.class);
    assertEquals(1, trackedEntityInstances.size());
    trackedEntityInstance = trackedEntityInstances.get(0);
    attributeValues = trackedEntityAttributeValueService.getTrackedEntityAttributeValues(trackedEntityInstance);
    assertEquals(4, attributeValues.size());
    manager.clear();
    // delete
    trackerImportParams = fromJson("tracker/te_program_with_tea_delete_data.json");
    trackerBundle = trackerBundleService.create(trackerImportParams);
    trackerBundleService.commit(trackerBundle);
    trackedEntityInstances = manager.getAll(TrackedEntityInstance.class);
    assertEquals(1, trackedEntityInstances.size());
    trackedEntityInstance = trackedEntityInstances.get(0);
    attributeValues = trackedEntityAttributeValueService.getTrackedEntityAttributeValues(trackedEntityInstance);
    assertEquals(1, attributeValues.size());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 57 with TrackerImportParams

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

the class TrackerImporterServiceTest method testSkipSideEffect.

@Test
void testSkipSideEffect() {
    TrackerImportParams parameters = TrackerImportParams.builder().events(params.getEvents()).enrollments(new ArrayList<>()).relationships(new ArrayList<>()).trackedEntities(new ArrayList<>()).skipSideEffects(true).userId("123").build();
    when(trackerBundleService.create(any(TrackerImportParams.class))).thenReturn(ParamsConverter.convert(parameters));
    subject.importTracker(parameters);
    verify(trackerBundleService, times(0)).handleTrackerSideEffects(anyList());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 58 with TrackerImportParams

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

the class TrackedEntityProgramAttributeFileResourceTest method testTrackedEntityProgramAttributeFileResourceValue.

@Test
void testTrackedEntityProgramAttributeFileResourceValue() throws IOException {
    FileResource fileResource = new FileResource("test.pdf", "application/pdf", 0, "d41d8cd98f00b204e9800998ecf8427e", FileResourceDomain.DOCUMENT);
    fileResource.setUid("Jzf6hHNP7jx");
    File file = File.createTempFile("file-resource", "test");
    fileResourceService.saveFileResource(fileResource, file);
    assertFalse(fileResource.isAssigned());
    TrackerImportParams trackerImportParams = fromJson("tracker/te_program_with_tea_fileresource_data.json");
    TrackerBundle trackerBundle = trackerBundleService.create(trackerImportParams);
    trackerBundleService.commit(trackerBundle);
    List<TrackedEntityInstance> trackedEntityInstances = manager.getAll(TrackedEntityInstance.class);
    assertEquals(1, trackedEntityInstances.size());
    TrackedEntityInstance trackedEntityInstance = trackedEntityInstances.get(0);
    List<TrackedEntityAttributeValue> attributeValues = trackedEntityAttributeValueService.getTrackedEntityAttributeValues(trackedEntityInstance);
    assertEquals(5, attributeValues.size());
    fileResource = fileResourceService.getFileResource(fileResource.getUid());
    assertTrue(fileResource.isAssigned());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) FileResource(org.hisp.dhis.fileresource.FileResource) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) File(java.io.File) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 59 with TrackerImportParams

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

the class TrackerBundleServiceTest method testTrackedEntityInstanceImport.

@Test
void testTrackedEntityInstanceImport() throws IOException {
    TrackerImportParams trackerImportParams = fromJson("tracker/trackedentity_basic_data.json");
    assertEquals(13, trackerImportParams.getTrackedEntities().size());
    TrackerBundle trackerBundle = trackerBundleService.create(trackerImportParams);
    trackerBundleService.commit(trackerBundle);
    List<TrackedEntityInstance> trackedEntityInstances = manager.getAll(TrackedEntityInstance.class);
    assertEquals(13, trackedEntityInstances.size());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 60 with TrackerImportParams

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

the class TrackerEventBundleServiceTest method testUpdateSingleEventData.

@Test
void testUpdateSingleEventData() throws IOException {
    TrackerImportParams trackerImportParams = fromJson("tracker/event_events_and_enrollment.json");
    trackerImportParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
    TrackerBundle trackerBundle = trackerBundleService.create(trackerImportParams);
    trackerBundleService.commit(trackerBundle);
    assertEquals(8, programStageInstanceStore.getAll().size());
    trackerBundle = trackerBundleService.create(TrackerImportParams.builder().events(trackerBundle.getEvents()).enrollments(trackerBundle.getEnrollments()).trackedEntities(trackerBundle.getTrackedEntities()).user(currentUserService.getCurrentUser()).build());
    trackerBundleService.commit(trackerBundle);
    assertEquals(8, programStageInstanceStore.getAll().size());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Aggregations

TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)163 Test (org.junit.jupiter.api.Test)142 TrackerImportReport (org.hisp.dhis.tracker.report.TrackerImportReport)105 TrackerTest (org.hisp.dhis.tracker.TrackerTest)46 User (org.hisp.dhis.user.User)26 ClassPathResource (org.springframework.core.io.ClassPathResource)23 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)21 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)17 InputStream (java.io.InputStream)16 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)11 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 List (java.util.List)9 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)9 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)8 Event (org.hisp.dhis.tracker.domain.Event)7 Pair (org.apache.commons.lang3.tuple.Pair)6 ProgramInstance (org.hisp.dhis.program.ProgramInstance)6 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)5 Program (org.hisp.dhis.program.Program)5