use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class DefaultMetadataSyncServiceTest method testShouldVerifyImportParamsAtomicTypeForTheGivenBestEffortVersion.
@Test
void testShouldVerifyImportParamsAtomicTypeForTheGivenBestEffortVersion() throws DhisVersionMismatchException {
MetadataSyncParams syncParams = new MetadataSyncParams();
MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
MetadataImportParams metadataImportParams = new MetadataImportParams();
syncParams.setVersion(metadataVersion);
syncParams.setImportParams(metadataImportParams);
MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
metadataSyncSummary.setMetadataVersion(metadataVersion);
String expectedMetadataSnapshot = "{\"date\":\"2016-05-24T05:27:25.128+0000\"}";
when(metadataVersionService.getVersionData("testVersion")).thenReturn(expectedMetadataSnapshot);
metadataSyncService.doMetadataSync(syncParams);
verify(metadataSyncImportHandler, times(1)).importMetadata((argThat(metadataSyncParams -> syncParams.getImportParams().getAtomicMode().equals(AtomicMode.NONE))), eq(expectedMetadataSnapshot));
verify(metadataVersionService, never()).createMetadataVersionInDataStore(metadataVersion.getName(), expectedMetadataSnapshot);
verify(metadataVersionDelegate, never()).downloadMetadataVersionSnapshot(metadataVersion);
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataSyncImportHandlerTest method testShouldThrowExceptionWhenImportServiceFails.
@Test
void testShouldThrowExceptionWhenImportServiceFails() {
syncParams.setImportParams(new MetadataImportParams());
syncParams.setVersion(metadataVersion);
when(metadataImportService.importMetadata(syncParams.getImportParams())).thenThrow(new MetadataSyncServiceException(""));
assertThrows(MetadataSyncImportException.class, () -> metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot));
verify(metadataVersionDelegate, never()).addNewMetadataVersion(metadataVersion);
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataSyncImportHandlerTest method testShouldImportMetadataWhenBestEffortWithWarnings.
@Test
void testShouldImportMetadataWhenBestEffortWithWarnings() {
syncParams.setImportParams(new MetadataImportParams());
syncParams.setVersion(metadataVersion);
MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
importReport.setStatus(Status.WARNING);
metadataVersion.setType(VersionType.BEST_EFFORT);
when(metadataImportService.importMetadata(syncParams.getImportParams())).thenReturn(importReport);
metadataSyncSummary.setImportReport(importReport);
metadataSyncSummary.setMetadataVersion(metadataVersion);
doNothing().when(metadataVersionDelegate).addNewMetadataVersion(metadataVersion);
MetadataSyncSummary actualMetadataSyncSummary = metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot);
verify(metadataVersionDelegate).addNewMetadataVersion(metadataVersion);
assertEquals(metadataSyncSummary.getImportReport(), actualMetadataSyncSummary.getImportReport());
assertEquals(metadataSyncSummary.getImportSummary(), actualMetadataSyncSummary.getImportSummary());
assertEquals(metadataSyncSummary.getMetadataVersion(), actualMetadataSyncSummary.getMetadataVersion());
assertEquals(metadataSyncSummary.getMetadataVersion().getType(), actualMetadataSyncSummary.getMetadataVersion().getType());
assertEquals(metadataSyncSummary.getImportReport().getStatus(), actualMetadataSyncSummary.getImportReport().getStatus());
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataSyncImportHandlerTest method testShouldReturnDefaultSummaryWhenImportStatusIsError.
@Test
void testShouldReturnDefaultSummaryWhenImportStatusIsError() {
syncParams.setImportParams(new MetadataImportParams());
syncParams.setVersion(metadataVersion);
MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
metadataSyncSummary.setImportReport(new ImportReport());
metadataSyncSummary.setMetadataVersion(metadataVersion);
importReport.setStatus(Status.ERROR);
when(metadataImportService.importMetadata(syncParams.getImportParams())).thenReturn(importReport);
MetadataSyncSummary actualMetadataSyncSummary = metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot);
verify(metadataVersionDelegate, never()).addNewMetadataVersion(metadataVersion);
assertEquals(metadataSyncSummary.getImportReport().toString(), actualMetadataSyncSummary.getImportReport().toString());
assertEquals(metadataSyncSummary.getImportSummary(), actualMetadataSyncSummary.getImportSummary());
assertEquals(metadataSyncSummary.getMetadataVersion(), actualMetadataSyncSummary.getMetadataVersion());
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class AbstractCrudController method putXmlObject.
@PutMapping(value = "/{uid}", consumes = { APPLICATION_XML_VALUE, TEXT_XML_VALUE })
@ResponseBody
public WebMessage putXmlObject(@PathVariable("uid") String pvUid, @CurrentUser User currentUser, HttpServletRequest request, HttpServletResponse response) throws Exception {
List<T> objects = getEntity(pvUid);
if (objects.isEmpty()) {
return notFound(getEntityClass(), pvUid);
}
if (!aclService.canUpdate(currentUser, objects.get(0))) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
}
T parsed = deserializeXmlEntity(request);
((BaseIdentifiableObject) parsed).setUid(pvUid);
preUpdateEntity(objects.get(0), parsed);
MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap()).setImportReportMode(ImportReportMode.FULL).setUser(currentUser).setImportStrategy(ImportStrategy.UPDATE).addObject(parsed);
ImportReport importReport = importService.importMetadata(params);
WebMessage webMessage = objectReport(importReport);
if (importReport.getStatus() == Status.OK) {
T entity = manager.get(getEntityClass(), pvUid);
postUpdateEntity(entity);
} else {
webMessage.setStatus(Status.ERROR);
}
return webMessage;
}
Aggregations