Search in sources :

Example 1 with TrackerEntityInstanceRequest

use of org.hisp.dhis.webapi.strategy.old.tracker.imports.request.TrackerEntityInstanceRequest in project dhis2-core by dhis2.

the class TrackedEntityInstanceStrategyHandlerImplTest method shouldThrowMediaTypeNotAllowed.

@Test
void shouldThrowMediaTypeNotAllowed() throws IOException {
    when(trackedEntityInstanceService.getTrackedEntityInstancesJson(any())).thenReturn(trackedEntityInstanceList);
    TrackerEntityInstanceRequest trackerEntityInstanceRequest = TrackerEntityInstanceRequest.builder().mediaType(MediaType.APPLICATION_PDF_VALUE).importOptions(importOptions).jobConfiguration(jobConfiguration).inputStream(inputStream).build();
    assertThrows(BadRequestException.class, () -> trackedEntityInstanceAsyncStrategy.mergeOrDeleteTrackedEntityInstances(trackerEntityInstanceRequest));
}
Also used : TrackerEntityInstanceRequest(org.hisp.dhis.webapi.strategy.old.tracker.imports.request.TrackerEntityInstanceRequest) Test(org.junit.jupiter.api.Test)

Example 2 with TrackerEntityInstanceRequest

use of org.hisp.dhis.webapi.strategy.old.tracker.imports.request.TrackerEntityInstanceRequest in project dhis2-core by dhis2.

the class TrackedEntityInstanceController method postTrackedEntityInstance.

private WebMessage postTrackedEntityInstance(ImportStrategy strategy, ImportOptions importOptions, HttpServletRequest request, String mediaType) throws IOException, BadRequestException {
    importOptions.setStrategy(strategy);
    importOptions.setSkipLastUpdated(true);
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    // For in memory Jobs
    JobConfiguration jobId = new JobConfiguration("inMemoryEventImport", TEI_IMPORT, currentUserService.getCurrentUser().getUid(), true);
    TrackerEntityInstanceRequest trackerEntityInstanceRequest = TrackerEntityInstanceRequest.builder().inputStream(inputStream).importOptions(importOptions).mediaType(mediaType).jobConfiguration(jobId).build();
    ImportSummaries importSummaries = trackedEntityInstanceStrategyHandler.mergeOrDeleteTrackedEntityInstances(trackerEntityInstanceRequest);
    if (!importOptions.isAsync()) {
        ImportSummary singleSummary = finalizeTrackedEntityInstancePostRequest(importOptions, request, importSummaries);
        return importSummaries(importSummaries).setLocation(singleSummary == null ? null : "/api/" + "trackedEntityInstances" + "/" + singleSummary.getReference());
    }
    return jobConfigurationReport(jobId).setLocation("/system/tasks/" + TEI_IMPORT);
}
Also used : InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackerEntityInstanceRequest(org.hisp.dhis.webapi.strategy.old.tracker.imports.request.TrackerEntityInstanceRequest) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 3 with TrackerEntityInstanceRequest

use of org.hisp.dhis.webapi.strategy.old.tracker.imports.request.TrackerEntityInstanceRequest in project dhis2-core by dhis2.

the class TrackedEntityInstanceStrategyHandlerImplTest method shouldCallSyncTrackedEntityXmlSyncStrategy.

@Test
void shouldCallSyncTrackedEntityXmlSyncStrategy() throws BadRequestException, IOException {
    when(trackedEntityInstanceService.getTrackedEntityInstancesXml(any())).thenReturn(trackedEntityInstanceList);
    TrackerEntityInstanceRequest trackerEntityInstanceRequest = TrackerEntityInstanceRequest.builder().mediaType(MediaType.APPLICATION_XML_VALUE).importOptions(importOptions).inputStream(inputStream).build();
    trackedEntityInstanceSyncStrategy.mergeOrDeleteTrackedEntityInstances(trackerEntityInstanceRequest);
    verify(trackedEntityInstanceService, times(1)).mergeOrDeleteTrackedEntityInstances(trackedEntityInstanceList, importOptions, null);
    verify(trackedEntityInstanceService, times(1)).getTrackedEntityInstancesXml(inputStream);
}
Also used : TrackerEntityInstanceRequest(org.hisp.dhis.webapi.strategy.old.tracker.imports.request.TrackerEntityInstanceRequest) Test(org.junit.jupiter.api.Test)

Example 4 with TrackerEntityInstanceRequest

use of org.hisp.dhis.webapi.strategy.old.tracker.imports.request.TrackerEntityInstanceRequest in project dhis2-core by dhis2.

the class TrackedEntityInstanceStrategyHandlerImplTest method shouldCallAsyncTrackedEntityXmlAsyncStrategy.

@Test
void shouldCallAsyncTrackedEntityXmlAsyncStrategy() throws IOException, BadRequestException {
    when(trackedEntityInstanceService.getTrackedEntityInstancesJson(any())).thenReturn(trackedEntityInstanceList);
    TrackerEntityInstanceRequest trackerEntityInstanceRequest = TrackerEntityInstanceRequest.builder().mediaType(MediaType.APPLICATION_XML_VALUE).importOptions(importOptions).jobConfiguration(jobConfiguration).inputStream(inputStream).build();
    trackedEntityInstanceAsyncStrategy.mergeOrDeleteTrackedEntityInstances(trackerEntityInstanceRequest);
    verify(trackedEntityInstanceService, times(1)).getTrackedEntityInstancesXml(inputStream);
    verify(taskExecutor, times(1)).executeTask(trackedEntitiesTaskArgumentCaptor.capture());
}
Also used : TrackerEntityInstanceRequest(org.hisp.dhis.webapi.strategy.old.tracker.imports.request.TrackerEntityInstanceRequest) Test(org.junit.jupiter.api.Test)

Example 5 with TrackerEntityInstanceRequest

use of org.hisp.dhis.webapi.strategy.old.tracker.imports.request.TrackerEntityInstanceRequest in project dhis2-core by dhis2.

the class TrackedEntityInstanceStrategyHandlerImplTest method shouldCallSyncTrackedEntityJsonSyncStrategy.

@Test
void shouldCallSyncTrackedEntityJsonSyncStrategy() throws IOException, BadRequestException {
    when(trackedEntityInstanceService.getTrackedEntityInstancesJson(any())).thenReturn(trackedEntityInstanceList);
    TrackerEntityInstanceRequest trackerEntityInstanceRequest = TrackerEntityInstanceRequest.builder().mediaType(MediaType.APPLICATION_JSON_VALUE).importOptions(importOptions).inputStream(inputStream).build();
    trackedEntityInstanceSyncStrategy.mergeOrDeleteTrackedEntityInstances(trackerEntityInstanceRequest);
    verify(trackedEntityInstanceService, times(1)).mergeOrDeleteTrackedEntityInstances(trackedEntityInstanceList, importOptions, null);
    verify(trackedEntityInstanceService, times(1)).getTrackedEntityInstancesJson(inputStream);
}
Also used : TrackerEntityInstanceRequest(org.hisp.dhis.webapi.strategy.old.tracker.imports.request.TrackerEntityInstanceRequest) Test(org.junit.jupiter.api.Test)

Aggregations

TrackerEntityInstanceRequest (org.hisp.dhis.webapi.strategy.old.tracker.imports.request.TrackerEntityInstanceRequest)8 Test (org.junit.jupiter.api.Test)7 InputStream (java.io.InputStream)1 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)1 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)1 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)1