Search in sources :

Example 1 with MetadataSyncSummary

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 ");
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)

Example 2 with MetadataSyncSummary

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);
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 3 with MetadataSyncSummary

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);
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 4 with MetadataSyncSummary

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();
}
Also used : MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 5 with MetadataSyncSummary

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()));
    }
}
Also used : Email(org.hisp.dhis.email.Email) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) Stats(org.hisp.dhis.feedback.Stats)

Aggregations

Test (org.junit.jupiter.api.Test)11 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)10 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)9 MetadataSyncSummary (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)9 MetadataSyncParams (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams)7 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)6 DhisSpringTest (org.hisp.dhis.DhisSpringTest)5 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)5 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext)4 DhisVersionMismatchException (org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)4 Test (org.junit.Test)3 MetadataSyncImportException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException)2 IOException (java.io.IOException)1 List (java.util.List)1 IntegrationTest (org.hisp.dhis.IntegrationTest)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 RemoteServerUnavailableException (org.hisp.dhis.dxf2.metadata.sync.exception.RemoteServerUnavailableException)1 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)1 Email (org.hisp.dhis.email.Email)1 Stats (org.hisp.dhis.feedback.Stats)1