use of org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException 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.exception.DhisVersionMismatchException in project dhis2-core by dhis2.
the class DefaultMetadataSyncServiceTest method testShouldNotStoreMetadataSnapshotInDataStoreWhenAlreadyExistsInLocalStore.
@Test
public void testShouldNotStoreMetadataSnapshotInDataStoreWhenAlreadyExistsInLocalStore() 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(expectedMetadataSnapshot);
when(metadataVersionService.isMetadataPassingIntegrity(metadataVersion, expectedMetadataSnapshot)).thenReturn(true);
when(metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot)).thenReturn(metadataSyncSummary);
MetadataSyncSummary actualSummary = metadataSyncService.doMetadataSync(syncParams);
verify(metadataVersionService, never()).createMetadataVersionInDataStore(metadataVersion.getName(), expectedMetadataSnapshot);
verify(metadataVersionDelegate, never()).downloadMetadataVersionSnapshot(metadataVersion);
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 MetadataSyncController method metadataSync.
@PreAuthorize("hasRole('ALL') or hasRole('F_METADATA_MANAGE')")
@GetMapping
public ResponseEntity<? extends WebMessageResponse> metadataSync(HttpServletRequest request, HttpServletResponse response) throws MetadataSyncException, BadRequestException, MetadataImportConflictException, OperationNotAllowedException {
MetadataSyncParams syncParams;
MetadataSyncSummary metadataSyncSummary = null;
synchronized (metadataSyncService) {
try {
syncParams = metadataSyncService.getParamsFromMap(contextService.getParameterValuesMap());
} catch (RemoteServerUnavailableException exception) {
throw new MetadataSyncException(exception.getMessage(), exception);
} catch (MetadataSyncServiceException serviceException) {
throw new BadRequestException("Error in parsing inputParams " + serviceException.getMessage(), serviceException);
}
try {
boolean isSyncRequired = metadataSyncService.isSyncRequired(syncParams);
if (isSyncRequired) {
metadataSyncSummary = metadataSyncService.doMetadataSync(syncParams);
validateSyncSummaryResponse(metadataSyncSummary);
} else {
throw new MetadataImportConflictException("Version already exists in system and hence not starting the sync.");
}
} catch (MetadataSyncImportException importerException) {
throw new MetadataSyncException("Runtime exception occurred while doing import: " + importerException.getMessage());
} catch (MetadataSyncServiceException serviceException) {
throw new MetadataSyncException("Exception occurred while doing metadata sync: " + serviceException.getMessage());
} catch (DhisVersionMismatchException versionMismatchException) {
throw new OperationNotAllowedException("Exception occurred while doing metadata sync: " + versionMismatchException.getMessage());
}
}
return new ResponseEntity<MetadataSyncSummary>(metadataSyncSummary, HttpStatus.OK);
}
use of org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException in project dhis2-core by dhis2.
the class MetadataSyncTaskTest method testShouldAbortIfDHISVersionMismatch.
@Test(expected = DhisVersionMismatchException.class)
public void testShouldAbortIfDHISVersionMismatch() throws Exception {
metadataVersions.add(metadataVersion);
when(metadataSyncPreProcessor.handleCurrentMetadataVersion(metadataRetryContext)).thenReturn(metadataVersion);
when(metadataSyncPreProcessor.handleMetadataVersionsList(metadataRetryContext, metadataVersion)).thenReturn(metadataVersions);
when(metadataSyncService.doMetadataSync(any(MetadataSyncParams.class))).thenThrow(new DhisVersionMismatchException(""));
when(metadataSyncService.isSyncRequired(any(MetadataSyncParams.class))).thenReturn(true);
metadataSyncTask.runSyncTask(metadataRetryContext);
verify(metadataSyncPreProcessor, times(1)).setUp(metadataRetryContext);
verify(metadataSyncPreProcessor, times(1)).handleAggregateDataPush(metadataRetryContext);
verify(metadataSyncPreProcessor, times(1)).handleEventDataPush(metadataRetryContext);
verify(metadataSyncPreProcessor, times(1)).handleCurrentMetadataVersion(metadataRetryContext);
verify(metadataSyncPreProcessor, times(1)).handleMetadataVersionsList(metadataRetryContext, metadataVersion);
verify(metadataSyncService, times(1)).doMetadataSync(any(MetadataSyncParams.class));
}
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;
}
Aggregations