Search in sources :

Example 21 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncPreProcessor method handleEventImportSummary.

private void handleEventImportSummary(ImportSummaries importSummary, MetadataRetryContext context) {
    if (importSummary != null) {
        boolean isImportError = false;
        StringBuilder summaryDescription = new StringBuilder();
        for (ImportSummary summary : importSummary.getImportSummaries()) {
            if (ImportStatus.ERROR.equals(summary.getStatus())) {
                isImportError = true;
                summaryDescription.append(summary.getDescription());
                summaryDescription.append("\n");
            }
        }
        if (isImportError) {
            log.error("Import Summary description: " + summaryDescription.toString());
            context.updateRetryContext(MetadataSyncTask.EVENT_PUSH_SUMMARY, summaryDescription.toString(), null, null);
            throw new MetadataSyncServiceException("The Event Data Push was not successful. ");
        }
    }
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary)

Example 22 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncPostProcessorTest method testShouldSendSuccessEmailIfSyncSummaryIsOk.

@Test
public void testShouldSendSuccessEmailIfSyncSummaryIsOk() throws Exception {
    metadataSyncSummary.setImportReport(new ImportReport());
    metadataSyncSummary.getImportReport().setStatus(Status.OK);
    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 23 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncPostProcessorTest method testShouldSendEmailToAdminWithProperSubjectAndBody.

@Test
public void testShouldSendEmailToAdminWithProperSubjectAndBody() throws Exception {
    ImportReport importReport = mock(ImportReport.class);
    when(importReport.getTypeReportMap()).thenReturn(new HashMap<>());
    metadataSyncSummary.setImportReport(importReport);
    metadataSyncSummary.getImportReport().setStatus(Status.OK);
    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 24 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncPreProcessorTest method testHandleMetadataVersionsListShouldReturnNullIfInstanceDoesNotHaveAnyVersions.

@Test
public void testHandleMetadataVersionsListShouldReturnNullIfInstanceDoesNotHaveAnyVersions() throws Exception {
    AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    MetadataVersion currentVersion = new MetadataVersion();
    currentVersion.setType(VersionType.BEST_EFFORT);
    currentVersion.setName("test_version");
    currentVersion.setCreated(new Date());
    currentVersion.setHashCode("samplehashcode");
    when(metadataVersionDelegate.getMetaDataDifference(currentVersion)).thenReturn(new ArrayList<MetadataVersion>());
    List<MetadataVersion> expectedListOfVersions = metadataSyncPreProcessor.handleMetadataVersionsList(mockRetryContext, currentVersion);
    assertTrue(expectedListOfVersions.size() == 0);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) Date(java.util.Date) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 25 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncPreProcessorTest method testhandleAggregateDataPushShouldNotThrowExceptionWhenDataPushIsSuccessful.

@Test
public void testhandleAggregateDataPushShouldNotThrowExceptionWhenDataPushIsSuccessful() throws Exception {
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    ImportSummary expectedSummary = new ImportSummary();
    expectedSummary.setStatus(ImportStatus.SUCCESS);
    AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
    when(metadataSyncPreProcessor.handleAggregateDataPush(mockRetryContext)).thenReturn(expectedSummary);
    ImportSummary actualSummary = metadataSyncPreProcessor.handleAggregateDataPush(mockRetryContext);
    assertEquals(expectedSummary.getStatus(), actualSummary.getStatus());
}
Also used : AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

DhisSpringTest (org.hisp.dhis.DhisSpringTest)18 Test (org.junit.Test)18 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext)16 IntegrationTest (org.hisp.dhis.IntegrationTest)14 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)11 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)9 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)9 Date (java.util.Date)6 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)6 ArrayList (java.util.ArrayList)5 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)5 MetadataSyncParams (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams)4 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)4 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)3 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)2 MetadataSyncSummary (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)2 DhisVersionMismatchException (org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)2 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)1 Status (org.hisp.dhis.feedback.Status)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1