Search in sources :

Example 6 with MetadataSyncServiceException

use of org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException in project dhis2-core by dhis2.

the class MetadataSyncPreProcessorTest method testHandleMetadataVersionsListShouldThrowExceptionIfAnyIssueWithMetadataDifference.

@Test(expected = MetadataSyncServiceException.class)
public void testHandleMetadataVersionsListShouldThrowExceptionIfAnyIssueWithMetadataDifference() throws Exception {
    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");
    List<MetadataVersion> listOfVersions = new ArrayList<>();
    listOfVersions.add(currentVersion);
    when(metadataVersionDelegate.getMetaDataDifference(currentVersion)).thenThrow(new MetadataSyncServiceException("test_message"));
    metadataSyncPreProcessor.handleMetadataVersionsList(mockRetryContext, currentVersion);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) ArrayList(java.util.ArrayList) Date(java.util.Date) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 7 with MetadataSyncServiceException

use of org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException 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 8 with MetadataSyncServiceException

use of org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException in project dhis2-core by dhis2.

the class MetadataSyncPreProcessor method handleCurrentMetadataVersion.

public MetadataVersion handleCurrentMetadataVersion(MetadataRetryContext context) {
    log.debug("Getting the current version of the system");
    MetadataVersion metadataVersion = null;
    try {
        metadataVersion = metadataVersionService.getCurrentVersion();
        log.info("Current Metadata Version of the system: " + metadataVersion);
    } catch (MetadataVersionServiceException ex) {
        context.updateRetryContext(MetadataSyncTask.GET_METADATAVERSION, ex.getMessage(), null, null);
        throw new MetadataSyncServiceException(ex.getMessage(), ex);
    }
    return metadataVersion;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)

Example 9 with MetadataSyncServiceException

use of org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException 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;
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) DhisVersionMismatchException(org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException) MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)

Example 10 with MetadataSyncServiceException

use of org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException in project dhis2-core by dhis2.

the class DefaultMetadataSyncService method doMetadataSync.

@Override
public synchronized MetadataSyncSummary doMetadataSync(MetadataSyncParams syncParams) throws MetadataSyncServiceException, DhisVersionMismatchException {
    MetadataVersion version = getMetadataVersion(syncParams);
    setMetadataImportMode(syncParams, version);
    String metadataVersionSnapshot = getMetadataVersionSnapshot(version);
    if (metadataSyncDelegate.shouldStopSync(metadataVersionSnapshot)) {
        throw new DhisVersionMismatchException("Metadata sync failed because your version of DHIS does not match the master version");
    }
    saveMetadataVersionSnapshotLocally(version, metadataVersionSnapshot);
    MetadataSyncSummary metadataSyncSummary = metadataSyncImportHandler.importMetadata(syncParams, metadataVersionSnapshot);
    log.info("Metadata Sync Summary: " + metadataSyncSummary);
    return metadataSyncSummary;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) DhisVersionMismatchException(org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)

Aggregations

MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)13 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)7 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)6 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)5 MetadataSyncParams (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams)4 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 IntegrationTest (org.hisp.dhis.IntegrationTest)3 MetadataSyncSummary (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)3 DhisVersionMismatchException (org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)3 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)2 MetadataSyncImportException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException)2 IOException (java.io.IOException)1 Date (java.util.Date)1 List (java.util.List)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)1 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)1