use of org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext in project dhis2-core by dhis2.
the class MetadataSyncPreProcessor method handleAggregateImportSummary.
//----------------------------------------------------------------------------------------
// Private Methods
//----------------------------------------------------------------------------------------
private void handleAggregateImportSummary(ImportSummary importSummary, MetadataRetryContext context) {
if (importSummary != null) {
ImportStatus status = importSummary.getStatus();
if (ImportStatus.ERROR.equals(status) || ImportStatus.WARNING.equals(status)) {
log.error("Import Summary description: " + importSummary.getDescription());
context.updateRetryContext(MetadataSyncTask.DATA_PUSH_SUMMARY, importSummary.getDescription(), null, null);
throw new MetadataSyncServiceException("The Data Push was not successful. ");
}
}
}
use of org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext in project dhis2-core by dhis2.
the class MetadataSyncTask method runSyncTask.
public synchronized void runSyncTask(MetadataRetryContext context) throws MetadataSyncServiceException, DhisVersionMismatchException {
metadataSyncPreProcessor.setUp(context);
metadataSyncPreProcessor.handleAggregateDataPush(context);
metadataSyncPreProcessor.handleEventDataPush(context);
MetadataVersion metadataVersion = metadataSyncPreProcessor.handleCurrentMetadataVersion(context);
List<MetadataVersion> metadataVersionList = metadataSyncPreProcessor.handleMetadataVersionsList(context, metadataVersion);
if (metadataVersionList != null) {
for (MetadataVersion dataVersion : metadataVersionList) {
MetadataSyncParams syncParams = new MetadataSyncParams(new MetadataImportParams(), dataVersion);
boolean isSyncRequired = metadataSyncService.isSyncRequired(syncParams);
MetadataSyncSummary metadataSyncSummary = null;
if (isSyncRequired) {
metadataSyncSummary = handleMetadataSync(context, dataVersion);
} else {
metadataSyncPostProcessor.handleVersionAlreadyExists(context, dataVersion);
break;
}
boolean abortStatus = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus(metadataSyncSummary, context, dataVersion);
if (abortStatus) {
break;
}
systemSettingManager.saveSystemSetting(SettingKey.LAST_SUCCESSFUL_METADATA_SYNC, dataVersion.getImportDate());
clearFailedVersionSettings();
}
}
log.info("Metadata sync cron job ended ");
}
use of org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext in project dhis2-core by dhis2.
the class MetadataSyncPreProcessor method handleEventDataPush.
public ImportSummaries handleEventDataPush(MetadataRetryContext context) {
log.debug("Entering event data push");
ImportSummaries importSummary = null;
AvailabilityStatus remoteServerAvailable = synchronizationManager.isRemoteServerAvailable();
if (!remoteServerAvailable.isAvailable()) {
String message = remoteServerAvailable.getMessage();
log.error(message);
context.updateRetryContext(MetadataSyncTask.EVENT_PUSH_SUMMARY, remoteServerAvailable.getMessage(), null, null);
throw new MetadataSyncServiceException(message);
}
try {
importSummary = synchronizationManager.executeEventPush();
handleEventImportSummary(importSummary, context);
} catch (Exception ex) {
log.error("Exception happened while trying to do event data push " + ex.getMessage(), ex);
if (ex instanceof MetadataSyncServiceException) {
throw (MetadataSyncServiceException) ex;
}
context.updateRetryContext(MetadataSyncTask.EVENT_PUSH_SUMMARY, ex.getMessage(), null, null);
throw new MetadataSyncServiceException(ex.getMessage(), ex);
}
log.debug("Exiting event data push");
return importSummary;
}
use of org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext 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);
}
use of org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext 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);
}
Aggregations