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