use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary 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.sync.MetadataSyncSummary in project dhis2-core by dhis2.
the class MetadataRetryContextTest method testIfSummaryIsNotNull.
@Test
public void testIfSummaryIsNotNull() throws Exception {
MetadataSyncSummary testSummary = new MetadataSyncSummary();
ImportReport importReport = new ImportReport();
importReport.setStatus(Status.ERROR);
testSummary.setImportReport(importReport);
metadataRetryContext.updateRetryContext(testKey, testMessage, mockVersion, testSummary);
verify(retryContext).setAttribute(testKey, testMessage);
}
use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary in project dhis2-core by dhis2.
the class MetadataSyncTaskTest method testHandleMetadataSyncIsThrowingException.
@Test(expected = MetadataSyncServiceException.class)
public void testHandleMetadataSyncIsThrowingException() throws Exception {
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);
metadataSyncTask.runSyncTask(metadataRetryContext);
verify(metadataSyncPreProcessor).setUp(metadataRetryContext);
verify(metadataSyncPreProcessor).handleAggregateDataPush(metadataRetryContext);
verify(metadataSyncPreProcessor).handleEventDataPush(metadataRetryContext);
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.sync.MetadataSyncSummary in project dhis2-core by dhis2.
the class MetadataRetryContextTest method testIfSummaryIsNull.
@Test
public void testIfSummaryIsNull() throws Exception {
MetadataSyncSummary metadataSyncSummary = mock(MetadataSyncSummary.class);
metadataRetryContext.updateRetryContext(testKey, testMessage, mockVersion, null);
verify(retryContext).setAttribute(testKey, testMessage);
verify(metadataSyncSummary, never()).getImportReport();
}
use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary in project dhis2-core by dhis2.
the class MetadataSyncPostProcessor method sendSuccessMailToAdmin.
public void sendSuccessMailToAdmin(MetadataSyncSummary metadataSyncSummary) {
ImportReport importReport = metadataSyncSummary.getImportReport();
StringBuilder text = new StringBuilder("Successful Import Report for the scheduler run for Metadata synchronization \n\n").append("Imported Version Details \n ").append("Version Name: " + metadataSyncSummary.getMetadataVersion().getName() + "\n").append("Version Type: " + metadataSyncSummary.getMetadataVersion().getType() + "\n");
if (importReport.getTypeReportCount() == 0) {
text.append("New Version created. It does not have any metadata changes. \n");
} else {
text.append("Imported Object Details: \n");
importReport.forEachTypeReport(typeReport -> {
Stats stats = typeReport.getStats();
text.append("Metadata Object Type: ").append(typeReport.getKlass()).append("\n").append("Stats: \n").append("total: " + stats.getTotal() + "\n");
if (stats.getCreated() > 0) {
text.append(" created: " + stats.getCreated() + "\n");
}
if (stats.getUpdated() > 0) {
text.append(" updated: " + stats.getUpdated() + "\n");
}
if (stats.getIgnored() > 0) {
text.append(" ignored: " + stats.getIgnored() + "\n");
}
});
text.append("\n\n");
}
if (text.length() > 0) {
log.info("Success mail will be sent with the following message: " + text);
emailService.sendSystemEmail(new Email("Success Notification: Metadata Synchronization", text.toString()));
}
}
Aggregations