Search in sources :

Example 71 with MetadataImportParams

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);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) Test(org.junit.jupiter.api.Test)

Example 72 with MetadataImportParams

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);
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) Test(org.junit.jupiter.api.Test)

Example 73 with MetadataImportParams

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());
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) Test(org.junit.jupiter.api.Test)

Example 74 with MetadataImportParams

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());
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) Test(org.junit.jupiter.api.Test)

Example 75 with MetadataImportParams

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;
}
Also used : BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)58 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)49 List (java.util.List)38 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)38 Test (org.junit.jupiter.api.Test)38 ClassPathResource (org.springframework.core.io.ClassPathResource)31 User (org.hisp.dhis.user.User)30 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)29 DataSet (org.hisp.dhis.dataset.DataSet)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)10 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)9 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)8 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)8 HashMap (java.util.HashMap)6 UserGroup (org.hisp.dhis.user.UserGroup)6 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)6 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5