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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations