use of org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException in project dhis2-core by dhis2.
the class DefaultMetadataSyncServiceTest method testShouldStoreMetadataSnapshotInDataStoreAndImport.
@Test
public void testShouldStoreMetadataSnapshotInDataStoreAndImport() throws DhisVersionMismatchException {
MetadataSyncParams syncParams = Mockito.mock(MetadataSyncParams.class);
MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.ATOMIC);
MetadataImportParams metadataImportParams = new MetadataImportParams();
MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
metadataSyncSummary.setMetadataVersion(metadataVersion);
String expectedMetadataSnapshot = "{\"date\":\"2016-05-24T05:27:25.128+0000\"}";
when(syncParams.getVersion()).thenReturn(metadataVersion);
when(syncParams.getImportParams()).thenReturn(metadataImportParams);
when(metadataVersionService.getVersionData("testVersion")).thenReturn(null);
when(metadataVersionDelegate.downloadMetadataVersionSnapshot(metadataVersion)).thenReturn(expectedMetadataSnapshot);
when(metadataVersionService.isMetadataPassingIntegrity(metadataVersion, expectedMetadataSnapshot)).thenReturn(true);
when(metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot)).thenReturn(metadataSyncSummary);
MetadataSyncSummary actualSummary = metadataSyncService.doMetadataSync(syncParams);
verify(metadataVersionService, times(1)).createMetadataVersionInDataStore(metadataVersion.getName(), expectedMetadataSnapshot);
assertEquals(null, actualSummary.getImportReport());
assertEquals(null, actualSummary.getImportSummary());
assertEquals(metadataVersion, actualSummary.getMetadataVersion());
}
use of org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException 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.DhisVersionMismatchException 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