use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.
the class MetadataSyncPostProcessor method handleSyncNotificationsAndAbortStatus.
public boolean handleSyncNotificationsAndAbortStatus(MetadataSyncSummary metadataSyncSummary, MetadataRetryContext retryContext, MetadataVersion dataVersion) {
ImportReport importReport = metadataSyncSummary.getImportReport();
if (importReport == null) {
handleImportFailedContext(null, retryContext, dataVersion);
return true;
}
Status syncStatus = importReport.getStatus();
log.info("Import completed. Import Status: " + syncStatus);
if (Status.OK.equals(syncStatus) || (Status.WARNING.equals(syncStatus) && VersionType.BEST_EFFORT.equals(dataVersion.getType()))) {
sendSuccessMailToAdmin(metadataSyncSummary);
return false;
}
if (Status.ERROR.equals(syncStatus)) {
handleImportFailedContext(metadataSyncSummary, retryContext, dataVersion);
return true;
}
return false;
}
use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.
the class MetadataSyncJobParametersTest method testHandleMetadataSyncIsThrowingException.
@Test
void testHandleMetadataSyncIsThrowingException() throws DhisVersionMismatchException {
when(metadataSyncService.doMetadataSync(any(MetadataSyncParams.class))).thenThrow(new MetadataSyncServiceException(""));
when(metadataSyncPreProcessor.handleCurrentMetadataVersion(metadataRetryContext)).thenReturn(metadataVersion);
when(metadataSyncPreProcessor.handleMetadataVersionsList(metadataRetryContext, metadataVersion)).thenReturn(metadataVersions);
doNothing().when(metadataRetryContext).updateRetryContext(any(String.class), any(String.class), eq(metadataVersion));
when(metadataSyncService.isSyncRequired(any(MetadataSyncParams.class))).thenReturn(true);
assertThrows(MetadataSyncServiceException.class, () -> metadataSyncJob.runSyncTask(metadataRetryContext, metadataSyncJobParameters));
verify(metadataSyncPreProcessor).setUp(metadataRetryContext);
verify(metadataSyncPreProcessor).handleDataValuePush(metadataRetryContext, metadataSyncJobParameters);
verify(metadataSyncPreProcessor).handleEventProgramsDataPush(metadataRetryContext, metadataSyncJobParameters);
verify(metadataSyncPreProcessor).handleTrackerProgramsDataPush(metadataRetryContext, metadataSyncJobParameters);
verify(metadataSyncPreProcessor).handleCurrentMetadataVersion(metadataRetryContext);
verify(metadataSyncPreProcessor).handleMetadataVersionsList(metadataRetryContext, metadataVersion);
verify(metadataSyncService).doMetadataSync(any(MetadataSyncParams.class));
verify(metadataSyncPostProcessor, never()).handleSyncNotificationsAndAbortStatus(metadataSyncSummary, metadataRetryContext, metadataVersion);
}
use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.
the class MetadataSyncPostProcessorTest method testShouldSendSuccessEmailIfSyncSummaryIsOk.
@Test
void testShouldSendSuccessEmailIfSyncSummaryIsOk() {
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.jobs.MetadataRetryContext in project dhis2-core by dhis2.
the class MetadataSyncPostProcessorTest method testShouldSendEmailToAdminWithProperSubjectAndBody.
@Test
void testShouldSendEmailToAdminWithProperSubjectAndBody() {
ImportReport importReport = mock(ImportReport.class);
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.jobs.MetadataRetryContext in project dhis2-core by dhis2.
the class MetadataSyncPreProcessorTest method testHandleMetadataVersionsListShouldReturnNullIfInstanceDoesNotHaveAnyVersions.
@Test
void testHandleMetadataVersionsListShouldReturnNullIfInstanceDoesNotHaveAnyVersions() {
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<>());
List<MetadataVersion> expectedListOfVersions = metadataSyncPreProcessor.handleMetadataVersionsList(mockRetryContext, currentVersion);
assertEquals(0, expectedListOfVersions.size());
}
Aggregations