Search in sources :

Example 11 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class MetadataSyncPostProcessorTest method testShouldSendSuccessEmailIfSyncSummaryIsWarning.

@Test
public void testShouldSendSuccessEmailIfSyncSummaryIsWarning() throws Exception {
    metadataSyncSummary.setImportReport(new ImportReport());
    metadataSyncSummary.getImportReport().setStatus(Status.WARNING);
    metadataSyncSummary.setMetadataVersion(dataVersion);
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    boolean status = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus(metadataSyncSummary, mockRetryContext, dataVersion);
    assertFalse(status);
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 12 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class MetadataSyncPostProcessorTest method testShouldSendSuccessEmailIfSyncSummaryIsError.

@Test
public void testShouldSendSuccessEmailIfSyncSummaryIsError() throws Exception {
    metadataSyncSummary.setImportReport(new ImportReport());
    metadataSyncSummary.getImportReport().setStatus(Status.ERROR);
    metadataSyncSummary.setMetadataVersion(dataVersion);
    MetadataRetryContext mockMetadataRetryContext = mock(MetadataRetryContext.class);
    RetryContext mockRetryContext = mock(RetryContext.class);
    when(mockMetadataRetryContext.getRetryContext()).thenReturn(mockRetryContext);
    boolean status = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus(metadataSyncSummary, mockMetadataRetryContext, dataVersion);
    assertTrue(status);
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) RetryContext(org.springframework.retry.RetryContext) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 13 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class MetadataRetryContextTest method testIfSummaryIsNotNull.

@Test
public void testIfSummaryIsNotNull() throws Exception {
    MetadataSyncSummary testSummary = new MetadataSyncSummary();
    ImportReport importReport = new ImportReport();
    importReport.setStatus(Status.ERROR);
    testSummary.setImportReport(importReport);
    metadataRetryContext.updateRetryContext(testKey, testMessage, mockVersion, testSummary);
    verify(retryContext).setAttribute(testKey, testMessage);
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 14 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class MetadataSyncImportHandlerTest method testShouldImportMetadata.

@Test
public void testShouldImportMetadata() {
    syncParams.setImportParams(new MetadataImportParams());
    syncParams.setVersion(metadataVersion);
    MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
    importReport.setStatus(Status.OK);
    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) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 15 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class MetadataImportController method postJsonMetadata.

@RequestMapping(value = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public void postJsonMetadata(HttpServletRequest request, HttpServletResponse response) throws IOException {
    MetadataImportParams params = metadataImportService.getParamsFromMap(contextService.getParameterValuesMap());
    params.setObjects(renderService.fromMetadata(StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream()), RenderFormat.JSON));
    if (params.hasTaskId()) {
        startAsync(params);
        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
    } else {
        ImportReport importReport = metadataImportService.importMetadata(params);
        renderService.toJson(response.getOutputStream(), importReport);
    }
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)28 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)15 Test (org.junit.Test)14 DhisSpringTest (org.hisp.dhis.DhisSpringTest)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 User (org.hisp.dhis.user.User)8 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 List (java.util.List)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext)4 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)4 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)4 IntegrationTest (org.hisp.dhis.IntegrationTest)3 ObjectReport (org.hisp.dhis.feedback.ObjectReport)3 TypeReport (org.hisp.dhis.feedback.TypeReport)3 IOException (java.io.IOException)2 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 Metadata (org.hisp.dhis.dxf2.metadata.Metadata)2