use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.
the class MetadataSyncPostProcessorTest method testShouldSendSuccessEmailIfSyncSummaryIsWarning.
@Test
void testShouldSendSuccessEmailIfSyncSummaryIsWarning() {
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.jobs.MetadataRetryContext in project dhis2-core by dhis2.
the class MetadataSyncTask method handleMetadataSync.
//----------------------------------------------------------------------------------------
// Private Methods
//----------------------------------------------------------------------------------------
private MetadataSyncSummary handleMetadataSync(MetadataRetryContext context, MetadataVersion dataVersion) throws DhisVersionMismatchException {
MetadataSyncParams syncParams = new MetadataSyncParams(new MetadataImportParams(), dataVersion);
MetadataSyncSummary metadataSyncSummary = null;
try {
metadataSyncSummary = metadataSyncService.doMetadataSync(syncParams);
} catch (MetadataSyncServiceException e) {
log.error("Exception happened while trying to do metadata sync " + e.getMessage(), e);
context.updateRetryContext(METADATA_SYNC, e.getMessage(), dataVersion);
throw e;
} catch (DhisVersionMismatchException e) {
context.updateRetryContext(METADATA_SYNC, e.getMessage(), dataVersion);
throw e;
}
return metadataSyncSummary;
}
use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.
the class MetadataSyncPreProcessor method handleAggregateDataPush.
public ImportSummary handleAggregateDataPush(MetadataRetryContext context) {
log.debug("Entering data push");
ImportSummary importSummary = null;
AvailabilityStatus remoteServerAvailable = synchronizationManager.isRemoteServerAvailable();
if (!(remoteServerAvailable.isAvailable())) {
String message = remoteServerAvailable.getMessage();
log.error(message);
context.updateRetryContext(MetadataSyncTask.DATA_PUSH_SUMMARY, remoteServerAvailable.getMessage(), null, null);
throw new MetadataSyncServiceException(message);
}
try {
importSummary = synchronizationManager.executeDataPush();
handleAggregateImportSummary(importSummary, context);
} catch (Exception ex) {
log.error("Exception happened while trying to do data push " + ex.getMessage(), ex);
if (ex instanceof MetadataSyncServiceException) {
throw (MetadataSyncServiceException) ex;
}
context.updateRetryContext(MetadataSyncTask.DATA_PUSH_SUMMARY, ex.getMessage(), null, null);
throw new MetadataSyncServiceException(ex.getMessage(), ex);
}
log.debug("Exiting data push");
return importSummary;
}
use of org.hisp.dhis.dxf2.metadata.jobs.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.jobs.MetadataRetryContext in project dhis2-core by dhis2.
the class MetadataSyncPreProcessorTest method testHandleEventDataPushShouldThrowExceptionWhenEventDataPushIsUnsuccessful.
@Test(expected = MetadataSyncServiceException.class)
public void testHandleEventDataPushShouldThrowExceptionWhenEventDataPushIsUnsuccessful() throws Exception {
MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
ImportSummaries expectedSummary = new ImportSummaries();
ImportSummary summary = new ImportSummary();
summary.setStatus(ImportStatus.ERROR);
expectedSummary.addImportSummary(summary);
AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
when(metadataSyncPreProcessor.handleEventDataPush(mockRetryContext)).thenReturn(expectedSummary);
ImportSummaries actualSummary = metadataSyncPreProcessor.handleEventDataPush(mockRetryContext);
assertEquals(expectedSummary.getImportSummaries().get(0).getStatus(), actualSummary.getImportSummaries().get(0).getStatus());
}
Aggregations