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));
}
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);
}
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);
}
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());
}
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);
}
Aggregations